newone #4
|
@ -39,4 +39,6 @@ public interface ServerNames {
|
||||||
*/
|
*/
|
||||||
String DATA_GOVERNANCE_NAME = "srt-cloud-data-governance";
|
String DATA_GOVERNANCE_NAME = "srt-cloud-data-governance";
|
||||||
String DATA_DATAX = "srt-cloud-datax";
|
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);
|
||||||
|
}
|
|
@ -12,6 +12,7 @@
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.srt</groupId>
|
<groupId>net.srt</groupId>
|
||||||
<artifactId>srt-cloud-api</artifactId>
|
<artifactId>srt-cloud-api</artifactId>
|
||||||
|
|
|
@ -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,79 @@
|
||||||
|
package net.srt.api;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.srt.api.module.data.governance.DataQualityApi;
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityConfigDto;
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityTaskColumnDto;
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityTaskDto;
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityTaskTableDto;
|
||||||
|
import net.srt.convert.QualityConfigConvert;
|
||||||
|
import net.srt.convert.QualityTaskColumnConvert;
|
||||||
|
import net.srt.convert.QualityTaskConvert;
|
||||||
|
import net.srt.convert.QualityTaskTableConvert;
|
||||||
|
import net.srt.entity.QualityTaskColumnEntity;
|
||||||
|
import net.srt.entity.QualityTaskEntity;
|
||||||
|
import net.srt.entity.QualityTaskTableEntity;
|
||||||
|
import net.srt.framework.common.utils.Result;
|
||||||
|
import net.srt.service.QualityConfigService;
|
||||||
|
import net.srt.service.QualityTaskColumnService;
|
||||||
|
import net.srt.service.QualityTaskService;
|
||||||
|
import net.srt.service.QualityTaskTableService;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: srt_cloud
|
||||||
|
* @BelongsPackage: net.srt.api
|
||||||
|
* @Author: jpz
|
||||||
|
* @CreateTime: 2023/12/25 21:01
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class QualityApiImpl implements DataQualityApi {
|
||||||
|
private final QualityConfigService qualityConfigService;
|
||||||
|
private final QualityTaskService qualityTaskService;
|
||||||
|
private final QualityTaskTableService taskTableService;
|
||||||
|
private final QualityTaskColumnService taskColumnService;
|
||||||
|
@Override
|
||||||
|
public Result<DataGovernanceQualityConfigDto> getById(Long id) {
|
||||||
|
return Result.ok(QualityConfigConvert.INSTANCE.convertDto(qualityConfigService.getById(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<DataGovernanceQualityTaskDto> addQualityTask(DataGovernanceQualityTaskDto qualityTaskDto) {
|
||||||
|
QualityTaskEntity entity= QualityTaskConvert.INSTANCE.covert(qualityTaskDto);
|
||||||
|
qualityTaskService.save(entity);
|
||||||
|
qualityTaskDto.setId(entity.getId());
|
||||||
|
return Result.ok(qualityTaskDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<String> updateQualityTask(DataGovernanceQualityTaskDto qualityTaskDto) {
|
||||||
|
QualityTaskEntity entity=QualityTaskConvert.INSTANCE.covert(qualityTaskDto);
|
||||||
|
qualityTaskService.updateById(entity);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<DataGovernanceQualityTaskTableDto> addTaskTable(DataGovernanceQualityTaskTableDto qualityTaskTableDto) {
|
||||||
|
QualityTaskTableEntity entity= QualityTaskTableConvert.INSTANCE.convert(qualityTaskTableDto);
|
||||||
|
taskTableService.save(entity);
|
||||||
|
qualityTaskTableDto.setId(entity.getId());
|
||||||
|
return Result.ok(qualityTaskTableDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<String> updateQualityTaskTable(DataGovernanceQualityTaskTableDto taskTable) {
|
||||||
|
QualityTaskTableEntity entity=QualityTaskTableConvert.INSTANCE.convert(taskTable);
|
||||||
|
taskTableService.updateById(entity);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<String> addQualityTaskColumns(List<DataGovernanceQualityTaskColumnDto> columnDtos) {
|
||||||
|
List<QualityTaskColumnEntity> columnEntities= QualityTaskColumnConvert.INSTANCE.convertListByDtos(columnDtos);
|
||||||
|
taskColumnService.saveBatch(columnEntities);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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 StandardDataType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字
|
||||||
|
*/
|
||||||
|
NUMBER(1, "数字","INT,LONG.NUMBER,BIGINT"),
|
||||||
|
/**
|
||||||
|
* 字符串
|
||||||
|
*/
|
||||||
|
STRING(2, "字符串","CHAR,VARCHAR,NVARCHAR,TEXT,LONGTEXT"),
|
||||||
|
/**
|
||||||
|
* 日期
|
||||||
|
*/
|
||||||
|
DATE(3, "日期","DATE,DATETIME.TIMESTAMP"),
|
||||||
|
/**
|
||||||
|
* 小数
|
||||||
|
*/
|
||||||
|
NUMBER_SACLE(4, "小数","DOUBLE,NUMBER"),
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
private final String longValue;
|
||||||
|
private final String dbDataTypes;
|
||||||
|
|
||||||
|
StandardDataType(Integer value, String longValue,String dbDataTypes) {
|
||||||
|
this.value = value;
|
||||||
|
this.longValue = longValue;
|
||||||
|
this.dbDataTypes = dbDataTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLongValue() {
|
||||||
|
return longValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDbDataTypes() {
|
||||||
|
return dbDataTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StandardDataType getByCode(String value) {
|
||||||
|
for (StandardDataType standardDataType : StandardDataType.values()) {
|
||||||
|
if (standardDataType.getValue().equals(Integer.parseInt(value))) {
|
||||||
|
return standardDataType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return StandardDataType.STRING;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
package net.srt.controller;
|
package net.srt.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.srt.framework.common.cache.bean.Neo4jInfo;
|
import net.srt.framework.common.cache.bean.Neo4jInfo;
|
||||||
import net.srt.framework.common.utils.Result;
|
import net.srt.framework.common.utils.Result;
|
||||||
|
import net.srt.framework.common.utils.TreeNode;
|
||||||
import net.srt.framework.common.utils.TreeNodeVo;
|
import net.srt.framework.common.utils.TreeNodeVo;
|
||||||
import net.srt.service.MetadataService;
|
import net.srt.service.MetadataService;
|
||||||
import net.srt.vo.MetadataVO;
|
import net.srt.vo.MetadataVO;
|
||||||
|
@ -20,6 +22,12 @@ import java.util.List;
|
||||||
public class MetadataController {
|
public class MetadataController {
|
||||||
private final MetadataService metadataService;
|
private final MetadataService metadataService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据父级id获取子节点信息
|
||||||
|
*
|
||||||
|
* @param parentId 父级id
|
||||||
|
* @return 子节点信息列表
|
||||||
|
*/
|
||||||
@GetMapping("/list-child")
|
@GetMapping("/list-child")
|
||||||
@Operation(summary = "根据父级id获取信息")
|
@Operation(summary = "根据父级id获取信息")
|
||||||
public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){
|
public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){
|
||||||
|
@ -27,6 +35,11 @@ public class MetadataController {
|
||||||
return Result.ok(treeNodeVos);
|
return Result.ok(treeNodeVos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取目录树
|
||||||
|
* @return 目录树数据
|
||||||
|
*/
|
||||||
@GetMapping("/list-floder")
|
@GetMapping("/list-floder")
|
||||||
@Operation(summary = "获取目录树")
|
@Operation(summary = "获取目录树")
|
||||||
public Result<List<TreeNodeVo>> listFloder(){
|
public Result<List<TreeNodeVo>> listFloder(){
|
||||||
|
@ -34,6 +47,11 @@ public class MetadataController {
|
||||||
return Result.ok(treeNodeVos);
|
return Result.ok(treeNodeVos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取库表目录树
|
||||||
|
* @return 结果包含库表目录树节点列表
|
||||||
|
*/
|
||||||
@GetMapping("/list-db")
|
@GetMapping("/list-db")
|
||||||
@Operation(summary = "获取库表目录树")
|
@Operation(summary = "获取库表目录树")
|
||||||
public Result<List<TreeNodeVo>> listDb(){
|
public Result<List<TreeNodeVo>> listDb(){
|
||||||
|
@ -41,6 +59,8 @@ public class MetadataController {
|
||||||
return Result.ok(treeNodeVos);
|
return Result.ok(treeNodeVos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/list-keyword")
|
@GetMapping("/list-keyword")
|
||||||
@Operation(summary = "模糊查询")
|
@Operation(summary = "模糊查询")
|
||||||
public Result<List<TreeNodeVo>> listByKeyword(String keyword){
|
public Result<List<TreeNodeVo>> listByKeyword(String keyword){
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.util.List;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class QualityConfigController {
|
public class QualityConfigController {
|
||||||
private final QualityConfigService qualityConfigService;
|
private final QualityConfigService qualityConfigService;
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
public Result<PageResult<QualityConfigVo>> page(@Valid QualityConfigQuery query){
|
public Result<PageResult<QualityConfigVo>> page(@Valid QualityConfigQuery query){
|
||||||
|
@ -75,7 +74,7 @@ public class QualityConfigController {
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@Operation(summary = "删除")
|
@Operation(summary = "删除")
|
||||||
public Result<String> delete(@RequestBody List<Long> idList){
|
public Result<String> delete(@RequestBody List<Long> idList){
|
||||||
qualityConfigService.delete(idList);
|
qualityConfigService.delete(idList);
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.srt.convert;
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityConfigDto;
|
||||||
import net.srt.entity.QualityConfigEntity;
|
import net.srt.entity.QualityConfigEntity;
|
||||||
import net.srt.vo.QualityConfigVo;
|
import net.srt.vo.QualityConfigVo;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -22,4 +23,6 @@ public interface QualityConfigConvert {
|
||||||
QualityConfigEntity convert(QualityConfigVo vo);
|
QualityConfigEntity convert(QualityConfigVo vo);
|
||||||
|
|
||||||
List<QualityConfigVo> convertList(List<QualityConfigEntity> list);
|
List<QualityConfigVo> convertList(List<QualityConfigEntity> list);
|
||||||
|
|
||||||
|
DataGovernanceQualityConfigDto convertDto(QualityConfigEntity entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.srt.convert;
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityTaskColumnDto;
|
||||||
import net.srt.entity.QualityTaskColumnEntity;
|
import net.srt.entity.QualityTaskColumnEntity;
|
||||||
import net.srt.vo.QualityTaskColumnVo;
|
import net.srt.vo.QualityTaskColumnVo;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -23,4 +24,6 @@ public interface QualityTaskColumnConvert {
|
||||||
List<QualityTaskColumnVo> convertList(List<QualityTaskColumnEntity> list);
|
List<QualityTaskColumnVo> convertList(List<QualityTaskColumnEntity> list);
|
||||||
|
|
||||||
QualityTaskColumnEntity conver(QualityTaskColumnVo vo);
|
QualityTaskColumnEntity conver(QualityTaskColumnVo vo);
|
||||||
|
|
||||||
|
List<QualityTaskColumnEntity> convertListByDtos(List<DataGovernanceQualityTaskColumnDto> dtos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.srt.convert;
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityTaskDto;
|
||||||
import net.srt.entity.QualityTaskEntity;
|
import net.srt.entity.QualityTaskEntity;
|
||||||
import net.srt.vo.QualityTaskVo;
|
import net.srt.vo.QualityTaskVo;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -22,4 +23,6 @@ public interface QualityTaskConvert {
|
||||||
List<QualityTaskVo> covertList(List<QualityTaskEntity> list);
|
List<QualityTaskVo> covertList(List<QualityTaskEntity> list);
|
||||||
|
|
||||||
QualityTaskVo covert(QualityTaskEntity entity);
|
QualityTaskVo covert(QualityTaskEntity entity);
|
||||||
|
|
||||||
|
QualityTaskEntity covert(DataGovernanceQualityTaskDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.srt.convert;
|
package net.srt.convert;
|
||||||
|
|
||||||
|
import net.srt.api.module.data.governance.dto.DataGovernanceQualityTaskTableDto;
|
||||||
import net.srt.entity.QualityTaskTableEntity;
|
import net.srt.entity.QualityTaskTableEntity;
|
||||||
import net.srt.vo.QualityTaskTableVo;
|
import net.srt.vo.QualityTaskTableVo;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
@ -20,4 +21,6 @@ public interface QualityTaskTableConvert {
|
||||||
List<QualityTaskTableVo> convertList(List<QualityTaskTableEntity> list);
|
List<QualityTaskTableVo> convertList(List<QualityTaskTableEntity> list);
|
||||||
|
|
||||||
QualityTaskTableVo convert(QualityTaskTableEntity entity);
|
QualityTaskTableVo convert(QualityTaskTableEntity entity);
|
||||||
|
|
||||||
|
QualityTaskTableEntity convert(DataGovernanceQualityTaskTableDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package net.srt.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName CompareResult
|
||||||
|
* @Author zrx
|
||||||
|
* @Date 2023/5/27 10:16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CompareResult {
|
||||||
|
private String property;
|
||||||
|
private String metadataVal;
|
||||||
|
private String standardVal;
|
||||||
|
private boolean standard;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package net.srt.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName StandardCheckDto
|
||||||
|
* @Author zrx
|
||||||
|
* @Date 2023/5/26 11:46
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class StandardCheckDto {
|
||||||
|
//数据属性比对结果
|
||||||
|
private List<CompareResult> compareResults;
|
||||||
|
//是否关联了码表
|
||||||
|
private Boolean relStandardCode;
|
||||||
|
//是否有码表数据
|
||||||
|
private Boolean hasStandardCode;
|
||||||
|
private String fillNumSql;
|
||||||
|
//符合标准数量
|
||||||
|
private Object fillNum;
|
||||||
|
private String notFillNumSql;
|
||||||
|
//不符合标准数量
|
||||||
|
private Object notFullNum;
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import net.srt.vo.MetadataVO;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface MetadataService extends BaseService<MetadataEntity> {
|
public interface MetadataService extends BaseService<MetadataEntity> {
|
||||||
|
|
||||||
List<TreeNodeVo> listByParentId(Long parentId);
|
List<TreeNodeVo> listByParentId(Long parentId);
|
||||||
|
|
||||||
List<TreeNodeVo> listFloder();
|
List<TreeNodeVo> listFloder();
|
||||||
|
@ -29,4 +30,5 @@ public interface MetadataService extends BaseService<MetadataEntity> {
|
||||||
void upNeo4jInfo(Neo4jInfo neo4jInfo);
|
void upNeo4jInfo(Neo4jInfo neo4jInfo);
|
||||||
|
|
||||||
Neo4jInfo getNeo4jInfo();
|
Neo4jInfo getNeo4jInfo();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEn
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TreeNodeVo> listByParentId(Long parentId) {
|
public List<TreeNodeVo> listByParentId(Long parentId) {
|
||||||
|
|
||||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(MetadataEntity::getParentId,parentId)
|
wrapper.eq(MetadataEntity::getParentId,parentId)
|
||||||
.orderByAsc(MetadataEntity::getOrderNo);
|
.orderByAsc(MetadataEntity::getOrderNo);
|
||||||
|
@ -180,6 +181,8 @@ public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEn
|
||||||
return tokenStoreCache.getNeo4jInfo(getProjectId());
|
return tokenStoreCache.getNeo4jInfo(getProjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void recursionAddParent(MetadataEntity metadataEntity, List<MetadataEntity> resultList){
|
private void recursionAddParent(MetadataEntity metadataEntity, List<MetadataEntity> resultList){
|
||||||
if(resultList.stream().noneMatch(item -> metadataEntity.getId().equals(item.getId()))) {
|
if(resultList.stream().noneMatch(item -> metadataEntity.getId().equals(item.getId()))) {
|
||||||
resultList.add(metadataEntity);
|
resultList.add(metadataEntity);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.srt.service.impl;
|
package net.srt.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
|
@ -22,6 +21,7 @@ import net.srt.service.QualityConfigService;
|
||||||
import net.srt.vo.QualityConfigVo;
|
import net.srt.vo.QualityConfigVo;
|
||||||
import org.springframework.security.core.parameters.P;
|
import org.springframework.security.core.parameters.P;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -38,97 +38,179 @@ import java.util.stream.Collectors;
|
||||||
public class QualityConfigServiceimpl extends BaseServiceImpl<QualityConfigDao, QualityConfigEntity> implements QualityConfigService {
|
public class QualityConfigServiceimpl extends BaseServiceImpl<QualityConfigDao, QualityConfigEntity> implements QualityConfigService {
|
||||||
private final QuartzDataGovernanceQualityApi quartzDataGovernanceQualityApi;
|
private final QuartzDataGovernanceQualityApi quartzDataGovernanceQualityApi;
|
||||||
private final MetadataDao metadataDao;
|
private final MetadataDao metadataDao;
|
||||||
|
/**
|
||||||
|
* 分页查询质量配置
|
||||||
|
*
|
||||||
|
* @param query 质量配置查询对象
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResult<QualityConfigVo> page(QualityConfigQuery query) {
|
public PageResult<QualityConfigVo> page(QualityConfigQuery query) {
|
||||||
IPage<QualityConfigEntity> page=baseMapper.selectPage(getPage(query),getWrapper(query));
|
IPage<QualityConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||||
return new PageResult<>(QualityConfigConvert.INSTANCE.convertList(page.getRecords()),page.getTotal());
|
return new PageResult<>(QualityConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id获取QualityConfigVo对象
|
||||||
|
*
|
||||||
|
* @param id QualityConfigVo的id值
|
||||||
|
* @return QualityConfigVo对象
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public QualityConfigVo get(Long id) {
|
public QualityConfigVo get(Long id) {
|
||||||
|
// 根据id从数据库中查询QualityConfigVo对象并转换为QualityConfigVo对象
|
||||||
QualityConfigVo qualityConfigvo= QualityConfigConvert.INSTANCE.convert(baseMapper.selectById(id));
|
QualityConfigVo qualityConfigvo= QualityConfigConvert.INSTANCE.convert(baseMapper.selectById(id));
|
||||||
|
// 获取QualityConfigVo对象中的metadataIds列表
|
||||||
List<Integer> metadataIds=qualityConfigvo.getMetadataIds();
|
List<Integer> metadataIds=qualityConfigvo.getMetadataIds();
|
||||||
|
// 创建LambdaQueryWrapper对象用于查询MetadataEntity对象
|
||||||
LambdaQueryWrapper<MetadataEntity> metadataWrapper= Wrappers.lambdaQuery();
|
LambdaQueryWrapper<MetadataEntity> metadataWrapper= Wrappers.lambdaQuery();
|
||||||
|
// 在查询中指定MetadataEntity对象的id字段需要在metadataIds列表中
|
||||||
metadataWrapper.in(MetadataEntity::getId,metadataIds);
|
metadataWrapper.in(MetadataEntity::getId,metadataIds);
|
||||||
|
// 根据metadataWrapper查询MetadataEntity对象列表
|
||||||
List<MetadataEntity> metadataEntities=metadataDao.selectList(metadataWrapper);
|
List<MetadataEntity> metadataEntities=metadataDao.selectList(metadataWrapper);
|
||||||
|
// 判断metadataEntities列表是否为空
|
||||||
if (CollectionUtils.isEmpty(metadataEntities)){
|
if (CollectionUtils.isEmpty(metadataEntities)){
|
||||||
|
// 若为空,则将提示信息设为"检测字段已删除,请检查数据信息"
|
||||||
qualityConfigvo.setMetadataStrs("检测字段已删除,请检查数据信息");
|
qualityConfigvo.setMetadataStrs("检测字段已删除,请检查数据信息");
|
||||||
}else {
|
}else {
|
||||||
|
// 否则,将metadataEntities列表中的path属性按分号连接起来,并将结果设为metadataStrs属性值
|
||||||
qualityConfigvo.setMetadataStrs(metadataEntities.stream().map(MetadataEntity::getPath).collect(Collectors.joining(";")));
|
qualityConfigvo.setMetadataStrs(metadataEntities.stream().map(MetadataEntity::getPath).collect(Collectors.joining(";")));
|
||||||
}
|
}
|
||||||
|
// 判断qualityConfigvo的ruleId属性是否为ASSOCIATION_CONSISTENCY常量的值
|
||||||
if (BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(qualityConfigvo.getRuleId())){
|
if (BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(qualityConfigvo.getRuleId())){
|
||||||
|
// 若是,则获取qualityConfigvo的param属性的columnMetaId值
|
||||||
QualityConfigParam param = qualityConfigvo.getParam();
|
QualityConfigParam param = qualityConfigvo.getParam();
|
||||||
Integer columnMetaId = param.getColumnMetaId();
|
Integer columnMetaId = param.getColumnMetaId();
|
||||||
|
// 根据columnMetaId从数据库中查询MetadataEntity对象
|
||||||
MetadataEntity entity = metadataDao.selectById(columnMetaId);
|
MetadataEntity entity = metadataDao.selectById(columnMetaId);
|
||||||
|
// 判断查询结果是否为空
|
||||||
if (entity!= null){
|
if (entity!= null){
|
||||||
|
// 若不为空,则将entity的path属性设为relMetadataStr属性值
|
||||||
qualityConfigvo.setRelMetadataStr(entity.getPath());
|
qualityConfigvo.setRelMetadataStr(entity.getPath());
|
||||||
}else {
|
}else {
|
||||||
|
// 若为空,则将提示信息设为"关联字段已被删除,请检查元数据信息"
|
||||||
qualityConfigvo.setMetadataStrs("关联字段已被删除,请检查元数据信息");
|
qualityConfigvo.setMetadataStrs("关联字段已被删除,请检查元数据信息");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 返回qualityConfigvo对象
|
||||||
return qualityConfigvo;
|
return qualityConfigvo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(QualityConfigVo vo) {
|
public void save(QualityConfigVo vo) {
|
||||||
|
// 将QualityConfigVo对象转换为QualityConfigEntity对象
|
||||||
QualityConfigEntity entity=QualityConfigConvert.INSTANCE.convert(vo);
|
QualityConfigEntity entity=QualityConfigConvert.INSTANCE.convert(vo);
|
||||||
|
|
||||||
|
// 设置entity的projectId为当前项目id
|
||||||
entity.setProjectId(getProjectId());
|
entity.setProjectId(getProjectId());
|
||||||
|
|
||||||
|
// 判断ruleId不为UNIQUENESS、LENGTH_CHECK、ASSOCIATION_CONSISTENCY和TIMELINESS时,设置entity的param为null
|
||||||
if (!BuiltInQualityRule.UNIQUENESS.getId().equals(entity.getRuleId())&&!BuiltInQualityRule.LENGTH_CHECK.getId().equals(entity.getRuleId())&& !BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(entity.getRuleId())&&!BuiltInQualityRule.TIMELINESS.getId().equals(entity.getRuleId())){
|
if (!BuiltInQualityRule.UNIQUENESS.getId().equals(entity.getRuleId())&&!BuiltInQualityRule.LENGTH_CHECK.getId().equals(entity.getRuleId())&& !BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(entity.getRuleId())&&!BuiltInQualityRule.TIMELINESS.getId().equals(entity.getRuleId())){
|
||||||
entity.setParam(null);
|
entity.setParam(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用baseMapper的insert方法将entity插入数据库
|
||||||
baseMapper.insert(entity);
|
baseMapper.insert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新质量规则配置
|
||||||
|
*
|
||||||
|
* @param vo 质量规则配置VO对象
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(QualityConfigVo vo) {
|
public void update(QualityConfigVo vo) {
|
||||||
if (!BuiltInQualityRule.UNIQUENESS.getId().equals(vo.getRuleId())&&!BuiltInQualityRule.LENGTH_CHECK.getId().equals(vo.getRuleId())&&!BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(vo.getRuleId())&&!BuiltInQualityRule.TIMELINESS.getId().equals(vo.getRuleId())){
|
if (!BuiltInQualityRule.UNIQUENESS.getId().equals(vo.getRuleId()) &&
|
||||||
|
!BuiltInQualityRule.LENGTH_CHECK.getId().equals(vo.getRuleId()) &&
|
||||||
|
!BuiltInQualityRule.ASSOCIATION_CONSISTENCY.getId().equals(vo.getRuleId()) &&
|
||||||
|
!BuiltInQualityRule.TIMELINESS.getId().equals(vo.getRuleId())) {
|
||||||
vo.setParam(null);
|
vo.setParam(null);
|
||||||
}
|
}
|
||||||
QualityConfigEntity entity=QualityConfigConvert.INSTANCE.convert(vo);
|
QualityConfigEntity entity = QualityConfigConvert.INSTANCE.convert(vo);
|
||||||
entity.setProjectId(getProjectId());
|
entity.setProjectId(getProjectId());
|
||||||
updateById(entity);
|
updateById(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void online(Long id) {
|
public void online(Long id) {
|
||||||
QualityConfigEntity entity=baseMapper.selectById(id);
|
// 根据id查询实体对象
|
||||||
|
QualityConfigEntity entity = baseMapper.selectById(id);
|
||||||
|
// 设置状态为1
|
||||||
entity.setStatus(1);
|
entity.setStatus(1);
|
||||||
|
// 释放资源
|
||||||
quartzDataGovernanceQualityApi.release(id);
|
quartzDataGovernanceQualityApi.release(id);
|
||||||
|
// 更新实体对象
|
||||||
baseMapper.updateById(entity);
|
baseMapper.updateById(entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void offline(Long id) {
|
public void offline(Long id) {
|
||||||
QualityConfigEntity entity=baseMapper.selectById(id);
|
// 根据id获取QualityConfigEntity对象
|
||||||
|
QualityConfigEntity entity = baseMapper.selectById(id);
|
||||||
|
|
||||||
|
// 将entity对象的状态设置为0
|
||||||
entity.setStatus(0);
|
entity.setStatus(0);
|
||||||
|
|
||||||
|
// 取消quartzDataGovernanceQualityApi的定时任务
|
||||||
quartzDataGovernanceQualityApi.cancel(id);
|
quartzDataGovernanceQualityApi.cancel(id);
|
||||||
|
|
||||||
|
// 更新entity对象的数据
|
||||||
baseMapper.updateById(entity);
|
baseMapper.updateById(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手动运行指定ID的数据治理任务
|
||||||
|
*
|
||||||
|
* @param id 指定的任务ID
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handRun(Long id) {
|
public void handRun(Long id) {
|
||||||
quartzDataGovernanceQualityApi.handRun(id);
|
quartzDataGovernanceQualityApi.handRun(id);
|
||||||
|
System.out.println("===================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(List<Long> idList) {
|
public void delete(List<Long> idList) {
|
||||||
|
// 遍历idList列表
|
||||||
for (Long id : idList) {
|
for (Long id : idList) {
|
||||||
|
// 调用quartzDataGovernanceQualityApi的cancel方法取消任务
|
||||||
quartzDataGovernanceQualityApi.cancel(id);
|
quartzDataGovernanceQualityApi.cancel(id);
|
||||||
}
|
}
|
||||||
|
// 删除指定idList列表的记录
|
||||||
removeByIds(idList);
|
removeByIds(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据给定的QualityConfigQuery对象生成LambdaQueryWrapper对象
|
||||||
|
*
|
||||||
|
* @param query QualityConfigQuery对象
|
||||||
|
* @return 生成的LambdaQueryWrapper对象
|
||||||
|
*/
|
||||||
private LambdaQueryWrapper<QualityConfigEntity> getWrapper(QualityConfigQuery query) {
|
private LambdaQueryWrapper<QualityConfigEntity> getWrapper(QualityConfigQuery query) {
|
||||||
LambdaQueryWrapper<QualityConfigEntity> wrapper= Wrappers.lambdaQuery();
|
LambdaQueryWrapper<QualityConfigEntity> wrapper = Wrappers.lambdaQuery();
|
||||||
wrapper.eq(query.getCategoryId()!=null,QualityConfigEntity::getCategoryId,query.getCategoryId())
|
// 设置类别ID等于给定值的条件
|
||||||
.like(StringUtil.isNotBlank(query.getName()),QualityConfigEntity::getName,query.getName())
|
wrapper.eq(query.getCategoryId() != null, QualityConfigEntity::getCategoryId, query.getCategoryId())
|
||||||
.eq(query.getStatus()!=null,QualityConfigEntity::getStatus,query.getStatus())
|
// 设置名称包含给定值的条件
|
||||||
.eq(query.getTaskType()!=null,QualityConfigEntity::getTaskType,query.getTaskType())
|
.like(StringUtil.isNotBlank(query.getName()), QualityConfigEntity::getName, query.getName())
|
||||||
.orderByDesc(QualityConfigEntity::getId );
|
// 设置状态等于给定值的条件
|
||||||
|
.eq(query.getStatus() != null, QualityConfigEntity::getStatus, query.getStatus())
|
||||||
|
// 设置任务类型等于给定值的条件
|
||||||
|
.eq(query.getTaskType() != null, QualityConfigEntity::getTaskType, query.getTaskType())
|
||||||
|
// 根据质量配置ID降序排序
|
||||||
|
.orderByDesc(QualityConfigEntity::getId);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "标准管理查询")
|
@Schema(description = "标准管理查询")
|
||||||
public class DatastandardVo implements Serializable {
|
public class DatastandardVo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@TableId("id")
|
@TableId("id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
|
@ -11,12 +11,6 @@
|
||||||
|
|
||||||
<artifactId>srt-cloud-data-service</artifactId>
|
<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>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.srt</groupId>
|
<groupId>net.srt</groupId>
|
||||||
|
@ -34,15 +28,24 @@
|
||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>net.srt</groupId>
|
||||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
<artifactId>srt-cloud-dbswitch</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>jsqlparser</artifactId>
|
||||||
|
<groupId>com.github.jsqlparser</groupId>
|
||||||
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>spring-boot-starter-logging</artifactId>
|
<artifactId>spring-boot-starter-logging</artifactId>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
@ -51,44 +54,14 @@
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.whvcse</groupId>
|
|
||||||
<artifactId>easy-captcha</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>knife4j-springdoc-ui</artifactId>
|
<artifactId>knife4j-springdoc-ui</artifactId>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<!--<finalName>${project.artifactId}</finalName>-->
|
<!-- <finalName>${project.artifactId}</finalName>-->
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
@ -126,7 +99,7 @@
|
||||||
<daemons>
|
<daemons>
|
||||||
<daemon>
|
<daemon>
|
||||||
<id>${project.artifactId}</id>
|
<id>${project.artifactId}</id>
|
||||||
<mainClass>net.srt.SystemApplication</mainClass>
|
<mainClass>net.net.srt.DataServiceApplication</mainClass>
|
||||||
<platforms>
|
<platforms>
|
||||||
<platform>jsw</platform>
|
<platform>jsw</platform>
|
||||||
</platforms>
|
</platforms>
|
||||||
|
@ -181,7 +154,7 @@
|
||||||
</daemons>
|
</daemons>
|
||||||
<programs>
|
<programs>
|
||||||
<program>
|
<program>
|
||||||
<mainClass>net.srt.SystemApplication</mainClass>
|
<mainClass>net.net.srt.DataServiceApplication</mainClass>
|
||||||
<id>${project.artifactId}</id>
|
<id>${project.artifactId}</id>
|
||||||
</program>
|
</program>
|
||||||
</programs>
|
</programs>
|
||||||
|
@ -189,24 +162,24 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!--打包 日常调试打包可以把该组件注释掉,不然install的速度比较慢-->
|
<!--打包 日常调试打包可以把该组件注释掉,不然install的速度比较慢-->
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<!-- <artifactId>maven-assembly-plugin</artifactId>-->
|
||||||
<configuration>
|
<!-- <configuration>-->
|
||||||
<descriptors>
|
<!-- <descriptors>-->
|
||||||
<descriptor>${project.parent.basedir}/assembly/assembly-win.xml</descriptor>
|
<!-- <descriptor>${project.parent.basedir}/assembly/assembly-win.xml</descriptor>-->
|
||||||
<descriptor>${project.parent.basedir}/assembly/assembly-linux.xml</descriptor>
|
<!-- <descriptor>${project.parent.basedir}/assembly/assembly-linux.xml</descriptor>-->
|
||||||
</descriptors>
|
<!-- </descriptors>-->
|
||||||
</configuration>
|
<!-- </configuration>-->
|
||||||
<executions>
|
<!-- <executions>-->
|
||||||
<execution>
|
<!-- <execution>-->
|
||||||
<id>make-assembly</id>
|
<!-- <id>make-assembly</id>-->
|
||||||
<phase>package</phase>
|
<!-- <phase>package</phase>-->
|
||||||
<goals>
|
<!-- <goals>-->
|
||||||
<goal>single</goal>
|
<!-- <goal>single</goal>-->
|
||||||
</goals>
|
<!-- </goals>-->
|
||||||
</execution>
|
<!-- </execution>-->
|
||||||
</executions>
|
<!-- </executions>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
|
|
||||||
<!--<plugin>
|
<!--<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -221,6 +194,5 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</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;
|
package net.srt.controller;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.srt.convert.DataServiceAppConvert;
|
import net.srt.convert.DataServiceAppConvert;
|
||||||
import net.srt.entity.DataServiceAppEntity;
|
import net.srt.entity.DataServiceAppEntity;
|
||||||
|
@ -8,77 +9,90 @@ import net.srt.framework.common.page.PageResult;
|
||||||
import net.srt.framework.common.utils.Result;
|
import net.srt.framework.common.utils.Result;
|
||||||
import net.srt.query.DataServiceAppQuery;
|
import net.srt.query.DataServiceAppQuery;
|
||||||
import net.srt.service.DataServiceAppService;
|
import net.srt.service.DataServiceAppService;
|
||||||
import net.srt.vo.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 org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceAppController
|
* 数据服务-app应用
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 08:53
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/app")
|
@RequestMapping("app")
|
||||||
|
@Tag(name="数据服务-app应用")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class DataServiceAppController {
|
public class DataServiceAppController {
|
||||||
private final DataServiceAppService dataServiceAppService;
|
private final DataServiceAppService dataServiceAppService;
|
||||||
|
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
@Operation(summary = "分页")
|
@Operation(summary = "分页")
|
||||||
public Result<PageResult<DataServiceAppVo> > page(@Valid DataServiceAppQuery query) {
|
//@PreAuthorize("hasAuthority('data-service:app:page')")
|
||||||
PageResult<DataServiceAppVo> pageResult = dataServiceAppService.page(query);
|
public Result<PageResult<DataServiceAppVO>> page(@Valid DataServiceAppQuery query){
|
||||||
return Result.ok(pageResult);
|
PageResult<DataServiceAppVO> page = dataServiceAppService.page(query);
|
||||||
|
return Result.ok(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
@Operation(summary = "信息")
|
@Operation(summary = "信息")
|
||||||
public Result<DataServiceAppVo> get(@PathVariable("id") Long id){
|
//@PreAuthorize("hasAuthority('data-service:app:info')")
|
||||||
DataServiceAppEntity dataServiceAppEntity = dataServiceAppService.getById(id);
|
public Result<DataServiceAppVO> get(@PathVariable("id") Long id){
|
||||||
return Result.ok(DataServiceAppConvert.INSTANCE.convert(dataServiceAppEntity));
|
DataServiceAppEntity entity = dataServiceAppService.getById(id);
|
||||||
|
|
||||||
|
return Result.ok(DataServiceAppConvert.INSTANCE.convert(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@Operation(summary = "保存")
|
@Operation(summary = "保存")
|
||||||
public Result<String> save(@RequestBody DataServiceAppVo vo){
|
//@PreAuthorize("hasAuthority('data-service:app:save')")
|
||||||
dataServiceAppService.save1(vo);
|
public Result<String> save(@RequestBody DataServiceAppVO vo){
|
||||||
|
dataServiceAppService.save(vo);
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@Operation(summary = "修改")
|
@Operation(summary = "修改")
|
||||||
public Result<String> update(@RequestBody @Valid DataServiceAppVo vo){
|
//@PreAuthorize("hasAuthority('data-service:app:update')")
|
||||||
dataServiceAppService.update1(vo);
|
public Result<String> update(@RequestBody @Valid DataServiceAppVO vo){
|
||||||
|
dataServiceAppService.update(vo);
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@Operation(summary = "删除")
|
@Operation(summary = "删除")
|
||||||
|
//@PreAuthorize("hasAuthority('data-service:app:delete')")
|
||||||
public Result<String> delete(@RequestBody List<Long> idList){
|
public Result<String> delete(@RequestBody List<Long> idList){
|
||||||
dataServiceAppService.delete(idList);
|
dataServiceAppService.delete(idList);
|
||||||
|
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/auth")
|
@PostMapping("/auth")
|
||||||
@Operation(summary = "添加授权")
|
@Operation(summary = "添加授权")
|
||||||
public Result<String> addAuth(@RequestBody DataServiceAppVo authVO){
|
@PreAuthorize("hasAuthority('data-service:app:auth')")
|
||||||
dataServiceAppService.addAuth(authVO);
|
public Result<String> addAuth(@RequestBody DataServiceApiAuthVO authVO){
|
||||||
return Result.ok();
|
dataServiceAppService.addAuth(authVO);
|
||||||
}
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping("/auth")
|
@PutMapping("/auth")
|
||||||
@Operation(summary = "修改授权")
|
@Operation(summary = "修改授权")
|
||||||
public Result<String> upAuth(@RequestBody DataServiceAppVo authVO){
|
@PreAuthorize("hasAuthority('data-service:app:auth')")
|
||||||
dataServiceAppService.upAuth(authVO);
|
public Result<String> upAuth(@RequestBody DataServiceApiAuthVO authVO){
|
||||||
return Result.ok();
|
dataServiceAppService.upAuth(authVO);
|
||||||
}
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping("/cancel-auth/{authId}")
|
@DeleteMapping("/cancel-auth/{authId}")
|
||||||
@Operation(summary = "取消授权")
|
@Operation(summary = "取消授权")
|
||||||
public Result<String> cancelAuth(@PathVariable Long authId){
|
@PreAuthorize("hasAuthority('data-service:app:cancel-auth')")
|
||||||
dataServiceAppService.cancelAuth(authId);
|
public Result<String> cancelAuth(@PathVariable Long authId){
|
||||||
return Result.ok();
|
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;
|
package net.srt.convert;
|
||||||
|
|
||||||
import net.srt.entity.DataServiceAppEntity;
|
import net.srt.entity.DataServiceAppEntity;
|
||||||
import net.srt.vo.DataServiceAppVo;
|
import net.srt.vo.DataServiceAppVO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceAppConvert
|
* 数据服务-app应用
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 09:06
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DataServiceAppConvert {
|
public interface DataServiceAppConvert {
|
||||||
DataServiceAppConvert INSTANCE = Mappers.getMapper(DataServiceAppConvert.class);
|
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;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceAppDao
|
* 数据服务-app应用
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 08:59
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DataServiceAppDao extends BaseDao<DataServiceAppEntity> {
|
public interface DataServiceAppDao extends BaseDao<DataServiceAppEntity> {
|
||||||
DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId);
|
|
||||||
|
DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 privates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启事务 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,62 +1,59 @@
|
||||||
package net.srt.entity;
|
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 com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceApppEntity
|
* 数据服务-app应用
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 08:46
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper=false)
|
||||||
@Data
|
@Data
|
||||||
@TableName("data_service_app")
|
@TableName("data_service_app")
|
||||||
public class DataServiceAppEntity extends BaseEntity {
|
public class DataServiceAppEntity extends BaseEntity {
|
||||||
/**
|
|
||||||
* 名称
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 备注
|
* 名称
|
||||||
*/
|
*/
|
||||||
private String note;
|
private String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* app_key
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String appKey;
|
private String note;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* app_secret
|
* app_key
|
||||||
*/
|
*/
|
||||||
private String appSecret;
|
private String appKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期描述
|
* app_secret
|
||||||
*/
|
*/
|
||||||
private String expireDesc;
|
private String appSecret;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期时间 -1永久;0 单次失效;> 0 失效时间
|
* 过期描述
|
||||||
*/
|
*/
|
||||||
private Long expireDuration;
|
private String expireDesc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间 -1永久;0 单次失效;> 0 失效时间
|
||||||
|
*/
|
||||||
|
private Long expireDuration;
|
||||||
|
|
||||||
|
private Integer ifMarket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属项目id
|
||||||
|
*/
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
private Integer ifMarket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 所属项目id
|
|
||||||
*/
|
|
||||||
private Long projectId;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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.getPrivates() == 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,18 +6,18 @@ import lombok.EqualsAndHashCode;
|
||||||
import net.srt.framework.common.query.Query;
|
import net.srt.framework.common.query.Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceAppQuery
|
* 数据服务-app应用查询
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 08:51
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@Schema(defaultValue = "app权限")
|
@Schema(description = "数据服务-app应用查询")
|
||||||
public class DataServiceAppQuery extends Query {
|
public class DataServiceAppQuery extends Query {
|
||||||
private String name;
|
private String name;
|
||||||
private String appKey;
|
private String appKey;
|
||||||
private Integer ifMarket;
|
private Integer ifMarket;
|
||||||
private Boolean ifInfo;
|
private Boolean ifInfo;
|
||||||
private Long applyId;
|
private Long applyId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.common.page.PageResult;
|
||||||
import net.srt.framework.mybatis.service.BaseService;
|
import net.srt.framework.mybatis.service.BaseService;
|
||||||
import net.srt.query.DataServiceAppQuery;
|
import net.srt.query.DataServiceAppQuery;
|
||||||
import net.srt.vo.DataServiceAppVo;
|
import net.srt.vo.DataServiceApiAuthVO;
|
||||||
|
import net.srt.vo.DataServiceAppVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceAppService
|
* 数据服务-app应用
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 08:53
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
public interface DataServiceAppService extends BaseService<DataServiceAppEntity> {
|
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 delete(List<Long> idList);
|
||||||
|
|
||||||
void addAuth(DataServiceAppVo authVO);
|
void addAuth(DataServiceApiAuthVO authVO);
|
||||||
|
|
||||||
void upAuth(DataServiceAppVo authVO);
|
void cancelAuth(Long authId);
|
||||||
|
|
||||||
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::getPrivates, 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.getPrivates() == 1 ? "是" : "否");
|
||||||
|
if (api.getPrivates() == 1) {
|
||||||
|
docs.append("\n- 获取鉴权token:").append("/data-service/api/token/generate?appKey=您的appKey&appSecret=您的appToken");
|
||||||
|
}
|
||||||
|
docs.append("\n- 接口备注:").append(api.getNote())
|
||||||
|
.append("\n- 请求参数示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getJsonParam()) ? api.getJsonParam() : "{}").append("\n```\n")
|
||||||
|
.append("\n- 响应结果示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getResponseResult()) ? api.getResponseResult() : "{\"code\":0,\"msg\":\"success\",\"data\":[]}").append("\n```\n")
|
||||||
|
.append("\n---\n");
|
||||||
|
}
|
||||||
|
response.setContentType("application/x-msdownload;charset=utf-8");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=API DOCS.md");
|
||||||
|
OutputStream os = null;
|
||||||
|
try {
|
||||||
|
os = response.getOutputStream();
|
||||||
|
os.write(docs.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (os != null)
|
||||||
|
os.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public 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.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import net.srt.convert.DataServiceApiAuthConvert;
|
||||||
import net.srt.convert.DataServiceAppConvert;
|
import net.srt.convert.DataServiceAppConvert;
|
||||||
|
import net.srt.dao.DataServiceApiAuthDao;
|
||||||
import net.srt.dao.DataServiceAppDao;
|
import net.srt.dao.DataServiceAppDao;
|
||||||
|
import net.srt.dto.AppToken;
|
||||||
|
import net.srt.entity.DataServiceApiAuthEntity;
|
||||||
import net.srt.entity.DataServiceAppEntity;
|
import net.srt.entity.DataServiceAppEntity;
|
||||||
|
import net.srt.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.exception.ServerException;
|
||||||
import net.srt.framework.common.page.PageResult;
|
import net.srt.framework.common.page.PageResult;
|
||||||
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||||
import net.srt.framework.security.user.SecurityUser;
|
import net.srt.framework.security.user.SecurityUser;
|
||||||
import net.srt.query.DataServiceAppQuery;
|
import net.srt.query.DataServiceAppQuery;
|
||||||
import net.srt.service.DataServiceAppService;
|
import net.srt.service.DataServiceAppService;
|
||||||
import net.srt.vo.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.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName : DataServiceAppServiceImpl
|
* 数据服务-app应用
|
||||||
* @Description :
|
*
|
||||||
* @Author : FJJ
|
* @author zrx 985134801@qq.com
|
||||||
* @Date: 2023-12-23 08:53
|
* @since 1.0.0 2023-02-16
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao, DataServiceAppEntity> implements DataServiceAppService {
|
public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao, DataServiceAppEntity> implements DataServiceAppService {
|
||||||
private final DataServiceAppDao dataServiceAppDao;
|
|
||||||
@Override
|
|
||||||
public PageResult<DataServiceAppVo> page(DataServiceAppQuery query) {
|
|
||||||
IPage<DataServiceAppEntity> page=baseMapper.selectPage(getPage(query),null);
|
|
||||||
return new PageResult<>(DataServiceAppConvert.INSTANCE.convertList(page.getRecords()),page.getTotal());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private final DataServiceApiAuthDao apiAuthDao;
|
||||||
public void save1(DataServiceAppVo vo) {
|
private final RedisCache redisCache;
|
||||||
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
|
|
||||||
baseMapper.insert(app);
|
@Override
|
||||||
}
|
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 save(DataServiceAppVO vo) {
|
||||||
|
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
|
||||||
|
buildApp(app);
|
||||||
|
baseMapper.insert(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(DataServiceAppVO vo) {
|
||||||
|
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
|
||||||
|
buildApp(app);
|
||||||
|
updateById(app);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private void buildApp(DataServiceAppEntity app) {
|
||||||
public void update1(DataServiceAppVo vo) {
|
app.setProjectId(getProjectId());
|
||||||
DataServiceAppEntity app = DataServiceAppConvert.INSTANCE.convert(vo);
|
if (app.getId() == null) {
|
||||||
updateById(app);
|
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
|
@Override
|
||||||
public void delete(List<Long> idList) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
removeByIds(idList);
|
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
|
@Override
|
||||||
public void addAuth(DataServiceAppVo authVO) {
|
public void addAuth(DataServiceApiAuthVO authVO) {
|
||||||
authVO.setProjectId(getProjectId());
|
authVO.setProjectId(getProjectId());
|
||||||
dataServiceAppDao.insert(DataServiceAppConvert.INSTANCE.convert(authVO));
|
apiAuthDao.insert(DataServiceApiAuthConvert.INSTANCE.convert(authVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upAuth(DataServiceAppVo authVO) {
|
public void cancelAuth(Long authId) {
|
||||||
dataServiceAppDao.updateById(DataServiceAppConvert.INSTANCE.convert(authVO));
|
apiAuthDao.deleteById(authId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelAuth(Long authId) {
|
public String tokenGenerate(String appKey, String appSecret) {
|
||||||
dataServiceAppDao.deleteById(authId);
|
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 privates;
|
||||||
|
|
||||||
|
@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:
|
server:
|
||||||
port: 8099
|
port: 8095
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
mvc:
|
mvc:
|
||||||
|
@ -15,7 +15,7 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 101.34.77.101:8848
|
server-addr: 101.34.77.101:8848
|
||||||
# 命名空间,默认:public
|
# 命名空间,默认:public
|
||||||
namespace: 09dff3e2-9790-4d4f-beb6-9baeb01ae040
|
namespace: 7e1e997d-5fa4-4f84-9f48-3e0adf830a37
|
||||||
service: ${spring.application.name}
|
service: ${spring.application.name}
|
||||||
group: srt2.0
|
group: srt2.0
|
||||||
config:
|
config:
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -61,11 +61,7 @@
|
||||||
<groupId>org.quartz-scheduler</groupId>
|
<groupId>org.quartz-scheduler</groupId>
|
||||||
<artifactId>quartz</artifactId>
|
<artifactId>quartz</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.srt</groupId>
|
|
||||||
<artifactId>srt-cloud-datax</artifactId>
|
|
||||||
<version>2.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ComponentScan(basePackages = "net.srt.framework.common.cache")
|
@ComponentScan(basePackages = {"net.srt.framework.common.cache","net.srt"})
|
||||||
public class QuartzApplication {
|
public class QuartzApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
package net.srt.quartz.api;
|
package net.srt.quartz.api;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.srt.api.module.data.integrate.DataAccessApi;
|
import net.srt.api.module.data.integrate.DataAccessApi;
|
||||||
import net.srt.api.module.data.integrate.constant.TaskType;
|
import net.srt.api.module.data.integrate.constant.TaskType;
|
||||||
import net.srt.api.module.data.integrate.dto.DataAccessDto;
|
import net.srt.api.module.data.integrate.dto.DataAccessDto;
|
||||||
import net.srt.api.module.data.integrate.dto.DataAccessTaskDto;
|
|
||||||
import net.srt.api.module.quartz.QuartzDataAccessApi;
|
import net.srt.api.module.quartz.QuartzDataAccessApi;
|
||||||
import net.srt.api.module.quartz.constant.QuartzJobType;
|
import net.srt.api.module.quartz.constant.QuartzJobType;
|
||||||
import net.srt.datax.feign.DataAccessFeign;
|
|
||||||
import net.srt.framework.common.utils.Result;
|
import net.srt.framework.common.utils.Result;
|
||||||
import net.srt.quartz.entity.ScheduleJobEntity;
|
import net.srt.quartz.entity.ScheduleJobEntity;
|
||||||
import net.srt.quartz.enums.JobGroupEnum;
|
import net.srt.quartz.enums.JobGroupEnum;
|
||||||
import net.srt.quartz.enums.ScheduleConcurrentEnum;
|
import net.srt.quartz.enums.ScheduleConcurrentEnum;
|
||||||
import net.srt.quartz.enums.ScheduleStatusEnum;
|
import net.srt.quartz.enums.ScheduleStatusEnum;
|
||||||
import net.srt.quartz.service.ScheduleJobService;
|
import net.srt.quartz.service.ScheduleJobService;
|
||||||
import net.srt.quartz.task.DataAccessTask;
|
|
||||||
import net.srt.quartz.utils.ScheduleUtils;
|
import net.srt.quartz.utils.ScheduleUtils;
|
||||||
import org.quartz.Scheduler;
|
import org.quartz.Scheduler;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
@ -32,7 +28,6 @@ public class QuartzDataAccessApiImpl implements QuartzDataAccessApi {
|
||||||
private final Scheduler scheduler;
|
private final Scheduler scheduler;
|
||||||
private final DataAccessApi dataAccessApi;
|
private final DataAccessApi dataAccessApi;
|
||||||
private final ScheduleJobService jobService;
|
private final ScheduleJobService jobService;
|
||||||
private final DataAccessFeign feign;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<String> releaseAccess(Long id) {
|
public Result<String> releaseAccess(Long id) {
|
||||||
|
@ -65,10 +60,7 @@ public class QuartzDataAccessApiImpl implements QuartzDataAccessApi {
|
||||||
|
|
||||||
private ScheduleJobEntity buildJobEntity(Long id) {
|
private ScheduleJobEntity buildJobEntity(Long id) {
|
||||||
DataAccessDto dataAccessDto = dataAccessApi.getById(id).getData();
|
DataAccessDto dataAccessDto = dataAccessApi.getById(id).getData();
|
||||||
if (dataAccessDto.getIsDatax().equals("datax")){
|
return ScheduleJobEntity.builder().typeId(id).projectId(dataAccessDto.getProjectId()).jobType(QuartzJobType.DATA_ACCESS.getValue()).jobName(String.format("[%s]%s", id.toString(), dataAccessDto.getTaskName())).concurrent(ScheduleConcurrentEnum.NO.getValue())
|
||||||
feign.execute(dataAccessDto);
|
|
||||||
}
|
|
||||||
return ScheduleJobEntity.builder().isDatax(dataAccessDto.getIsDatax()).typeId(id).projectId(dataAccessDto.getProjectId()).jobType(QuartzJobType.DATA_ACCESS.getValue()).jobName(String.format("[%s]%s", id.toString(), dataAccessDto.getTaskName())).concurrent(ScheduleConcurrentEnum.NO.getValue())
|
|
||||||
.beanName("dataAccessTask").method("run").jobGroup(JobGroupEnum.DATA_ACCESS.getValue()).saveLog(true).cronExpression(dataAccessDto.getCron()).status(ScheduleStatusEnum.NORMAL.getValue())
|
.beanName("dataAccessTask").method("run").jobGroup(JobGroupEnum.DATA_ACCESS.getValue()).saveLog(true).cronExpression(dataAccessDto.getCron()).status(ScheduleStatusEnum.NORMAL.getValue())
|
||||||
.params(String.valueOf(id)).once(TaskType.ONE_TIME_FULL_SYNC.getCode().equals(dataAccessDto.getTaskType())).build();
|
.params(String.valueOf(id)).once(TaskType.ONE_TIME_FULL_SYNC.getCode().equals(dataAccessDto.getTaskType())).build();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,288 @@
|
||||||
|
package net.srt.quartz.task;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.srt.api.module.data.governance.DataMetadataCollectApi;
|
||||||
|
import net.srt.api.module.data.governance.constant.*;
|
||||||
|
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.api.module.data.integrate.DataDatabaseApi;
|
||||||
|
import net.srt.api.module.data.integrate.DataProjectApi;
|
||||||
|
import net.srt.api.module.data.integrate.dto.DataDatabaseDto;
|
||||||
|
import net.srt.flink.common.utils.LogUtil;
|
||||||
|
import net.srt.framework.common.cache.bean.DataProjectCacheBean;
|
||||||
|
import net.srt.framework.common.utils.DateUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import srt.cloud.framework.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||||
|
import srt.cloud.framework.dbswitch.core.model.ColumnDescription;
|
||||||
|
import srt.cloud.framework.dbswitch.core.model.TableDescription;
|
||||||
|
import srt.cloud.framework.dbswitch.core.service.IMetaDataByJdbcService;
|
||||||
|
import srt.cloud.framework.dbswitch.core.service.impl.MetaDataByJdbcServiceImpl;
|
||||||
|
import srt.cloud.framework.dbswitch.core.util.JdbcUrlUtils;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName DataGovernanceMetadataCollectTask
|
||||||
|
* @Author zrx
|
||||||
|
* @Date 2023/04/-2 13:12
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DataGovernanceMetadataCollectTask {
|
||||||
|
|
||||||
|
private final DataMetadataCollectApi dataMetadataCollectApi;
|
||||||
|
private final DataDatabaseApi dataDatabaseApi;
|
||||||
|
private final DataProjectApi dataProjectApi;
|
||||||
|
|
||||||
|
public void run(String metadataCollectId, Thread currentThread) {
|
||||||
|
log.info("metadata collect task start to run...");
|
||||||
|
Long collectTaskId = Long.parseLong(metadataCollectId);
|
||||||
|
DataGovernanceMetadataCollectDto metadataCollectDto = dataMetadataCollectApi.getById(collectTaskId).getData();
|
||||||
|
if (metadataCollectDto == null) {
|
||||||
|
log.error("metadata collect task not found...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Long projectId = metadataCollectDto.getProjectId();
|
||||||
|
//生成同步任务
|
||||||
|
DataGovernanceMetadataCollectRecordDto collectRecord = new DataGovernanceMetadataCollectRecordDto();
|
||||||
|
collectRecord.setProjectId(projectId);
|
||||||
|
collectRecord.setMetadataCollectId(collectTaskId);
|
||||||
|
collectRecord.setStatus(MetadataCollectRunStatus.RUNNING.getCode());
|
||||||
|
collectRecord.setStartTime(new Date());
|
||||||
|
collectRecord.setCreateTime(new Date());
|
||||||
|
collectRecord = dataMetadataCollectApi.addCollectRecord(collectRecord);
|
||||||
|
StringBuilder realTimeLog = new StringBuilder();
|
||||||
|
try {
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append("Start to collect database info...\r\n");
|
||||||
|
Integer dbType = metadataCollectDto.getDbType();
|
||||||
|
//如果是数据库
|
||||||
|
DataDatabaseDto databaseDto;
|
||||||
|
if (DbType.DATABASE.getValue().equals(dbType)) {
|
||||||
|
databaseDto = dataDatabaseApi.getById(metadataCollectDto.getDatabaseId()).getData();
|
||||||
|
if (databaseDto == null) {
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append("Database not exists or get database info failed,get metadata info failed\r\n");
|
||||||
|
collectRecord.setRealTimeLog(realTimeLog.toString());
|
||||||
|
collectRecord.setErrorLog(DateUtils.formatDateTime(new Date()) + " Database not exists or get database info failed,get metadata info failed\r\n");
|
||||||
|
collectRecord.setEndTime(new Date());
|
||||||
|
collectRecord.setStatus(MetadataCollectRunStatus.FAILED.getCode());
|
||||||
|
dataMetadataCollectApi.upCollectRecord(collectRecord);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//获取中台库信息
|
||||||
|
databaseDto = new DataDatabaseDto();
|
||||||
|
DataProjectCacheBean project = dataProjectApi.getById(projectId).getData();
|
||||||
|
databaseDto.setId(-1L);
|
||||||
|
Map<String, String> jdbcParams = JdbcUrlUtils.findParamsByMySqlJdbcUrl(project.getDbUrl());
|
||||||
|
if (jdbcParams != null) {
|
||||||
|
databaseDto.setDatabaseIp(jdbcParams.get("addresss"));
|
||||||
|
databaseDto.setDatabasePort(jdbcParams.get("port"));
|
||||||
|
}
|
||||||
|
databaseDto.setName(project.getName() + "<中台库>");
|
||||||
|
databaseDto.setDatabaseName(project.getDbName());
|
||||||
|
databaseDto.setJdbcUrl(project.getDbUrl());
|
||||||
|
databaseDto.setUserName(project.getDbUsername());
|
||||||
|
databaseDto.setPassword(project.getDbPassword());
|
||||||
|
databaseDto.setDatabaseType(project.getDbType());
|
||||||
|
}
|
||||||
|
DataGovernanceMetadataDto rootMetadata = dataMetadataCollectApi.getMetadataById(metadataCollectDto.getMetadataId()).getData();
|
||||||
|
//获取入库策略
|
||||||
|
Integer strategy = metadataCollectDto.getStrategy();
|
||||||
|
//创建库元数据信息
|
||||||
|
DataGovernanceMetadataDto databaseMetadata = new DataGovernanceMetadataDto();
|
||||||
|
databaseMetadata.setProjectId(projectId);
|
||||||
|
databaseMetadata.setCollectTaskId(collectTaskId);
|
||||||
|
databaseMetadata.setParentId(metadataCollectDto.getMetadataId());
|
||||||
|
databaseMetadata.setName(databaseDto.getName());
|
||||||
|
databaseMetadata.setPath(rootMetadata.getPath() + "/" + databaseMetadata.getName());
|
||||||
|
databaseMetadata.setCode(databaseDto.getDatabaseName());
|
||||||
|
//设置为库类型
|
||||||
|
databaseMetadata.setMetamodelId(BuiltInMetamodel.SCHEMA.getId());
|
||||||
|
databaseMetadata.setIcon(BuiltInMetamodel.SCHEMA.getIcon());
|
||||||
|
databaseMetadata.setIfLeaf(0);
|
||||||
|
databaseMetadata.setDbType(dbType);
|
||||||
|
databaseMetadata.setDatasourceId(databaseDto.getId());
|
||||||
|
//判断是否有该库的元数据
|
||||||
|
DataGovernanceMetadataDto dbDatabaseMetadata = dataMetadataCollectApi.getByParentIdAndDatasourceId(databaseMetadata.getParentId(), databaseMetadata.getDatasourceId()).getData();
|
||||||
|
if (dbDatabaseMetadata != null) {
|
||||||
|
databaseMetadata.setId(dbDatabaseMetadata.getId());
|
||||||
|
}
|
||||||
|
databaseMetadata = dataMetadataCollectApi.addOrUpdateMetadata(databaseMetadata);
|
||||||
|
//添加属性
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_COMMENT, projectId, databaseMetadata.getId(), databaseDto.getName()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_TYPE, projectId, databaseMetadata.getId(), ProductTypeEnum.getByIndex(databaseDto.getDatabaseType()).name()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_IP, projectId, databaseMetadata.getId(), databaseDto.getDatabaseIp()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_PORT, projectId, databaseMetadata.getId(), databaseDto.getDatabasePort()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_DATABASE, projectId, databaseMetadata.getId(), databaseDto.getDatabaseName()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_USERNAME, projectId, databaseMetadata.getId(), databaseDto.getUserName()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_PASSWORD, projectId, databaseMetadata.getId(), databaseDto.getPassword()));
|
||||||
|
addOrUpdateProperty(databaseMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.SCHEMA_JDBC_URL, projectId, databaseMetadata.getId(), databaseDto.getJdbcUrl()));
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append("Start to collect tables info...\r\n");
|
||||||
|
updateRealTimeLog(collectRecord, realTimeLog);
|
||||||
|
//查询表元数据信息
|
||||||
|
ProductTypeEnum productTypeEnum = ProductTypeEnum.getByIndex(databaseDto.getDatabaseType());
|
||||||
|
IMetaDataByJdbcService metaDataService = new MetaDataByJdbcServiceImpl(productTypeEnum);
|
||||||
|
|
||||||
|
List<TableDescription> tables = metaDataService.queryTableList(databaseDto.getJdbcUrl(), databaseDto.getUserName(), databaseDto.getPassword(),
|
||||||
|
ProductTypeEnum.ORACLE.equals(productTypeEnum) ? databaseDto.getUserName() : databaseDto.getDatabaseName());
|
||||||
|
|
||||||
|
if (currentThread.isInterrupted()) {
|
||||||
|
interrupt(collectRecord, realTimeLog);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<DataGovernanceMetadataDto> dbTables = dataMetadataCollectApi.listParentIdAndDatasourceId(databaseMetadata.getId(), databaseDto.getId(), BuiltInMetamodel.TABLE.getId()).getData();
|
||||||
|
//如果是全量,查询数据库中已有的数据
|
||||||
|
if (MetadataStrategyType.ALL.getValue().equals(strategy)) {
|
||||||
|
//如果库里有,tables中没有,删除
|
||||||
|
for (DataGovernanceMetadataDto dbTable : dbTables) {
|
||||||
|
if (tables.stream().noneMatch(item -> item.getTableName().equals(dbTable.getCode()))) {
|
||||||
|
dataMetadataCollectApi.deleteMetadata(dbTable.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//采集表的元数据
|
||||||
|
for (TableDescription table : tables) {
|
||||||
|
if (currentThread.isInterrupted()) {
|
||||||
|
interrupt(collectRecord, realTimeLog);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append(String.format("Start to collect table [%s] info...、\r\n", table.getTableName()));
|
||||||
|
updateRealTimeLog(collectRecord, realTimeLog);
|
||||||
|
//创建表元数据信息
|
||||||
|
DataGovernanceMetadataDto tableMetadata = new DataGovernanceMetadataDto();
|
||||||
|
tableMetadata.setProjectId(projectId);
|
||||||
|
tableMetadata.setCollectTaskId(collectTaskId);
|
||||||
|
tableMetadata.setParentId(databaseMetadata.getId());
|
||||||
|
tableMetadata.setName(StringUtil.isNotBlank(table.getRemarks()) ? table.getRemarks() : table.getTableName());
|
||||||
|
tableMetadata.setPath(databaseMetadata.getPath() + "/" + tableMetadata.getName());
|
||||||
|
tableMetadata.setCode(table.getTableName());
|
||||||
|
//设置为表类型
|
||||||
|
tableMetadata.setMetamodelId(BuiltInMetamodel.TABLE.getId());
|
||||||
|
tableMetadata.setIcon(BuiltInMetamodel.TABLE.getIcon());
|
||||||
|
tableMetadata.setIfLeaf(0);
|
||||||
|
tableMetadata.setDbType(dbType);
|
||||||
|
tableMetadata.setDatasourceId(databaseDto.getId());
|
||||||
|
//判断是否有该库的元数据
|
||||||
|
DataGovernanceMetadataDto finalTableMetadata = tableMetadata;
|
||||||
|
DataGovernanceMetadataDto dbTableMetadata = dbTables.stream().filter(item -> item.getCode().equals(finalTableMetadata.getCode())).findFirst().orElse(null);
|
||||||
|
if (dbTableMetadata != null) {
|
||||||
|
tableMetadata.setId(dbTableMetadata.getId());
|
||||||
|
}
|
||||||
|
tableMetadata = dataMetadataCollectApi.addOrUpdateMetadata(tableMetadata);
|
||||||
|
//添加属性
|
||||||
|
addOrUpdateProperty(tableMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.TABLE_COMMENT, projectId, tableMetadata.getId(), table.getRemarks()));
|
||||||
|
addOrUpdateProperty(tableMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.TABLE_SPACE, projectId, tableMetadata.getId(), null));
|
||||||
|
//获取表的字段
|
||||||
|
List<ColumnDescription> columns = metaDataService.queryTableColumnMeta(databaseDto.getJdbcUrl(), databaseDto.getUserName(), databaseDto.getPassword(), ProductTypeEnum.ORACLE.equals(productTypeEnum) ? databaseDto.getUserName() : databaseDto.getDatabaseName(), table.getTableName());
|
||||||
|
List<String> pks = metaDataService.queryTablePrimaryKeys(databaseDto.getJdbcUrl(), databaseDto.getUserName(), databaseDto.getPassword(), ProductTypeEnum.ORACLE.equals(productTypeEnum) ? databaseDto.getUserName() : databaseDto.getDatabaseName(), table.getTableName());
|
||||||
|
|
||||||
|
List<DataGovernanceMetadataDto> dbColumns = dataMetadataCollectApi.listParentIdAndDatasourceId(tableMetadata.getId(), databaseDto.getId(), BuiltInMetamodel.COLUMN.getId()).getData();
|
||||||
|
//如果是全量
|
||||||
|
if (MetadataStrategyType.ALL.getValue().equals(strategy)) {
|
||||||
|
//如果库里有,columns 中没有,删除
|
||||||
|
for (DataGovernanceMetadataDto dbColumn : dbColumns) {
|
||||||
|
if (columns.stream().noneMatch(item -> item.getFieldName().equals(dbColumn.getCode()))) {
|
||||||
|
dataMetadataCollectApi.deleteMetadata(dbColumn.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (ColumnDescription column : columns) {
|
||||||
|
if (pks.contains(column.getFieldName())) {
|
||||||
|
column.setPk(true);
|
||||||
|
}
|
||||||
|
DataGovernanceMetadataDto columnMetadata = new DataGovernanceMetadataDto();
|
||||||
|
columnMetadata.setProjectId(projectId);
|
||||||
|
columnMetadata.setCollectTaskId(collectTaskId);
|
||||||
|
columnMetadata.setParentId(tableMetadata.getId());
|
||||||
|
columnMetadata.setName(StringUtil.isNotBlank(column.getRemarks()) ? column.getRemarks() : column.getFieldName());
|
||||||
|
columnMetadata.setPath(tableMetadata.getPath() + "/" + columnMetadata.getName());
|
||||||
|
columnMetadata.setCode(column.getFieldName());
|
||||||
|
//设置为字段类型
|
||||||
|
columnMetadata.setMetamodelId(BuiltInMetamodel.COLUMN.getId());
|
||||||
|
columnMetadata.setIcon(BuiltInMetamodel.COLUMN.getIcon());
|
||||||
|
columnMetadata.setIfLeaf(0);
|
||||||
|
columnMetadata.setDbType(dbType);
|
||||||
|
columnMetadata.setDatasourceId(databaseDto.getId());
|
||||||
|
//判断是否有该元数据
|
||||||
|
DataGovernanceMetadataDto finalColumnMetadata = columnMetadata;
|
||||||
|
DataGovernanceMetadataDto dbColumnMetadata = dbColumns.stream().filter(item -> item.getCode().equals(finalColumnMetadata.getCode())).findFirst().orElse(null);
|
||||||
|
//DataGovernanceMetadataDto dbColumnMetadata = dataMetadataApi.getByParentIdAndOtherInfo(columnMetadata.getParentId(), columnMetadata.getDatasourceId(), columnMetadata.getCode(), columnMetadata.getMetamodelId()).getData();
|
||||||
|
if (dbColumnMetadata != null) {
|
||||||
|
columnMetadata.setId(dbColumnMetadata.getId());
|
||||||
|
}
|
||||||
|
columnMetadata = dataMetadataCollectApi.addOrUpdateMetadata(columnMetadata);
|
||||||
|
//添加属性
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_COMMENT, projectId, columnMetadata.getId(), column.getRemarks()));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_DATA_TYPE, projectId, columnMetadata.getId(), column.getFieldTypeName()));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_DATA_LENGTH, projectId, columnMetadata.getId(), String.valueOf(column.getDisplaySize())));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_DATA_PRECISION, projectId, columnMetadata.getId(), String.valueOf(column.getPrecisionSize())));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_DATA_SCALE, projectId, columnMetadata.getId(), String.valueOf(column.getScaleSize())));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_COL_KEY, projectId, columnMetadata.getId(), column.isPk() ? "是" : "否"));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_UNI_KEY, projectId, columnMetadata.getId(), column.isNonIndexUnique() ? "否" : "是"));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_NULLABLE, projectId, columnMetadata.getId(), column.isNullable() ? "是" : "否"));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_AUTO_INCREMENT, projectId, columnMetadata.getId(), column.isAutoIncrement() ? "是" : "否"));
|
||||||
|
addOrUpdateProperty(columnMetadata, BuiltInMetamodelProperty.buildProerty(BuiltInMetamodelProperty.COLUMN_DATA_DEFAULT, projectId, columnMetadata.getId(), column.getDefaultValue()));
|
||||||
|
}
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append(String.format("Collect table [%s] info succeed\r\n", table.getTableName()));
|
||||||
|
updateRealTimeLog(collectRecord, realTimeLog);
|
||||||
|
}
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append("Collect database info succeed\r\n");
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append("All metadata collect succeed\r\n");
|
||||||
|
collectRecord.setEndTime(new Date());
|
||||||
|
collectRecord.setStatus(MetadataCollectRunStatus.SUCCESS.getCode());
|
||||||
|
collectRecord.setRealTimeLog(realTimeLog.toString());
|
||||||
|
dataMetadataCollectApi.upCollectRecord(collectRecord);
|
||||||
|
log.info("metadata collect task success end");
|
||||||
|
} catch (Exception e) {
|
||||||
|
realTimeLog.append(LogUtil.getError(e));
|
||||||
|
collectRecord.setStatus(MetadataCollectRunStatus.FAILED.getCode());
|
||||||
|
collectRecord.setRealTimeLog(realTimeLog.toString());
|
||||||
|
collectRecord.setErrorLog(LogUtil.getError(e));
|
||||||
|
collectRecord.setEndTime(new Date());
|
||||||
|
dataMetadataCollectApi.upCollectRecord(collectRecord);
|
||||||
|
log.info("metadata collect task failed end");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void interrupt(DataGovernanceMetadataCollectRecordDto collectRecord, StringBuilder realTimeLog) {
|
||||||
|
collectRecord.setStatus(MetadataCollectRunStatus.FAILED.getCode());
|
||||||
|
realTimeLog.append(DateUtils.formatDateTime(new Date())).append(" ").append("The collect task has been canceled when is running\r\n");
|
||||||
|
collectRecord.setRealTimeLog(realTimeLog.toString());
|
||||||
|
collectRecord.setErrorLog(DateUtils.formatDateTime(new Date()) + " The collect task has been canceled when is running");
|
||||||
|
collectRecord.setEndTime(new Date());
|
||||||
|
dataMetadataCollectApi.upCollectRecord(collectRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加或删除属性
|
||||||
|
*/
|
||||||
|
private void addOrUpdateProperty(DataGovernanceMetadataDto metadataDto, DataGovernanceMetadataPropertyDto metadataPropertyDto) {
|
||||||
|
DataGovernanceMetadataPropertyDto dbProperty = dataMetadataCollectApi.getByPropertyIdAndMetadataId(metadataPropertyDto.getMetamodelPropertyId(), metadataDto.getId()).getData();
|
||||||
|
if (dbProperty != null) {
|
||||||
|
metadataPropertyDto.setId(dbProperty.getId());
|
||||||
|
}
|
||||||
|
dataMetadataCollectApi.addOrUpdateMetadataProperty(metadataPropertyDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新日志
|
||||||
|
*
|
||||||
|
* @param collectRecord
|
||||||
|
* @param realTimeLog
|
||||||
|
*/
|
||||||
|
private void updateRealTimeLog(DataGovernanceMetadataCollectRecordDto collectRecord, StringBuilder realTimeLog) {
|
||||||
|
collectRecord.setRealTimeLog(realTimeLog.toString());
|
||||||
|
dataMetadataCollectApi.upCollectRecord(collectRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package net.srt.quartz.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.srt.api.module.data.development.DataProductionScheduleApi;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName DataProductionScheduleTask
|
||||||
|
* @Author zrx
|
||||||
|
* @Date 2023/1/19 14:39
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DataProductionScheduleTask {
|
||||||
|
private final DataProductionScheduleApi dataProductionScheduleApi;
|
||||||
|
|
||||||
|
public void run(String id, Thread currentThread) {
|
||||||
|
log.info("start run data-production-schedule");
|
||||||
|
String recordId = dataProductionScheduleApi.scheduleRun(Long.parseLong(id)).getData();
|
||||||
|
//查询调度状态
|
||||||
|
do {
|
||||||
|
ThreadUtil.sleep(5000);
|
||||||
|
/*if (currentThread.isInterrupted()) {
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
} while (!dataProductionScheduleApi.scheduleComplete(Integer.parseInt(recordId)).getData());
|
||||||
|
log.info("run data-production-schedule success");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package net.srt.quartz.utils;
|
package net.srt.quartz.utils;
|
||||||
|
|
||||||
import net.srt.datax.feign.DataAccessFeign;
|
|
||||||
import net.srt.framework.common.exception.ServerException;
|
import net.srt.framework.common.exception.ServerException;
|
||||||
import net.srt.quartz.entity.ScheduleJobEntity;
|
import net.srt.quartz.entity.ScheduleJobEntity;
|
||||||
import net.srt.quartz.enums.ScheduleConcurrentEnum;
|
import net.srt.quartz.enums.ScheduleConcurrentEnum;
|
||||||
|
|
|
@ -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