666666
parent
079bf4a08e
commit
e511093a1e
|
@ -39,4 +39,6 @@ public interface ServerNames {
|
|||
*/
|
||||
String DATA_GOVERNANCE_NAME = "srt-cloud-data-governance";
|
||||
String DATA_DATAX = "srt-cloud-datax";
|
||||
|
||||
String DATA_SERVICE_NAME = "srt-cloud-data-service";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package net.srt.api.module.data.service;
|
||||
|
||||
import net.srt.api.ServerNames;
|
||||
import net.srt.api.module.data.service.dto.DataServiceApiAuthDto;
|
||||
import net.srt.api.module.data.service.dto.DataServiceApiConfigDto;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @ClassName DataAccessApi
|
||||
* @Author zrx
|
||||
* @Date 2022/10/26 11:39
|
||||
*/
|
||||
@FeignClient(name = ServerNames.DATA_SERVICE_NAME, contextId = "data-service-api")
|
||||
public interface DataServiceApi {
|
||||
/**
|
||||
* 根据id获取
|
||||
*/
|
||||
@GetMapping(value = "api/api-config/{id}")
|
||||
Result<DataServiceApiConfigDto> getById(@PathVariable Long id);
|
||||
|
||||
/**
|
||||
* 添加授权
|
||||
*/
|
||||
@PostMapping(value = "api/api-auth")
|
||||
Result<String> auth(@RequestBody DataServiceApiAuthDto apiAuthDto);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package net.srt.api;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.srt.api.module.data.governance.DataMetadataApi;
|
||||
import net.srt.api.module.data.governance.dto.DataGovernanceMetadataDto;
|
||||
import net.srt.convert.MetadataConvert;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.service.MetadataService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @BelongsProject: srt_cloud
|
||||
* @BelongsPackage: net.srt.api
|
||||
* @Author: jpz
|
||||
* @CreateTime: 2023/12/25 19:38
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class MetadataApiImpl implements DataMetadataApi {
|
||||
private final MetadataService metadataService;
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataDto> getById(Integer id) {
|
||||
return Result.ok(MetadataConvert.INSTANCE.convertDto(metadataService.getById(id)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
package net.srt.api;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.srt.api.module.data.governance.DataMetadataCollectApi;
|
||||
import net.srt.api.module.data.governance.constant.DbType;
|
||||
import net.srt.api.module.data.governance.dto.DataGovernanceMetadataCollectDto;
|
||||
import net.srt.api.module.data.governance.dto.DataGovernanceMetadataCollectRecordDto;
|
||||
import net.srt.api.module.data.governance.dto.DataGovernanceMetadataDto;
|
||||
import net.srt.api.module.data.governance.dto.DataGovernanceMetadataPropertyDto;
|
||||
import net.srt.convert.MetadataCollectConvert;
|
||||
import net.srt.convert.MetadataCollectRecordConvert;
|
||||
import net.srt.convert.MetadataConvert;
|
||||
import net.srt.convert.MetadataPropertyConvert;
|
||||
import net.srt.entity.MetadataCollectEntity;
|
||||
import net.srt.entity.MetadataCollectRecordEntity;
|
||||
import net.srt.entity.MetadataEntity;
|
||||
import net.srt.entity.MetadataPropertyEntity;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.service.MetadataCollectRecordService;
|
||||
import net.srt.service.MetadataCollectService;
|
||||
import net.srt.service.MetadataPropertyService;
|
||||
import net.srt.service.MetadataService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.nio.file.Watchable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @BelongsProject: srt_cloud
|
||||
* @BelongsPackage: net.srt.api
|
||||
* @Author: jpz
|
||||
* @CreateTime: 2023/12/25 19:45
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class MetadataCollectApiImpl implements DataMetadataCollectApi {
|
||||
private final MetadataService metadataService;
|
||||
private final MetadataCollectService metadataCollectService;
|
||||
private final MetadataCollectRecordService metadataCollectRecordService;
|
||||
private final MetadataPropertyService metadataPropertyService;
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataCollectDto> getById(Long id) {
|
||||
return Result.ok(MetadataCollectConvert.INSTANCE.convertDto(metadataCollectService.getById(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataGovernanceMetadataCollectRecordDto addCollectRecord(DataGovernanceMetadataCollectRecordDto collectRecordDto) {
|
||||
MetadataCollectRecordEntity convert = MetadataCollectRecordConvert.INSTANCE.convert(collectRecordDto);
|
||||
metadataCollectRecordService.save(convert);
|
||||
collectRecordDto.setId(convert.getId());
|
||||
return collectRecordDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upCollectRecord(DataGovernanceMetadataCollectRecordDto collectRecordDto) {
|
||||
metadataCollectRecordService.updateById(MetadataCollectRecordConvert.INSTANCE.convert(collectRecordDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataDto> getByParentIdAndDatasourceId(Long parnetId, Long datasourceId) {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper= Wrappers.lambdaQuery();
|
||||
wrapper.eq(MetadataEntity::getParentId,parnetId).eq(MetadataEntity::getDatasourceId,datasourceId).last("limit 1");
|
||||
return Result.ok(MetadataConvert.INSTANCE.convertDto(metadataService.getOne(wrapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataDto> getMetadataById(Long metadataId) {
|
||||
return Result.ok(MetadataConvert.INSTANCE.convertDto(metadataService.getById(metadataId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataDto> getByParentIdAndOtherInfo(Long parnetId, Long datasourceId, String code, Long metamodelId) {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(MetadataEntity::getParentId,parnetId).eq(datasourceId!=null,MetadataEntity::getDatasourceId,datasourceId)
|
||||
.eq(MetadataEntity::getCode,code)
|
||||
.eq(datasourceId==null,MetadataEntity::getDbType, DbType.MIDDLE_DB.getValue())
|
||||
.eq(MetadataEntity::getMetamodelId,metamodelId)
|
||||
.last("limit 1");
|
||||
return Result.ok(MetadataConvert.INSTANCE.convertDto(metadataService.getOne(wrapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataGovernanceMetadataDto addOrUpdateMetadata(DataGovernanceMetadataDto metadataDto) {
|
||||
MetadataEntity entity=MetadataConvert.INSTANCE.convert(metadataDto);
|
||||
if (metadataDto.getId()!=null){
|
||||
metadataService.updateById(entity);
|
||||
}else{
|
||||
metadataService.save(entity);
|
||||
}
|
||||
metadataDto.setId(entity.getId());
|
||||
return metadataDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataPropertyDto> getByPropertyIdAndMetadataId(Long propertyId, Long metadataId) {
|
||||
LambdaQueryWrapper<MetadataPropertyEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(MetadataPropertyEntity::getId,propertyId).eq(MetadataPropertyEntity::getMetadataId,metadataId).last("limit 1");
|
||||
return Result.ok(MetadataPropertyConvert.INSTANCE.convertDto(metadataPropertyService.getOne(wrapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOrUpdateMetadataProperty(DataGovernanceMetadataPropertyDto metadataPropertyDto) {
|
||||
if (metadataPropertyDto.getId()!=null){
|
||||
metadataPropertyService .save(MetadataPropertyConvert.INSTANCE.convert(metadataPropertyDto));
|
||||
}else {
|
||||
metadataPropertyService.updateById(MetadataPropertyConvert.INSTANCE.convert(metadataPropertyDto));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<DataGovernanceMetadataDto>> listParentIdAndDatasourceId(Long parentId, Long datasourceId, Long metamodelId) {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper= Wrappers.lambdaQuery();
|
||||
wrapper.eq(MetadataEntity::getParentId,parentId).eq(MetadataEntity::getDatasourceId,datasourceId).eq(MetadataEntity::getMetamodelId,metamodelId);
|
||||
return Result.ok(MetadataConvert.INSTANCE.convertDtoList(metadataService.list(wrapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMetadata(Long id) {
|
||||
metadataService.delete(id);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataCollectDto> getByDatasourceId(Long id) {
|
||||
LambdaQueryWrapper<MetadataCollectEntity> wrapper=Wrappers.lambdaQuery();
|
||||
wrapper.eq(MetadataCollectEntity::getDatabaseId,id).last("limit 1");
|
||||
return Result.ok(MetadataCollectConvert.INSTANCE.convertDto(metadataCollectService.getOne(wrapper)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DataGovernanceMetadataDto> getMetadataByDatasourceId(Long id) {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(MetadataEntity::getDatasourceId,id).last("limit 1");
|
||||
return Result.ok(MetadataConvert.INSTANCE.convertDto(metadataService.getOne(wrapper)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.srt.api;
|
||||
|
||||
/**
|
||||
* @BelongsProject: srt_cloud
|
||||
* @BelongsPackage: net.srt.api
|
||||
* @Author: jpz
|
||||
* @CreateTime: 2023/12/25 21:01
|
||||
*/
|
||||
public class QualityApiImpl {
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package net.srt.controller;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.framework.common.cache.bean.Neo4jInfo;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.framework.common.utils.TreeNode;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.service.MetadataService;
|
||||
import net.srt.vo.MetadataVO;
|
||||
|
@ -20,6 +22,12 @@ import java.util.List;
|
|||
public class MetadataController {
|
||||
private final MetadataService metadataService;
|
||||
|
||||
/**
|
||||
* 根据父级id获取子节点信息
|
||||
*
|
||||
* @param parentId 父级id
|
||||
* @return 子节点信息列表
|
||||
*/
|
||||
@GetMapping("/list-child")
|
||||
@Operation(summary = "根据父级id获取信息")
|
||||
public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){
|
||||
|
@ -27,6 +35,11 @@ public class MetadataController {
|
|||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取目录树
|
||||
* @return 目录树数据
|
||||
*/
|
||||
@GetMapping("/list-floder")
|
||||
@Operation(summary = "获取目录树")
|
||||
public Result<List<TreeNodeVo>> listFloder(){
|
||||
|
@ -34,6 +47,11 @@ public class MetadataController {
|
|||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取库表目录树
|
||||
* @return 结果包含库表目录树节点列表
|
||||
*/
|
||||
@GetMapping("/list-db")
|
||||
@Operation(summary = "获取库表目录树")
|
||||
public Result<List<TreeNodeVo>> listDb(){
|
||||
|
@ -41,6 +59,8 @@ public class MetadataController {
|
|||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/list-keyword")
|
||||
@Operation(summary = "模糊查询")
|
||||
public Result<List<TreeNodeVo>> listByKeyword(String keyword){
|
||||
|
|
|
@ -29,4 +29,5 @@ public interface MetadataService extends BaseService<MetadataEntity> {
|
|||
void upNeo4jInfo(Neo4jInfo neo4jInfo);
|
||||
|
||||
Neo4jInfo getNeo4jInfo();
|
||||
|
||||
}
|
||||
|
|
|
@ -180,6 +180,8 @@ public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEn
|
|||
return tokenStoreCache.getNeo4jInfo(getProjectId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void recursionAddParent(MetadataEntity metadataEntity, List<MetadataEntity> resultList){
|
||||
if(resultList.stream().noneMatch(item -> metadataEntity.getId().equals(item.getId()))) {
|
||||
resultList.add(metadataEntity);
|
||||
|
|
|
@ -11,12 +11,6 @@
|
|||
|
||||
<artifactId>srt-cloud-data-service</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>
|
||||
|
@ -34,15 +28,24 @@
|
|||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
<groupId>net.srt</groupId>
|
||||
<artifactId>srt-cloud-dbswitch</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jsqlparser</artifactId>
|
||||
<groupId>com.github.jsqlparser</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
|
@ -51,40 +54,10 @@
|
|||
<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>
|
||||
<dependency>
|
||||
<groupId>org.apache.ant</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -126,7 +99,7 @@
|
|||
<daemons>
|
||||
<daemon>
|
||||
<id>${project.artifactId}</id>
|
||||
<mainClass>net.srt.SystemApplication</mainClass>
|
||||
<mainClass>net.net.srt.DataServiceApplication</mainClass>
|
||||
<platforms>
|
||||
<platform>jsw</platform>
|
||||
</platforms>
|
||||
|
@ -181,7 +154,7 @@
|
|||
</daemons>
|
||||
<programs>
|
||||
<program>
|
||||
<mainClass>net.srt.SystemApplication</mainClass>
|
||||
<mainClass>net.net.srt.DataServiceApplication</mainClass>
|
||||
<id>${project.artifactId}</id>
|
||||
</program>
|
||||
</programs>
|
||||
|
@ -189,24 +162,24 @@
|
|||
</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>-->
|
||||
<!-- <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>
|
||||
|
@ -221,6 +194,5 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务微服务
|
||||
* 启动报 command too long 参考 https://blog.csdn.net/liumingzhe1/article/details/105413389?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-105413389-blog-122864040.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-105413389-blog-122864040.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=1
|
||||
* @author zrx 985134801@qq.com
|
||||
*/
|
||||
@EnableFeignClients
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class DataServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DataServiceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* @ClassName : ${NAME}
|
||||
* @Description : ${description}
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-22 20:44
|
||||
*/
|
||||
@EnableFeignClients
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class ServiceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package net.srt.api;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.srt.api.module.data.service.DataServiceApi;
|
||||
import net.srt.api.module.data.service.dto.DataServiceApiAuthDto;
|
||||
import net.srt.api.module.data.service.dto.DataServiceApiConfigDto;
|
||||
import net.srt.convert.DataServiceApiAuthConvert;
|
||||
import net.srt.convert.DataServiceApiConfigConvert;
|
||||
import net.srt.dao.DataServiceApiAuthDao;
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.service.DataServiceApiConfigService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @ClassName DataAccessApiImpl
|
||||
* @Author zrx
|
||||
* @Date 2022/10/26 11:50
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class DataServiceApiImpl implements DataServiceApi {
|
||||
|
||||
private final DataServiceApiConfigService apiConfigService;
|
||||
private final DataServiceApiAuthDao apiAuthDao;
|
||||
|
||||
@Override
|
||||
public Result<DataServiceApiConfigDto> getById(Long id) {
|
||||
return Result.ok(DataServiceApiConfigConvert.INSTANCE.convertDto(apiConfigService.getById(id)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> auth(DataServiceApiAuthDto apiAuthDto) {
|
||||
DataServiceApiConfigEntity apiConfigEntity = apiConfigService.getById(apiAuthDto.getApiId());
|
||||
apiAuthDto.setGroupId(apiConfigEntity.getGroupId());
|
||||
//判断是否存在
|
||||
LambdaQueryWrapper<DataServiceApiAuthEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(DataServiceApiAuthEntity::getAppId, apiAuthDto.getAppId()).eq(DataServiceApiAuthEntity::getApiId, apiAuthDto.getApiId()).last("LIMIT 1");
|
||||
DataServiceApiAuthEntity apiAuthEntity = apiAuthDao.selectOne(wrapper);
|
||||
if (apiAuthEntity != null) {
|
||||
if (!apiAuthDto.getHasActiveApply()) {
|
||||
//如果已经没有有效的申请,则删除该授权
|
||||
apiAuthDao.deleteById(apiAuthEntity.getId());
|
||||
} else {
|
||||
apiAuthDto.setId(apiAuthEntity.getId());
|
||||
apiAuthDao.updateById(DataServiceApiAuthConvert.INSTANCE.convertDto(apiAuthDto));
|
||||
}
|
||||
} else {
|
||||
apiAuthDao.insert(DataServiceApiAuthConvert.INSTANCE.convertDto(apiAuthDto));
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.srt.constant;
|
||||
|
||||
|
||||
/**
|
||||
* FlinkType
|
||||
*
|
||||
* @author zrx
|
||||
**/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.srt.constant;
|
||||
|
||||
|
||||
/**
|
||||
* FlinkType
|
||||
*
|
||||
* @author zrx
|
||||
**/
|
||||
public enum SqlDbType {
|
||||
|
||||
/**
|
||||
* 数据库
|
||||
*/
|
||||
DATABASE(1, "数据库"),
|
||||
/**
|
||||
* 数据库
|
||||
*/
|
||||
MIDDLE_DB(2, "数据库");
|
||||
|
||||
|
||||
private final Integer value;
|
||||
private final String longValue;
|
||||
|
||||
SqlDbType(Integer value, String longValue) {
|
||||
this.value = value;
|
||||
this.longValue = longValue;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getLongValue() {
|
||||
return longValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
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.convert.DataServiceApiConfigConvert;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.query.DataServiceApiConfigQuery;
|
||||
import net.srt.service.DataServiceApiConfigService;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import net.srt.vo.DataServiceApiConfigVO;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api-config")
|
||||
@Tag(name = "数据服务-api配置")
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiConfigController {
|
||||
private final DataServiceApiConfigService dataServiceApiConfigService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:page')")
|
||||
public Result<PageResult<DataServiceApiConfigVO>> page(@Valid DataServiceApiConfigQuery query) {
|
||||
PageResult<DataServiceApiConfigVO> page = dataServiceApiConfigService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("page-resource")
|
||||
@Operation(summary = "根据资源id获取挂载的api列表")
|
||||
public Result<PageResult<DataServiceApiConfigVO>> pageResource(@Valid DataServiceApiConfigQuery query) {
|
||||
PageResult<DataServiceApiConfigVO> page = dataServiceApiConfigService.pageResource(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
public Result<DataServiceApiConfigVO> get(@PathVariable("id") Long id) {
|
||||
DataServiceApiConfigEntity entity = dataServiceApiConfigService.getById(id);
|
||||
|
||||
return Result.ok(DataServiceApiConfigConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:save')")
|
||||
public Result<String> save(@RequestBody DataServiceApiConfigVO vo) {
|
||||
dataServiceApiConfigService.save(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:update')")
|
||||
public Result<String> update(@RequestBody @Valid DataServiceApiConfigVO vo) {
|
||||
dataServiceApiConfigService.update(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList) {
|
||||
dataServiceApiConfigService.delete(idList);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取服务的api前缀地址")
|
||||
@GetMapping("/getIpPort")
|
||||
public Result<String> getIpPort() {
|
||||
return Result.ok(dataServiceApiConfigService.getIpPort());
|
||||
}
|
||||
|
||||
@Operation(summary = "执行sql语句")
|
||||
@PostMapping("/sql/execute")
|
||||
public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto sqlDto) {
|
||||
return Result.ok(dataServiceApiConfigService.sqlExecute(sqlDto));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上线
|
||||
*/
|
||||
@Operation(summary = "上线")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:online')")
|
||||
@PutMapping(value = "/{id}/online")
|
||||
public Result<String> online(@PathVariable Long id) {
|
||||
dataServiceApiConfigService.online(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下线
|
||||
*/
|
||||
@Operation(summary = "下线")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:offline')")
|
||||
@PutMapping(value = "/{id}/offline")
|
||||
public Result<String> offline(@PathVariable Long id) {
|
||||
dataServiceApiConfigService.offline(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@GetMapping("page-auth")
|
||||
@Operation(summary = "获取授权分页")
|
||||
public Result<PageResult<DataServiceApiConfigVO>> pageAuth(@Valid DataServiceApiConfigQuery query) {
|
||||
PageResult<DataServiceApiConfigVO> page = dataServiceApiConfigService.pageAuth(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权信息
|
||||
*/
|
||||
@Operation(summary = "获取授权信息")
|
||||
@GetMapping(value = "/auth-info/{authId}")
|
||||
public Result<DataServiceApiAuthVO> getAuthInfo(@PathVariable Long authId) {
|
||||
return Result.ok(dataServiceApiConfigService.getAuthInfo(authId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出 api 文档
|
||||
*/
|
||||
@Operation(summary = "导出 api 文档")
|
||||
@PostMapping(value = "/export-docs")
|
||||
public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) {
|
||||
dataServiceApiConfigService.exportDocs(ids, response);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取服务的ip和端口号")
|
||||
@GetMapping("/ip-port")
|
||||
public Result<String> ipPort() {
|
||||
return Result.ok(dataServiceApiConfigService.ipPort());
|
||||
}
|
||||
|
||||
@Operation(summary = "重置授权的调用次数")
|
||||
@PutMapping("/reset-requested/{authId}")
|
||||
public Result<String> resetRequested(@PathVariable Long authId) {
|
||||
dataServiceApiConfigService.resetRequested(authId);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package net.srt.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@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));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
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.convert.DataServiceApiGroupConvert;
|
||||
import net.srt.entity.DataServiceApiGroupEntity;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.service.DataServiceApiGroupService;
|
||||
import net.srt.vo.DataServiceApiGroupVO;
|
||||
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")
|
||||
@Tag(name="数据服务-api分组")
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiGroupController {
|
||||
private final DataServiceApiGroupService dataServiceApiGroupService;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "查询分组树")
|
||||
public Result<List<TreeNodeVo>> listTree() {
|
||||
return Result.ok(dataServiceApiGroupService.listTree());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@GetMapping("list-api-tree")
|
||||
@Operation(summary = "查询分组树-带api")
|
||||
public Result<List<TreeNodeVo>> listTreeWithApi() {
|
||||
return Result.ok(dataServiceApiGroupService.listTreeWithApi());
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:info')")
|
||||
public Result<DataServiceApiGroupVO> get(@PathVariable("id") Long id){
|
||||
DataServiceApiGroupEntity entity = dataServiceApiGroupService.getById(id);
|
||||
|
||||
return Result.ok(DataServiceApiGroupConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:save')")
|
||||
public Result<String> save(@RequestBody DataServiceApiGroupVO vo){
|
||||
dataServiceApiGroupService.save(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:update')")
|
||||
public Result<String> update(@RequestBody @Valid DataServiceApiGroupVO vo){
|
||||
dataServiceApiGroupService.update(vo);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:delete')")
|
||||
public Result<String> delete(@PathVariable Long id){
|
||||
dataServiceApiGroupService.delete(id);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
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.service.DataServiceApiLogService;
|
||||
import net.srt.vo.DataServiceApiLogVO;
|
||||
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-02-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("log")
|
||||
@Tag(name="数据服务-api请求日志")
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiLogController {
|
||||
private final DataServiceApiLogService dataServiceApiLogService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('data-service:log:page')")
|
||||
public Result<PageResult<DataServiceApiLogVO>> page(@Valid DataServiceApiLogQuery query){
|
||||
PageResult<DataServiceApiLogVO> page = dataServiceApiLogService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('data-service:log:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
dataServiceApiLogService.delete(idList);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
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.convert.DataServiceAppConvert;
|
||||
import net.srt.entity.DataServiceAppEntity;
|
||||
|
@ -8,53 +9,63 @@ import net.srt.framework.common.page.PageResult;
|
|||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.query.DataServiceAppQuery;
|
||||
import net.srt.service.DataServiceAppService;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import net.srt.vo.DataServiceAppVO;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceAppController
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 08:53
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/app")
|
||||
@RequestMapping("app")
|
||||
@Tag(name="数据服务-app应用")
|
||||
@AllArgsConstructor
|
||||
public class DataServiceAppController {
|
||||
private final DataServiceAppService dataServiceAppService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
public Result<PageResult<DataServiceAppVo> > page(@Valid DataServiceAppQuery query) {
|
||||
PageResult<DataServiceAppVo> pageResult = dataServiceAppService.page(query);
|
||||
return Result.ok(pageResult);
|
||||
//@PreAuthorize("hasAuthority('data-service:app:page')")
|
||||
public Result<PageResult<DataServiceAppVO>> page(@Valid DataServiceAppQuery query){
|
||||
PageResult<DataServiceAppVO> page = dataServiceAppService.page(query);
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
public Result<DataServiceAppVo> get(@PathVariable("id") Long id){
|
||||
DataServiceAppEntity dataServiceAppEntity = dataServiceAppService.getById(id);
|
||||
return Result.ok(DataServiceAppConvert.INSTANCE.convert(dataServiceAppEntity));
|
||||
//@PreAuthorize("hasAuthority('data-service:app:info')")
|
||||
public Result<DataServiceAppVO> get(@PathVariable("id") Long id){
|
||||
DataServiceAppEntity entity = dataServiceAppService.getById(id);
|
||||
|
||||
return Result.ok(DataServiceAppConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
public Result<String> save(@RequestBody DataServiceAppVo vo){
|
||||
dataServiceAppService.save1(vo);
|
||||
//@PreAuthorize("hasAuthority('data-service:app:save')")
|
||||
public Result<String> save(@RequestBody DataServiceAppVO vo){
|
||||
dataServiceAppService.save(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
public Result<String> update(@RequestBody @Valid DataServiceAppVo vo){
|
||||
dataServiceAppService.update1(vo);
|
||||
//@PreAuthorize("hasAuthority('data-service:app:update')")
|
||||
public Result<String> update(@RequestBody @Valid DataServiceAppVO vo){
|
||||
dataServiceAppService.update(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
//@PreAuthorize("hasAuthority('data-service:app:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
dataServiceAppService.delete(idList);
|
||||
|
||||
|
@ -63,20 +74,23 @@ public class DataServiceAppController {
|
|||
|
||||
@PostMapping("/auth")
|
||||
@Operation(summary = "添加授权")
|
||||
public Result<String> addAuth(@RequestBody DataServiceAppVo authVO){
|
||||
@PreAuthorize("hasAuthority('data-service:app:auth')")
|
||||
public Result<String> addAuth(@RequestBody DataServiceApiAuthVO authVO){
|
||||
dataServiceAppService.addAuth(authVO);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping("/auth")
|
||||
@Operation(summary = "修改授权")
|
||||
public Result<String> upAuth(@RequestBody DataServiceAppVo authVO){
|
||||
@PreAuthorize("hasAuthority('data-service:app:auth')")
|
||||
public Result<String> upAuth(@RequestBody DataServiceApiAuthVO authVO){
|
||||
dataServiceAppService.upAuth(authVO);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping("/cancel-auth/{authId}")
|
||||
@Operation(summary = "取消授权")
|
||||
@PreAuthorize("hasAuthority('data-service:app:cancel-auth')")
|
||||
public Result<String> cancelAuth(@PathVariable Long authId){
|
||||
dataServiceAppService.cancelAuth(authId);
|
||||
return Result.ok();
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.api.module.data.service.dto.DataServiceApiAuthDto;
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-权限关联表
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiAuthConvert {
|
||||
DataServiceApiAuthConvert INSTANCE = Mappers.getMapper(DataServiceApiAuthConvert.class);
|
||||
|
||||
DataServiceApiAuthEntity convert(DataServiceApiAuthVO vo);
|
||||
|
||||
DataServiceApiAuthVO convert(DataServiceApiAuthEntity entity);
|
||||
|
||||
List<DataServiceApiAuthVO> convertList(List<DataServiceApiAuthEntity> list);
|
||||
|
||||
DataServiceApiAuthEntity convertDto(DataServiceApiAuthDto apiAuthDto);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.api.module.data.service.dto.DataServiceApiConfigDto;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.vo.DataServiceApiConfigVO;
|
||||
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 DataServiceApiConfigConvert {
|
||||
DataServiceApiConfigConvert INSTANCE = Mappers.getMapper(DataServiceApiConfigConvert.class);
|
||||
|
||||
DataServiceApiConfigEntity convert(DataServiceApiConfigVO vo);
|
||||
|
||||
DataServiceApiConfigVO convert(DataServiceApiConfigEntity entity);
|
||||
|
||||
DataServiceApiConfigDto convertDto(DataServiceApiConfigEntity entity);
|
||||
|
||||
List<DataServiceApiConfigVO> convertList(List<DataServiceApiConfigEntity> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.entity.DataServiceApiGroupEntity;
|
||||
import net.srt.vo.DataServiceApiGroupVO;
|
||||
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 DataServiceApiGroupConvert {
|
||||
DataServiceApiGroupConvert INSTANCE = Mappers.getMapper(DataServiceApiGroupConvert.class);
|
||||
|
||||
DataServiceApiGroupEntity convert(DataServiceApiGroupVO vo);
|
||||
|
||||
DataServiceApiGroupVO convert(DataServiceApiGroupEntity entity);
|
||||
|
||||
List<DataServiceApiGroupVO> convertList(List<DataServiceApiGroupEntity> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiLogConvert {
|
||||
DataServiceApiLogConvert INSTANCE = Mappers.getMapper(DataServiceApiLogConvert.class);
|
||||
|
||||
DataServiceApiLogEntity convert(DataServiceApiLogVO vo);
|
||||
|
||||
DataServiceApiLogVO convert(DataServiceApiLogEntity entity);
|
||||
|
||||
List<DataServiceApiLogVO> convertList(List<DataServiceApiLogEntity> list);
|
||||
|
||||
}
|
|
@ -1,25 +1,26 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.entity.DataServiceAppEntity;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
import net.srt.vo.DataServiceAppVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceAppConvert
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 09:06
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceAppConvert {
|
||||
DataServiceAppConvert INSTANCE = Mappers.getMapper(DataServiceAppConvert.class);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-权限关联表
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiAuthDao extends BaseDao<DataServiceApiAuthEntity> {
|
||||
|
||||
void increaseRequestedTimes(@Param("id") Long id);
|
||||
|
||||
void increaseRequestedSuccessTimes(Long id);
|
||||
|
||||
void increaseRequestedFailedTimes(Long id);
|
||||
|
||||
void resetRequested(Long authId);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiConfigDao extends BaseDao<DataServiceApiConfigEntity> {
|
||||
|
||||
List<DataServiceApiConfigEntity> getAuthList(Map<String, Object> params);
|
||||
|
||||
List<DataServiceApiConfigEntity> getResourceList(Map<String, Object> params);
|
||||
|
||||
void increaseRequestedTimes(@Param("id") Long id);
|
||||
|
||||
void increaseRequestedSuccessTimes(Long id);
|
||||
|
||||
void increaseRequestedFailedTimes(Long id);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.DataServiceApiGroupEntity;
|
||||
import net.srt.framework.mybatis.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiGroupDao extends BaseDao<DataServiceApiGroupEntity> {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.DataServiceApiLogEntity;
|
||||
import net.srt.framework.mybatis.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiLogDao extends BaseDao<DataServiceApiLogEntity> {
|
||||
|
||||
}
|
|
@ -6,12 +6,13 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceAppDao
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 08:59
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceAppDao extends BaseDao<DataServiceAppEntity> {
|
||||
|
||||
DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package net.srt.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* SqlDto
|
||||
*
|
||||
* @author zrx
|
||||
* @since 2021/12/29 19:42
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
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;
|
||||
}
|
|
@ -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;
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,75 @@
|
|||
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;
|
||||
|
||||
|
||||
/**
|
||||
* 数据服务-权限关联表
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@Data
|
||||
@TableName("data_service_api_auth1")
|
||||
public class DataServiceApiAuthEntity 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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package net.srt.entity;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
@TableName("data_service_api_config")
|
||||
public class DataServiceApiConfigEntity extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 分组id
|
||||
*/
|
||||
private Long groupId;
|
||||
|
||||
/**
|
||||
* api地址
|
||||
*/
|
||||
private String path;
|
||||
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String note;
|
||||
|
||||
/**
|
||||
* sql语句
|
||||
*/
|
||||
private String sqlText;
|
||||
|
||||
private String sqlSeparator;
|
||||
private Integer sqlMaxRow;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String sqlParam;
|
||||
|
||||
/**
|
||||
* application/json 类API对应的json参数示例
|
||||
*/
|
||||
private String jsonParam;
|
||||
private String responseResult;
|
||||
|
||||
/**
|
||||
* 参数类型
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 是否发布 0-否 1-是
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||
private Date releaseTime;
|
||||
@TableField(updateStrategy = FieldStrategy.IGNORED)
|
||||
private Long releaseUserId;
|
||||
|
||||
/**
|
||||
* 1-数据库 2-中台库
|
||||
*/
|
||||
private Integer sqlDbType;
|
||||
|
||||
/**
|
||||
* 数据库id
|
||||
*/
|
||||
private Long databaseId;
|
||||
|
||||
/**
|
||||
* 是否私有 0-否 1-是
|
||||
*/
|
||||
private Integer previlege;
|
||||
|
||||
/**
|
||||
* 是否开启事务 0-否 1-是
|
||||
*/
|
||||
private Integer openTrans;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 已调用次数
|
||||
*/
|
||||
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||
private Integer requestedTimes;
|
||||
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||
private Integer requestedSuccessTimes;
|
||||
@TableField(updateStrategy = FieldStrategy.NEVER)
|
||||
private Integer requestedFailedTimes;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Long authId;
|
||||
@TableField(exist = false)
|
||||
private String groupPath;
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package net.srt.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@Data
|
||||
@TableName("data_service_api_group")
|
||||
public class DataServiceApiGroupEntity extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 父级id(顶级为0)
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 1-文件夹 2-api目录
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 序号
|
||||
*/
|
||||
private Integer orderNo;
|
||||
|
||||
/**
|
||||
* 路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package net.srt.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
@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;
|
||||
|
||||
/**
|
||||
* app的id
|
||||
*/
|
||||
private Long appId;
|
||||
|
||||
/**
|
||||
* api的id
|
||||
*/
|
||||
private Long apiId;
|
||||
|
||||
private String appName;
|
||||
private String apiName;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String error;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,26 +1,21 @@
|
|||
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApppEntity
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 08:46
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@Data
|
||||
@TableName("data_service_app")
|
||||
public class DataServiceAppEntity extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
|
@ -62,4 +57,6 @@ public class DataServiceAppEntity extends BaseEntity {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package net.srt.handler;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName ResponseResult
|
||||
* @Author zrx
|
||||
* @Date 2023/2/15 12:41
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class ApiResult {
|
||||
private Boolean ifQuery;
|
||||
private String sql;
|
||||
private Long time;
|
||||
private Boolean success;
|
||||
private String errorMsg;
|
||||
private Integer affectedRows;
|
||||
private List<String> columns;
|
||||
private List<Map<String, Object>> rowData;
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package net.srt.handler;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MappingHandlerMapping {
|
||||
|
||||
public static final String API_PREFIX = "/api/";
|
||||
private static Map<String, DataServiceApiConfigEntity> mappings = new ConcurrentHashMap<>();
|
||||
private final RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||
private final MappingRequestHandler handler;
|
||||
private Method method;
|
||||
|
||||
{
|
||||
try {
|
||||
method = MappingRequestHandler.class.getDeclaredMethod(
|
||||
"invoke", HttpServletRequest.class, String.class, Map.class, Map.class, Map.class);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static DataServiceApiConfigEntity getMappingApiInfo(HttpServletRequest request) {
|
||||
NativeWebRequest webRequest = new ServletWebRequest(request);
|
||||
//获取请求路径
|
||||
String requestMapping = (String) webRequest.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
return getMappingApiInfo(buildMappingKey(request.getMethod(), requestMapping));
|
||||
}
|
||||
|
||||
public static DataServiceApiConfigEntity getMappingApiInfo(String key) {
|
||||
return mappings.get(key);
|
||||
}
|
||||
|
||||
public static String buildMappingKey(String requestMethod, String requestMapping) {
|
||||
return requestMethod.toUpperCase() + ":" + requestMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册请求映射
|
||||
*
|
||||
* @param api
|
||||
*/
|
||||
public void registerMapping(DataServiceApiConfigEntity api) {
|
||||
String mappingKey = getMappingKey(api);
|
||||
if (mappings.containsKey(mappingKey)) {
|
||||
// 取消注册
|
||||
mappings.remove(mappingKey);
|
||||
requestMappingHandlerMapping.unregisterMapping(getRequestMapping(api));
|
||||
}
|
||||
log.info("注册接口:{}", api.getName());
|
||||
RequestMappingInfo requestMapping = getRequestMapping(api);
|
||||
mappings.put(mappingKey, api);
|
||||
requestMappingHandlerMapping.registerMapping(requestMapping, handler, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消注册请求映射
|
||||
*
|
||||
* @param api
|
||||
*/
|
||||
public void unregisterMapping(DataServiceApiConfigEntity api) {
|
||||
log.info("取消注册接口:{}", api.getName());
|
||||
String mappingKey = getMappingKey(api);
|
||||
if (mappings.containsKey(mappingKey)) {
|
||||
// 取消注册
|
||||
mappings.remove(mappingKey);
|
||||
requestMappingHandlerMapping.unregisterMapping(getRequestMapping(api));
|
||||
}
|
||||
}
|
||||
|
||||
private String getMappingKey(DataServiceApiConfigEntity api) {
|
||||
return buildMappingKey(api.getType(), API_PREFIX + api.getPath());
|
||||
}
|
||||
|
||||
private RequestMappingInfo getRequestMapping(DataServiceApiConfigEntity api) {
|
||||
return RequestMappingInfo.paths(API_PREFIX + api.getPath()).methods(RequestMethod.valueOf(api.getType())).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,172 @@
|
|||
package net.srt.handler;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.srt.dao.DataServiceApiAuthDao;
|
||||
import net.srt.dao.DataServiceApiConfigDao;
|
||||
import net.srt.dao.DataServiceAppDao;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.entity.DataServiceApiLogEntity;
|
||||
import net.srt.entity.DataServiceAppEntity;
|
||||
import net.srt.flink.common.utils.JSONUtil;
|
||||
import net.srt.flink.common.utils.LogUtil;
|
||||
import net.srt.framework.common.exception.ErrorCode;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
import net.srt.framework.common.utils.IpUtils;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.service.DataServiceApiExecuteService;
|
||||
import net.srt.service.DataServiceApiLogService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MappingRequestHandler {
|
||||
|
||||
private final DataServiceApiConfigDao apiConfigDao;
|
||||
private final DataServiceApiExecuteService apiExecuteService;
|
||||
private final DataServiceApiAuthDao apiAuthDao;
|
||||
private final DataServiceAppDao appDao;
|
||||
private final DataServiceApiLogService apiLogService;
|
||||
|
||||
@SneakyThrows
|
||||
@ResponseBody
|
||||
public Object invoke(HttpServletRequest request,
|
||||
@RequestHeader(required = false) String apiToken,
|
||||
@PathVariable(required = false) Map<String, Object> pathVariables,
|
||||
@RequestParam(required = false) Map<String, Object> requestParams,
|
||||
@RequestBody(required = false) Map<String, Object> requestBodys) {
|
||||
DataServiceApiConfigEntity apiConfigEntity = null;
|
||||
DataServiceApiAuthEntity authEntity = null;
|
||||
//日志
|
||||
long now = System.currentTimeMillis();
|
||||
DataServiceApiLogEntity apiLogEntity = new DataServiceApiLogEntity();
|
||||
apiLogEntity.setUrl(request.getRequestURI());
|
||||
apiLogEntity.setIp(IpUtils.getIpAddr(request));
|
||||
apiLogEntity.setStatus(HttpStatus.OK.value());
|
||||
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (!CollectionUtils.isEmpty(pathVariables)) {
|
||||
log.info("pathVariables:{}", pathVariables.toString());
|
||||
params.putAll(pathVariables);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(requestParams)) {
|
||||
log.info("requestParams:{}", requestParams.toString());
|
||||
params.putAll(requestParams);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(requestBodys)) {
|
||||
log.info("requestBodys:{}", requestBodys.toString());
|
||||
params.putAll(requestBodys);
|
||||
}
|
||||
DataServiceApiConfigEntity mappingApiInfo = MappingHandlerMapping.getMappingApiInfo(request);
|
||||
//获取最新的api信息
|
||||
apiConfigEntity = apiConfigDao.selectById(mappingApiInfo.getId());
|
||||
Assert.notNull(apiConfigEntity, "api已被删除,调用失败");
|
||||
//日志
|
||||
apiLogEntity.setProjectId(apiConfigEntity.getProjectId());
|
||||
apiLogEntity.setApiId(apiConfigEntity.getId());
|
||||
apiLogEntity.setApiName(apiConfigEntity.getName());
|
||||
|
||||
if (!request.getMethod().equalsIgnoreCase(apiConfigEntity.getType())) {
|
||||
throw new ServerException(String.format("不支持的请求类型,请使用 【%s】方式请求", apiConfigEntity.getType()));
|
||||
}
|
||||
//如果是私有接口,鉴权
|
||||
if (apiConfigEntity.getPrevilege() == 1) {
|
||||
if (StringUtil.isBlank(apiToken)) {
|
||||
throw new ServerException("No Token!");
|
||||
}
|
||||
//检验token
|
||||
Long appId = apiExecuteService.verifyToken(apiToken);
|
||||
DataServiceAppEntity appEntity = appDao.selectById(appId);
|
||||
Assert.notNull(appEntity, "应用已被删除,调用失败");
|
||||
|
||||
//日志
|
||||
apiLogEntity.setAppId(appEntity.getId());
|
||||
apiLogEntity.setAppName(appEntity.getName());
|
||||
|
||||
LambdaQueryWrapper<DataServiceApiAuthEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiAuthEntity::getApiId, apiConfigEntity.getId()).eq(DataServiceApiAuthEntity::getAppId, appId).last(" limit 1");
|
||||
authEntity = apiAuthDao.selectOne(wrapper);
|
||||
if (authEntity == null) {
|
||||
throw new ServerException("API 未授权!");
|
||||
}
|
||||
//判断是否超过次数
|
||||
if (authEntity.getRequestTimes() != -1 && authEntity.getRequestedTimes() >= authEntity.getRequestTimes()) {
|
||||
throw new ServerException("API 已超出调用次数限制!");
|
||||
}
|
||||
//判断是否已过期
|
||||
if (authEntity.getStartTime() != null && authEntity.getStartTime().getTime() >= System.currentTimeMillis()) {
|
||||
throw new ServerException("API 不在有效期内,调用失败!");
|
||||
}
|
||||
if (authEntity.getEndTime() != null && authEntity.getEndTime().getTime() <= System.currentTimeMillis()) {
|
||||
throw new ServerException("API 不在有效期内,调用失败!");
|
||||
}
|
||||
}
|
||||
|
||||
JdbcSelectResult jdbcSelectResult = apiExecuteService.sqlExecute(SqlDto.builder().databaseId(apiConfigEntity.getDatabaseId())
|
||||
.jsonParams(JSONUtil.toJsonString(params))
|
||||
.openTrans(apiConfigEntity.getOpenTrans())
|
||||
.projectId(apiConfigEntity.getProjectId())
|
||||
.sqlDbType(apiConfigEntity.getSqlDbType())
|
||||
.sqlSeparator(apiConfigEntity.getSqlSeparator())
|
||||
.sqlMaxRow(apiConfigEntity.getSqlMaxRow())
|
||||
.statement(apiConfigEntity.getSqlText())
|
||||
.build());
|
||||
List<JdbcSelectResult> results = jdbcSelectResult.getResults();
|
||||
//有任何一条结果错误,则报错
|
||||
for (JdbcSelectResult result : results) {
|
||||
if (!result.getSuccess()) {
|
||||
throw new ServerException(result.getErrorMsg());
|
||||
}
|
||||
}
|
||||
JdbcSelectResult lastResult = results.isEmpty() ? null : results.get(results.size() - 1);
|
||||
apiConfigDao.increaseRequestedSuccessTimes(apiConfigEntity.getId());
|
||||
if (authEntity != null) {
|
||||
apiAuthDao.increaseRequestedSuccessTimes(authEntity.getId());
|
||||
}
|
||||
return Result.ok(lastResult != null ? ApiResult.builder().sql(lastResult.getSql()).ifQuery(lastResult.getIfQuery()).success(lastResult.getSuccess()).errorMsg(lastResult.getErrorMsg())
|
||||
.affectedRows(lastResult.getCount()).time(lastResult.getTime()).columns(lastResult.getColumns()).rowData(lastResult.getRowData()).build() : null);
|
||||
} catch (Exception e) {
|
||||
apiLogEntity.setStatus(ErrorCode.INTERNAL_SERVER_ERROR.getCode());
|
||||
apiLogEntity.setError(LogUtil.getError(e));
|
||||
if (apiConfigEntity != null) {
|
||||
//api失败调用次数++
|
||||
apiConfigDao.increaseRequestedFailedTimes(apiConfigEntity.getId());
|
||||
}
|
||||
if (authEntity != null) {
|
||||
//授权api失败调用次数++
|
||||
apiAuthDao.increaseRequestedFailedTimes(authEntity.getId());
|
||||
}
|
||||
throw new ServerException(e.getMessage());
|
||||
} finally {
|
||||
if (apiConfigEntity != null) {
|
||||
//api调用次数++
|
||||
apiConfigDao.increaseRequestedTimes(apiConfigEntity.getId());
|
||||
}
|
||||
if (authEntity != null) {
|
||||
//授权api调用次数++
|
||||
apiAuthDao.increaseRequestedTimes(authEntity.getId());
|
||||
}
|
||||
apiLogEntity.setDuration(System.currentTimeMillis() - now);
|
||||
//添加日志
|
||||
apiLogService.save(apiLogEntity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package net.srt.init;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.handler.MappingHandlerMapping;
|
||||
import net.srt.service.DataServiceApiConfigService;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName BusinessInitializer
|
||||
* @Author zrx
|
||||
* @Date 2022/11/27 12:14
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
public class BusinessInitializer implements ApplicationRunner {
|
||||
|
||||
private final DataServiceApiConfigService apiConfigService;
|
||||
private final MappingHandlerMapping mappingHandlerMapping;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("init api service");
|
||||
//初始化注册已发布的api
|
||||
List<DataServiceApiConfigEntity> apiConfigEntities = apiConfigService.listActive();
|
||||
for (DataServiceApiConfigEntity api : apiConfigEntities) {
|
||||
mappingHandlerMapping.registerMapping(api);
|
||||
}
|
||||
log.info("init api service end");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置查询
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(description = "数据服务-api配置查询")
|
||||
public class DataServiceApiConfigQuery 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 previlege;
|
||||
private Integer openTrans;
|
||||
private Integer queryApply;
|
||||
private Integer ifMarket;
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志查询
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(description = "数据服务-api请求日志查询")
|
||||
public class DataServiceApiLogQuery extends Query {
|
||||
private String ip;
|
||||
private String apiName;
|
||||
}
|
|
@ -6,14 +6,14 @@ import lombok.EqualsAndHashCode;
|
|||
import net.srt.framework.common.query.Query;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceAppQuery
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 08:51
|
||||
* 数据服务-app应用查询
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(defaultValue = "app权限")
|
||||
@Schema(description = "数据服务-app应用查询")
|
||||
public class DataServiceAppQuery extends Query {
|
||||
private String name;
|
||||
private String appKey;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package net.srt.service;
|
||||
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.query.DataServiceApiConfigQuery;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import net.srt.vo.DataServiceApiConfigVO;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
public interface DataServiceApiConfigService extends BaseService<DataServiceApiConfigEntity> {
|
||||
|
||||
PageResult<DataServiceApiConfigVO> page(DataServiceApiConfigQuery query);
|
||||
|
||||
PageResult<DataServiceApiConfigVO> pageResource(DataServiceApiConfigQuery query);
|
||||
|
||||
void save(DataServiceApiConfigVO vo);
|
||||
|
||||
void update(DataServiceApiConfigVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
String getIpPort();
|
||||
|
||||
JdbcSelectResult sqlExecute(SqlDto sqlDto);
|
||||
|
||||
void online(Long id);
|
||||
|
||||
void offline(Long id);
|
||||
|
||||
PageResult<DataServiceApiConfigVO> pageAuth(DataServiceApiConfigQuery query);
|
||||
|
||||
List<DataServiceApiConfigEntity> listActive();
|
||||
|
||||
List<DataServiceApiConfigEntity> listActiveByGroupId(Long id);
|
||||
|
||||
DataServiceApiAuthVO getAuthInfo(Long authId);
|
||||
|
||||
void exportDocs(List<Long> ids, HttpServletResponse response);
|
||||
|
||||
String ipPort();
|
||||
|
||||
void resetRequested(Long authId);
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package net.srt.service;
|
||||
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
public interface DataServiceApiExecuteService extends BaseService<DataServiceApiConfigEntity> {
|
||||
|
||||
JdbcSelectResult sqlExecute(SqlDto sqlDto);
|
||||
|
||||
Long verifyToken(String apiToken);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package net.srt.service;
|
||||
|
||||
import net.srt.entity.DataServiceApiGroupEntity;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.vo.DataServiceApiGroupVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
public interface DataServiceApiGroupService extends BaseService<DataServiceApiGroupEntity> {
|
||||
|
||||
void save(DataServiceApiGroupVO vo);
|
||||
|
||||
void update(DataServiceApiGroupVO vo);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
List<TreeNodeVo> listTree();
|
||||
|
||||
List<TreeNodeVo> listTreeWithApi();
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
public interface DataServiceApiLogService extends BaseService<DataServiceApiLogEntity> {
|
||||
|
||||
PageResult<DataServiceApiLogVO> page(DataServiceApiLogQuery query);
|
||||
|
||||
void save(DataServiceApiLogVO vo);
|
||||
|
||||
void update(DataServiceApiLogVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
}
|
|
@ -4,28 +4,32 @@ import net.srt.entity.DataServiceAppEntity;
|
|||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.query.DataServiceAppQuery;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import net.srt.vo.DataServiceAppVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceAppService
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 08:53
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
public interface DataServiceAppService extends BaseService<DataServiceAppEntity> {
|
||||
PageResult<DataServiceAppVo> page(DataServiceAppQuery query);
|
||||
|
||||
void save1(DataServiceAppVo vo);
|
||||
PageResult<DataServiceAppVO> page(DataServiceAppQuery query);
|
||||
|
||||
void update1(DataServiceAppVo vo);
|
||||
void save(DataServiceAppVO vo);
|
||||
|
||||
void update(DataServiceAppVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
void addAuth(DataServiceAppVo authVO);
|
||||
|
||||
void upAuth(DataServiceAppVo authVO);
|
||||
void addAuth(DataServiceApiAuthVO authVO);
|
||||
|
||||
void cancelAuth(Long authId);
|
||||
|
||||
String tokenGenerate(String appKey, String appSecret);
|
||||
|
||||
void upAuth(DataServiceApiAuthVO authVO);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,293 @@
|
|||
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.DataServiceApiAuthConvert;
|
||||
import net.srt.convert.DataServiceApiConfigConvert;
|
||||
import net.srt.dao.DataServiceApiAuthDao;
|
||||
import net.srt.dao.DataServiceApiConfigDao;
|
||||
import net.srt.dao.DataServiceApiGroupDao;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.entity.DataServiceApiGroupEntity;
|
||||
import net.srt.framework.common.constant.Constant;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
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.handler.MappingHandlerMapping;
|
||||
import net.srt.query.DataServiceApiConfigQuery;
|
||||
import net.srt.service.DataServiceApiConfigService;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import net.srt.vo.DataServiceApiConfigVO;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiConfigServiceImpl extends BaseServiceImpl<DataServiceApiConfigDao, DataServiceApiConfigEntity> implements DataServiceApiConfigService {
|
||||
|
||||
private final DiscoveryClient discoveryClient;
|
||||
private final DataServiceApiExecuteServiceImpl apiExecuteService;
|
||||
private final MappingHandlerMapping mappingHandlerMapping;
|
||||
private final DataServiceApiAuthDao apiAuthDao;
|
||||
private final DataServiceApiGroupDao dataServiceApiGroupDao;
|
||||
|
||||
@Override
|
||||
public PageResult<DataServiceApiConfigVO> page(DataServiceApiConfigQuery query) {
|
||||
IPage<DataServiceApiConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
||||
return new PageResult<>(DataServiceApiConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DataServiceApiConfigVO> pageResource(DataServiceApiConfigQuery query) {
|
||||
// 查询参数
|
||||
Map<String, Object> params = getParams(query);
|
||||
// 分页查询
|
||||
query.setOrder("dsac.id");
|
||||
IPage<DataServiceApiConfigEntity> page = getPage(query);
|
||||
params.put(Constant.PAGE, page);
|
||||
// 数据列表
|
||||
List<DataServiceApiConfigEntity> list = baseMapper.getResourceList(params);
|
||||
List<DataServiceApiConfigVO> dataServiceApiConfigVOS = DataServiceApiConfigConvert.INSTANCE.convertList(list);
|
||||
for (DataServiceApiConfigVO dataServiceApiConfigVO : dataServiceApiConfigVOS) {
|
||||
DataServiceApiGroupEntity groupEntity = dataServiceApiGroupDao.selectById(dataServiceApiConfigVO.getGroupId());
|
||||
dataServiceApiConfigVO.setGroup(groupEntity != null ? groupEntity.getPath() : null);
|
||||
}
|
||||
return new PageResult<>(dataServiceApiConfigVOS, page.getTotal());
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DataServiceApiConfigEntity> getWrapper(DataServiceApiConfigQuery query) {
|
||||
LambdaQueryWrapper<DataServiceApiConfigEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(query.getGroupId() != null, DataServiceApiConfigEntity::getGroupId, query.getGroupId())
|
||||
.like(StringUtil.isNotBlank(query.getName()), DataServiceApiConfigEntity::getName, query.getName())
|
||||
.like(StringUtil.isNotBlank(query.getPath()), DataServiceApiConfigEntity::getPath, query.getPath())
|
||||
.eq(StringUtil.isNotBlank(query.getContentType()), DataServiceApiConfigEntity::getContentType, query.getContentType())
|
||||
.eq(query.getStatus() != null, DataServiceApiConfigEntity::getStatus, query.getStatus())
|
||||
.eq(query.getSqlDbType() != null, DataServiceApiConfigEntity::getSqlDbType, query.getSqlDbType())
|
||||
.eq(query.getDatabaseId() != null, DataServiceApiConfigEntity::getDatabaseId, query.getDatabaseId())
|
||||
.eq(query.getPrevilege() != null, DataServiceApiConfigEntity::getPrevilege, query.getPrevilege())
|
||||
.eq(query.getOpenTrans() != null, DataServiceApiConfigEntity::getOpenTrans, query.getOpenTrans())
|
||||
.orderByDesc(DataServiceApiConfigEntity::getCreateTime).orderByDesc(DataServiceApiConfigEntity::getId);
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataServiceApiConfigVO vo) {
|
||||
DataServiceApiConfigEntity entity = DataServiceApiConfigConvert.INSTANCE.convert(vo);
|
||||
entity.setProjectId(getProjectId());
|
||||
//判断路径是否重复
|
||||
DataServiceApiConfigEntity one = getOneByPath(vo);
|
||||
if (one != null) {
|
||||
throw new ServerException(String.format("已存在路径为【%s】的 API 【%s】,路径不可重复!", one.getPath(), one.getName()));
|
||||
}
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DataServiceApiConfigVO vo) {
|
||||
DataServiceApiConfigEntity entity = DataServiceApiConfigConvert.INSTANCE.convert(vo);
|
||||
entity.setProjectId(getProjectId());
|
||||
DataServiceApiConfigEntity dbEntity = getById(vo.getId());
|
||||
DataServiceApiConfigEntity one = getOneByPath(vo);
|
||||
if (one != null && !dbEntity.getPath().equals(one.getPath())) {
|
||||
throw new ServerException(String.format("已存在路径为【%s】的 API 【%s】,路径不可重复!", one.getPath(), one.getName()));
|
||||
}
|
||||
if (entity.getStatus() == 0) {
|
||||
entity.setReleaseTime(null);
|
||||
entity.setReleaseUserId(null);
|
||||
}
|
||||
updateById(entity);
|
||||
//如果服务已上线,先下线,再上线
|
||||
if (entity.getStatus() == 1) {
|
||||
mappingHandlerMapping.unregisterMapping(dbEntity);
|
||||
mappingHandlerMapping.registerMapping(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private DataServiceApiConfigEntity getOneByPath(DataServiceApiConfigVO vo) {
|
||||
LambdaQueryWrapper<DataServiceApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiConfigEntity::getPath, vo.getPath()).last(" limit 1");
|
||||
return baseMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
//同步删除授权信息
|
||||
for (Long apiId : idList) {
|
||||
LambdaQueryWrapper<DataServiceApiAuthEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiAuthEntity::getApiId, apiId);
|
||||
apiAuthDao.delete(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@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/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcSelectResult sqlExecute(SqlDto sqlDto) {
|
||||
return apiExecuteService.sqlExecute(sqlDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void online(Long id) {
|
||||
//注册接口
|
||||
DataServiceApiConfigEntity apiConfigEntity = getById(id);
|
||||
mappingHandlerMapping.registerMapping(apiConfigEntity);
|
||||
//更新状态
|
||||
apiConfigEntity.setStatus(1);
|
||||
apiConfigEntity.setReleaseTime(new Date());
|
||||
apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
|
||||
baseMapper.updateById(apiConfigEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offline(Long id) {
|
||||
DataServiceApiConfigEntity apiConfigEntity = getById(id);
|
||||
mappingHandlerMapping.unregisterMapping(apiConfigEntity);
|
||||
//更新状态
|
||||
apiConfigEntity.setStatus(0);
|
||||
apiConfigEntity.setReleaseTime(null);
|
||||
apiConfigEntity.setReleaseUserId(null);
|
||||
baseMapper.updateById(apiConfigEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DataServiceApiConfigVO> pageAuth(DataServiceApiConfigQuery query) {
|
||||
// 查询参数
|
||||
Map<String, Object> params = getParams(query);
|
||||
// 分页查询
|
||||
query.setOrder("dsac.id");
|
||||
IPage<DataServiceApiConfigEntity> page = getPage(query);
|
||||
params.put(Constant.PAGE, page);
|
||||
// 数据列表
|
||||
List<DataServiceApiConfigEntity> list = baseMapper.getAuthList(params);
|
||||
return new PageResult<>(DataServiceApiConfigConvert.INSTANCE.convertList(list), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataServiceApiConfigEntity> listActive() {
|
||||
LambdaQueryWrapper<DataServiceApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiConfigEntity::getStatus, 1);
|
||||
return baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataServiceApiConfigEntity> listActiveByGroupId(Long id) {
|
||||
LambdaQueryWrapper<DataServiceApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiConfigEntity::getStatus, 1).eq(DataServiceApiConfigEntity::getGroupId, id).orderByDesc(DataServiceApiConfigEntity::getId);
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
return baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataServiceApiAuthVO getAuthInfo(Long authId) {
|
||||
return DataServiceApiAuthConvert.INSTANCE.convert(apiAuthDao.selectById(authId));
|
||||
}
|
||||
|
||||
@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<DataServiceApiConfigEntity> apiConfigEntities = baseMapper.selectBatchIds(ids);
|
||||
for (DataServiceApiConfigEntity 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.getPrevilege() == 1 ? "是" : "否");
|
||||
if (api.getPrevilege() == 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 String ipPort() {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||
return instances.get(0).getHost() + ":" + instances.get(0).getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetRequested(Long authId) {
|
||||
apiAuthDao.resetRequested(authId);
|
||||
}
|
||||
|
||||
private Map<String, Object> getParams(DataServiceApiConfigQuery 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("previlege", query.getPrevilege());
|
||||
params.put("openTrans", query.getOpenTrans());
|
||||
// 数据权限
|
||||
params.put(Constant.DATA_SCOPE, getDataScope("dsac", null, null, "project_id", false, true));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package net.srt.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.api.module.data.integrate.DataDatabaseApi;
|
||||
import net.srt.api.module.data.integrate.dto.DataDatabaseDto;
|
||||
import net.srt.constant.SqlDbType;
|
||||
import net.srt.dao.DataServiceApiConfigDao;
|
||||
import net.srt.dto.AppToken;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.flink.common.utils.JSONUtil;
|
||||
import net.srt.flink.process.context.ProcessContextHolder;
|
||||
import net.srt.framework.common.cache.RedisCache;
|
||||
import net.srt.framework.common.cache.RedisKeys;
|
||||
import net.srt.framework.common.cache.bean.DataProjectCacheBean;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.srt.service.DataServiceApiExecuteService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import srt.cloud.framework.dbswitch.common.type.ProductTypeEnum;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
import srt.cloud.framework.dbswitch.core.service.IMetaDataByJdbcService;
|
||||
import srt.cloud.framework.dbswitch.core.service.impl.MetaDataByJdbcServiceImpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiExecuteServiceImpl extends BaseServiceImpl<DataServiceApiConfigDao, DataServiceApiConfigEntity> implements DataServiceApiExecuteService {
|
||||
|
||||
private final DataDatabaseApi dataDatabaseApi;
|
||||
private final RedisCache redisCache;
|
||||
|
||||
public JdbcSelectResult sqlExecute(SqlDto sqlDto) {
|
||||
Map<String, Object> sqlParam = JSONUtil.parseObject(sqlDto.getJsonParams(), new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
boolean ifMiddleDb = SqlDbType.MIDDLE_DB.getValue().equals(sqlDto.getSqlDbType());
|
||||
DataDatabaseDto database;
|
||||
if (ifMiddleDb) {
|
||||
DataProjectCacheBean project = sqlDto.getProjectId() == null ? getProject() : getProject(sqlDto.getProjectId());
|
||||
database = new DataDatabaseDto();
|
||||
database.setDatabaseName(project.getDbName());
|
||||
database.setJdbcUrl(project.getDbUrl());
|
||||
database.setUserName(project.getDbUsername());
|
||||
database.setPassword(project.getDbPassword());
|
||||
database.setDatabaseType(project.getDbType());
|
||||
} else {
|
||||
database = dataDatabaseApi.getById(sqlDto.getDatabaseId()).getData();
|
||||
}
|
||||
try {
|
||||
// zrx
|
||||
ProductTypeEnum productTypeEnum = ProductTypeEnum.getByIndex(database.getDatabaseType());
|
||||
IMetaDataByJdbcService metaDataService = new MetaDataByJdbcServiceImpl(productTypeEnum);
|
||||
String jdbcUrl = database.getJdbcUrl();
|
||||
String userName = database.getUserName();
|
||||
String password = database.getPassword();
|
||||
return metaDataService.queryDataByApiSql(jdbcUrl, userName, password, sqlDto.getStatement(), sqlDto.getOpenTrans(), sqlDto.getSqlSeparator(), sqlParam, sqlDto.getSqlMaxRow());
|
||||
} finally {
|
||||
ProcessContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long verifyToken(String apiToken) {
|
||||
AppToken appToken = JSONUtil.parseObject((String) redisCache.get(RedisKeys.getAppTokenKey(apiToken)), AppToken.class);
|
||||
if (appToken == null) {
|
||||
throw new ServerException("token 不合法!");
|
||||
}
|
||||
Long expireTime = appToken.getExpireAt();
|
||||
// 单次失效
|
||||
if (expireTime == 0) {
|
||||
redisCache.delete(apiToken);
|
||||
return appToken.getAppId();
|
||||
}
|
||||
// 永久有效
|
||||
else if (expireTime == -1) {
|
||||
return appToken.getAppId();
|
||||
}
|
||||
// 设置了有效的失效时间
|
||||
else {
|
||||
if (expireTime > System.currentTimeMillis()) {
|
||||
return appToken.getAppId();
|
||||
} else {
|
||||
// token已经过期就清除
|
||||
redisCache.delete(apiToken);
|
||||
throw new ServerException("token 已过期!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package net.srt.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.constant.ApiGroupType;
|
||||
import net.srt.convert.DataServiceApiGroupConvert;
|
||||
import net.srt.dao.DataServiceApiGroupDao;
|
||||
import net.srt.entity.DataServiceApiConfigEntity;
|
||||
import net.srt.entity.DataServiceApiGroupEntity;
|
||||
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.DataServiceApiConfigService;
|
||||
import net.srt.service.DataServiceApiGroupService;
|
||||
import net.srt.vo.DataServiceApiGroupVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiGroupServiceImpl extends BaseServiceImpl<DataServiceApiGroupDao, DataServiceApiGroupEntity> implements DataServiceApiGroupService {
|
||||
|
||||
private final DataServiceApiConfigService apiConfigService;
|
||||
|
||||
@Override
|
||||
public void save(DataServiceApiGroupVO vo) {
|
||||
DataServiceApiGroupEntity entity = DataServiceApiGroupConvert.INSTANCE.convert(vo);
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
entity.setProjectId(getProjectId());
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DataServiceApiGroupVO vo) {
|
||||
DataServiceApiGroupEntity entity = DataServiceApiGroupConvert.INSTANCE.convert(vo);
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
entity.setProjectId(getProjectId());
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
private String recursionPath(DataServiceApiGroupEntity groupEntity, String path) {
|
||||
if (StringUtil.isBlank(path)) {
|
||||
path = groupEntity.getName();
|
||||
}
|
||||
if (groupEntity.getParentId() != 0) {
|
||||
DataServiceApiGroupEntity parent = getById(groupEntity.getParentId());
|
||||
path = parent.getName() + "/" + path;
|
||||
return recursionPath(parent, path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
//查询有没有子节点
|
||||
LambdaQueryWrapper<DataServiceApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiGroupEntity::getParentId, id).last(" limit 1");
|
||||
DataServiceApiGroupEntity one = baseMapper.selectOne(wrapper);
|
||||
if (one != null) {
|
||||
throw new ServerException("存在子节点,不允许删除!");
|
||||
}
|
||||
//查询有没有api与之关联
|
||||
LambdaQueryWrapper<DataServiceApiConfigEntity> serviceApiConfigWrapper = new LambdaQueryWrapper<>();
|
||||
serviceApiConfigWrapper.eq(DataServiceApiConfigEntity::getGroupId, id).last(" limit 1");
|
||||
DataServiceApiConfigEntity apiConfigEntity = apiConfigService.getOne(serviceApiConfigWrapper);
|
||||
if (apiConfigEntity != null) {
|
||||
throw new ServerException("节点下有 api 与之关联,不允许删除!");
|
||||
}
|
||||
removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNodeVo> listTree() {
|
||||
List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
|
||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
}
|
||||
|
||||
private List<TreeNodeVo> getTreeNodeVos() {
|
||||
LambdaQueryWrapper<DataServiceApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
wrapper.orderByAsc(DataServiceApiGroupEntity::getOrderNo);
|
||||
List<DataServiceApiGroupEntity> apiGroupEntities = baseMapper.selectList(wrapper);
|
||||
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("/")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNodeVo> listTreeWithApi() {
|
||||
List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
|
||||
List<TreeNodeVo> treeNodeVosWithApi = new ArrayList<>();
|
||||
for (TreeNodeVo treeNodeVo : treeNodeVos) {
|
||||
treeNodeVosWithApi.add(treeNodeVo);
|
||||
if (ApiGroupType.API.getValue().equals(treeNodeVo.getType())) {
|
||||
//查询底下已发布的api
|
||||
List<DataServiceApiConfigEntity> apis = apiConfigService.listActiveByGroupId(treeNodeVo.getId());
|
||||
for (DataServiceApiConfigEntity api : apis) {
|
||||
TreeNodeVo apiNode = new TreeNodeVo();
|
||||
apiNode.setId(api.getId());
|
||||
apiNode.setParentId(treeNodeVo.getId());
|
||||
apiNode.setParentPath(treeNodeVo.getPath());
|
||||
apiNode.setOrderNo(api.getId().intValue());
|
||||
apiNode.setLabel(api.getName());
|
||||
apiNode.setName(api.getName());
|
||||
treeNodeVosWithApi.add(apiNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return BuildTreeUtils.buildTree(treeNodeVosWithApi);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
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 org.springframework.transaction.annotation.Transactional;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiLogServiceImpl extends BaseServiceImpl<DataServiceApiLogDao, DataServiceApiLogEntity> implements DataServiceApiLogService {
|
||||
|
||||
@Override
|
||||
public PageResult<DataServiceApiLogVO> page(DataServiceApiLogQuery query) {
|
||||
IPage<DataServiceApiLogEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
||||
return new PageResult<>(DataServiceApiLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataServiceApiLogVO vo) {
|
||||
DataServiceApiLogEntity entity = DataServiceApiLogConvert.INSTANCE.convert(vo);
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DataServiceApiLogVO vo) {
|
||||
DataServiceApiLogEntity entity = DataServiceApiLogConvert.INSTANCE.convert(vo);
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,81 +4,188 @@ 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.DataServiceApiAuthConvert;
|
||||
import net.srt.convert.DataServiceAppConvert;
|
||||
import net.srt.dao.DataServiceApiAuthDao;
|
||||
import net.srt.dao.DataServiceAppDao;
|
||||
import net.srt.dto.AppToken;
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.entity.DataServiceAppEntity;
|
||||
import net.srt.flink.common.utils.JSONUtil;
|
||||
import net.srt.framework.common.cache.RedisCache;
|
||||
import net.srt.framework.common.cache.RedisKeys;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
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.DataServiceAppQuery;
|
||||
import net.srt.service.DataServiceAppService;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
import net.srt.vo.DataServiceApiAuthVO;
|
||||
import net.srt.vo.DataServiceAppVO;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceAppServiceImpl
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-23 08:53
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao, DataServiceAppEntity> implements DataServiceAppService {
|
||||
private final DataServiceAppDao dataServiceAppDao;
|
||||
|
||||
private final DataServiceApiAuthDao apiAuthDao;
|
||||
private final RedisCache redisCache;
|
||||
|
||||
@Override
|
||||
public PageResult<DataServiceAppVo> page(DataServiceAppQuery query) {
|
||||
IPage<DataServiceAppEntity> page=baseMapper.selectPage(getPage(query),null);
|
||||
public PageResult<DataServiceAppVO> page(DataServiceAppQuery query) {
|
||||
if (query.getApplyId() != null) {
|
||||
DataServiceAppEntity dataServiceAppEntity = baseMapper.selectByApplyId(query.getApplyId());
|
||||
List<DataServiceAppEntity> list = new ArrayList<>(1);
|
||||
if (dataServiceAppEntity != null) {
|
||||
list.add(dataServiceAppEntity);
|
||||
return new PageResult<>(DataServiceAppConvert.INSTANCE.convertList(list), 1);
|
||||
}
|
||||
return new PageResult<>(new ArrayList<>(), 0);
|
||||
}
|
||||
IPage<DataServiceAppEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
||||
return new PageResult<>(DataServiceAppConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DataServiceAppEntity> getWrapper(DataServiceAppQuery query) {
|
||||
LambdaQueryWrapper<DataServiceAppEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StringUtil.isNotBlank(query.getName()), DataServiceAppEntity::getName, query.getName())
|
||||
.eq(DataServiceAppEntity::getIfMarket, query.getIfMarket() != null ? query.getIfMarket() : 0)
|
||||
.eq(query.getIfMarket() != null, DataServiceAppEntity::getCreator, SecurityUser.getUserId())
|
||||
.eq(StringUtil.isNotBlank(query.getAppKey()), DataServiceAppEntity::getAppKey, query.getAppKey())
|
||||
.orderByDesc(DataServiceAppEntity::getCreateTime).orderByDesc(DataServiceAppEntity::getId);
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save1(DataServiceAppVo vo) {
|
||||
public void save(DataServiceAppVO vo) {
|
||||
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
|
||||
buildApp(app);
|
||||
baseMapper.insert(app);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void update1(DataServiceAppVo vo) {
|
||||
public void update(DataServiceAppVO vo) {
|
||||
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
|
||||
buildApp(app);
|
||||
updateById(app);
|
||||
}
|
||||
|
||||
private void buildApp(DataServiceAppEntity app) {
|
||||
app.setProjectId(getProjectId());
|
||||
if (app.getId() == null) {
|
||||
app.setAppKey(RandomStringUtils.random(16, true, true));
|
||||
app.setAppSecret(RandomStringUtils.random(32, true, true));
|
||||
}
|
||||
switch (app.getExpireDesc()) {
|
||||
case "10min":
|
||||
app.setExpireDuration(10 * 60L);
|
||||
break;
|
||||
case "1hour":
|
||||
app.setExpireDuration(60 * 60L);
|
||||
break;
|
||||
case "1day":
|
||||
app.setExpireDuration(60 * 60 * 24L);
|
||||
break;
|
||||
case "30day":
|
||||
app.setExpireDuration(60 * 60 * 24 * 30L);
|
||||
break;
|
||||
case "once":
|
||||
app.setExpireDuration(0L);
|
||||
break;
|
||||
case "forever":
|
||||
app.setExpireDuration(-1L);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
//判断是否有app授权与之关联
|
||||
for (Long appId : idList) {
|
||||
LambdaQueryWrapper<DataServiceApiAuthEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceApiAuthEntity::getAppId, appId).last(" limit 1");
|
||||
DataServiceApiAuthEntity authEntity = apiAuthDao.selectOne(wrapper);
|
||||
if (authEntity != null) {
|
||||
throw new ServerException("该应用下有与之关联授权的 api,不可删除!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAuth(DataServiceAppVo authVO) {
|
||||
public void addAuth(DataServiceApiAuthVO authVO) {
|
||||
authVO.setProjectId(getProjectId());
|
||||
dataServiceAppDao.insert(DataServiceAppConvert.INSTANCE.convert(authVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upAuth(DataServiceAppVo authVO) {
|
||||
dataServiceAppDao.updateById(DataServiceAppConvert.INSTANCE.convert(authVO));
|
||||
apiAuthDao.insert(DataServiceApiAuthConvert.INSTANCE.convert(authVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAuth(Long authId) {
|
||||
dataServiceAppDao.deleteById(authId);
|
||||
apiAuthDao.deleteById(authId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tokenGenerate(String appKey, String appSecret) {
|
||||
LambdaQueryWrapper<DataServiceAppEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataServiceAppEntity::getAppKey, appKey).last(" limit 1");
|
||||
DataServiceAppEntity appEntity = baseMapper.selectOne(wrapper);
|
||||
if (appEntity == null) {
|
||||
throw new ServerException("appKey 不存在!");
|
||||
}
|
||||
if (!appSecret.equals(appEntity.getAppSecret())) {
|
||||
throw new ServerException("密钥有误,请检查!");
|
||||
}
|
||||
//生成token
|
||||
String token = RandomStringUtils.random(32, true, true);
|
||||
AppToken appToken = new AppToken();
|
||||
appToken.setToken(token);
|
||||
appToken.setAppKey(appKey);
|
||||
appToken.setAppId(appEntity.getId());
|
||||
//单次失效
|
||||
if (appEntity.getExpireDuration() == 0) {
|
||||
appToken.setExpireAt(0L);
|
||||
}
|
||||
// 永久有效
|
||||
else if (appEntity.getExpireDuration() == -1) {
|
||||
appToken.setExpireAt(-1L);
|
||||
}
|
||||
// 设置了有效的失效时间
|
||||
else if (appEntity.getExpireDuration() > 0) {
|
||||
long expireAt = System.currentTimeMillis() + appEntity.getExpireDuration() * 1000;
|
||||
appToken.setExpireAt(expireAt);
|
||||
}
|
||||
|
||||
redisCache.set(RedisKeys.getAppTokenKey(token), JSONUtil.toJsonString(appToken), RedisCache.NOT_EXPIRE);
|
||||
|
||||
//clean old token
|
||||
String oldToken = (String) redisCache.get(RedisKeys.getAppIdKey(appEntity.getId()));
|
||||
if (StringUtil.isNotBlank(oldToken)) {
|
||||
redisCache.delete(RedisKeys.getAppTokenKey(oldToken));
|
||||
}
|
||||
//appid和最新token关系记录下来,便于下次可以找到旧token可以删除,否则缓存中token越来越多
|
||||
redisCache.set(RedisKeys.getAppIdKey(appEntity.getId()), token, RedisCache.NOT_EXPIRE);
|
||||
|
||||
return appToken.getToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upAuth(DataServiceApiAuthVO authVO) {
|
||||
apiAuthDao.updateById(DataServiceApiAuthConvert.INSTANCE.convert(authVO));
|
||||
}
|
||||
|
||||
|
||||
// private LambdaQueryWrapper<DataServiceAppEntity> getWrapper(DataServiceAppQuery query) {
|
||||
// LambdaQueryWrapper<DataServiceAppEntity> wrapper = Wrappers.lambdaQuery();
|
||||
// wrapper.like(StringUtil.isNotBlank(query.getName()), DataServiceAppEntity::getName, query.getName())
|
||||
// .eq(DataServiceAppEntity::getIfMarket, query.getIfMarket() != null ? query.getIfMarket() : 0)
|
||||
// .eq(query.getIfMarket() != null, DataServiceAppEntity::getCreator, SecurityUser.getUserId())
|
||||
// .eq(StringUtil.isNotBlank(query.getAppKey()), DataServiceAppEntity::getAppKey, query.getAppKey())
|
||||
// .orderByDesc(DataServiceAppEntity::getCreateTime).orderByDesc(DataServiceAppEntity::getId);
|
||||
// return wrapper;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-权限关联表
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "数据服务-权限关联表")
|
||||
public class DataServiceApiAuthVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "app的id")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "分组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "api的id")
|
||||
private Long apiId;
|
||||
|
||||
@Schema(description = "调用次数 不限次数为-1")
|
||||
private Integer requestTimes;
|
||||
|
||||
@Schema(description = "已调用次数")
|
||||
private Integer requestedTimes;
|
||||
private Integer requestedSuccessTimes;
|
||||
private Integer requestedFailedTimes;
|
||||
|
||||
@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;
|
||||
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date startTime;
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date endTime;
|
||||
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
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 : DataServiceApiAuthVo
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-24 11:29
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "数据服务-权限关联表")
|
||||
public class DataServiceApiAuthVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "app的id")
|
||||
private Long appId;
|
||||
|
||||
@Schema(description = "分组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "api的id")
|
||||
private Long apiId;
|
||||
|
||||
@Schema(description = "调用次数 不限次数为-1")
|
||||
private Integer requestTimes;
|
||||
|
||||
@Schema(description = "已调用次数")
|
||||
private Integer requestedTimes;
|
||||
private Integer requestedSuccessTimes;
|
||||
private Integer requestedFailedTimes;
|
||||
|
||||
@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;
|
||||
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date startTime;
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date endTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
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
|
||||
@Schema(description = "数据服务-api配置")
|
||||
public class DataServiceApiConfigVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "分组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "api地址")
|
||||
private String path;
|
||||
|
||||
private String type;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "描述")
|
||||
private String note;
|
||||
|
||||
@Schema(description = "sql语句")
|
||||
private String sqlText;
|
||||
private String sqlSeparator;
|
||||
private Integer sqlMaxRow;
|
||||
|
||||
private String sqlParam;
|
||||
|
||||
@Schema(description = "application/json 类API对应的json参数示例")
|
||||
private String jsonParam;
|
||||
private String responseResult;
|
||||
|
||||
@Schema(description = "参数类型")
|
||||
private String contentType;
|
||||
|
||||
@Schema(description = "是否发布 0-否 1-是")
|
||||
private Integer status;
|
||||
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date releaseTime;
|
||||
private Long releaseUserId;
|
||||
|
||||
@Schema(description = "1-数据库 2-中台库")
|
||||
private Integer sqlDbType;
|
||||
|
||||
@Schema(description = "数据库id")
|
||||
private Long databaseId;
|
||||
|
||||
@Schema(description = "是否私有 0-否 1-是")
|
||||
private Integer previlege;
|
||||
|
||||
@Schema(description = "是否开启事务 0-否 1-是")
|
||||
private Integer openTrans;
|
||||
|
||||
@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;
|
||||
|
||||
@Schema(description = "已调用次数")
|
||||
private Integer requestedTimes;
|
||||
private Integer requestedSuccessTimes;
|
||||
private Integer requestedFailedTimes;
|
||||
|
||||
private Long authId;
|
||||
|
||||
private String group;
|
||||
@TableField(exist = false)
|
||||
private String groupPath;
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "数据服务-api分组")
|
||||
public class DataServiceApiGroupVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父级id(顶级为0)")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "1-文件夹 2-api目录")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "序号")
|
||||
private Integer orderNo;
|
||||
|
||||
@Schema(description = "路径")
|
||||
private String path;
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 数据服务-api请求日志
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-22
|
||||
*/
|
||||
@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;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
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;
|
||||
|
||||
/**
|
||||
* 数据服务-app应用
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-02-16
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "数据服务-app应用")
|
||||
public class DataServiceAppVO 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 = "app_key")
|
||||
private String appKey;
|
||||
|
||||
@Schema(description = "app_secret")
|
||||
private String appSecret;
|
||||
|
||||
@Schema(description = "过期描述")
|
||||
private String expireDesc;
|
||||
|
||||
/**
|
||||
* 过期时间 -1永久;0 单次失效;> 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;
|
||||
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
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 : DataServiceAppVo
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-22 21:21
|
||||
*/
|
||||
@Data
|
||||
@Schema(defaultValue = "app权限")
|
||||
public class DataServiceAppVo 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 = "app_key")
|
||||
private String appKey;
|
||||
|
||||
@Schema(description = "app_secret")
|
||||
private String appSecret;
|
||||
|
||||
@Schema(description = "过期描述")
|
||||
private String expireDesc;
|
||||
|
||||
/**
|
||||
* 过期时间 -1永久;0 单次失效;> 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;
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#数据集成
|
||||
server:
|
||||
port: 8099
|
||||
port: 8095
|
||||
|
||||
spring:
|
||||
mvc:
|
||||
|
@ -15,7 +15,7 @@ spring:
|
|||
discovery:
|
||||
server-addr: 101.34.77.101:8848
|
||||
# 命名空间,默认:public
|
||||
namespace: 09dff3e2-9790-4d4f-beb6-9baeb01ae040
|
||||
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37
|
||||
service: ${spring.application.name}
|
||||
group: srt2.0
|
||||
config:
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,67 +0,0 @@
|
|||
package net.srt.quartz.api;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.srt.api.module.data.governance.DataMetadataCollectApi;
|
||||
import net.srt.api.module.data.governance.constant.MetadataCollectType;
|
||||
import net.srt.api.module.data.governance.dto.DataGovernanceMetadataCollectDto;
|
||||
import net.srt.api.module.quartz.QuartzDataGovernanceMetadataCollectApi;
|
||||
import net.srt.api.module.quartz.constant.QuartzJobType;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.quartz.entity.ScheduleJobEntity;
|
||||
import net.srt.quartz.enums.JobGroupEnum;
|
||||
import net.srt.quartz.enums.ScheduleConcurrentEnum;
|
||||
import net.srt.quartz.enums.ScheduleStatusEnum;
|
||||
import net.srt.quartz.service.ScheduleJobService;
|
||||
import net.srt.quartz.utils.ScheduleUtils;
|
||||
import org.quartz.Scheduler;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 短信服务API
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class QuartzDataGovernanceMetadataCollectApiImpl implements QuartzDataGovernanceMetadataCollectApi {
|
||||
|
||||
private final Scheduler scheduler;
|
||||
private final DataMetadataCollectApi dataMetadataCollectApi;
|
||||
private final ScheduleJobService jobService;
|
||||
|
||||
@Override
|
||||
public Result<String> release(Long id) {
|
||||
ScheduleJobEntity jobEntity = buildJobEntity(id);
|
||||
//判断是否存在,不存在,新增,存在,设置主键
|
||||
jobService.buildSystemJob(jobEntity);
|
||||
ScheduleUtils.createScheduleJob(scheduler, jobEntity);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> cancel(Long id) {
|
||||
ScheduleJobEntity jobEntity = buildJobEntity(id);
|
||||
jobService.buildSystemJob(jobEntity);
|
||||
ScheduleUtils.deleteScheduleJob(scheduler, jobEntity);
|
||||
//更新任务状态为暂停
|
||||
jobService.pauseSystemJob(jobEntity);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> handRun(Long id) {
|
||||
ScheduleJobEntity jobEntity = buildJobEntity(id);
|
||||
jobEntity.setOnce(true);
|
||||
jobEntity.setSaveLog(false);
|
||||
ScheduleUtils.run(scheduler, jobEntity);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
private ScheduleJobEntity buildJobEntity(Long id) {
|
||||
DataGovernanceMetadataCollectDto collectDto = dataMetadataCollectApi.getById(id).getData();
|
||||
return ScheduleJobEntity.builder().typeId(id).projectId(collectDto.getProjectId()).jobType(QuartzJobType.DATA_GOVERNANCE.getValue()).jobName(String.format("[%s]%s", id.toString(), collectDto.getName())).concurrent(ScheduleConcurrentEnum.NO.getValue())
|
||||
.beanName("dataGovernanceMetadataCollectTask").method("run").jobGroup(JobGroupEnum.DATA_GOVERNANCE.getValue()).saveLog(true).cronExpression(collectDto.getCron()).status(ScheduleStatusEnum.NORMAL.getValue())
|
||||
.params(String.valueOf(id)).once(MetadataCollectType.ONCE.getValue().equals(collectDto.getTaskType())).build();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package net.srt.quartz.api;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.srt.api.module.data.development.DataProductionScheduleApi;
|
||||
import net.srt.api.module.data.development.dto.DataProductionScheduleDto;
|
||||
import net.srt.api.module.quartz.QuartzDataProductionScheduleApi;
|
||||
import net.srt.api.module.quartz.constant.QuartzJobType;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.quartz.entity.ScheduleJobEntity;
|
||||
import net.srt.quartz.enums.JobGroupEnum;
|
||||
import net.srt.quartz.enums.ScheduleConcurrentEnum;
|
||||
import net.srt.quartz.enums.ScheduleStatusEnum;
|
||||
import net.srt.quartz.service.ScheduleJobService;
|
||||
import net.srt.quartz.utils.ScheduleUtils;
|
||||
import org.quartz.Scheduler;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 短信服务API
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class QuartzDataProductionScheduleApiImpl implements QuartzDataProductionScheduleApi {
|
||||
|
||||
private final Scheduler scheduler;
|
||||
private final DataProductionScheduleApi scheduleApi;
|
||||
private final ScheduleJobService jobService;
|
||||
|
||||
@Override
|
||||
public Result<String> release(Long id) {
|
||||
ScheduleJobEntity jobEntity = buildJobEntity(id);
|
||||
//判断是否存在,不存在,新增,存在,设置主键
|
||||
jobService.buildSystemJob(jobEntity);
|
||||
ScheduleUtils.createScheduleJob(scheduler, jobEntity);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> cancle(Long id) {
|
||||
ScheduleJobEntity jobEntity = buildJobEntity(id);
|
||||
jobService.buildSystemJob(jobEntity);
|
||||
ScheduleUtils.deleteScheduleJob(scheduler, jobEntity);
|
||||
//更新任务状态为暂停
|
||||
jobService.pauseSystemJob(jobEntity);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
private ScheduleJobEntity buildJobEntity(Long id) {
|
||||
DataProductionScheduleDto scheduleDto = scheduleApi.getById(id).getData();
|
||||
return ScheduleJobEntity.builder().typeId(id).projectId(scheduleDto.getProjectId()).jobType(QuartzJobType.DATA_PRODUCTION.getValue()).jobName(String.format("[%s]%s", id.toString(), scheduleDto.getName())).concurrent(ScheduleConcurrentEnum.NO.getValue())
|
||||
.beanName("dataProductionScheduleTask").method("run").jobGroup(JobGroupEnum.DATA_PRODUCTION.getValue()).saveLog(true).cronExpression(scheduleDto.getCron()).status(ScheduleStatusEnum.NORMAL.getValue())
|
||||
.params(String.valueOf(id)).once(scheduleDto.getIfCycle() == 0).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package net.srt.system.convert;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @ClassName : DatastandardEntity
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-21 11:09
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
@TableName("standard_management")
|
||||
public class DatastandardEntity extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId("id")
|
||||
private Long id;
|
||||
private Integer categoryId;
|
||||
private String engName;
|
||||
private String cnName;
|
||||
private Integer codeNum;
|
||||
private String dataType;
|
||||
private Integer dataLength;
|
||||
private Integer dataPrecision;
|
||||
private Integer nullable;
|
||||
private Integer standardCodeId;
|
||||
private Integer type;
|
||||
private String note;
|
||||
private Integer projectId;
|
||||
private Integer status;
|
||||
private Integer version;
|
||||
private Integer deleted;
|
||||
private Integer ifStandardRel;
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package net.srt.system.convert;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName : StandardManagementVo
|
||||
* @Description : 标准管理表
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-20 11:24
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "标准管理查询")
|
||||
public class StandardManagementVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableId("id")
|
||||
private Long id;
|
||||
private Integer categoryId;
|
||||
private String engName;
|
||||
private String cnName;
|
||||
private Integer codeNum;
|
||||
private String dataType;
|
||||
private Integer dataLength;
|
||||
private Integer dataPrecision;
|
||||
private Integer nullable;
|
||||
private Integer standardCodeId;
|
||||
private Integer type;
|
||||
private String note;
|
||||
private Integer projectId;
|
||||
private Integer status;
|
||||
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;
|
||||
private String updater;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
private Integer ifStandardRel;
|
||||
private String group;
|
||||
}
|
Loading…
Reference in New Issue