Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	srt-cloud-data-governance/src/main/resources/bootstrap.yml
#	srt-cloud-data-integrate/src/main/resources/bootstrap.yml
#	srt-cloud-framework/srt-cloud-flink/build/app/flink-app-1.14-2.0.0-jar-with-dependencies.jar
#	srt-cloud-framework/srt-cloud-flink/build/extends/flink-catalog-mysql-1.14-2.0.0.jar
#	srt-cloud-framework/srt-cloud-flink/build/extends/flink-client-1.14-2.0.0.jar
#	srt-cloud-gateway/src/main/resources/bootstrap.yml
#	srt-cloud-module/srt-cloud-datax-service/src/main/resources/bootstrap.yml
#	srt-cloud-module/srt-cloud-datax/src/main/resources/bootstrap.yml
#	srt-cloud-module/srt-cloud-message/src/main/resources/bootstrap.yml
#	srt-cloud-module/srt-cloud-quartz/src/main/resources/bootstrap.yml
#	srt-cloud-system/src/main/resources/bootstrap.yml
#	srt-data-development/src/main/resources/bootstrap.yml
dev
jpz 2023-12-28 22:31:21 +08:00
commit 0f286587b2
119 changed files with 4126 additions and 267 deletions

View File

@ -25,6 +25,7 @@
<module>srt-data-development</module> <module>srt-data-development</module>
<module>srt-cloud-data-governance</module> <module>srt-cloud-data-governance</module>
<module>srt-cloud-data-service</module> <module>srt-cloud-data-service</module>
<module>srt-cloud-data-assets</module>
</modules> </modules>
<properties> <properties>

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.srt</groupId>
<artifactId>srt-cloud</artifactId>
<version>2.0.0</version>
</parent>
<artifactId>srt-cloud-data-assets</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.srt</groupId>
<artifactId>srt-cloud-api</artifactId>
<version>2.0.0</version>
</dependency>
<!--使用log42j-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>net.srt</groupId>
<artifactId>srt-cloud-mybatis</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-springdoc-ui</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
</dependency>
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java-bundle</artifactId>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
</dependency>
</dependencies>
<build>
<!--<finalName>${project.artifactId}</finalName>-->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<!-- 如果不配置 generate-daemons则打包命令为 mvn clean package appassembler:assemble -->
<!-- 如果配置了 generate-daemons打包命令可以是 mvn clean package 也可以是 mvn clean package appassembler:assemble -->
<executions>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- flat与lib共同决定将项目用的的所有jar包复制到lib目录下 -->
<repositoryLayout>flat</repositoryLayout>
<!--从哪里copy配置文件-->
<configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<!--是否copy配置文件-->
<copyConfigurationDirectory>true</copyConfigurationDirectory>
<!--配置文件存放在conf目录路径-->
<configurationDirectory>conf</configurationDirectory>
<!-- 打包的jar以及maven依赖的jar放到这个目录里面 -->
<repositoryName>lib</repositoryName>
<!-- 可执行脚本的目录 -->
<binFolder>bin</binFolder>
<encoding>UTF-8</encoding>
<logsDirectory>logs</logsDirectory>
<daemons>
<daemon>
<id>${project.artifactId}</id>
<mainClass>net.srt.SystemApplication</mainClass>
<platforms>
<platform>jsw</platform>
</platforms>
<generatorConfigurations>
<generatorConfiguration>
<generator>jsw</generator>
<includes>
<include>linux-x86-32</include>
<include>linux-x86-64</include>
<include>windows-x86-32</include>
<include>windows-x86-64</include>
</includes>
<configuration>
<property>
<name>configuration.directory.in.classpath.first</name>
<value>conf</value>
</property>
<property>
<name>wrapper.ping.timeout</name>
<value>120</value>
</property>
<property>
<name>set.default.REPO_DIR</name>
<value>lib</value>
</property>
<property>
<name>wrapper.logfile</name>
<value>logs/wrapper.log</value>
</property>
</configuration>
</generatorConfiguration>
</generatorConfigurations>
<jvmSettings>
<!-- jvm参数 -->
<!--<systemProperties>
<systemProperty>com.sun.management.jmxremote</systemProperty>
<systemProperty>com.sun.management.jmxremote.port=1984</systemProperty>
<systemProperty>com.sun.management.jmxremote.authenticate=false</systemProperty>
<systemProperty>com.sun.management.jmxremote.ssl=false</systemProperty>
</systemProperties>-->
<extraArguments>
<extraArgument>-server</extraArgument>
<extraArgument>-Dfile.encoding=utf-8</extraArgument>
<extraArgument>-Xms128m</extraArgument>
<extraArgument>-Xmx1024m</extraArgument>
<extraArgument>-XX:+PrintGCDetails</extraArgument><!--输出GC的详细日志-->
<extraArgument>-XX:+PrintGCDateStamps</extraArgument><!--输出GC的时间戳-->
<extraArgument>-Xloggc:logs/gc.log</extraArgument><!--日志文件的输出路径-->
</extraArguments>
</jvmSettings>
</daemon>
</daemons>
<programs>
<program>
<mainClass>net.srt.SystemApplication</mainClass>
<id>${project.artifactId}</id>
</program>
</programs>
</configuration>
</plugin>
<!--打包 日常调试打包可以把该组件注释掉不然install的速度比较慢-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${project.parent.basedir}/assembly/assembly-win.xml</descriptor>
<descriptor>${project.parent.basedir}/assembly/assembly-linux.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -9,13 +9,13 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
* @ClassName : ${NAME} * @ClassName : ${NAME}
* @Description : ${description} * @Description : ${description}
* @Author : FJJ * @Author : FJJ
* @Date: 2023-12-22 20:44 * @Date: 2023-12-27 21:47
*/ */
@EnableFeignClients @EnableFeignClients
@EnableDiscoveryClient @EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
public class ServiceApplication { public class AssetsApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args); SpringApplication.run(AssetsApplication.class, args);
} }
} }

View File

@ -0,0 +1,7 @@
auth:
ignore_urls:
- /auth/captcha
- /auth/login
- /auth/send/code
- /auth/mobile
- /upload/**

View File

@ -0,0 +1,46 @@
server:
port: 8098
spring:
mvc:
servlet:
load-on-startup: 1
application:
name: srt-cloud-data-assets
profiles:
active: dev
cloud:
nacos:
discovery:
server-addr: 101.34.77.101:8848
# 命名空间默认public
namespace: 09dff3e2-9790-4d4f-beb6-9baeb01ae040
service: ${spring.application.name}
group: srt2.0
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
namespace: ${spring.cloud.nacos.discovery.namespace}
file-extension: yaml
# 指定配置
extension-configs:
- data-id: datasource.yaml
refresh: true
servlet:
multipart:
max-request-size: 100MB
max-file-size: 1024MB
storage:
enabled: true
config:
# 存储类型local、aliyun
type: local
# 访问域名
domain: http://localhost:8082/sys
# 配置访问前缀
prefix:
local:
# 本地上传路径
path: D://upload
cbx:
isCaptcha: false

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--status用于设置log4j2框架内部的日志信息输出设置成OFF将禁止log4j2内部日志输出毕竟这个日志对我们没有什么作用如果设置成trace你会看到log4j2内部各种详细输出monitorInterval是监控间隔例如下面的设置是指log4j2每隔600秒自动监控该配置文件是否有变化如果有变化则根据文件内容新的配置生成日志-->
<configuration status="OFF" monitorInterval="600">
<Properties>
<property name="LOG_PATH">./logs/</property>
<property name="LOG_FILE">srt-cloud-system</property>
</Properties>
<!--定义添加器-->
<appenders>
<!--Console是输出控制台的标签target可以控制往控制台输出日志的颜色例如SYSTEM_OUT就是蓝色的SYSTEM_ERR就是红色的-->
<Console name="Console" target="SYSTEM_OUT">
<!--控制台只输出level及以上级别的信息onMatch为true代表符合level标准的才输出onMismatch为true代表不符合level标准的就不输出-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<!--这个是输出日志的格式如果对里面的参数不理解可以去看我的这篇文章网址是“https://blog.csdn.net/qq_42449963/article/details/104617356”-->
<!--<PatternLayout pattern=" %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>-->
<PatternLayout
pattern=" %d{yyyy-MM-dd HH:mm:ss.SSS} %highlight{%6p} %style{%5pid}{bright,magenta} --- [%15.15t] %style{%c{20}}{bright,cyan}: %m%n"/>
</Console>
<!--这种存储文件的方式更加合理可以设置多长时间把文件归档一次也可以设置多大文件归档一次如果都把所有的日志存在一个文件里面文件会受不了的解释一下参数信息fileName后面如果后面不跟/例如dev/logs/app.log那就会把日志文件放在project工程下面不是所属的项目下面如果后面跟/,例如/dev/logs/app.log那就会把日志文件直接放在项目所在盘符的根目录下例如项目在E盘存放那就会把日志文件直接放在E盘的根目录下如果后面直接加盘符那就会存在特定的位置例如F:/dev/logs/app.log,那就会直接放在F盘中特定的位置上面都是经过测验的fileName后面的app.log文件相当于是一个缓存文件我们会把日志信息先放在app.log中当达到我们设置的要求之后会把app.log中的日志信息转移到filePattern指定的日志文件中转移的内容就会从app.log日志文件中清除没有转移的内容还存放在app.log中等到下一次符合要求的时候在进行一次转移-->
<!--$${date:yyyy-MM}用在文件上面输出的是目录的名字例如2020-03%d{MM-dd-yyyy}输入的就是月日年例如03-02-2020%i按照轮询输出毕竟一天可能有符合要求的多个日志文件生成所以需要在后面加一个类似于后缀的东西当天的第一个日志文件可能是-1.log.gz第二个文件就是-2.log.gz-->
<RollingFile name="RollingFile" fileName="${LOG_PATH}/${LOG_FILE}.log"
filePattern="${LOG_PATH}/$${date:yyyy-MM}/${LOG_FILE}-%d{yyyy-MM-dd}-%i.log">
<!--%thread:线程名;%-5level:级别从左显示5个字符宽度;%msg:在代码中需要输出的日志消息;%class{36}:估计显示的是完整类名-->
<PatternLayout pattern=" %d{yyyy-MM-dd HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
<!--<SizeBasedTriggeringPolicy size="300MB"/>-->
<Policies>
<!--TimeBasedTriggeringPolicy基于时间的触发策略integer属性和上面<RollingFile>标签中的filePattern的值有关,例如filePattern=”xxx%d{yyyy-MM-dd}xx” interval=”1” 表示将1天一个日志文件filePattern=”xxx%d{yyyy-MM-dd-HH}xxx” interval=”1”表示一个小时一个日志文件,也就是说interval的单位取决于filePattern中的最小时间单位modulate是boolean以0点钟为边界进行偏移计算应该就是假设你中午启动项目晚上0点也是一天了而不是经过24小时才算一天-->
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<!--当app.log文件大小到达100MB的时候就归档一次日志文件也就是把app.log中的那前面100MB文件取出来放到上面<RollingFile >中的filePattern后面的路径中-->
<SizeBasedTriggeringPolicy size="100MB"/>
</Policies>
</RollingFile>
</appenders>
<loggers>
<logger name="net.srt.system.dao" level="DEBUG" additivity="false">
<appender-ref ref="Console"/>
</logger>
<!--level="info"代表只能打印出info及其以上的信息Console是上面Console标签的名字往这一写就可以往控制台上输出内容了RollingFile是上面RollingFile标签的名字往这一写就会往设定的文件中输出内容了当程序运行的时候就会被创建日志输出文件不过里面没有任何日志内容是否往里面输入日志是通过下面的appender-ref标签控制的-->
<root level="info">
<appender-ref ref="Console"/>
<!--一般不使用这个,只是让你知道有这个输出日志文件的方式而已-->
<!--<appender-ref ref="File"/>-->
<appender-ref ref="RollingFile"/>
</root>
</loggers>
</configuration>

View File

@ -18,6 +18,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
public class GovernanceApplication { public class GovernanceApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(GovernanceApplication.class, args); SpringApplication.run(GovernanceApplication.class, args);
System.out.println("原神启动!!!!!!!!!!!!!");
} }
} }

View File

@ -23,7 +23,7 @@ public class MetadataController {
@GetMapping("/list-child") @GetMapping("/list-child")
@Operation(summary = "根据父级id获取信息") @Operation(summary = "根据父级id获取信息")
public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){ public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){
List<TreeNodeVo> treeNodeVos = metadataService.listByParentId(parentId); List<TreeNodeVo> treeNodeVos = metadataService.listByPatenId(parentId);
return Result.ok(treeNodeVos); return Result.ok(treeNodeVos);
} }
@ -44,7 +44,7 @@ public class MetadataController {
@GetMapping("/list-keyword") @GetMapping("/list-keyword")
@Operation(summary = "模糊查询") @Operation(summary = "模糊查询")
public Result<List<TreeNodeVo>> listByKeyword(String keyword){ public Result<List<TreeNodeVo>> listByKeyword(String keyword){
List<TreeNodeVo> treeNodeVos = metadataService.listByKeyword(keyword); List<TreeNodeVo> treeNodeVos = metadataService.listKeyword(keyword);
return Result.ok(treeNodeVos); return Result.ok(treeNodeVos);
} }
@ -78,13 +78,13 @@ public class MetadataController {
@PostMapping("/neo4j") @PostMapping("/neo4j")
@Operation(summary = "更新neo4j的url") @Operation(summary = "更新neo4j的url")
public Result<String> upNeo4jInfo(@RequestBody Neo4jInfo neo4jInfo){ public Result<String> upNeo4jInfo(@RequestBody Neo4jInfo neo4jInfo){
metadataService.upNeo4jInfo(neo4jInfo); metadataService.updateNeo4j(neo4jInfo);
return Result.ok(); return Result.ok();
} }
@GetMapping("/neo4j") @GetMapping("/neo4j")
@Operation(summary = "获取neo4j的url") @Operation(summary = "获取neo4j的url")
public Result<Neo4jInfo> getNeo4jInfo(){ public Result<Neo4jInfo> getNeo4jInfo(){
return Result.ok(metadataService.getNeo4jInfo()); return Result.ok(metadataService.getNeo4j());
} }
} }

View File

@ -2,6 +2,10 @@ package net.srt.controller;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import net.srt.convert.StandardConvert;
import net.srt.entity.DatastandardEntity;
import net.srt.entity.StandardEntity;
import net.srt.framework.common.utils.BeanUtil;
import net.srt.framework.common.utils.Result; import net.srt.framework.common.utils.Result;
import net.srt.framework.common.utils.TreeNodeVo; import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.service.StandardService; import net.srt.service.StandardService;
@ -9,6 +13,8 @@ import net.srt.vo.StandardManagementVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -30,6 +36,13 @@ public class StandardController {
return Result.ok(standardService.listTree()); return Result.ok(standardService.listTree());
} }
@GetMapping("{id}")
@Operation(summary = "信息")
public Result<StandardManagementVo> get(@PathVariable("id") Long id){
StandardEntity entity = standardService.getById(id);
return Result.ok(StandardConvert.INSTANCE.convert(entity));
}
@PostMapping @PostMapping
@Operation(summary = "保存") @Operation(summary = "保存")
@ -45,9 +58,9 @@ public class StandardController {
return Result.ok(); return Result.ok();
} }
@DeleteMapping @DeleteMapping("/{id}")
@Operation(summary = "删除") @Operation(summary = "删除")
public Result<String> delete(Long id) { public Result<String> delete(@PathVariable Long id) {
standardService.delete(id); standardService.delete(id);
return Result.ok(); return Result.ok();
} }

View File

@ -12,5 +12,4 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface StandardDao extends BaseMapper<StandardEntity> { public interface StandardDao extends BaseMapper<StandardEntity> {
} }

View File

@ -0,0 +1,34 @@
package net.srt.init;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.srt.service.MetadataCollectRecordService;
import net.srt.service.QualityTaskService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class BusinessInitializer implements ApplicationRunner {
private final MetadataCollectRecordService metadataCollectRecordService;
private final QualityTaskService qualityTaskService;
@Override
public void run(ApplicationArguments args) {
initScheduleMonitor();
}
/**
* init task monitor
*/
private void initScheduleMonitor() {
// //处理没执行完的采集任务
// metadataCollectRecordService.dealNotFinished();
// //处理没执行完的质量检测任务
// qualityTaskService.dealNotFinished();
}
}

View File

@ -8,25 +8,31 @@ import net.srt.vo.MetadataVO;
import java.util.List; import java.util.List;
/**
* @BelongsProject: srt_cloud
* @BelongsPackage: net.srt.service
* @Author: jpz
* @CreateTime: 2023/12/24 14:35
*/
public interface MetadataService extends BaseService<MetadataEntity> { public interface MetadataService extends BaseService<MetadataEntity> {
List<TreeNodeVo> listByParentId(Long parentId); List<TreeNodeVo> listByPatenId(Long parentId);
List<TreeNodeVo> listFloder(); List<TreeNodeVo> listFloder();
List<TreeNodeVo> listDb(); List<TreeNodeVo> listDb();
List<TreeNodeVo> listByKeyword(String keyword); List<TreeNodeVo> listKeyword(String keyword);
MetadataVO get(Long id); MetadataVO get(Long id);
void save(MetadataVO vo); void save(MetadataVO vo);
void update(MetadataVO vo); void update(MetadataVO vo);
void delete(Long id); void delete(Long id);
void upNeo4jInfo(Neo4jInfo neo4jInfo); void updateNeo4j(Neo4jInfo neo4jInfo);
Neo4jInfo getNeo4jInfo(); Neo4jInfo getNeo4j();
} }

View File

@ -38,7 +38,7 @@ public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEn
private final TokenStoreCache tokenStoreCache; private final TokenStoreCache tokenStoreCache;
@Override @Override
public List<TreeNodeVo> listByParentId(Long parentId) { public List<TreeNodeVo> listByPatenId(Long parentId) {
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MetadataEntity::getParentId,parentId) wrapper.eq(MetadataEntity::getParentId,parentId)
.orderByAsc(MetadataEntity::getOrderNo); .orderByAsc(MetadataEntity::getOrderNo);
@ -93,9 +93,9 @@ public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEn
} }
@Override @Override
public List<TreeNodeVo> listByKeyword(String keyword) { public List<TreeNodeVo> listKeyword(String keyword) {
if(StringUtil.isBlank(keyword)){ if(StringUtil.isBlank(keyword)){
return listByParentId(0L); return listByPatenId(0L);
} }
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.like(MetadataEntity::getName,keyword) wrapper.like(MetadataEntity::getName,keyword)
@ -171,12 +171,12 @@ public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEn
} }
@Override @Override
public void upNeo4jInfo(Neo4jInfo neo4jInfo) { public void updateNeo4j(Neo4jInfo neo4jInfo) {
tokenStoreCache.saveNeo4jInfo(getProjectId(),neo4jInfo); tokenStoreCache.saveNeo4jInfo(getProjectId(),neo4jInfo);
} }
@Override @Override
public Neo4jInfo getNeo4jInfo() { public Neo4jInfo getNeo4j() {
return tokenStoreCache.getNeo4jInfo(getProjectId()); return tokenStoreCache.getNeo4jInfo(getProjectId());
} }

View File

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sun.org.apache.bcel.internal.generic.LADD;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.srt.api.module.data.governance.constant.BuiltInQualityRule; import net.srt.api.module.data.governance.constant.BuiltInQualityRule;
import net.srt.api.module.data.governance.dto.quality.QualityConfigParam; import net.srt.api.module.data.governance.dto.quality.QualityConfigParam;
@ -20,7 +19,6 @@ import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
import net.srt.query.QualityConfigQuery; import net.srt.query.QualityConfigQuery;
import net.srt.service.QualityConfigService; import net.srt.service.QualityConfigService;
import net.srt.vo.QualityConfigVo; import net.srt.vo.QualityConfigVo;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import srt.cloud.framework.dbswitch.common.util.StringUtil; import srt.cloud.framework.dbswitch.common.util.StringUtil;
@ -46,28 +44,28 @@ public class QualityConfigServiceimpl extends BaseServiceImpl<QualityConfigDao,
@Override @Override
public QualityConfigVo get(Long id) { public QualityConfigVo get(Long id) {
QualityConfigVo qualityConfigvo= QualityConfigConvert.INSTANCE.convert(baseMapper.selectById(id)); QualityConfigVo QualityConfigVo= QualityConfigConvert.INSTANCE.convert(baseMapper.selectById(id));
List<Integer> metadataIds=qualityConfigvo.getMetadataIds(); List<Integer> metadataIds=QualityConfigVo.getMetadataIds();
LambdaQueryWrapper<MetadataEntity> metadataWrapper= Wrappers.lambdaQuery(); LambdaQueryWrapper<MetadataEntity> metadataWrapper= Wrappers.lambdaQuery();
metadataWrapper.in(MetadataEntity::getId,metadataIds); metadataWrapper.in(MetadataEntity::getId,metadataIds);
List<MetadataEntity> metadataEntities=metadataDao.selectList(metadataWrapper); List<MetadataEntity> metadataEntities=metadataDao.selectList(metadataWrapper);
if (CollectionUtils.isEmpty(metadataEntities)){ if (CollectionUtils.isEmpty(metadataEntities)){
qualityConfigvo.setMetadataStrs("检测字段已删除,请检查数据信息"); QualityConfigVo.setMetadataStrs("检测字段已删除,请检查数据信息");
}else { }else {
qualityConfigvo.setMetadataStrs(metadataEntities.stream().map(MetadataEntity::getPath).collect(Collectors.joining(";"))); QualityConfigVo.setMetadataStrs(metadataEntities.stream().map(MetadataEntity::getPath).collect(Collectors.joining(";")));
} }
if (BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(qualityConfigvo.getRuleId())){ if (BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(QualityConfigVo.getRuleId())){
QualityConfigParam param = qualityConfigvo.getParam(); QualityConfigParam param = QualityConfigVo.getParam();
Integer columnMetaId = param.getColumnMetaId(); Integer columnMetaId = param.getColumnMetaId();
MetadataEntity entity = metadataDao.selectById(columnMetaId); MetadataEntity entity = metadataDao.selectById(columnMetaId);
if (entity!= null){ if (entity!= null){
qualityConfigvo.setRelMetadataStr(entity.getPath()); QualityConfigVo.setRelMetadataStr(entity.getPath());
}else { }else {
qualityConfigvo.setMetadataStrs("关联字段已被删除,请检查元数据信息"); QualityConfigVo.setMetadataStrs("关联字段已被删除,请检查元数据信息");
} }
} }
return qualityConfigvo; return QualityConfigVo;
} }
@Override @Override

View File

@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
import net.srt.controller.StandardController; import net.srt.controller.StandardController;
import net.srt.convert.StandardConvert; import net.srt.convert.StandardConvert;
import net.srt.dao.StandardDao; import net.srt.dao.StandardDao;
import net.srt.entity.MetamodelEntity;
import net.srt.entity.StandardEntity; import net.srt.entity.StandardEntity;
import net.srt.framework.common.exception.ServerException; import net.srt.framework.common.exception.ServerException;
import net.srt.framework.common.utils.BeanUtil; import net.srt.framework.common.utils.BeanUtil;
@ -66,7 +67,7 @@ public class StandardServiceImpl extends BaseServiceImpl<StandardDao, StandardEn
StandardEntity entity = StandardConvert.INSTANCE.convert(vo); StandardEntity entity = StandardConvert.INSTANCE.convert(vo);
entity.setPath(recursionPath(entity, null)); entity.setPath(recursionPath(entity, null));
entity.setProjectId(getProjectId()); entity.setProjectId(getProjectId());
updateById(entity); baseMapper.updateById(entity);
} }
@ -91,6 +92,7 @@ public class StandardServiceImpl extends BaseServiceImpl<StandardDao, StandardEn
if (one != null) { if (one != null) {
throw new ServerException("存在子节点,不允许删除!"); throw new ServerException("存在子节点,不允许删除!");
} }
//删除
removeById(id); removeById(id);
} }

View File

@ -18,6 +18,7 @@ import java.util.Date;
@Data @Data
@Schema(description = "标准管理查询") @Schema(description = "标准管理查询")
public class DatastandardVo implements Serializable { public class DatastandardVo implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@TableId("id") @TableId("id")
private Long id; private Long id;

View File

@ -15,7 +15,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -111,7 +111,7 @@ public class DataDatabaseController {
return Result.ok(schemaTableDataVo); return Result.ok(schemaTableDataVo);
} }
@GetMapping("/list-all") @GetMapping("/list-all/{t}")
@Operation(summary = "获取当前用户所能看到的的数据表") @Operation(summary = "获取当前用户所能看到的的数据表")
public Result<List<DataDatabaseVO>> listAll() { public Result<List<DataDatabaseVO>> listAll() {
List<DataDatabaseVO> list = dataDatabaseService.listAll(); List<DataDatabaseVO> list = dataDatabaseService.listAll();

View File

@ -15,7 +15,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -0,0 +1,15 @@
package net.srt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class DataServiceApplication {
public static void main(String[] args) {
SpringApplication.run(DataServiceApplication.class, args);
}
}

View File

@ -0,0 +1,8 @@
package net.srt.constants;
import lombok.Data;
@Data
public class ApiConstants {
public static final String API_PREFIX = "/api/v1"; // 例如这里定义了一个API的前缀
}

View File

@ -0,0 +1,53 @@
package net.srt.constants;
import net.srt.dao.ApiConfigDao;
import net.srt.entity.ApiConfigEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;
@Controller
@RequestMapping("/api")
public class ApiController {
private boolean isOnline = true;
@GetMapping("/status")
public ResponseEntity<String> getStatus() {
String status = isOnline ? "online" : "offline";
return ResponseEntity.ok("API status: " + status);
}
@GetMapping("/resource/{id}")
public ResponseEntity<String> getResource(@PathVariable Long id) {
if (!isOnline) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
}
// 处理获取资源的逻辑...
String resource = ""; // 假设这里是获取资源的代码
if (resource != null) {
return ResponseEntity.ok("Resource: " + resource);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
}
}
@GetMapping("/offline")
public ResponseEntity<String> offline() {
isOnline = false;
return ResponseEntity.ok("API is now offline");
}
@GetMapping("/online")
public ResponseEntity<String> online() {
isOnline = true;
return ResponseEntity.ok("API is now online");
}
}

View File

@ -0,0 +1,19 @@
package net.srt.constants;
public enum ApiGroupType {
FOLDER(1,"数据库"),
API(2,"数据库");
private final Integer value;
private final String longValue;
ApiGroupType(Integer value, String longValue) {
this.value = value;
this.longValue = longValue;
}
public Integer getValue() {
return value;
}
public String getLongValue() {
return longValue;
}
}

View File

@ -0,0 +1,140 @@
package net.srt.controller;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import net.srt.convert.ApiConfigConvert;
import net.srt.dto.SqlDto;
import net.srt.entity.ApiConfigEntity;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.common.utils.Result;
import net.srt.query.ApiConfigQuery;
import net.srt.service.ApiConfigService;
import net.srt.vo.ApiConfigVo;
import net.srt.vo.DataServiceApiAuthVo;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
@RestController
@RequestMapping("/api-config")
@AllArgsConstructor
public class ApiConfigController {
private final ApiConfigService apiConfigService;
@GetMapping("page")
@Operation(summary = "分页")
@PreAuthorize("hasAuthority('data-service:api-config:page')")
public Result<PageResult<ApiConfigVo>> page(@Valid ApiConfigQuery query) {
PageResult<ApiConfigVo> page = apiConfigService.page(query);
return Result.ok(page);
}
@GetMapping("page-resource")
@Operation(summary = "根据resourceId分页获取")
public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query);
return Result.ok(page);
}
@GetMapping("page-auth")
public Result<PageResult<ApiConfigVo>> pageAuth(@Valid ApiConfigQuery query) {
PageResult<ApiConfigVo> page = apiConfigService.page(query);
return Result.ok(page);
}
//取消授权
// @PutMapping("/auth-info")
// @Operation(summary = "修改授权")
// public Result<String> upAuth(@RequestBody DataServiceApiAuthVo authVO){
// apiConfigService.upAuth(authVO);
// return Result.ok();
// }
@Operation(summary = "回显")
@GetMapping(value = "/auth-info/{authId}")
public Result<DataServiceApiAuthVo> getAuthId(@PathVariable Long authId){
return Result.ok(apiConfigService.getAuthInfo(authId));
}
//重置调用次数
@Operation(summary = "重置调用次数")
@PutMapping("/reset-requested/{authId}")
public Result<String > resetRequested(@PathVariable Long authId){
apiConfigService.resetRequested(authId);
return Result.ok();
}
@GetMapping("{id}")
@Operation(summary = "信息")
@PreAuthorize("hasAnyAuthority('data-service:api-config:info')")
public Result<ApiConfigVo> get(@PathVariable("id") Long id){
ApiConfigEntity entity=apiConfigService.getById(id);
return Result.ok(ApiConfigConvert.INSTANCE.convert(entity));
}
@PostMapping
@Operation(summary = "保存")
@PreAuthorize("hasAnyAuthority('data-service:api-config:save')")
public Result<String> save(@RequestBody ApiConfigVo vo) {
apiConfigService.save(vo);
return Result.ok();
}
@PutMapping
@Operation(summary = "修改")
@PreAuthorize("hasAnyAuthority('data-service:api-config:update')")
public Result<String> update(@RequestBody ApiConfigVo vo){
apiConfigService.update(vo);
return Result.ok();
}
@DeleteMapping
@Operation(summary = "删除")
@PreAuthorize("hasAnyAuthority('data-service:api-config:delete')")
public Result<String> delete(@RequestBody List<Long> idList){
apiConfigService.delete(idList);
return Result.ok();
}
@GetMapping("getIpPort")
public Result<String> getIpPort() {
return Result.ok(apiConfigService.getIpPort());
}
@Operation(summary = "获取服务的ip和端口号")
@GetMapping("/ip-port")
public Result<String> ipPort() {
return Result.ok(apiConfigService.ipPort());
}
@Operation(summary = "上线")
@PreAuthorize("hasAnyAuthority('data-service:api-config:online')")
@PutMapping("/{id}/online")
public Result<String> online(@PathVariable Long id) {
apiConfigService.online(id);
return Result.ok();
}
@Operation(summary = "下线")
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')")
@PutMapping("/{id}/offline")
public Result<String> offline(@PathVariable Long id){
apiConfigService.offline(id);
return Result.ok();
}
@Operation(summary = "执行sql")
@PostMapping("/sql/execute")
public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto dto) {
return Result.ok(apiConfigService.sqlExecute(dto));
}
@Operation(summary = "导出 api 文档")
@PostMapping(value = "/export-docs")
public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) {
apiConfigService.exportDocs(ids, response);
}
}

View File

@ -0,0 +1,69 @@
package net.srt.controller;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import net.srt.convert.ApiGroupConvert;
import net.srt.entity.ApiGroupEntity;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.common.utils.Result;
import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.query.ApiConfigQuery;
import net.srt.service.ApiGroupService;
import net.srt.vo.ApiConfigVo;
import net.srt.vo.ApiGroupVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* -api
*
* @author zrx 985134801@qq.com
* @since 1.0.0 2023-01-28
*/
@RestController
@RequestMapping("/api-group")
@AllArgsConstructor
public class ApiGroupController {
private final ApiGroupService apiGroupService;
@GetMapping
@Operation(summary = "查询文件分组树")
public Result<List<TreeNodeVo>> listTree() {
return Result.ok(apiGroupService.listTree());
}
@GetMapping("{id}")
@Operation(summary = "信息")
@PreAuthorize("hasAuthority('data-service:api-group:info')")
public Result<ApiGroupVo> get(@PathVariable("id") Long id){
ApiGroupEntity entity = apiGroupService.getById(id);
return Result.ok(ApiGroupConvert.INSTANCE.convert(entity));
}
@PostMapping
@Operation(summary = "保存")
@PreAuthorize("hasAuthority('data-service:api-group:save')")
public Result<String> save(@RequestBody ApiGroupVo vo) {
apiGroupService.save(vo);
return Result.ok();
}
@PutMapping
@Operation(summary = "修改")
@PreAuthorize("hasAuthority('data-service:api-group:update')")
public Result<String> update(@RequestBody @Valid ApiGroupVo vo) {
apiGroupService.update(vo);
return Result.ok();
}
@DeleteMapping("/{id}")
@Operation(summary = "删除")
@PreAuthorize("hasAuthority('data-service:api-group:delete')")
public Result<String> delete(@PathVariable Long id) {
apiGroupService.delete(id);
return Result.ok();
}
}

View File

@ -0,0 +1,29 @@
package net.srt.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.srt.dao.DataServiceAppDao;
import net.srt.framework.common.utils.Result;
import net.srt.service.DataServiceAppService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName : DataServiceApiController
* @Description :
* @Author : FJJ
* @Date: 2023-12-26 20:38
*/
@RestController
@RequestMapping("api")
@Tag(name = "api")
@AllArgsConstructor
public class DataServiceApiController {
private final DataServiceAppService dataServiceAppService;
@GetMapping("/token/generate")
public Result<String> tokenGenerate(@RequestParam String appKey, @RequestParam String appSecret) {
return Result.ok(dataServiceAppService.tokenGenerate(appKey, appSecret));
}
}

View File

@ -0,0 +1,43 @@
package net.srt.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.common.utils.Result;
import net.srt.query.DataServiceApiLogQuery;
import net.srt.query.DataServiceAppQuery;
import net.srt.service.DataServiceApiLogService;
import net.srt.vo.DataServiceApiLogVo;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* @ClassName : DataServiceApiLogController
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:29
*/
@RestController
@RequestMapping("log")
@Tag(name = "api请求日志")
@AllArgsConstructor
public class DataServiceApiLogController {
private final DataServiceApiLogService dataServiceApiLogService;
@GetMapping("page")
@Operation(summary = "分页")
public Result<PageResult<DataServiceApiLogVo>> page(@Valid DataServiceApiLogQuery query){
//查询数据
PageResult<DataServiceApiLogVo> page=dataServiceApiLogService.dataPageList(query);
return Result.ok(page);
}
@DeleteMapping
@Operation(summary ="删除")
public Result<String> delete(@RequestBody List<Long> idList){
dataServiceApiLogService.removeId(idList);
return Result.ok();
}
}

View File

@ -8,7 +8,9 @@ import net.srt.framework.common.page.PageResult;
import net.srt.framework.common.utils.Result; import net.srt.framework.common.utils.Result;
import net.srt.query.DataServiceAppQuery; import net.srt.query.DataServiceAppQuery;
import net.srt.service.DataServiceAppService; import net.srt.service.DataServiceAppService;
import net.srt.vo.DataServiceApiAuthVo;
import net.srt.vo.DataServiceAppVo; import net.srt.vo.DataServiceAppVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
@ -32,12 +34,12 @@ public class DataServiceAppController {
PageResult<DataServiceAppVo> pageResult = dataServiceAppService.page(query); PageResult<DataServiceAppVo> pageResult = dataServiceAppService.page(query);
return Result.ok(pageResult); return Result.ok(pageResult);
} }
@GetMapping("{id}") // @GetMapping("{id}")
@Operation(summary = "信息") // @Operation(summary = "信息")
public Result<DataServiceAppVo> get(@PathVariable("id") Long id){ // public Result<DataServiceAppVo> get(@PathVariable("id") Long id){
DataServiceAppEntity dataServiceAppEntity = dataServiceAppService.getById(id); // DataServiceAppEntity dataServiceAppEntity = dataServiceAppService.getById(id);
return Result.ok(DataServiceAppConvert.INSTANCE.convert(dataServiceAppEntity)); // return Result.ok(DataServiceAppConvert.INSTANCE.convert(dataServiceAppEntity));
} // }
@PostMapping @PostMapping
@Operation(summary = "保存") @Operation(summary = "保存")
@ -61,16 +63,19 @@ public class DataServiceAppController {
return Result.ok(); return Result.ok();
} }
@PostMapping("/auth") @PostMapping("/auth")
@Operation(summary = "添加授权") @Operation(summary = "添加授权")
public Result<String> addAuth(@RequestBody DataServiceAppVo authVO){ public Result<String> addAuth(@RequestBody DataServiceApiAuthVo authVO){
dataServiceAppService.addAuth(authVO); dataServiceAppService.addAuth(authVO);
return Result.ok(); return Result.ok();
} }
@PutMapping("/auth") @PutMapping("/auth")
@Operation(summary = "修改授权") @Operation(summary = "修改授权")
public Result<String> upAuth(@RequestBody DataServiceAppVo authVO){ public Result<String> upAuth(@RequestBody DataServiceApiAuthVo authVO){
dataServiceAppService.upAuth(authVO); dataServiceAppService.upAuth(authVO);
return Result.ok(); return Result.ok();
} }
@ -81,4 +86,5 @@ public class DataServiceAppController {
dataServiceAppService.cancelAuth(authId); dataServiceAppService.cancelAuth(authId);
return Result.ok(); return Result.ok();
} }
} }

View File

@ -0,0 +1,30 @@
package net.srt.convert;
import net.srt.dto.ApiConfigDto;
import net.srt.entity.ApiConfigEntity;
import net.srt.vo.ApiConfigVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* -api
*
* @author zrx 985134801@qq.com
* @since 1.0.0 2023-01-28
*/
@Mapper
public interface ApiConfigConvert {
ApiConfigConvert INSTANCE = Mappers.getMapper(ApiConfigConvert.class);
ApiConfigEntity convert(ApiConfigVo vo);
ApiConfigVo convert(ApiConfigEntity entity);
ApiConfigDto convertDto(ApiConfigEntity entity);
List<ApiConfigVo> convertList(List<ApiConfigEntity> list);
}

View File

@ -0,0 +1,26 @@
package net.srt.convert;
import net.srt.entity.ApiGroupEntity;
import net.srt.vo.ApiGroupVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* -api
*
* @author zrx 985134801@qq.com
* @since 1.0.0 2023-01-28
*/
@Mapper
public interface ApiGroupConvert {
ApiGroupConvert INSTANCE = Mappers.getMapper(ApiGroupConvert.class);
ApiGroupEntity convert(ApiGroupVo vo);
ApiGroupVo convert(ApiGroupEntity entity);
List<ApiGroupVo> convertList(List<ApiGroupEntity> list);
}

View File

@ -0,0 +1,26 @@
package net.srt.convert;
import net.srt.entity.DataServiceApiAuthEntity;
import net.srt.vo.DataServiceApiAuthVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @ClassName : DataServiceApiAuthConvert
* @Description :
* @Author : FJJ
* @Date: 2023-12-26 19:45
*/
@Mapper
public interface DataServiceApiAuthConvert {
DataServiceApiAuthConvert INSTANCE = Mappers.getMapper(DataServiceApiAuthConvert.class);
DataServiceApiAuthEntity convert(DataServiceApiAuthVo vo);
DataServiceApiAuthVo convert(DataServiceApiAuthEntity entity);
List<DataServiceApiAuthVo> convertList(List<DataServiceApiAuthEntity> list);
}

View File

@ -0,0 +1,24 @@
package net.srt.convert;
import net.srt.entity.DataServiceApiLogEntity;
import net.srt.vo.DataServiceApiLogVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @ClassName : DataServiceApiLogConvert
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:30
*/
@Mapper
public interface DataServiceApiLogConvert {
DataServiceApiLogConvert INSTANCE = Mappers.getMapper(DataServiceApiLogConvert.class);
DataServiceApiLogEntity convert(DataServiceApiLogVo vo);
DataServiceApiLogVo convert(DataServiceApiLogEntity entity);
List<DataServiceApiLogVo> convertList(List<DataServiceApiLogEntity> list);
}

View File

@ -19,6 +19,7 @@ public interface DataServiceAppConvert {
DataServiceAppEntity convert(DataServiceAppVo vo); DataServiceAppEntity convert(DataServiceAppVo vo);
DataServiceAppVo convert(DataServiceAppEntity entity); DataServiceAppVo convert(DataServiceAppEntity entity);
List<DataServiceAppVo> convertList(List<DataServiceAppEntity> list); List<DataServiceAppVo> convertList(List<DataServiceAppEntity> list);

View File

@ -0,0 +1,22 @@
package net.srt.dao;
import net.srt.entity.ApiConfigEntity;
import net.srt.framework.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface ApiConfigDao extends BaseDao<ApiConfigEntity> {
List<ApiConfigEntity> getResourceList(Map<String, Object> params);
ApiConfigEntity getById(Long id);
void updateById(@Param("apiId") Long apiId, @Param("id") Long id);
List<ApiConfigEntity> getAuthList(Map<String, Object> params);
void updateAuthId(@Param("authId") Long authId);
}

View File

@ -0,0 +1,9 @@
package net.srt.dao;
import net.srt.entity.ApiGroupEntity;
import net.srt.framework.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ApiGroupDao extends BaseDao<ApiGroupEntity> {
}

View File

@ -0,0 +1,18 @@
package net.srt.dao;
import net.srt.entity.DataServiceApiAuthEntity;
import net.srt.framework.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @ClassName : DataServiceApiAuthDao
* @Description :
* @Author : FJJ
* @Date: 2023-12-26 15:23
*/
@Mapper
public interface DataServiceApiAuthDao extends BaseDao<DataServiceApiAuthEntity> {
void resetRequested(Long authId);
}

View File

@ -0,0 +1,15 @@
package net.srt.dao;
import net.srt.entity.DataServiceApiLogEntity;
import net.srt.framework.mybatis.dao.BaseDao;
import org.apache.ibatis.annotations.Mapper;
/**
* @ClassName : DataServiceApiLogDao
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:30
*/
@Mapper
public interface DataServiceApiLogDao extends BaseDao<DataServiceApiLogEntity> {
}

View File

@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.Param;
*/ */
@Mapper @Mapper
public interface DataServiceAppDao extends BaseDao<DataServiceAppEntity> { public interface DataServiceAppDao extends BaseDao<DataServiceAppEntity> {
DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId); // DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId);
} }

View File

@ -0,0 +1,48 @@
package net.srt.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.srt.framework.common.utils.DateUtils;
import java.io.Serializable;
import java.util.Date;
@Data
public class ApiConfigDto implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Long groupId;
private String path;
private String type;
private String name;
private String note;
private String sqlText;
private String sqlSeparator;
private Integer sqlMaxRow;
private String sqlParam;
private String jsonParam;
private String responseResult;
private String contentType;
private Integer status;
private Date releaseTime;
private Long releaseUserId;
private Integer sqlDbType;
private Long databaseId;
private Integer privates;
private Integer openTrans;
private Long projectId;
private Integer version;
private Integer deleted;
private Long creator;
private Date createTime;
private Long updater;
private Date updateTime;
private Integer requestedTimes;
private Integer requestedSuccessTimes;
private Integer requestedFailedTimes;
private Long authId;
private String group;
}

View File

@ -0,0 +1,17 @@
package net.srt.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AppToken implements Serializable {
private Long appId;
private String appKey;
private String token;
private Long expireAt;
}

View File

@ -0,0 +1,15 @@
package net.srt.dto;
import lombok.Data;
@Data
public class SqlDto {
private Integer sqlDbType;
private Long projectId;
private String statement;
private String sqlSeparator;
private Long databaseId;
private Integer openTrans;
private String jsonParams;
private Integer sqlMaxRow;
}

View File

@ -0,0 +1,38 @@
package net.srt.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import net.srt.framework.mybatis.entity.BaseEntity;
import java.util.ArrayList;
import java.util.Date;
@Data
@TableName("data_service_api_config")
public class ApiConfigEntity extends BaseEntity {
private Long groupId;
private String path;
private String type;
private String name;
private String note;
private String sqlText;
private String sqlSeparator;
private Integer sqlMaxRow;
private String sqlParam;
private String jsonParam;
private String responseResult;
private String contentType;
private Integer status;
private Date releaseTime;
private Long releaseUserId;
private Integer sqlDbType;
private Long databaseId;
private Integer privates;
private Integer openTrans;
private Long projectId;
private Integer requestedTimes;
private Integer requestedSuccessTimes;
private Integer requestedFailedTimes;
private Long authId;
private String groupPath;
}

View File

@ -0,0 +1,17 @@
package net.srt.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import net.srt.framework.mybatis.entity.BaseEntity;
@Data
@TableName("data_service_api_group")
public class ApiGroupEntity extends BaseEntity {
private Long parentId;
private Integer type;
private String name;
private String description;
private Integer orderNo;
private String path;
private Long projectId;
}

View File

@ -1,70 +0,0 @@
//package net.srt.entity;
//
//import com.baomidou.mybatisplus.annotation.FieldFill;
//import com.baomidou.mybatisplus.annotation.FieldStrategy;
//import com.baomidou.mybatisplus.annotation.TableField;
//import com.baomidou.mybatisplus.annotation.TableName;
//import lombok.Data;
//import lombok.EqualsAndHashCode;
//import net.srt.framework.mybatis.entity.BaseEntity;
//
//import java.util.Date;
//
///**
// * @ClassName : DataServiceApiAuthEnitiy
// * @Description :
// * @Author : FJJ
// * @Date: 2023-12-24 11:30
// */
//@EqualsAndHashCode(callSuper=false)
//@Data
//@TableName("data_service_api_auth1")
//public class DataServiceApiAuthEnitiy extends BaseEntity {
//
// /**
// * app的id
// */
// private Long appId;
//
// /**
// * 分组id
// */
// private Long groupId;
//
// /**
// * api的id
// */
// private Long apiId;
//
// /**
// * 调用次数 不限次数为-1
// */
// private Integer requestTimes;
//
// @TableField(updateStrategy = FieldStrategy.IGNORED)
// private Date startTime;
// @TableField(updateStrategy = FieldStrategy.IGNORED)
// private Date endTime;
//
// /**
// * 已调用次数
// */
// @TableField(updateStrategy = FieldStrategy.NEVER)
// private Integer requestedTimes;
// @TableField(updateStrategy = FieldStrategy.NEVER)
// private Integer requestedSuccessTimes;
// @TableField(updateStrategy = FieldStrategy.NEVER)
// private Integer requestedFailedTimes;
//
// /**
// * 所属项目id
// */
// private Long projectId;
//
// /**
// * 真删
// */
// @TableField(fill = FieldFill.INSERT)
// private Integer deleted;
//
//}

View File

@ -0,0 +1,68 @@
package net.srt.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.srt.framework.mybatis.entity.BaseEntity;
import java.util.Date;
/**
* @ClassName : DataServiceApiAuthEntity
* @Description :
* @Author : FJJ
* @Date: 2023-12-26 15:20
*/
@EqualsAndHashCode(callSuper = false)
@Data
@TableName("data_service_api_auth")
public class DataServiceApiAuthEntity extends BaseEntity {
/**
* appid
*/
private Long appId;
/**
* id
*/
private Long groupId;
/**
* apiid
*/
private Long apiId;
/**
* -1
*/
private Integer requestTimes;
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Date startTime;
@TableField(updateStrategy = FieldStrategy.IGNORED)
private Date endTime;
/**
*
*/
@TableField(updateStrategy = FieldStrategy.NEVER)
private Integer requestedTimes;
@TableField(updateStrategy = FieldStrategy.NEVER)
private Integer requestedSuccessTimes;
@TableField(updateStrategy = FieldStrategy.NEVER)
private Integer requestedFailedTimes;
/**
* id
*/
private Long projectId;
/**
*
*/
@TableField(fill = FieldFill.INSERT)
private Integer deleted;
}

View File

@ -0,0 +1,61 @@
package net.srt.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.srt.framework.mybatis.entity.BaseEntity;
/**
* @ClassName : DataServiceApiLogEntity
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:11
*/
@EqualsAndHashCode(callSuper = false)
@Data
@TableName("data_service_api_log")
public class DataServiceApiLogEntity extends BaseEntity {
/**
* url
*/
private String url;
/**
*
*/
private Integer status;
/**
*
*/
private Long duration;
/**
* IP
*/
private String ip;
/**
* appid
*/
private Long appId;
/**
* apiid
*/
private Long apiId;
private String appName;
private String apiName;
/**
*
*/
private String error;
/**
* id
*/
private Long projectId;
}

View File

@ -0,0 +1,27 @@
package net.srt.handler;
// 导入必要的类
import net.srt.constants.ApiConstants;
import net.srt.entity.ApiConfigEntity;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import java.util.HashMap;
import java.util.Map;
// 假设这是你的接口处理类
public class ApiHandler {
private Map<RequestMappingInfo, ApiConfigEntity> mappings = new HashMap<>();
public void registerApi(ApiConfigEntity api) {
RequestMappingInfo mappingInfo = RequestMappingInfo
.paths(ApiConstants.API_PREFIX + api.getPath()) // 使用API_PREFIX常量
.methods(RequestMethod.valueOf(api.getType()))
.build();
mappings.put(mappingInfo, api);
}
}

View File

@ -0,0 +1,21 @@
package net.srt.handler;
import net.srt.constants.ApiConstants;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
public class ApiRegistration {
private RequestMappingHandlerMapping handlerMapping; // 注入或实例化 RequestMappingHandlerMapping 对象
public void registerApi(String path, String method, Object handler, String handlerMethod) throws NoSuchMethodException {
RequestMappingInfo mappingInfo = RequestMappingInfo
.paths(ApiConstants.API_PREFIX + path)
.methods(RequestMethod.valueOf(method))
.build();
HandlerMethod handlerMethodObject = new HandlerMethod(handler, handlerMethod);
handlerMapping.registerMapping(mappingInfo, handlerMethodObject.getBean(), handlerMethodObject.getMethod());
}
}

View File

@ -0,0 +1,9 @@
package net.srt.handler;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
public interface MappingRequestHandler {
Object invoke(HttpServletRequest request, String apiToken, Map<String, Object> pathVariables,
Map<String, Object> requestParams, Map<String, Object> requestBodys);
}

View File

@ -0,0 +1,25 @@
package net.srt.handler;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Map;
public class MappingRequestHandlerExample {
private final MappingRequestHandler handler;
private Method method;
public MappingRequestHandlerExample(MappingRequestHandler handler) {
this.handler = handler;
try {
method = MappingRequestHandler.class.getDeclaredMethod(
"invoke", HttpServletRequest.class, String.class, Map.class, Map.class, Map.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public void getHandlerAndMethod() {
System.out.println("Handler: " + handler);
System.out.println("Method: " + method);
}
}

View File

@ -0,0 +1,21 @@
package net.srt.query;
import lombok.Data;
import net.srt.framework.common.query.Query;
@Data
public class ApiConfigQuery extends Query {
private Long groupId;
private Long resourceId;
private Long appId;
private String name;
private String path;
private String contentType;
private Integer status;
private Integer sqlDbType;
private Long databaseId;
private Integer privates;
private Integer openTrans;
private Integer queryApply;
private Integer ifMarket;
}

View File

@ -0,0 +1,20 @@
package net.srt.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.srt.framework.common.query.Query;
/**
* @ClassName : DataServiceApiLogQuery
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:27
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(description = "api日志")
public class DataServiceApiLogQuery extends Query {
private String ip;
private String apiName;
}

View File

@ -0,0 +1,47 @@
package net.srt.service;
import cn.hutool.http.server.HttpServerResponse;
import net.srt.dto.SqlDto;
import net.srt.entity.ApiConfigEntity;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.mybatis.service.BaseService;
import net.srt.query.ApiConfigQuery;
import net.srt.vo.ApiConfigVo;
import net.srt.vo.DataServiceApiAuthVo;
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface ApiConfigService extends BaseService<ApiConfigEntity> {
String getIpPort();
PageResult<ApiConfigVo> page(ApiConfigQuery query);
void save(ApiConfigVo vo);
void update(ApiConfigVo vo);
void delete(List<Long> idList);
PageResult<ApiConfigVo> pageResource(ApiConfigQuery query);
List<ApiConfigEntity> listActiveByGroupId(Long id);
void online(Long id);
void offline(Long id);
String ipPort();
JdbcSelectResult sqlExecute(SqlDto dto);
void exportDocs(List<Long> ids, HttpServletResponse response);
void upAuth(DataServiceApiAuthVo authVO);
DataServiceApiAuthVo getAuthInfo(Long authId);
void resetRequested(Long authId);
}

View File

@ -0,0 +1,18 @@
package net.srt.service;
import net.srt.entity.ApiGroupEntity;
import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.framework.mybatis.service.BaseService;
import net.srt.vo.ApiGroupVo;
import java.util.List;
public interface ApiGroupService extends BaseService<ApiGroupEntity> {
List<TreeNodeVo> listTree();
void save(ApiGroupVo vo);
void update(ApiGroupVo vo);
void delete(Long id);
}

View File

@ -0,0 +1,10 @@
package net.srt.service;
/**
* @ClassName : DataServiceApiAuthService
* @Description :
* @Author : FJJ
* @Date: 2023-12-26 15:23
*/
public interface DataServiceApiAuthService {
}

View File

@ -0,0 +1,21 @@
package net.srt.service;
import net.srt.entity.DataServiceApiLogEntity;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.mybatis.service.BaseService;
import net.srt.query.DataServiceApiLogQuery;
import net.srt.vo.DataServiceApiLogVo;
import java.util.List;
/**
* @ClassName : DataServiceApiLogService
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:31
*/
public interface DataServiceApiLogService extends BaseService<DataServiceApiLogEntity> {
PageResult<DataServiceApiLogVo> dataPageList(DataServiceApiLogQuery query);
void removeId(List<Long> idList);
}

View File

@ -4,6 +4,7 @@ import net.srt.entity.DataServiceAppEntity;
import net.srt.framework.common.page.PageResult; import net.srt.framework.common.page.PageResult;
import net.srt.framework.mybatis.service.BaseService; import net.srt.framework.mybatis.service.BaseService;
import net.srt.query.DataServiceAppQuery; import net.srt.query.DataServiceAppQuery;
import net.srt.vo.DataServiceApiAuthVo;
import net.srt.vo.DataServiceAppVo; import net.srt.vo.DataServiceAppVo;
import java.util.List; import java.util.List;
@ -23,9 +24,11 @@ public interface DataServiceAppService extends BaseService<DataServiceAppEntity>
void delete(List<Long> idList); void delete(List<Long> idList);
void addAuth(DataServiceAppVo authVO); void addAuth(DataServiceApiAuthVo authVO);
void upAuth(DataServiceAppVo authVO); void upAuth(DataServiceApiAuthVo authVO);
void cancelAuth(Long authId); void cancelAuth(Long authId);
String tokenGenerate(String appKey, String appSecret);
} }

View File

@ -0,0 +1,287 @@
package net.srt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import net.srt.api.ServerNames;
import net.srt.convert.ApiConfigConvert;
import net.srt.convert.DataServiceApiAuthConvert;
import net.srt.dao.ApiConfigDao;
import net.srt.dao.ApiGroupDao;
import net.srt.dao.DataServiceApiAuthDao;
import net.srt.dto.SqlDto;
import net.srt.entity.ApiConfigEntity;
import net.srt.entity.ApiGroupEntity;
import net.srt.entity.DataServiceApiAuthEntity;
import net.srt.framework.common.constant.Constant;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
import net.srt.framework.security.user.SecurityUser;
import net.srt.query.ApiConfigQuery;
import net.srt.service.ApiConfigService;
import net.srt.vo.ApiConfigVo;
import net.srt.vo.DataServiceApiAuthVo;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import srt.cloud.framework.dbswitch.common.util.StringUtil;
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Service
@AllArgsConstructor
public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfigEntity> implements ApiConfigService {
private final ApiGroupDao apiGroupDao;
private final DiscoveryClient discoveryClient;
private final ApiConfigDao apiConfigDao;
private final DataServiceApiAuthDao dataServiceApiAuthDao;
private final Map<String, ApiConfigEntity> mappings = new ConcurrentHashMap<>();
@Override
public String getIpPort() {
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
return instances.get(0).getHost() + ":" + instances.get(0).getPort()+"/data-service/api/";
}
public void online(Long id) {
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
if (apiConfigEntity != null) {
apiConfigEntity.setStatus(1);
apiConfigEntity.setReleaseTime(new Date());
apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
String routeKey = getRouteKeyByRequestTypeAndUrl(apiConfigEntity.getType(), apiConfigEntity.getPath());
boolean isExists = checkIfExists(routeKey);
if (isExists) {
ApiConfigEntity configEntity = mappings.get(routeKey);
if (configEntity != null) { // 添加 null 判断
offline(configEntity.getId()); // 修正方法调用为传入id
// 从 mappings 中移除该 routeKey
mappings.remove(routeKey);
}
} else {
mappings.put(routeKey, apiConfigEntity);
}
apiConfigDao.updateById(apiConfigEntity);
}
}
private boolean checkIfExists(String routeKey) {
// 这里是全局的 mappings
Map<String, ApiConfigEntity> globalMappings = getGlobalMappings();
return globalMappings.containsKey(routeKey);
}
private Map<String, ApiConfigEntity> getGlobalMappings() {
return mappings;
}
private String getRouteKeyByRequestTypeAndUrl(String type, String path) {
return getRouteKey(type, path);
}
private String getRouteKey(String type, String path) {
return type.toUpperCase() + "_" + path.toLowerCase();
}
@Override
public void offline(Long id) { // 修正参数类型为 Long id
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
if (apiConfigEntity != null) {
apiConfigEntity.setStatus(0);
apiConfigEntity.setReleaseTime(null);
apiConfigEntity.setReleaseUserId(null);
apiConfigDao.updateById(apiConfigEntity);
}else{
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
}
}
// @Override
// public void online(Long id) {
// ApiConfigEntity apiConfigEntity = new ApiConfigEntity();
// apiConfigEntity.setId(id);
// apiConfigEntity.setStatus(1);
// apiConfigEntity.setReleaseTime(new Date());
// apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
//
// apiConfigDao.updateById(apiConfigEntity);
// }
@Override
public String ipPort() {
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
return instances.get(0).getHost() + ":" + instances.get(0).getPort();
}
@Override
public JdbcSelectResult sqlExecute(SqlDto dto) {
return null;
}
@Override
public void exportDocs(List<Long> ids, HttpServletResponse response) {
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
ServiceInstance instance = instances.get(0);
StringBuilder docs = new StringBuilder("## 接口文档\n---\n");
List<ApiConfigEntity> apiConfigEntities = baseMapper.selectBatchIds(ids);
for (ApiConfigEntity api : apiConfigEntities) {
docs.append("### ").append(api.getName())
.append("\n- IP地址").append(instance.getHost())
.append("\n- 端口:").append(instance.getPort())
.append("\n- 接口地址:/data-service/api/").append(api.getPath())
.append("\n- 请求方式:").append(api.getType())
.append("\n- Content-Type").append(api.getContentType())
.append("\n- 是否需要鉴权:").append(api.getPrivates() == 1 ? "是" : "否");
if (api.getPrivates() == 1) {
docs.append("\n- 获取鉴权token").append("/data-service/api/token/generate?appKey=您的appKey&appSecret=您的appToken");
}
docs.append("\n- 接口备注:").append(api.getNote())
.append("\n- 请求参数示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getJsonParam()) ? api.getJsonParam() : "{}").append("\n```\n")
.append("\n- 响应结果示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getResponseResult()) ? api.getResponseResult() : "{\"code\":0,\"msg\":\"success\",\"data\":[]}").append("\n```\n")
.append("\n---\n");
}
response.setContentType("application/x-msdownload;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=API DOCS.md");
OutputStream os = null;
try {
os = response.getOutputStream();
os.write(docs.toString().getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (os != null)
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void upAuth(DataServiceApiAuthVo authVO) {
dataServiceApiAuthDao.updateById(DataServiceApiAuthConvert.INSTANCE.convert(authVO));
}
@Override
public DataServiceApiAuthVo getAuthInfo(Long authId) {
return DataServiceApiAuthConvert.INSTANCE.convert(dataServiceApiAuthDao.selectById(authId));
}
@Override
public void resetRequested(Long authId) {
dataServiceApiAuthDao.resetRequested(authId);
}
@Override
public PageResult<ApiConfigVo> page(ApiConfigQuery query) {
// 查询参数
Map<String, Object> params = getParams(query);
// 分页查询
query.setOrder("dsac.id");
IPage<ApiConfigEntity> page = getPage(query);
params.put(Constant.PAGE, page);
// 数据列表
List<ApiConfigEntity> list = baseMapper.getAuthList(params);
return new PageResult<>(ApiConfigConvert.INSTANCE.convertList(list), page.getTotal());
}
private LambdaQueryWrapper getWrapper(ApiConfigQuery query) {
LambdaQueryWrapper<ApiConfigEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StringUtil.isNotBlank(query.getName()), ApiConfigEntity::getName, query.getName());
wrapper.like(StringUtil.isNotBlank(query.getPath()), ApiConfigEntity::getPath, query.getPath());
wrapper.eq(StringUtil.isNotBlank(query.getContentType()), ApiConfigEntity::getContentType, query.getContentType());
wrapper.eq(query.getStatus()!= null, ApiConfigEntity::getStatus, query.getStatus());
wrapper.eq(query.getSqlDbType() != null, ApiConfigEntity::getSqlDbType, query.getSqlDbType());
wrapper.eq(query.getDatabaseId()!= null, ApiConfigEntity::getDatabaseId, query.getDatabaseId());
wrapper.eq(query.getPrivates()!= null, ApiConfigEntity::getPrivates, query.getPrivates());
wrapper.eq(query.getOpenTrans()!= null, ApiConfigEntity::getOpenTrans, query.getOpenTrans());
dataScopeWithoutOrgId(wrapper);
wrapper.orderByDesc(ApiConfigEntity::getCreateTime);
wrapper.orderByDesc(ApiConfigEntity::getId);
return wrapper;
}
@Override
public void save(ApiConfigVo vo) {
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
entity.setProjectId(getProjectId());
baseMapper.insert(entity);
}
@Override
public void update(ApiConfigVo vo) {
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
entity.setProjectId(getProjectId());
updateById(entity);
}
@Override
public void delete(List<Long> idList) {
removeByIds(idList);
}
@Override
public PageResult<ApiConfigVo> pageResource(ApiConfigQuery query) {
// 查询参数
Map<String, Object> params = getParams(query);
IPage<ApiConfigEntity> page = getPage(query);
params.put(Constant.PAGE, page);
// 数据列表
List<ApiConfigEntity> list = baseMapper.getResourceList(params);
List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(list);
for (ApiConfigVo apiConfigVo : apiConfigVos) {
ApiGroupEntity groupEntity = apiGroupDao.selectById(apiConfigVo.getGroupId());
apiConfigVo.setGroup(groupEntity != null ? groupEntity.getPath() : null);
}
return new PageResult<>(apiConfigVos, page.getTotal());
}
@Override
public List<ApiConfigEntity> listActiveByGroupId(Long id) {
LambdaQueryWrapper<ApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ApiConfigEntity::getStatus, 1).eq(ApiConfigEntity::getGroupId, id).orderByDesc(ApiConfigEntity::getId);
dataScopeWithoutOrgId(wrapper);
return baseMapper.selectList(wrapper);
}
private Map<String, Object> getParams(ApiConfigQuery query) {
Map<String, Object> params = new HashMap<>();
params.put("ifMarket", query.getIfMarket());
params.put("queryApply", query.getQueryApply());
if (query.getQueryApply() != null && query.getQueryApply() == 1) {
params.put("userId", SecurityUser.getUserId());
}
params.put("resourceId", query.getResourceId());
params.put("groupId", query.getGroupId());
params.put("appId", query.getAppId());
params.put("name", query.getName());
params.put("path", query.getPath());
params.put("contentType", query.getContentType());
params.put("status", query.getStatus());
params.put("sqlDbType", query.getSqlDbType());
params.put("databaseId", query.getDatabaseId());
params.put("privates", query.getPrivates());
params.put("openTrans", query.getOpenTrans());
// 数据权限
params.put(Constant.DATA_SCOPE, getDataScope("dsac", null, null, "project_id", false, true));
return params;
}
}

View File

@ -0,0 +1,140 @@
package net.srt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.AllArgsConstructor;
import net.srt.constants.ApiGroupType;
import net.srt.convert.ApiGroupConvert;
import net.srt.dao.ApiGroupDao;
import net.srt.entity.ApiConfigEntity;
import net.srt.entity.ApiGroupEntity;
import net.srt.framework.common.exception.ServerException;
import net.srt.framework.common.utils.BeanUtil;
import net.srt.framework.common.utils.BuildTreeUtils;
import net.srt.framework.common.utils.TreeNodeVo;
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
import net.srt.service.ApiConfigService;
import net.srt.service.ApiGroupService;
import net.srt.vo.ApiGroupVo;
import org.springframework.stereotype.Service;
import srt.cloud.framework.dbswitch.common.util.StringUtil;
import java.util.ArrayList;
import java.util.List;
@Service
@AllArgsConstructor
public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEntity> implements ApiGroupService{
private final ApiConfigService apiConfigService;
/**
* API
* @return API
*/
@Override
public List<TreeNodeVo> listTree() {
// 查询所有API分组实体对象并转换为树节点VO对象列表
List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
// 构建树形结构,并返回根节点列表
return BuildTreeUtils.buildTree(treeNodeVos);
}
/**
* APIVO
* @return APIVO
*/
private List<TreeNodeVo> getTreeNodeVos() {
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
dataScopeWithoutOrgId(wrapper); // 加入数据权限过滤
wrapper.orderByAsc(ApiGroupEntity::getOrderNo); // 按orderNo升序排序
List<ApiGroupEntity> apiGroupEntities = baseMapper.selectList(wrapper);
// 将实体对象列表转换为VO对象列表
return BeanUtil.copyListProperties(apiGroupEntities, TreeNodeVo::new, (oldItem, newItem) -> {
// 设置节点名称
newItem.setLabel(oldItem.getName());
// 设置节点值
newItem.setValue(oldItem.getId());
newItem.setDisabled(oldItem.getType() == 1); // 如果是虚拟节点,设置禁用状态
if (newItem.getPath().contains("/")) { // 设置父级节点路径
newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/")));
}
});
}
/**
* API
* @param vo APIVO
*/
@Override
public void save(ApiGroupVo vo) {
// 将VO对象转换为实体对象
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
// 递归生成路径
entity.setPath(recursionPath(entity, null));
// 设置项目ID
entity.setProjectId(getProjectId());
// 执行插入操作
baseMapper.insert(entity); // 使用 insertSelective() 方法进行插入操作
}
/**
* API
* @param vo APIVO
*/
@Override
public void update(ApiGroupVo vo) {
// 将VO对象转换为实体对象
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
// 递归生成路径
entity.setPath(recursionPath(entity, null));
// 设置项目ID
entity.setProjectId(getProjectId());
// 执行更新操作
updateById(entity);
}
/**
* API
* @param groupEntity
* @param path
* @return
*/
//1
private String recursionPath(ApiGroupEntity groupEntity, String path) {
if (StringUtil.isBlank(path)) {
// 如果路径为空,则将路径设置为组实体的名称
path = groupEntity.getName();
}
if (groupEntity.getParentId() != 0) {
// 如果组实体的父ID不为0
// 查询父级组实体
ApiGroupEntity parent = getById(groupEntity.getParentId()); // 通过父ID获取父级组实体
path = parent.getName() + "/" + path; // 将父级组实体的名称与当前路径拼接起来,中间以斜杠分隔
return recursionPath(parent, path); // 递归调用recursionPath方法传入父级组实体和拼接后的路径
}
return path;
}
/**
* IDAPI
* @param id APIID
*/
@Override
public void delete(Long id) {
// 查询是否存在子节点
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ApiGroupEntity::getParentId, id).last(" limit 1");
ApiGroupEntity one = baseMapper.selectOne(wrapper);
if (one != null) {
throw new ServerException("存在子节点,不允许删除!");
}
// 查询是否有API配置与之关联
LambdaQueryWrapper<ApiConfigEntity> serviceApiConfigWrapper = new LambdaQueryWrapper<>();
serviceApiConfigWrapper.eq(ApiConfigEntity::getGroupId, id).last(" limit 1");
ApiConfigEntity apiConfigEntity = apiConfigService.getOne(serviceApiConfigWrapper);
if (apiConfigEntity != null) {
throw new ServerException("节点下有 api 与之关联,不允许删除!");
}
// 执行删除操作
removeById(id);
}
}

View File

@ -0,0 +1,10 @@
package net.srt.service.impl;
/**
* @ClassName : DataServiceApiAuthServiceImpl
* @Description :
* @Author : FJJ
* @Date: 2023-12-26 15:23
*/
public class DataServiceApiAuthServiceImpl {
}

View File

@ -0,0 +1,51 @@
package net.srt.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import net.srt.convert.DataServiceApiLogConvert;
import net.srt.dao.DataServiceApiLogDao;
import net.srt.entity.DataServiceApiLogEntity;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
import net.srt.query.DataServiceApiLogQuery;
import net.srt.service.DataServiceApiLogService;
import net.srt.vo.DataServiceApiLogVo;
import org.springframework.stereotype.Service;
import srt.cloud.framework.dbswitch.common.util.StringUtil;
import java.util.List;
/**
* @ClassName : DataServiceApiLogServiceImpl
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:31
*/
@Service
@AllArgsConstructor
public class DataServiceApiLogServiceImpl extends BaseServiceImpl<DataServiceApiLogDao, DataServiceApiLogEntity> implements DataServiceApiLogService {
@Override
public PageResult<DataServiceApiLogVo> dataPageList(DataServiceApiLogQuery query) {
IPage<DataServiceApiLogEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
return new PageResult<>(DataServiceApiLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
}
@Override
public void removeId(List<Long> idList) {
removeByIds(idList);
}
private LambdaQueryWrapper<DataServiceApiLogEntity> getWrapper(DataServiceApiLogQuery query) {
LambdaQueryWrapper<DataServiceApiLogEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StringUtil.isNotBlank(query.getIp()), DataServiceApiLogEntity::getIp, query.getIp())
.like(StringUtil.isNotBlank(query.getApiName()), DataServiceApiLogEntity::getApiName, query.getApiName())
.orderByDesc(DataServiceApiLogEntity::getCreateTime).orderByDesc(DataServiceApiLogEntity::getId);
dataScopeWithoutOrgId(wrapper);
return wrapper;
}
}

View File

@ -4,8 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.srt.convert.DataServiceApiAuthConvert;
import net.srt.convert.DataServiceAppConvert; import net.srt.convert.DataServiceAppConvert;
import net.srt.dao.ApiConfigDao;
import net.srt.dao.DataServiceApiAuthDao;
import net.srt.dao.DataServiceAppDao; import net.srt.dao.DataServiceAppDao;
import net.srt.dto.AppToken;
import net.srt.entity.DataServiceApiAuthEntity;
import net.srt.entity.DataServiceAppEntity; import net.srt.entity.DataServiceAppEntity;
import net.srt.framework.common.exception.ServerException; import net.srt.framework.common.exception.ServerException;
import net.srt.framework.common.page.PageResult; import net.srt.framework.common.page.PageResult;
@ -13,7 +18,9 @@ import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
import net.srt.framework.security.user.SecurityUser; import net.srt.framework.security.user.SecurityUser;
import net.srt.query.DataServiceAppQuery; import net.srt.query.DataServiceAppQuery;
import net.srt.service.DataServiceAppService; import net.srt.service.DataServiceAppService;
import net.srt.vo.DataServiceApiAuthVo;
import net.srt.vo.DataServiceAppVo; import net.srt.vo.DataServiceAppVo;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import srt.cloud.framework.dbswitch.common.util.StringUtil; import srt.cloud.framework.dbswitch.common.util.StringUtil;
@ -30,6 +37,8 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao, DataServiceAppEntity> implements DataServiceAppService { public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao, DataServiceAppEntity> implements DataServiceAppService {
private final DataServiceAppDao dataServiceAppDao; private final DataServiceAppDao dataServiceAppDao;
private final ApiConfigDao apiConfigDao;
private final DataServiceApiAuthDao dataServiceApiAuthDao;
@Override @Override
public PageResult<DataServiceAppVo> page(DataServiceAppQuery query) { public PageResult<DataServiceAppVo> page(DataServiceAppQuery query) {
IPage<DataServiceAppEntity> page=baseMapper.selectPage(getPage(query),null); IPage<DataServiceAppEntity> page=baseMapper.selectPage(getPage(query),null);
@ -44,6 +53,7 @@ public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao
@Override @Override
public void update1(DataServiceAppVo vo) { public void update1(DataServiceAppVo vo) {
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo); DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
@ -56,29 +66,65 @@ public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao
} }
@Override @Override
public void addAuth(DataServiceAppVo authVO) { public void addAuth(DataServiceApiAuthVo authVO) {
authVO.setProjectId(getProjectId()); authVO.setProjectId(getProjectId());
dataServiceAppDao.insert(DataServiceAppConvert.INSTANCE.convert(authVO)); DataServiceApiAuthEntity entity = DataServiceApiAuthConvert.INSTANCE.convert(authVO);
dataServiceApiAuthDao.insert(entity);
Long id = entity.getApiId();
apiConfigDao.updateById(authVO.getApiId(),id);
} }
//修改授权
@Override @Override
public void upAuth(DataServiceAppVo authVO) { public void upAuth(DataServiceApiAuthVo authVO) {
dataServiceAppDao.updateById(DataServiceAppConvert.INSTANCE.convert(authVO)); DataServiceApiAuthEntity entity = DataServiceApiAuthConvert.INSTANCE.convert(authVO);
dataServiceApiAuthDao.updateById(entity);
} }
//取消授权
@Override @Override
public void cancelAuth(Long authId) { public void cancelAuth(Long authId) {
dataServiceAppDao.deleteById(authId); dataServiceApiAuthDao.deleteById(authId);
apiConfigDao.updateAuthId(authId);
}
@Override
public String tokenGenerate(String appKey, String appSecret) {
LambdaQueryWrapper<DataServiceAppEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(DataServiceAppEntity::getAppKey,appKey).last("limit 1");
DataServiceAppEntity dataServiceAppEntity = baseMapper.selectOne(wrapper);
if (dataServiceAppEntity==null){
throw new RuntimeException("appKey不存在");
}
if (!appSecret.equals(dataServiceAppEntity.getAppSecret())){
throw new ServerException("appSecret错误");
}
//生成token
String token = RandomStringUtils.random(32, true, true);
AppToken appToken = new AppToken();
appToken.setToken(token);
appToken.setAppKey(appKey);
appToken.setAppId(dataServiceAppEntity.getId());
if (dataServiceAppEntity.getExpireDuration()==0){
appToken.setExpireAt(0L);
} else if (dataServiceAppEntity.getExpireDuration()== -1) {
appToken.setExpireAt(-1L);
}else if (dataServiceAppEntity.getExpireDuration()>0){
long l = System.currentTimeMillis() + dataServiceAppEntity.getExpireDuration() * 1000;
appToken.setExpireAt(l);
}
return appToken.getToken();
} }
// private LambdaQueryWrapper<DataServiceAppEntity> getWrapper(DataServiceAppQuery query) { private LambdaQueryWrapper<DataServiceAppEntity> getWrapper(DataServiceAppQuery query) {
// LambdaQueryWrapper<DataServiceAppEntity> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<DataServiceAppEntity> wrapper = Wrappers.lambdaQuery();
// wrapper.like(StringUtil.isNotBlank(query.getName()), DataServiceAppEntity::getName, query.getName()) wrapper.like(StringUtil.isNotBlank(query.getName()), DataServiceAppEntity::getName, query.getName())
// .eq(DataServiceAppEntity::getIfMarket, query.getIfMarket() != null ? query.getIfMarket() : 0) .eq(DataServiceAppEntity::getIfMarket, query.getIfMarket() != null ? query.getIfMarket() : 0)
// .eq(query.getIfMarket() != null, DataServiceAppEntity::getCreator, SecurityUser.getUserId()) .eq(query.getIfMarket() != null, DataServiceAppEntity::getCreator, SecurityUser.getUserId())
// .eq(StringUtil.isNotBlank(query.getAppKey()), DataServiceAppEntity::getAppKey, query.getAppKey()) .eq(StringUtil.isNotBlank(query.getAppKey()), DataServiceAppEntity::getAppKey, query.getAppKey())
// .orderByDesc(DataServiceAppEntity::getCreateTime).orderByDesc(DataServiceAppEntity::getId); .orderByDesc(DataServiceAppEntity::getCreateTime).orderByDesc(DataServiceAppEntity::getId);
// return wrapper; return wrapper;
// } }
} }

View File

@ -0,0 +1,145 @@
package net.srt.utils;
import javax.crypto.Cipher;
import java.security.Key;
/**
* @ClassName : EncrypDES
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 09:31
*/
public class EncrypDES {
// 字符串默认键值
private static String strDefaultKey = "inventec2020@#$%^&";
//加密工具
private Cipher encryptCipher = null;
// 解密工具
private Cipher decryptCipher = null;
/**
* 使
*/
public EncrypDES() throws Exception {
this(strDefaultKey);
}
/**
*
* @param strKey
* @throws Exception
*/
public EncrypDES(String strKey) throws Exception {
// Security.addProvider(new com.sun.crypto.provider.SunJCE());
Key key = getKey(strKey.getBytes());
encryptCipher = Cipher.getInstance("DES");
encryptCipher.init(Cipher.ENCRYPT_MODE, key);
decryptCipher = Cipher.getInstance("DES");
decryptCipher.init(Cipher.DECRYPT_MODE, key);
}
/**
* byte16 byte[]{8,18}0813public static byte[]
*
* hexStr2ByteArr(String strIn)
*
* @param arrB byte
* @return
* @throws Exception
*/
public static String byteArr2HexStr(byte[] arrB) throws Exception {
int iLen = arrB.length;
// 每个byte用2个字符才能表示所以字符串的长度是数组长度的2倍
StringBuffer sb = new StringBuffer(iLen * 2);
for (int i = 0; i < iLen; i++) {
int intTmp = arrB[i];
// 把负数转换为正数
while (intTmp < 0) {
intTmp = intTmp + 256;
}
// 小于0F的数需要在前面补0
if (intTmp < 16) {
sb.append("0");
}
sb.append(Integer.toString(intTmp, 16));
}
return sb.toString();
}
/**
* 16bytepublic static String byteArr2HexStr(byte[] arrB)
*
* @param strIn
* @return byte
*/
public static byte[] hexStr2ByteArr(String strIn) throws Exception {
byte[] arrB = strIn.getBytes();
int iLen = arrB.length;
// 两个字符表示一个字节所以字节数组长度是字符串长度除以2
byte[] arrOut = new byte[iLen / 2];
for (int i = 0; i < iLen; i = i + 2) {
String strTmp = new String(arrB, i, 2);
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
}
return arrOut;
}
/**
*
*
* @param arrB
* @return
*/
public byte[] encrypt(byte[] arrB) throws Exception {
return encryptCipher.doFinal(arrB);
}
/**
*
* @param strIn
* @return
*/
public String encrypt(String strIn) throws Exception {
return byteArr2HexStr(encrypt(strIn.getBytes()));
}
/**
*
* @param arrB
* @return
*/
public byte[] decrypt(byte[] arrB) throws Exception {
return decryptCipher.doFinal(arrB);
}
/**
*
* @param strIn
* @return
*/
public String decrypt(String strIn) throws Exception {
return new String(decrypt(hexStr2ByteArr(strIn)));
}
/**
* 8 8088
* @param arrBTmp
* @return
*/
private Key getKey(byte[] arrBTmp) throws Exception {
// 创建一个空的8位字节数组默认值为0
byte[] arrB = new byte[8];
// 将原始字节数组转换为8位
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
arrB[i] = arrBTmp[i];
}
// 生成密钥
Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
return key;
}
}

View File

@ -0,0 +1,56 @@
package net.srt.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.srt.framework.common.utils.DateUtils;
import java.io.Serializable;
import java.util.Date;
/**
* -api
*
* @author zrx 985134801@qq.com
* @since 1.0.0 2023-01-28
*/
@Data
public class ApiConfigVo implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Long groupId;
private String path;
private String type;
private String name;
private String note;
private String sqlText;
private String sqlSeparator;
private Integer sqlMaxRow;
private String sqlParam;
private String jsonParam;
private String responseResult;
private String contentType;
private Integer status;
private Date releaseTime;
private Long releaseUserId;
private Integer sqlDbType;
private Long databaseId;
private Integer privates;
private Integer openTrans;
private Long projectId;
private Integer version;
private Integer deleted;
private Long creator;
private Date createTime;
private Long updater;
private Date updateTime;
private Integer requestedTimes;
private Integer requestedSuccessTimes;
private Integer requestedFailedTimes;
private Long authId;
private String group;
private String groupPath;
private Integer previlege;
}

View File

@ -0,0 +1,25 @@
package net.srt.vo;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class ApiGroupVo implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Long parentId;
private Integer type;
private String name;
private String description;
private Integer orderNo;
private String path;
private Long projectId;
private Integer version;
private Integer deleted;
private Long creator;
private Date createTime;
private Long updater;
private Date updateTime;
}

View File

@ -19,33 +19,35 @@ import java.util.Date;
public class DataServiceApiAuthVo implements Serializable { public class DataServiceApiAuthVo implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Schema(description = "主键id") @Schema(description = "id")
private Long id; private Long id;
@Schema(description = "app的id") @Schema(description = "appId")
private Long appId; private Long appId;
@Schema(description = "分组id") @Schema(description = "groupId")
private Long groupId; private Long groupId;
@Schema(description = "api的id") @Schema(description = "apiId")
private Long apiId; private Long apiId;
@Schema(description = "调用次数 不限次数为-1") @Schema(description = "调用的次数:不限次数为-1")
private Integer requestTimes; private Integer requestTimes;
@Schema(description = "已调次数") @Schema(description = "已调次数")
private Integer requestedTimes; private Integer requestedTimes;
private Integer requestedSuccessTimes; private Integer requestedSuccessTimes;
private Integer requestedFailedTimes; private Integer requestedFailedTimes;
@Schema(description = "所属项目id") @Schema(description = "所属项目id")
private Long projectId; private Long projectId;
private Long authId;
@Schema(description = "版本号") @Schema(description = "版本号")
private Integer version; private Integer version;
@Schema(description = "删除标识 0:正常 1已删除") @Schema(description = "删除标识 0是正常 1是已删除")
private Integer deleted; private Integer deleted;
@Schema(description = "创建者") @Schema(description = "创建者")

View File

@ -0,0 +1,72 @@
package net.srt.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.srt.framework.common.utils.DateUtils;
import java.io.Serializable;
import java.util.Date;
/**
* @ClassName : DataServiceApiLog
* @Description :
* @Author : FJJ
* @Date: 2023-12-25 11:05
*/
@Data
@Schema(description = "api请求日志")
public class DataServiceApiLogVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键id")
private Long id;
@Schema(description = "url")
private String url;
@Schema(description = "响应状态码")
private Integer status;
@Schema(description = "时长")
private Long duration;
@Schema(description = "IP地址")
private String ip;
@Schema(description = "app的id")
private String appId;
@Schema(description = "api的id")
private String apiId;
private String appName;
private String apiName;
@Schema(description = "错误信息")
private String error;
@Schema(description = "项目id")
private Long projectId;
@Schema(description = "版本号")
private Integer version;
@Schema(description = "删除标识 0正常 1已删除")
private Integer deleted;
@Schema(description = "创建者")
private Long creator;
@Schema(description = "创建时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date createTime;
@Schema(description = "更新者")
private Long updater;
@Schema(description = "更新时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date updateTime;
}

View File

@ -0,0 +1,73 @@
package net.srt.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.srt.framework.common.utils.DateUtils;
import java.io.Serializable;
import java.util.Date;
/**
* @BelongsProject: data-center
* @BelongsPackage: net.srt.vo
* @Author: yanqiang
* @CreateTime: 2023-12-24 15:21
*/
@Data
@Schema(description = "api日志")
public class ServiceApiLogVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键id")
private Long id;
@Schema(description = "url")
private String url;
@Schema(description = "响应状态码")
private Integer status;
@Schema(description = "时长")
private Long duration;
@Schema(description = "IP地址")
private String ip;
@Schema(description = "app的id")
private String appId;
@Schema(description = "api的id")
private String apiId;
private String appName;
private String apiName;
@Schema(description = "错误信息")
private String error;
@Schema(description = "项目id")
private Long projectId;
@Schema(description = "版本号")
private Integer version;
@Schema(description = "删除标识 0正常 1已删除")
private Integer deleted;
@Schema(description = "创建者")
private Long creator;
@Schema(description = "创建时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date createTime;
@Schema(description = "更新者")
private Long updater;
@Schema(description = "更新时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date updateTime;
}

View File

@ -0,0 +1,70 @@
package net.srt.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.srt.framework.common.utils.DateUtils;
import java.io.Serializable;
import java.util.Date;
/**
* @BelongsProject: data-center
* @BelongsPackage: net.srt.vo
* @Author: yanqiang
* @CreateTime: 2023-12-21 20:50
*/
@Data
@Schema(description = "数据app")
public class ServiceAppVo implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键id")
private Long id;
@Schema(description = "名称")
private String name;
@Schema(description = "备注")
private String note;
@Schema(description = "appKey")
private String appKey;
@Schema(description = "appSecret")
private String appSecret;
@Schema(description = "过期时间")
private String expireDesc;
/**
* -10 > 0
*/
private Long expireDuration;
private Integer ifMarket;
@Schema(description = "项目id")
private Long projectId;
@Schema(description = "版本号")
private Integer version;
@Schema(description = "0正常 1已删除")
private Integer deleted;
@Schema(description = "创建人")
private Long creator;
@Schema(description = "创建时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date createTime;
@Schema(description = "更新人")
private Long updater;
@Schema(description = "更新时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date updateTime;
}

View File

@ -14,8 +14,8 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 09dff3e2-9790-4d4f-beb6-9baeb01ae040 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.srt.dao.ApiConfigDao">
<update id="updateById">
update data_service_api_config set auth_id=#{apiId} where id=#{id}
</update>
<update id="updateAuthId">
update data_service_api_config set auth_id=null where auth_id=#{authId}
</update>
<select id="getResourceList" resultType="net.srt.entity.ApiConfigEntity">
<choose>
<when test="queryApply!=null and queryApply==1">
SELECT * FROM data_service_api_config
WHERE id IN (SELECT mount_id FROM data_assets_resource_mount WHERE mount_type=2 AND resource_id=#{resourceId})
AND deleted=0
</when>
<otherwise>
SELECT
dsac.*
FROM
data_service_api_config dsac
INNER JOIN data_assets_resource_mount darm ON dsac.id = darm.mount_id
WHERE
darm.mount_type=2
AND darm.resource_id=#{resourceId}
AND dsac.deleted=0
</otherwise>
</choose>
</select>
<select id="getById" resultType="net.srt.entity.ApiConfigEntity">
SELECT * FROM data_service_api_config WHERE id = #{id}
</select>
<select id="getAuthList" resultType="net.srt.entity.ApiConfigEntity">
<choose>
<when test="ifMarket != null and ifMarket==1">
SELECT
dsac.*,
dsaa.id AS auth_id,
dsag.path AS group_path
FROM
data_service_api_config dsac
INNER JOIN data_service_api_group dsag ON dsac.group_id=dsag.id
INNER JOIN data_service_api_auth dsaa ON dsac.id = dsaa.api_id
WHERE
dsaa.app_id=#{appId}
AND dsac.deleted=0
AND dsaa.deleted=0
</when>
<otherwise>
SELECT
dsac.*,
dsaa.id AS auth_id
FROM
data_service_api_config dsac
LEFT JOIN data_service_api_auth dsaa ON dsac.id = dsaa.api_id AND dsaa.app_id=#{appId}
AND dsaa.deleted=0
WHERE
dsac.group_id = #{groupId}
AND dsac.privates=1
AND dsac.deleted=0
</otherwise>
</choose>
<if test="name != null and name.trim() != ''">
AND dsac.name LIKE "%"#{name}"%"
</if>
<if test="path != null and path.trim() != ''">
AND dsac.path LIKE "%"#{path}"%"
</if>
<if test="contentType != null and contentType.trim() != ''">
AND dsac.content_type = #{contentType}
</if>
<if test="status != null">
AND dsac.status = #{status}
</if>
<if test="sqlDbType != null">
AND dsac.sql_db_type = #{sqlDbType}
</if>
<if test="databaseId != null">
AND dsac.database_id = #{databaseId}
</if>
<if test="privates != null">
AND dsac.privates = #{privates}
</if>
<if test="openTrans != null">
AND dsac.open_trans = #{openTrans}
</if>
ORDER BY dsac.create_time DESC,dsac.id DESC
</select>
</mapper>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.srt.dao.DataServiceApiAuthDao">
<update id="resetRequested">
UPDATE data_service_api_auth SET requested_times=0,requested_success_times=0,requested_failed_times=0 WHERE id =#{id}
</update>
</mapper>

View File

@ -5,7 +5,7 @@
<mapper namespace="net.srt.dao.DataServiceAppDao"> <mapper namespace="net.srt.dao.DataServiceAppDao">
<select id="selectByApplyId" resultType="net.srt.entity.DataServiceAppEntity"> <!-- <select id="selectByApplyId" resultType="net.srt.entity.DataServiceAppEntity">-->
SELECT dsa.* FROM data_service_app dsa INNER JOIN data_market_resource_apply dmra ON dsa.id=dmra.app_id WHERE dmra.id=#{applyId} <!-- SELECT dsa.* FROM data_service_app dsa INNER JOIN data_market_resource_apply dmra ON dsa.id=dmra.app_id WHERE dmra.id=#{applyId}-->
</select> <!-- </select>-->
</mapper> </mapper>

View File

@ -198,13 +198,20 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M,
/** /**
* MyBatis-Plus * MyBatis-Plus
*/ */
// protected void dataScopeWithoutOrgId(LambdaQueryWrapper<T> queryWrapper) {
// DataScope dataScope = getDataScope(null, null, null, null, false, true);
// if (dataScope != null) {
// queryWrapper.apply(dataScope.getSqlFilter());
// }
// }
protected void dataScopeWithoutOrgId(LambdaQueryWrapper<T> queryWrapper) { protected void dataScopeWithoutOrgId(LambdaQueryWrapper<T> queryWrapper) {
DataScope dataScope = getDataScope(null, null, null, null, false, true); DataScope dataScope = this.getDataScope((String)null, (String)null, (String)null, (String)null, false, true);
if (dataScope != null) { if (dataScope != null) {
queryWrapper.apply(dataScope.getSqlFilter()); queryWrapper.apply(dataScope.getSqlFilter(), new Object[0]);
}
} }
}
/** /**
* MyBatis-Plus * MyBatis-Plus
*/ */

View File

@ -40,7 +40,6 @@ public class SecurityFilterConfig {
.and().authorizeRequests() .and().authorizeRequests()
.antMatchers(permits).permitAll() .antMatchers(permits).permitAll()
.antMatchers(HttpMethod.OPTIONS).permitAll() .antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers("/datax/**").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
.and().exceptionHandling().authenticationEntryPoint(new SecurityAuthenticationEntryPoint()) .and().exceptionHandling().authenticationEntryPoint(new SecurityAuthenticationEntryPoint())
.and().headers().frameOptions().disable() .and().headers().frameOptions().disable()

View File

@ -11,7 +11,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -101,11 +101,11 @@
<!-- mvn install:install-file -Dfile=lib/datax-core-0.0.1-SNAPSHOT.jar -DgroupId=com.alibaba.datax -DartifactId=mysqlreader -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar <!-- mvn install:install-file -Dfile=lib/datax-core-0.0.1-SNAPSHOT.jar -DgroupId=com.alibaba.datax -DartifactId=mysqlreader -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
--> -->
<dependency> <!-- <dependency>-->
<groupId>com.alibaba.datax</groupId> <!-- <groupId>com.alibaba.datax</groupId>-->
<artifactId>mysqlreader</artifactId> <!-- <artifactId>mysqlreader</artifactId>-->
<version>0.0.1-SNAPSHOT</version> <!-- <version>0.0.1-SNAPSHOT</version>-->
</dependency> <!-- </dependency>-->
<!-- mvn install:install-file -Dfile=lib/datax-core-0.0.1-SNAPSHOT.jar -DgroupId=com.alibaba.datax -DartifactId=mysqlwriter -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar <!-- mvn install:install-file -Dfile=lib/datax-core-0.0.1-SNAPSHOT.jar -DgroupId=com.alibaba.datax -DartifactId=mysqlwriter -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
--> -->
@ -117,11 +117,11 @@
<!-- mvn install:install-file -Dfile=lib/datax-core-0.0.1-SNAPSHOT.jar -DgroupId=com.alibaba.datax -DartifactId=oraclereader -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar <!-- mvn install:install-file -Dfile=lib/datax-core-0.0.1-SNAPSHOT.jar -DgroupId=com.alibaba.datax -DartifactId=oraclereader -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar
--> -->
<dependency> <!-- <dependency>-->
<groupId>com.alibaba.datax</groupId> <!-- <groupId>com.alibaba.datax</groupId>-->
<artifactId>oraclereader</artifactId> <!-- <artifactId>oraclereader</artifactId>-->
<version>0.0.1-SNAPSHOT</version> <!-- <version>0.0.1-SNAPSHOT</version>-->
</dependency> <!-- </dependency>-->
<!--httpclient--> <!--httpclient-->
<dependency> <dependency>

View File

@ -11,7 +11,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -11,7 +11,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -63,7 +63,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.srt</groupId> <groupId>net.srt</groupId>
<artifactId>srt-cloud-datax</artifactId> <artifactId>srt-cloud-api</artifactId>
<version>2.0.0</version> <version>2.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -170,24 +170,25 @@
</plugin> </plugin>
<!--打包 日常调试打包可以把该组件注释掉不然install的速度比较慢--> <!--打包 日常调试打包可以把该组件注释掉不然install的速度比较慢-->
<plugin> <!-- <plugin>-->
<artifactId>maven-assembly-plugin</artifactId> <!-- <artifactId>maven-assembly-plugin</artifactId>-->
<configuration> <!-- <configuration>-->
<descriptors> <!-- <descriptors>-->
<descriptor>${project.parent.parent.basedir}/assembly/assembly-win.xml</descriptor> <!-- <descriptor>../../../srt-cloud-3z/assembly/assembly-win.xml</descriptor>-->
<descriptor>${project.parent.parent.basedir}/assembly/assembly-linux.xml</descriptor> <!-- <descriptor>../../../srt-cloud-3z/assembly/assembly-linux.xml</descriptor>-->
</descriptors> <!-- </descriptors>-->
</configuration> <!-- </configuration>-->
<executions> <!-- <executions>-->
<execution> <!-- <execution>-->
<id>make-assembly</id> <!-- <id>make-assembly</id>-->
<phase>package</phase> <!-- <phase>package</phase>-->
<goals> <!-- <goals>-->
<goal>single</goal> <!-- <goal>single</goal>-->
</goals> <!-- </goals>-->
</execution> <!-- </execution>-->
</executions> <!-- </executions>-->
</plugin> <!-- </plugin>-->
<!--<plugin> <!--<plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -14,7 +14,6 @@ import org.springframework.context.annotation.ComponentScan;
@EnableFeignClients @EnableFeignClients
@EnableDiscoveryClient @EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = "net.srt.framework.common.cache")
public class QuartzApplication { public class QuartzApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -8,7 +8,6 @@ import net.srt.api.module.data.integrate.dto.DataAccessDto;
import net.srt.api.module.data.integrate.dto.DataAccessTaskDto; import net.srt.api.module.data.integrate.dto.DataAccessTaskDto;
import net.srt.api.module.quartz.QuartzDataAccessApi; import net.srt.api.module.quartz.QuartzDataAccessApi;
import net.srt.api.module.quartz.constant.QuartzJobType; import net.srt.api.module.quartz.constant.QuartzJobType;
import net.srt.datax.feign.DataAccessFeign;
import net.srt.framework.common.utils.Result; import net.srt.framework.common.utils.Result;
import net.srt.quartz.entity.ScheduleJobEntity; import net.srt.quartz.entity.ScheduleJobEntity;
import net.srt.quartz.enums.JobGroupEnum; import net.srt.quartz.enums.JobGroupEnum;
@ -32,7 +31,6 @@ public class QuartzDataAccessApiImpl implements QuartzDataAccessApi {
private final Scheduler scheduler; private final Scheduler scheduler;
private final DataAccessApi dataAccessApi; private final DataAccessApi dataAccessApi;
private final ScheduleJobService jobService; private final ScheduleJobService jobService;
private final DataAccessFeign feign;
@Override @Override
public Result<String> releaseAccess(Long id) { public Result<String> releaseAccess(Long id) {
@ -53,24 +51,48 @@ public class QuartzDataAccessApiImpl implements QuartzDataAccessApi {
return Result.ok(); return Result.ok();
} }
/**
*
* @param id ID
* @return
*/
@Override @Override
public Result<String> handRun(Long id) { public Result<String> handRun(Long id) {
// 构建任务实体
ScheduleJobEntity jobEntity = buildJobEntity(id); ScheduleJobEntity jobEntity = buildJobEntity(id);
// 设置任务为单例,且不保存日志
jobEntity.setOnce(true); jobEntity.setOnce(true);
jobEntity.setSaveLog(false); jobEntity.setSaveLog(false);
// 执行任务
ScheduleUtils.run(scheduler, jobEntity); ScheduleUtils.run(scheduler, jobEntity);
// 返回运行结果
return Result.ok(); return Result.ok();
} }
/**
* id
* @param id id
* @return
*/
private ScheduleJobEntity buildJobEntity(Long id) { private ScheduleJobEntity buildJobEntity(Long id) {
DataAccessDto dataAccessDto = dataAccessApi.getById(id).getData(); DataAccessDto dataAccessDto = dataAccessApi.getById(id).getData();
if (dataAccessDto.getIsDatax().equals("datax")){ return ScheduleJobEntity.builder()
feign.execute(dataAccessDto); .typeId(id)
.projectId(dataAccessDto.getProjectId())
.jobType(QuartzJobType.DATA_ACCESS.getValue())
.jobName(String.format("[%s]%s", id.toString(), dataAccessDto.getTaskName()))
.concurrent(ScheduleConcurrentEnum.NO.getValue())
.beanName("dataAccessTask")
.method("run")
.jobGroup(JobGroupEnum.DATA_ACCESS.getValue())
.saveLog(true)
.cronExpression(dataAccessDto.getCron())
.status(ScheduleStatusEnum.NORMAL.getValue())
.params(String.valueOf(id))
.once(TaskType.ONE_TIME_FULL_SYNC.getCode().equals(dataAccessDto.getTaskType()))
.build();
} }
return ScheduleJobEntity.builder().isDatax(dataAccessDto.getIsDatax()).typeId(id).projectId(dataAccessDto.getProjectId()).jobType(QuartzJobType.DATA_ACCESS.getValue()).jobName(String.format("[%s]%s", id.toString(), dataAccessDto.getTaskName())).concurrent(ScheduleConcurrentEnum.NO.getValue())
.beanName("dataAccessTask").method("run").jobGroup(JobGroupEnum.DATA_ACCESS.getValue()).saveLog(true).cronExpression(dataAccessDto.getCron()).status(ScheduleStatusEnum.NORMAL.getValue())
.params(String.valueOf(id)).once(TaskType.ONE_TIME_FULL_SYNC.getCode().equals(dataAccessDto.getTaskType())).build();
}
} }

View File

@ -1,6 +1,5 @@
package net.srt.quartz.utils; package net.srt.quartz.utils;
import net.srt.datax.feign.DataAccessFeign;
import net.srt.framework.common.exception.ServerException; import net.srt.framework.common.exception.ServerException;
import net.srt.quartz.entity.ScheduleJobEntity; import net.srt.quartz.entity.ScheduleJobEntity;
import net.srt.quartz.enums.ScheduleConcurrentEnum; import net.srt.quartz.enums.ScheduleConcurrentEnum;

View File

@ -11,7 +11,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -14,7 +14,7 @@ spring:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37 namespace: 9de208a6-cb30-41ae-a880-78196c99c050
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config:

View File

@ -9,6 +9,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import java.util.List; import java.util.List;
@ -16,6 +17,7 @@ import static com.alibaba.druid.sql.SQLUtils.toSQLString;
@EnableDiscoveryClient @EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
@EnableFeignClients
@MapperScan("net.srt.Fink.mapper") @MapperScan("net.srt.Fink.mapper")
@MapperScan("net.srt.Hadoop.mapper") @MapperScan("net.srt.Hadoop.mapper")
@MapperScan("net.srt.disposition.mapper") @MapperScan("net.srt.disposition.mapper")

View File

@ -0,0 +1,85 @@
package net.srt.disposition.controller;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import net.srt.disposition.dto.DataCheckSqlDto;
import net.srt.disposition.dto.DataSqlDto;
import net.srt.disposition.entity.DataCentre;
import net.srt.disposition.entity.DataCheckSqlEntity;
import net.srt.disposition.entity.DevelopmentOperationalRecordsQuery;
import net.srt.disposition.service.DataCenterService;
import net.srt.disposition.service.DataCheckSqlService;
import net.srt.disposition.vo.*;
import net.srt.flink.common.result.SqlExplainResult;
import net.srt.framework.common.page.PageResult;
import net.srt.framework.common.utils.Result;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
@RestController
@AllArgsConstructor
@RequestMapping("/task")
public class DataCheckSqlController {
private DataCheckSqlService dataCheckSqlService;
private DataCenterService dataCenterService;
@PostMapping
public Result add(@RequestBody DataCheckSqlDto dataCheckSqlDto){
dataCheckSqlService.add(dataCheckSqlDto);
return Result.ok();
}
@GetMapping("/history/page")
public Result<PageResult<DataCentre>> historyPage(@RequestBody DevelopmentOperationalRecordsQuery query){
PageResult<DataCentre> dataCentrePageResult= dataCenterService.dataCenterService(query);
return Result.ok(dataCentrePageResult);
}
@DeleteMapping("/history")
@Operation(summary = "运维中心删除")
public Result<PageResult<DevelopmentOperationalRecordsVo>> deleted(@RequestBody List<Long> ids){
dataCenterService.deleted(ids);
return Result.ok();
}
@GetMapping("/env-list")
@Operation(summary = "运维中心删除")
public Result<List<DevelopmentTaskSaveVo>> envList(){
List<DevelopmentTaskSaveVo> developmentTaskSaveVos = dataCenterService.listEnvList();
return Result.ok(developmentTaskSaveVos);
}
@GetMapping("/console-log")
public Result<LogVo> consoleLog(){
return Result.ok(dataCheckSqlService.getLog());
}
@GetMapping("/clear-log")
public Result checkLog(){
dataCheckSqlService.clearLog();
return Result.ok();
}
@PostMapping("/explain-sql")
public Result<List<SqlExplainResult>> explainSql(@RequestBody DataSqlDto dataSqlDto){
List<SqlExplainResult> dataSqlVo=dataCheckSqlService.explainSql(dataSqlDto);
return Result.ok(dataSqlVo);
}
@PostMapping("/execute-sql")
public Result<DataCheckVo> executeSql(@RequestBody DataSqlDto dataSqlDto){
DataCheckVo dataSqlVo=dataCheckSqlService.executeSql(dataSqlDto);
return Result.ok(dataSqlVo);
}
@GetMapping("/{id}")
public Result<DataCheckSqlEntity> get(@PathVariable Integer id) {
DataCheckSqlEntity dataCheckSqlEntity = dataCheckSqlService.find(id);
return Result.ok(dataCheckSqlEntity);
}
}

View File

@ -26,7 +26,7 @@ public class DataProductionTreeController {
} }
@PostMapping @PostMapping
public Result add(@RequestBody DataProductionTreeDto dataProductionTreeDto){ public Result<String> add(@RequestBody DataProductionTreeDto dataProductionTreeDto){
dataProductionService.add(dataProductionTreeDto); dataProductionService.add(dataProductionTreeDto);
return Result.ok(); return Result.ok();
} }

View File

@ -0,0 +1,18 @@
package net.srt.disposition.convert;
import net.srt.disposition.entity.DataCentre;
import net.srt.disposition.vo.DevelopmentTaskSaveVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DataCentreConvert {
DataCentreConvert INSTANCE = Mappers.getMapper(DataCentreConvert.class);
List<DataCentre> convertList(List<DataCentre> records);
List<DevelopmentTaskSaveVo> convert(List<DataCentre> entities);
}

View File

@ -0,0 +1,13 @@
package net.srt.disposition.convert;
import net.srt.disposition.dto.DataCheckSqlDto;
import net.srt.disposition.entity.DataCheckSqlEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface DataCheckSqlConvert {
DataCheckSqlConvert INSTANCE = Mappers.getMapper(DataCheckSqlConvert.class);
DataCheckSqlEntity convert(DataCheckSqlDto dataCheckSqlDto);
}

View File

@ -0,0 +1,24 @@
package net.srt.disposition.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import net.srt.disposition.entity.DataDatabaseDevEntity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
@Data
public class DataCheckSqlDto {
private String alias;
private Long catalogueId;
private Long databaseId;
private List<DataDatabaseDevEntity> databaseList;
private Integer dialect;
private Long id;
private String name;
private Integer openTrans;
private Integer pvdataNum;
private Integer sqlDbType;
private String statement;
}

View File

@ -0,0 +1,59 @@
package net.srt.disposition.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import net.srt.disposition.entity.DataDatabaseDevEntity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
@Data
public class DataSqlDto {
private Long alertGroupId;
private String alias;
private String batchModel;
private String checkPoint;
private Long clusterConfigurationId;
private Long clusterId;
private String configJson;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date creatTime;
private String creator;
private Long databaseId;
private List<DataDatabaseDevEntity> databaseList;
private String deleted;
private Integer dialect;
private String enabled;
private Long envId;
private String fragment;
private Long id;
private Long jarId;
private Long jobInstanceId;
private String jobName;
private Integer maxRowNum;
private String name;
private String note;
private Integer parallelism;
private boolean processEnd;
private Long projectId;
private Integer pvdataNum;
private String savePointPath;
private String savePointStrategy;
private Integer sqlDbType;
private String statement;
private String statementSet;
private String step;
private Integer taskId;
private String type;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updateTime;
private String updater;
private String usrAutoCancel;
private String usrChangeLog;
private String userResult;
private String version;
private Long versionId;
}

View File

@ -0,0 +1,23 @@
package net.srt.disposition.dto;
import lombok.Data;
import net.srt.disposition.entity.DataDatabaseDevEntity;
import java.util.List;
@Data
public class DataSqlSaveDto {
private String alias;
private Integer catalogueId;
private Integer databaseId;
private List<DataDatabaseDevEntity> databaseList;
private Integer dialect;
private Integer id;
private String name;
private Integer openTrans;
private boolean processEnd;
private Integer pvdataNum;
private Integer sqlDbType;
private String statement;
}

View File

@ -0,0 +1,58 @@
package net.srt.disposition.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@TableName("data_centre")
public class DataCentre {
private Long id;
private Long projectId;
private Integer sqlDbType;
private Long databaseId;
private Long clusterId;
private Long clusterConfigurationId;
private String session;
private Long jobId;
private String jobName;
private String jobManagerAddress;
private Integer status;
private Integer dialect;
private String type;
private String statement;
private String error;
private String result;
private String configJson;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date startTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endTime;
private Long taskId;
private String executeType;
private Long scheduleId;
private Long scheduleRecordId;
private Long scheduleNodeRecordId;
private Integer version;
private Integer deleted;
private String creator;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updateTime;@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date finishTime;
private String instanceStatus;
private String executeSql;
private String executeNo;
private String jib;
private Integer duration;
}

View File

@ -0,0 +1,58 @@
package net.srt.disposition.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
@TableName("data_check_sql")
public class DataCheckSqlEntity {
private Long id;
@TableId
private Long taskId;
private String name;
private Long projectId;
private String alias;
private Integer dialect;
private String type;
private Integer checkPoint;
private Integer savePointStrategy;
private String savePointPath;
private Integer parallelism;
private Boolean fragment;
private Boolean statementSet;
private Boolean batchModel;
private Long clusterId;
private Long clusterConfigurationId;
private Integer sqlDbType;
private Long databaseId;
private Integer openTrans;
private Long jarId;
private Long envId;
private Long alertGroupId;
private String configJson;
private String note;
private Integer step;
private Long jobInstanceId;
private Boolean useAutoCancel;
private Boolean useChangeLog;
private Boolean useResult;
private Integer pvdataNum;
private Boolean enabled;
private Long versionId;
private Integer version;
private Integer deleted;
private Long creator;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
private Long updater;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
private String statement;
}

View File

@ -0,0 +1,42 @@
package net.srt.disposition.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.srt.framework.mybatis.entity.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data
public class DataDatabaseDevEntity {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private String creator;
private String databaseDocument;
private String databaseIndex;
private String databaseIp;
private String databaseKafka;
private String databaseName;
private String databasePort;
private Integer databaseType;
private Integer deleted;
private Long id;
private String isJdbc;
private String isRtApprove;
private String jdbcUrl;
private String name;
private String noReReason;
private String password;
private Integer projectId;
private Integer status;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updateTime;
private String updater;
private String userName;
private Integer version;
}

Some files were not shown because too many files have changed in this diff Show More