fjj8.0
parent
c8fbf556fa
commit
f7fb97d164
|
@ -18,6 +18,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||
public class GovernanceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GovernanceApplication.class, args);
|
||||
System.out.println("原神启动!!!!!!!!!!!!!");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +1,92 @@
|
|||
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.cache.bean.Neo4jInfo;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.service.MetadataService;
|
||||
import net.srt.vo.MetadataVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("metadata")
|
||||
@Tag(name = "数据治理-元数据")
|
||||
@AllArgsConstructor
|
||||
public class MetadataController {
|
||||
private final MetadataService metadataService;
|
||||
|
||||
@GetMapping("/list-child")
|
||||
@Operation(summary = "根据父级id获取信息")
|
||||
public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){
|
||||
List<TreeNodeVo> treeNodeVos = metadataService.listByParentId(parentId);
|
||||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
@GetMapping("/list-floder")
|
||||
@Operation(summary = "获取目录树")
|
||||
public Result<List<TreeNodeVo>> listFloder(){
|
||||
List<TreeNodeVo> treeNodeVos = metadataService.listFloder();
|
||||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
@GetMapping("/list-db")
|
||||
@Operation(summary = "获取库表目录树")
|
||||
public Result<List<TreeNodeVo>> listDb(){
|
||||
List<TreeNodeVo> treeNodeVos = metadataService.listDb();
|
||||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
@GetMapping("/list-keyword")
|
||||
@Operation(summary = "模糊查询")
|
||||
public Result<List<TreeNodeVo>> listByKeyword(String keyword){
|
||||
List<TreeNodeVo> treeNodeVos = metadataService.listByKeyword(keyword);
|
||||
return Result.ok(treeNodeVos);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
public Result<MetadataVO> get(@PathVariable("id") Long id){
|
||||
return Result.ok(metadataService.get(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
public Result<String> save(@RequestBody MetadataVO vo){
|
||||
metadataService.save(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
public Result<String> update(@RequestBody @Valid MetadataVO vo) {
|
||||
metadataService.update(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@Operation(summary = "删除")
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
metadataService.delete(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PostMapping("/neo4j")
|
||||
@Operation(summary = "更新neo4j的url")
|
||||
public Result<String> upNeo4jInfo(@RequestBody Neo4jInfo neo4jInfo){
|
||||
metadataService.upNeo4jInfo(neo4jInfo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/neo4j")
|
||||
@Operation(summary = "获取neo4j的url")
|
||||
public Result<Neo4jInfo> getNeo4jInfo(){
|
||||
return Result.ok(metadataService.getNeo4jInfo());
|
||||
}
|
||||
}
|
||||
//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.cache.bean.Neo4jInfo;
|
||||
//import net.srt.framework.common.utils.Result;
|
||||
//import net.srt.framework.common.utils.TreeNodeVo;
|
||||
//import net.srt.service.MetadataService;
|
||||
//
|
||||
//import net.srt.vo.MetadataVO;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import javax.validation.Valid;
|
||||
//import java.util.List;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("metadata")
|
||||
//@Tag(name = "数据治理-元数据")
|
||||
//@AllArgsConstructor
|
||||
//public class MetadataController {
|
||||
//
|
||||
// private final MetadataService metadataService;
|
||||
//
|
||||
// @GetMapping("/list-child")
|
||||
// @Operation(summary = "根据父级id获取信息")
|
||||
// public Result<List<TreeNodeVo>> listByParentId(@RequestParam Long parentId){
|
||||
// List<TreeNodeVo> treeNodeVos = metadataService.listByParentId(parentId);
|
||||
// return Result.ok(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/list-floder")
|
||||
// @Operation(summary = "获取目录树")
|
||||
// public Result<List<TreeNodeVo>> listFloder(){
|
||||
// List<TreeNodeVo> treeNodeVos = metadataService.listFloder();
|
||||
// return Result.ok(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/list-db")
|
||||
// @Operation(summary = "获取库表目录树")
|
||||
// public Result<List<TreeNodeVo>> listDb(){
|
||||
// List<TreeNodeVo> treeNodeVos = metadataService.listDb();
|
||||
// return Result.ok(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/list-keyword")
|
||||
// @Operation(summary = "模糊查询")
|
||||
// public Result<List<TreeNodeVo>> listByKeyword(String keyword){
|
||||
// List<TreeNodeVo> treeNodeVos = metadataService.listByKeyword(keyword);
|
||||
// return Result.ok(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @GetMapping("{id}")
|
||||
// @Operation(summary = "信息")
|
||||
// public Result<MetadataVO> get(@PathVariable("id") Long id){
|
||||
// return Result.ok(metadataService.get(id));
|
||||
// }
|
||||
//
|
||||
// @PostMapping
|
||||
// @Operation(summary = "保存")
|
||||
// public Result<String> save(@RequestBody MetadataVO vo){
|
||||
// metadataService.save(vo);
|
||||
// return Result.ok();
|
||||
// }
|
||||
//
|
||||
// @PutMapping
|
||||
// @Operation(summary = "修改")
|
||||
// public Result<String> update(@RequestBody @Valid MetadataVO vo) {
|
||||
// metadataService.update(vo);
|
||||
// return Result.ok();
|
||||
// }
|
||||
//
|
||||
// @DeleteMapping("{id}")
|
||||
// @Operation(summary = "删除")
|
||||
// public Result<String> delete(@PathVariable Long id) {
|
||||
// metadataService.delete(id);
|
||||
// return Result.ok();
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/neo4j")
|
||||
// @Operation(summary = "更新neo4j的url")
|
||||
// public Result<String> upNeo4jInfo(@RequestBody Neo4jInfo neo4jInfo){
|
||||
// metadataService.upNeo4jInfo(neo4jInfo);
|
||||
// return Result.ok();
|
||||
// }
|
||||
//
|
||||
// @GetMapping("/neo4j")
|
||||
// @Operation(summary = "获取neo4j的url")
|
||||
// public Result<Neo4jInfo> getNeo4jInfo(){
|
||||
// return Result.ok(metadataService.getNeo4jInfo());
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.srt.controller;
|
|||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import net.srt.convert.StandardConvert;
|
||||
import net.srt.entity.DatastandardEntity;
|
||||
import net.srt.entity.StandardEntity;
|
||||
import net.srt.framework.common.utils.BeanUtil;
|
||||
|
@ -35,6 +36,13 @@ public class StandardController {
|
|||
return Result.ok(standardService.listTree());
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
public Result<StandardManagementVo> get(@PathVariable("id") Long id){
|
||||
StandardEntity entity = standardService.getById(id);
|
||||
|
||||
return Result.ok(StandardConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
|
@ -50,9 +58,9 @@ public class StandardController {
|
|||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除")
|
||||
public Result<String> delete(Long id) {
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
standardService.delete(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
|
|
@ -12,5 +12,4 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
*/
|
||||
@Mapper
|
||||
public interface StandardDao extends BaseMapper<StandardEntity> {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
package net.srt.service;
|
||||
|
||||
import net.srt.entity.MetadataEntity;
|
||||
import net.srt.framework.common.cache.bean.Neo4jInfo;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.vo.MetadataVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MetadataService extends BaseService<MetadataEntity> {
|
||||
List<TreeNodeVo> listByParentId(Long parentId);
|
||||
|
||||
List<TreeNodeVo> listFloder();
|
||||
|
||||
List<TreeNodeVo> listDb();
|
||||
|
||||
List<TreeNodeVo> listByKeyword(String keyword);
|
||||
|
||||
MetadataVO get(Long id);
|
||||
|
||||
void save(MetadataVO vo);
|
||||
|
||||
|
||||
void update(MetadataVO vo);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void upNeo4jInfo(Neo4jInfo neo4jInfo);
|
||||
|
||||
Neo4jInfo getNeo4jInfo();
|
||||
}
|
||||
//package net.srt.service;
|
||||
//
|
||||
//import net.srt.entity.MetadataEntity;
|
||||
//import net.srt.framework.common.cache.bean.Neo4jInfo;
|
||||
//import net.srt.framework.common.utils.TreeNodeVo;
|
||||
//import net.srt.framework.mybatis.service.BaseService;
|
||||
//import net.srt.vo.MetadataVO;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//public interface MetadataService extends BaseService<MetadataEntity> {
|
||||
// List<TreeNodeVo> listByParentId(Long parentId);
|
||||
//
|
||||
// List<TreeNodeVo> listFloder();
|
||||
//
|
||||
// List<TreeNodeVo> listDb();
|
||||
//
|
||||
// List<TreeNodeVo> listByKeyword(String keyword);
|
||||
//
|
||||
// MetadataVO get(Long id);
|
||||
//
|
||||
// void save(MetadataVO vo);
|
||||
//
|
||||
//
|
||||
// void update(MetadataVO vo);
|
||||
//
|
||||
// void delete(Long id);
|
||||
//
|
||||
// void upNeo4jInfo(Neo4jInfo neo4jInfo);
|
||||
//
|
||||
// Neo4jInfo getNeo4jInfo();
|
||||
//}
|
||||
|
|
|
@ -1,233 +1,233 @@
|
|||
package net.srt.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.servers.Server;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.api.module.data.governance.constant.BuiltInMetamodel;
|
||||
import net.srt.convert.MetadataConvert;
|
||||
import net.srt.dao.MetadataDao;
|
||||
import net.srt.dao.MetadataPropertyDao;
|
||||
import net.srt.entity.MetadataEntity;
|
||||
import net.srt.entity.MetadataPropertyEntity;
|
||||
import net.srt.framework.common.cache.bean.Neo4jInfo;
|
||||
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.framework.security.cache.TokenStoreCache;
|
||||
import net.srt.service.MetadataService;
|
||||
import net.srt.vo.MetadataVO;
|
||||
import net.srt.vo.MetamodelPropertyVO;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Server
|
||||
@AllArgsConstructor
|
||||
public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEntity> implements MetadataService {
|
||||
|
||||
private final MetadataDao metadataDao;
|
||||
private final MetadataPropertyDao metadataPropertyDao;
|
||||
private final TokenStoreCache tokenStoreCache;
|
||||
|
||||
@Override
|
||||
public List<TreeNodeVo> listByParentId(Long parentId) {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MetadataEntity::getParentId,parentId)
|
||||
.orderByAsc(MetadataEntity::getOrderNo);
|
||||
dataScopeWithOrgId(wrapper);
|
||||
List<MetadataEntity> metadataEntities = baseMapper.selectList(wrapper);
|
||||
return BeanUtil.copyListProperties(metadataEntities,TreeNodeVo::new, (oldItem, newItem) ->{
|
||||
newItem.setLabel(oldItem.getName());
|
||||
newItem.setValue(oldItem.getId());
|
||||
newItem.setLeaf(BuiltInMetamodel.COLUMN.getId().equals(oldItem.getMetamodelId()));
|
||||
if(newItem.getPath().contains("/")){
|
||||
newItem.setParentPath(newItem.getPath().substring(0,newItem.getPath().lastIndexOf("/")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNodeVo> listFloder() {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MetadataEntity::getIfLeaf,1)
|
||||
.orderByAsc(MetadataEntity::getOrderNo)
|
||||
.orderByAsc(MetadataEntity::getId);
|
||||
dataScopeWithOrgId(wrapper);
|
||||
List<MetadataEntity> metadatas = baseMapper.selectList(wrapper);
|
||||
List<TreeNodeVo> treeNodeVos = BeanUtil.copyListProperties(metadatas, TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
newItem.setLabel(oldItem.getName());
|
||||
newItem.setValue(oldItem.getId());
|
||||
if (newItem.getPath().contains("/")) {
|
||||
newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/")));
|
||||
}
|
||||
});
|
||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNodeVo> listDb() {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(MetadataEntity::getMetamodelId,BuiltInMetamodel.SCHEMA.getId(),BuiltInMetamodel.TABLE.getId())
|
||||
.or()
|
||||
.isNull(MetadataEntity::getMetamodelId)
|
||||
.orderByAsc(MetadataEntity::getOrderNo);
|
||||
dataScopeWithOrgId(wrapper);
|
||||
List<MetadataEntity> metadatas = baseMapper.selectList(wrapper);
|
||||
List<TreeNodeVo> treeNodeVos = BeanUtil.copyListProperties(metadatas,TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
newItem.setLabel(oldItem.getName());
|
||||
newItem.setValue(oldItem.getId());
|
||||
newItem.setDisabled(!BuiltInMetamodel.TABLE.getId().equals(oldItem.getMetamodelId()));
|
||||
if(newItem.getPath().contains("/")) {
|
||||
newItem.setParentPath(newItem.getPath().substring(0,newItem.getPath().lastIndexOf("/")));
|
||||
}
|
||||
});
|
||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TreeNodeVo> listByKeyword(String keyword) {
|
||||
if(StringUtil.isBlank(keyword)){
|
||||
return listByParentId(0L);
|
||||
}
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.like(MetadataEntity::getName,keyword)
|
||||
.or()
|
||||
.like(MetadataEntity::getCode,keyword)
|
||||
.orderByAsc(MetadataEntity::getOrderNo)
|
||||
.orderByAsc(MetadataEntity::getId);
|
||||
dataScopeWithOrgId(wrapper);
|
||||
List<MetadataEntity> metadatas = baseMapper.selectList(wrapper);
|
||||
List<MetadataEntity> resultList = new ArrayList<>();
|
||||
//递归获取父级
|
||||
for (MetadataEntity metadata : metadatas) {
|
||||
recursionAddParent(metadata,resultList);
|
||||
}
|
||||
List<MetadataEntity> result = resultList.stream().sorted(Comparator.comparing(MetadataEntity::getOrderNo)).collect(Collectors.toList());
|
||||
List<TreeNodeVo> treeNodeVos = BeanUtil.copyListProperties(result ,TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
newItem.setLabel(oldItem.getName());
|
||||
newItem.setValue(oldItem.getId());
|
||||
newItem.setLeaf(BuiltInMetamodel.COLUMN.getId().equals(oldItem.getMetamodelId()));
|
||||
if(newItem.getPath().contains("/")) {
|
||||
newItem.setParentPath(newItem.getPath().substring(0,newItem.getPath().lastIndexOf("/")));
|
||||
}
|
||||
});
|
||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataVO get(Long id) {
|
||||
MetadataEntity metadataEntity = getById(id);
|
||||
MetadataVO metadataVO = MetadataConvert.INSTANCE.convert(metadataEntity);
|
||||
metadataVO.setProperties(metadataPropertyDao.listPropertyById(id,metadataEntity.getMetamodelId()));
|
||||
return metadataVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(MetadataVO vo) {
|
||||
MetadataEntity entity = MetadataConvert.INSTANCE.convert(vo);
|
||||
entity.setProjectId(getProjectId());
|
||||
entity.setPath(recursionPath(entity,null));
|
||||
buildField(entity);
|
||||
MetadataEntity parentMetadata = baseMapper.selectById(vo.getParentId());
|
||||
if(parentMetadata != null) {
|
||||
entity.setDbType(parentMetadata.getDbType());
|
||||
entity.setDatasourceId(parentMetadata.getDatasourceId());
|
||||
entity.setCollectTaskId(parentMetadata.getCollectTaskId());
|
||||
}
|
||||
baseMapper.insert(entity);
|
||||
buildProperties(entity,vo.getProperties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(MetadataVO vo) {
|
||||
MetadataEntity entity = MetadataConvert.INSTANCE.convert(vo);
|
||||
entity.setProjectId(getProjectId());
|
||||
entity.setPath(recursionPath(entity,null));
|
||||
buildField(entity);
|
||||
updateById(entity);
|
||||
buildProperties(entity,vo.getProperties());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MetadataEntity::getParentId,id).last("limit 1");
|
||||
if(baseMapper.selectOne(wrapper)!=null){
|
||||
throw new ServerException("存在子节点,不可删除!");
|
||||
}
|
||||
removeById(id);
|
||||
LambdaQueryWrapper<MetadataPropertyEntity> propertyWrapper = new LambdaQueryWrapper<>();
|
||||
propertyWrapper.eq(MetadataPropertyEntity::getMetadataId,id);
|
||||
metadataPropertyDao.delete(propertyWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upNeo4jInfo(Neo4jInfo neo4jInfo) {
|
||||
tokenStoreCache.saveNeo4jInfo(getProjectId(),neo4jInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Neo4jInfo getNeo4jInfo() {
|
||||
return tokenStoreCache.getNeo4jInfo(getProjectId());
|
||||
}
|
||||
|
||||
private void recursionAddParent(MetadataEntity metadataEntity, List<MetadataEntity> resultList){
|
||||
if(resultList.stream().noneMatch(item -> metadataEntity.getId().equals(item.getId()))) {
|
||||
resultList.add(metadataEntity);
|
||||
}
|
||||
|
||||
if(metadataEntity.getParentId()!=0){
|
||||
MetadataEntity parent = getById(metadataEntity.getParentId());
|
||||
recursionAddParent(parent,resultList);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildField(MetadataEntity entity){
|
||||
if(entity.getMetamodelId()!=null){
|
||||
entity.setIcon(metadataDao.selectById(entity.getMetamodelId()).getIcon());
|
||||
}
|
||||
if(entity.getIfLeaf() == 1 && entity.getMetamodelId() == null) {
|
||||
entity.setIcon("/src/assets/folder.png");
|
||||
}
|
||||
}
|
||||
|
||||
private String recursionPath(MetadataEntity metadataEntity, String path) {
|
||||
if(StringUtil.isBlank(path)){
|
||||
path = metadataEntity.getName();
|
||||
}
|
||||
if(metadataEntity.getParentId()!=0){
|
||||
MetadataEntity parent = getById(metadataEntity.getParentId());
|
||||
path = parent.getName() + "/" +path;
|
||||
return recursionPath(parent,path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private void buildProperties(MetadataEntity entity, List<MetamodelPropertyVO> properties){
|
||||
if(!CollectionUtils.isEmpty(properties)){
|
||||
LambdaQueryWrapper<MetadataPropertyEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MetadataPropertyEntity::getMetadataId,entity.getId());
|
||||
for (MetamodelPropertyVO property : properties) {
|
||||
MetadataPropertyEntity metadataPropertyEntity = new MetadataPropertyEntity();
|
||||
metadataPropertyEntity.setMetamodelPropertyId(property.getId());
|
||||
metadataPropertyEntity.setMetadataId(entity.getId());
|
||||
metadataPropertyEntity.setProperty(property.getValue());
|
||||
metadataPropertyEntity.setProjectId(entity.getProjectId());
|
||||
if(property.getMetadataPropertyId()!=null){
|
||||
metadataPropertyEntity.setId(property.getMetadataPropertyId());
|
||||
metadataPropertyDao.updateById(metadataPropertyEntity);
|
||||
}else {
|
||||
metadataPropertyDao.insert(metadataPropertyEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//package net.srt.service.impl;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
//import io.swagger.v3.oas.annotations.servers.Server;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import net.srt.api.module.data.governance.constant.BuiltInMetamodel;
|
||||
//import net.srt.convert.MetadataConvert;
|
||||
//import net.srt.dao.MetadataDao;
|
||||
//import net.srt.dao.MetadataPropertyDao;
|
||||
//import net.srt.entity.MetadataEntity;
|
||||
//import net.srt.entity.MetadataPropertyEntity;
|
||||
//import net.srt.framework.common.cache.bean.Neo4jInfo;
|
||||
//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.framework.security.cache.TokenStoreCache;
|
||||
//import net.srt.service.MetadataService;
|
||||
//import net.srt.vo.MetadataVO;
|
||||
//import net.srt.vo.MetamodelPropertyVO;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//import org.springframework.util.CollectionUtils;
|
||||
//import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Comparator;
|
||||
//import java.util.List;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//@Server
|
||||
//@AllArgsConstructor
|
||||
//public class MetadataServiceImpl extends BaseServiceImpl<MetadataDao, MetadataEntity> implements MetadataService {
|
||||
//
|
||||
// private final MetadataDao metadataDao;
|
||||
// private final MetadataPropertyDao metadataPropertyDao;
|
||||
// private final TokenStoreCache tokenStoreCache;
|
||||
//
|
||||
// @Override
|
||||
// public List<TreeNodeVo> listByParentId(Long parentId) {
|
||||
// LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.eq(MetadataEntity::getParentId,parentId)
|
||||
// .orderByAsc(MetadataEntity::getOrderNo);
|
||||
// dataScopeWithOrgId(wrapper);
|
||||
// List<MetadataEntity> metadataEntities = baseMapper.selectList(wrapper);
|
||||
// return BeanUtil.copyListProperties(metadataEntities,TreeNodeVo::new, (oldItem, newItem) ->{
|
||||
// newItem.setLabel(oldItem.getName());
|
||||
// newItem.setValue(oldItem.getId());
|
||||
// newItem.setLeaf(BuiltInMetamodel.COLUMN.getId().equals(oldItem.getMetamodelId()));
|
||||
// if(newItem.getPath().contains("/")){
|
||||
// newItem.setParentPath(newItem.getPath().substring(0,newItem.getPath().lastIndexOf("/")));
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<TreeNodeVo> listFloder() {
|
||||
// LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.eq(MetadataEntity::getIfLeaf,1)
|
||||
// .orderByAsc(MetadataEntity::getOrderNo)
|
||||
// .orderByAsc(MetadataEntity::getId);
|
||||
// dataScopeWithOrgId(wrapper);
|
||||
// List<MetadataEntity> metadatas = baseMapper.selectList(wrapper);
|
||||
// List<TreeNodeVo> treeNodeVos = BeanUtil.copyListProperties(metadatas, TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
// newItem.setLabel(oldItem.getName());
|
||||
// newItem.setValue(oldItem.getId());
|
||||
// if (newItem.getPath().contains("/")) {
|
||||
// newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/")));
|
||||
// }
|
||||
// });
|
||||
// return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<TreeNodeVo> listDb() {
|
||||
// LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.in(MetadataEntity::getMetamodelId,BuiltInMetamodel.SCHEMA.getId(),BuiltInMetamodel.TABLE.getId())
|
||||
// .or()
|
||||
// .isNull(MetadataEntity::getMetamodelId)
|
||||
// .orderByAsc(MetadataEntity::getOrderNo);
|
||||
// dataScopeWithOrgId(wrapper);
|
||||
// List<MetadataEntity> metadatas = baseMapper.selectList(wrapper);
|
||||
// List<TreeNodeVo> treeNodeVos = BeanUtil.copyListProperties(metadatas,TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
// newItem.setLabel(oldItem.getName());
|
||||
// newItem.setValue(oldItem.getId());
|
||||
// newItem.setDisabled(!BuiltInMetamodel.TABLE.getId().equals(oldItem.getMetamodelId()));
|
||||
// if(newItem.getPath().contains("/")) {
|
||||
// newItem.setParentPath(newItem.getPath().substring(0,newItem.getPath().lastIndexOf("/")));
|
||||
// }
|
||||
// });
|
||||
// return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<TreeNodeVo> listByKeyword(String keyword) {
|
||||
// if(StringUtil.isBlank(keyword)){
|
||||
// return listByParentId(0L);
|
||||
// }
|
||||
// LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.like(MetadataEntity::getName,keyword)
|
||||
// .or()
|
||||
// .like(MetadataEntity::getCode,keyword)
|
||||
// .orderByAsc(MetadataEntity::getOrderNo)
|
||||
// .orderByAsc(MetadataEntity::getId);
|
||||
// dataScopeWithOrgId(wrapper);
|
||||
// List<MetadataEntity> metadatas = baseMapper.selectList(wrapper);
|
||||
// List<MetadataEntity> resultList = new ArrayList<>();
|
||||
// //递归获取父级
|
||||
// for (MetadataEntity metadata : metadatas) {
|
||||
// recursionAddParent(metadata,resultList);
|
||||
// }
|
||||
// List<MetadataEntity> result = resultList.stream().sorted(Comparator.comparing(MetadataEntity::getOrderNo)).collect(Collectors.toList());
|
||||
// List<TreeNodeVo> treeNodeVos = BeanUtil.copyListProperties(result ,TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
// newItem.setLabel(oldItem.getName());
|
||||
// newItem.setValue(oldItem.getId());
|
||||
// newItem.setLeaf(BuiltInMetamodel.COLUMN.getId().equals(oldItem.getMetamodelId()));
|
||||
// if(newItem.getPath().contains("/")) {
|
||||
// newItem.setParentPath(newItem.getPath().substring(0,newItem.getPath().lastIndexOf("/")));
|
||||
// }
|
||||
// });
|
||||
// return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public MetadataVO get(Long id) {
|
||||
// MetadataEntity metadataEntity = getById(id);
|
||||
// MetadataVO metadataVO = MetadataConvert.INSTANCE.convert(metadataEntity);
|
||||
// metadataVO.setProperties(metadataPropertyDao.listPropertyById(id,metadataEntity.getMetamodelId()));
|
||||
// return metadataVO;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void save(MetadataVO vo) {
|
||||
// MetadataEntity entity = MetadataConvert.INSTANCE.convert(vo);
|
||||
// entity.setProjectId(getProjectId());
|
||||
// entity.setPath(recursionPath(entity,null));
|
||||
// buildField(entity);
|
||||
// MetadataEntity parentMetadata = baseMapper.selectById(vo.getParentId());
|
||||
// if(parentMetadata != null) {
|
||||
// entity.setDbType(parentMetadata.getDbType());
|
||||
// entity.setDatasourceId(parentMetadata.getDatasourceId());
|
||||
// entity.setCollectTaskId(parentMetadata.getCollectTaskId());
|
||||
// }
|
||||
// baseMapper.insert(entity);
|
||||
// buildProperties(entity,vo.getProperties());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void update(MetadataVO vo) {
|
||||
// MetadataEntity entity = MetadataConvert.INSTANCE.convert(vo);
|
||||
// entity.setProjectId(getProjectId());
|
||||
// entity.setPath(recursionPath(entity,null));
|
||||
// buildField(entity);
|
||||
// updateById(entity);
|
||||
// buildProperties(entity,vo.getProperties());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void delete(Long id) {
|
||||
// LambdaQueryWrapper<MetadataEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.eq(MetadataEntity::getParentId,id).last("limit 1");
|
||||
// if(baseMapper.selectOne(wrapper)!=null){
|
||||
// throw new ServerException("存在子节点,不可删除!");
|
||||
// }
|
||||
// removeById(id);
|
||||
// LambdaQueryWrapper<MetadataPropertyEntity> propertyWrapper = new LambdaQueryWrapper<>();
|
||||
// propertyWrapper.eq(MetadataPropertyEntity::getMetadataId,id);
|
||||
// metadataPropertyDao.delete(propertyWrapper);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void upNeo4jInfo(Neo4jInfo neo4jInfo) {
|
||||
// tokenStoreCache.saveNeo4jInfo(getProjectId(),neo4jInfo);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Neo4jInfo getNeo4jInfo() {
|
||||
// return tokenStoreCache.getNeo4jInfo(getProjectId());
|
||||
// }
|
||||
//
|
||||
// private void recursionAddParent(MetadataEntity metadataEntity, List<MetadataEntity> resultList){
|
||||
// if(resultList.stream().noneMatch(item -> metadataEntity.getId().equals(item.getId()))) {
|
||||
// resultList.add(metadataEntity);
|
||||
// }
|
||||
//
|
||||
// if(metadataEntity.getParentId()!=0){
|
||||
// MetadataEntity parent = getById(metadataEntity.getParentId());
|
||||
// recursionAddParent(parent,resultList);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void buildField(MetadataEntity entity){
|
||||
// if(entity.getMetamodelId()!=null){
|
||||
// entity.setIcon(metadataDao.selectById(entity.getMetamodelId()).getIcon());
|
||||
// }
|
||||
// if(entity.getIfLeaf() == 1 && entity.getMetamodelId() == null) {
|
||||
// entity.setIcon("/src/assets/folder.png");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private String recursionPath(MetadataEntity metadataEntity, String path) {
|
||||
// if(StringUtil.isBlank(path)){
|
||||
// path = metadataEntity.getName();
|
||||
// }
|
||||
// if(metadataEntity.getParentId()!=0){
|
||||
// MetadataEntity parent = getById(metadataEntity.getParentId());
|
||||
// path = parent.getName() + "/" +path;
|
||||
// return recursionPath(parent,path);
|
||||
// }
|
||||
// return path;
|
||||
// }
|
||||
//
|
||||
// private void buildProperties(MetadataEntity entity, List<MetamodelPropertyVO> properties){
|
||||
// if(!CollectionUtils.isEmpty(properties)){
|
||||
// LambdaQueryWrapper<MetadataPropertyEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
// wrapper.eq(MetadataPropertyEntity::getMetadataId,entity.getId());
|
||||
// for (MetamodelPropertyVO property : properties) {
|
||||
// MetadataPropertyEntity metadataPropertyEntity = new MetadataPropertyEntity();
|
||||
// metadataPropertyEntity.setMetamodelPropertyId(property.getId());
|
||||
// metadataPropertyEntity.setMetadataId(entity.getId());
|
||||
// metadataPropertyEntity.setProperty(property.getValue());
|
||||
// metadataPropertyEntity.setProjectId(entity.getProjectId());
|
||||
// if(property.getMetadataPropertyId()!=null){
|
||||
// metadataPropertyEntity.setId(property.getMetadataPropertyId());
|
||||
// metadataPropertyDao.updateById(metadataPropertyEntity);
|
||||
// }else {
|
||||
// metadataPropertyDao.insert(metadataPropertyEntity);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
|||
import net.srt.controller.StandardController;
|
||||
import net.srt.convert.StandardConvert;
|
||||
import net.srt.dao.StandardDao;
|
||||
import net.srt.entity.MetamodelEntity;
|
||||
import net.srt.entity.StandardEntity;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
import net.srt.framework.common.utils.BeanUtil;
|
||||
|
@ -66,7 +67,7 @@ public class StandardServiceImpl extends BaseServiceImpl<StandardDao, StandardEn
|
|||
StandardEntity entity = StandardConvert.INSTANCE.convert(vo);
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
entity.setProjectId(getProjectId());
|
||||
updateById(entity);
|
||||
baseMapper.updateById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,6 +92,7 @@ public class StandardServiceImpl extends BaseServiceImpl<StandardDao, StandardEn
|
|||
if (one != null) {
|
||||
throw new ServerException("存在子节点,不允许删除!");
|
||||
}
|
||||
//删除
|
||||
removeById(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package net.srt.constants;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ApiConstants {
|
||||
public static final String API_PREFIX = "/api/v1"; // 例如,这里定义了一个API的前缀
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package net.srt.constants;
|
||||
|
||||
import net.srt.dao.ApiConfigDao;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/api")
|
||||
public class ApiController {
|
||||
|
||||
private boolean isOnline = true;
|
||||
|
||||
@GetMapping("/status")
|
||||
public ResponseEntity<String> getStatus() {
|
||||
String status = isOnline ? "online" : "offline";
|
||||
return ResponseEntity.ok("API status: " + status);
|
||||
}
|
||||
|
||||
@GetMapping("/resource/{id}")
|
||||
public ResponseEntity<String> getResource(@PathVariable Long id) {
|
||||
if (!isOnline) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
|
||||
}
|
||||
|
||||
// 处理获取资源的逻辑...
|
||||
|
||||
String resource = ""; // 假设这里是获取资源的代码
|
||||
|
||||
if (resource != null) {
|
||||
return ResponseEntity.ok("Resource: " + resource);
|
||||
} else {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/offline")
|
||||
public ResponseEntity<String> offline() {
|
||||
isOnline = false;
|
||||
return ResponseEntity.ok("API is now offline");
|
||||
}
|
||||
|
||||
@GetMapping("/online")
|
||||
public ResponseEntity<String> online() {
|
||||
isOnline = true;
|
||||
return ResponseEntity.ok("API is now online");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package net.srt.constants;
|
||||
|
||||
public enum ApiGroupType {
|
||||
FOLDER(1,"数据库"),
|
||||
API(2,"数据库");
|
||||
private final Integer value;
|
||||
private final String longValue;
|
||||
|
||||
ApiGroupType(Integer value, String longValue) {
|
||||
this.value = value;
|
||||
this.longValue = longValue;
|
||||
}
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
public String getLongValue() {
|
||||
return longValue;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
package net.srt.controller;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.convert.ApiConfigConvert;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.query.ApiConfigQuery;
|
||||
import net.srt.service.ApiConfigService;
|
||||
import net.srt.vo.ApiConfigVo;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api-config")
|
||||
@AllArgsConstructor
|
||||
public class ApiConfigController {
|
||||
private final ApiConfigService apiConfigService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('data-service:api-config:page')")
|
||||
public Result<PageResult<ApiConfigVo>> page(@Valid ApiConfigQuery query) {
|
||||
PageResult<ApiConfigVo> page = apiConfigService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
@GetMapping("page-resource")
|
||||
@Operation(summary = "根据resourceId分页获取")
|
||||
public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){
|
||||
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("page-auth")
|
||||
@Operation(summary = "根据resourceId分页获取")
|
||||
public Result<PageResult<ApiConfigVo>> pageAuth(@Valid ApiConfigQuery query) {
|
||||
PageResult<ApiConfigVo> page = apiConfigService.page(query);
|
||||
|
||||
return Result.ok(page);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:info')")
|
||||
public Result<ApiConfigVo> get(@PathVariable("id") Long id){
|
||||
ApiConfigEntity entity=apiConfigService.getById(id);
|
||||
return Result.ok(ApiConfigConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:save')")
|
||||
public Result<String> save(@RequestBody ApiConfigVo vo) {
|
||||
apiConfigService.save(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:update')")
|
||||
public Result<String> update(@RequestBody ApiConfigVo vo){
|
||||
apiConfigService.update(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
apiConfigService.delete(idList);
|
||||
return Result.ok();
|
||||
}
|
||||
@GetMapping("getIpPort")
|
||||
public Result<String> getIpPort() {
|
||||
return Result.ok(apiConfigService.getIpPort());
|
||||
}
|
||||
@Operation(summary = "获取服务的ip和端口号")
|
||||
@GetMapping("/ip-port")
|
||||
public Result<String> ipPort() {
|
||||
return Result.ok(apiConfigService.ipPort());
|
||||
}
|
||||
@Operation(summary = "上线")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:online')")
|
||||
@PutMapping("/{id}/online")
|
||||
public Result<String> online(@PathVariable Long id) {
|
||||
apiConfigService.online(id);
|
||||
return Result.ok();
|
||||
}
|
||||
@Operation(summary = "下线")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')")
|
||||
@PutMapping("/{id}/offline")
|
||||
public Result<String> offline(@PathVariable Long id){
|
||||
apiConfigService.offline(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "执行sql")
|
||||
@PostMapping("/sql/execute")
|
||||
public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto dto) {
|
||||
return Result.ok(apiConfigService.sqlExecute(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "导出 api 文档")
|
||||
@PostMapping(value = "/export-docs")
|
||||
public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) {
|
||||
apiConfigService.exportDocs(ids, response);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package net.srt.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.convert.ApiGroupConvert;
|
||||
import net.srt.entity.ApiGroupEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.query.ApiConfigQuery;
|
||||
import net.srt.service.ApiGroupService;
|
||||
import net.srt.vo.ApiConfigVo;
|
||||
import net.srt.vo.ApiGroupVo;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api-group")
|
||||
@AllArgsConstructor
|
||||
public class ApiGroupController {
|
||||
private final ApiGroupService apiGroupService;
|
||||
@GetMapping
|
||||
@Operation(summary = "查询文件分组树")
|
||||
public Result<List<TreeNodeVo>> listTree() {
|
||||
return Result.ok(apiGroupService.listTree());
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:info')")
|
||||
public Result<ApiGroupVo> get(@PathVariable("id") Long id){
|
||||
ApiGroupEntity entity = apiGroupService.getById(id);
|
||||
|
||||
return Result.ok(ApiGroupConvert.INSTANCE.convert(entity));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:save')")
|
||||
public Result<String> save(@RequestBody ApiGroupVo vo) {
|
||||
apiGroupService.save(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:update')")
|
||||
public Result<String> update(@RequestBody @Valid ApiGroupVo vo) {
|
||||
apiGroupService.update(vo);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:delete')")
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
apiGroupService.delete(id);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package net.srt.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.dao.DataServiceAppDao;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.service.DataServiceAppService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiController
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-26 20:38
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@Tag(name = "api")
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiController {
|
||||
private final DataServiceAppService dataServiceAppService;
|
||||
@GetMapping("/token/generate")
|
||||
public Result<String> tokenGenerate(@RequestParam String appKey, @RequestParam String appSecret) {
|
||||
return Result.ok(dataServiceAppService.tokenGenerate(appKey, appSecret));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package net.srt.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.query.DataServiceApiLogQuery;
|
||||
import net.srt.query.DataServiceAppQuery;
|
||||
import net.srt.service.DataServiceApiLogService;
|
||||
import net.srt.vo.DataServiceApiLogVo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogController
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:29
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("log")
|
||||
@Tag(name = "api请求日志")
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiLogController {
|
||||
private final DataServiceApiLogService dataServiceApiLogService;
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
public Result<PageResult<DataServiceApiLogVo>> page(@Valid DataServiceApiLogQuery query){
|
||||
//查询数据
|
||||
PageResult<DataServiceApiLogVo> page=dataServiceApiLogService.dataPageList(query);
|
||||
return Result.ok(page);
|
||||
}
|
||||
@DeleteMapping
|
||||
@Operation(summary ="删除")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
dataServiceApiLogService.removeId(idList);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -8,7 +8,9 @@ import net.srt.framework.common.page.PageResult;
|
|||
import net.srt.framework.common.utils.Result;
|
||||
import net.srt.query.DataServiceAppQuery;
|
||||
import net.srt.service.DataServiceAppService;
|
||||
import net.srt.vo.DataServiceApiAuthVo;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
@ -61,16 +63,18 @@ public class DataServiceAppController {
|
|||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/auth")
|
||||
@Operation(summary = "添加授权")
|
||||
public Result<String> addAuth(@RequestBody DataServiceAppVo authVO){
|
||||
public Result<String> addAuth(@RequestBody DataServiceApiAuthVo authVO){
|
||||
dataServiceAppService.addAuth(authVO);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@PutMapping("/auth")
|
||||
@Operation(summary = "修改授权")
|
||||
public Result<String> upAuth(@RequestBody DataServiceAppVo authVO){
|
||||
public Result<String> upAuth(@RequestBody DataServiceApiAuthVo authVO){
|
||||
dataServiceAppService.upAuth(authVO);
|
||||
return Result.ok();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.dto.ApiConfigDto;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import net.srt.vo.ApiConfigVo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface ApiConfigConvert {
|
||||
ApiConfigConvert INSTANCE = Mappers.getMapper(ApiConfigConvert.class);
|
||||
|
||||
ApiConfigEntity convert(ApiConfigVo vo);
|
||||
|
||||
ApiConfigVo convert(ApiConfigEntity entity);
|
||||
|
||||
ApiConfigDto convertDto(ApiConfigEntity entity);
|
||||
|
||||
List<ApiConfigVo> convertList(List<ApiConfigEntity> list);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.entity.ApiGroupEntity;
|
||||
import net.srt.vo.ApiGroupVo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据服务-api分组
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface ApiGroupConvert {
|
||||
ApiGroupConvert INSTANCE = Mappers.getMapper(ApiGroupConvert.class);
|
||||
|
||||
ApiGroupEntity convert(ApiGroupVo vo);
|
||||
|
||||
ApiGroupVo convert(ApiGroupEntity entity);
|
||||
|
||||
List<ApiGroupVo> convertList(List<ApiGroupEntity> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.vo.DataServiceApiAuthVo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiAuthConvert
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-26 19:45
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiAuthConvert {
|
||||
DataServiceApiAuthConvert INSTANCE = Mappers.getMapper(DataServiceApiAuthConvert.class);
|
||||
|
||||
|
||||
DataServiceApiAuthEntity convert(DataServiceApiAuthVo vo);
|
||||
|
||||
DataServiceApiAuthVo convert(DataServiceApiAuthEntity entity);
|
||||
|
||||
List<DataServiceApiAuthVo> convertList(List<DataServiceApiAuthEntity> list);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package net.srt.convert;
|
||||
|
||||
import net.srt.entity.DataServiceApiLogEntity;
|
||||
import net.srt.vo.DataServiceApiLogVo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogConvert
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:30
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiLogConvert {
|
||||
DataServiceApiLogConvert INSTANCE = Mappers.getMapper(DataServiceApiLogConvert.class);
|
||||
DataServiceApiLogEntity convert(DataServiceApiLogVo vo);
|
||||
|
||||
DataServiceApiLogVo convert(DataServiceApiLogEntity entity);
|
||||
|
||||
List<DataServiceApiLogVo> convertList(List<DataServiceApiLogEntity> list);
|
||||
}
|
|
@ -19,6 +19,7 @@ public interface DataServiceAppConvert {
|
|||
|
||||
DataServiceAppEntity convert(DataServiceAppVo vo);
|
||||
|
||||
|
||||
DataServiceAppVo convert(DataServiceAppEntity entity);
|
||||
|
||||
List<DataServiceAppVo> convertList(List<DataServiceAppEntity> list);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import net.srt.framework.mybatis.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface ApiConfigDao extends BaseDao<ApiConfigEntity> {
|
||||
List<ApiConfigEntity> getResourceList(Map<String, Object> params);
|
||||
|
||||
ApiConfigEntity getById(Long id);
|
||||
|
||||
void updateById(@Param("apiId") Long apiId, @Param("id") Long id);
|
||||
|
||||
List<ApiConfigEntity> getAuthList(Map<String, Object> params);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.ApiGroupEntity;
|
||||
import net.srt.framework.mybatis.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ApiGroupDao extends BaseDao<ApiGroupEntity> {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.framework.mybatis.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiAuthDao
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-26 15:23
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiAuthDao extends BaseDao<DataServiceApiAuthEntity> {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package net.srt.dao;
|
||||
|
||||
import net.srt.entity.DataServiceApiLogEntity;
|
||||
import net.srt.framework.mybatis.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogDao
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:30
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataServiceApiLogDao extends BaseDao<DataServiceApiLogEntity> {
|
||||
}
|
|
@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.Param;
|
|||
*/
|
||||
@Mapper
|
||||
public interface DataServiceAppDao extends BaseDao<DataServiceAppEntity> {
|
||||
DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId);
|
||||
// DataServiceAppEntity selectByApplyId(@Param("applyId") Long applyId);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package net.srt.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.common.utils.DateUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
public class ApiConfigDto implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Long id;
|
||||
private Long groupId;
|
||||
private String path;
|
||||
private String type;
|
||||
private String name;
|
||||
private String note;
|
||||
private String sqlText;
|
||||
private String sqlSeparator;
|
||||
private Integer sqlMaxRow;
|
||||
private String sqlParam;
|
||||
private String jsonParam;
|
||||
private String responseResult;
|
||||
private String contentType;
|
||||
private Integer status;
|
||||
private Date releaseTime;
|
||||
private Long releaseUserId;
|
||||
private Integer sqlDbType;
|
||||
private Long databaseId;
|
||||
private Integer privates;
|
||||
private Integer openTrans;
|
||||
private Long projectId;
|
||||
private Integer version;
|
||||
private Integer deleted;
|
||||
private Long creator;
|
||||
private Date createTime;
|
||||
private Long updater;
|
||||
private Date updateTime;
|
||||
private Integer requestedTimes;
|
||||
private Integer requestedSuccessTimes;
|
||||
private Integer requestedFailedTimes;
|
||||
private Long authId;
|
||||
private String group;
|
||||
|
||||
}
|
|
@ -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,15 @@
|
|||
package net.srt.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SqlDto {
|
||||
private Integer sqlDbType;
|
||||
private Long projectId;
|
||||
private String statement;
|
||||
private String sqlSeparator;
|
||||
private Long databaseId;
|
||||
private Integer openTrans;
|
||||
private String jsonParams;
|
||||
private Integer sqlMaxRow;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package net.srt.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("data_service_api_config")
|
||||
public class ApiConfigEntity extends BaseEntity {
|
||||
private Long groupId;
|
||||
private String path;
|
||||
private String type;
|
||||
private String name;
|
||||
private String note;
|
||||
private String sqlText;
|
||||
private String sqlSeparator;
|
||||
private Integer sqlMaxRow;
|
||||
private String sqlParam;
|
||||
private String jsonParam;
|
||||
private String responseResult;
|
||||
private String contentType;
|
||||
private Integer status;
|
||||
private Date releaseTime;
|
||||
private Long releaseUserId;
|
||||
private Integer sqlDbType;
|
||||
private Long databaseId;
|
||||
private Integer privates;
|
||||
private Integer openTrans;
|
||||
private Long projectId;
|
||||
private Integer requestedTimes;
|
||||
private Integer requestedSuccessTimes;
|
||||
private Integer requestedFailedTimes;
|
||||
private Long authId;
|
||||
private String groupPath;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package net.srt.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
@Data
|
||||
@TableName("data_service_api_group")
|
||||
public class ApiGroupEntity extends BaseEntity {
|
||||
private Long parentId;
|
||||
private Integer type;
|
||||
private String name;
|
||||
private String description;
|
||||
private Integer orderNo;
|
||||
private String path;
|
||||
private Long projectId;
|
||||
}
|
|
@ -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,69 @@
|
|||
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 : DataServiceApiAuthEntity
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-26 15:20
|
||||
*/
|
||||
@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,61 @@
|
|||
package net.srt.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.srt.framework.mybatis.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogEntity
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:11
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Data
|
||||
@TableName("data_service_api_log1")
|
||||
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;
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package net.srt.handler;
|
||||
|
||||
// 导入必要的类
|
||||
|
||||
import net.srt.constants.ApiConstants;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
// 假设这是你的接口处理类
|
||||
public class ApiHandler {
|
||||
private Map<RequestMappingInfo, ApiConfigEntity> mappings = new HashMap<>();
|
||||
|
||||
public void registerApi(ApiConfigEntity api) {
|
||||
RequestMappingInfo mappingInfo = RequestMappingInfo
|
||||
.paths(ApiConstants.API_PREFIX + api.getPath()) // 使用API_PREFIX常量
|
||||
.methods(RequestMethod.valueOf(api.getType()))
|
||||
.build();
|
||||
|
||||
mappings.put(mappingInfo, api);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package net.srt.handler;
|
||||
|
||||
import net.srt.constants.ApiConstants;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
public class ApiRegistration {
|
||||
private RequestMappingHandlerMapping handlerMapping; // 注入或实例化 RequestMappingHandlerMapping 对象
|
||||
|
||||
public void registerApi(String path, String method, Object handler, String handlerMethod) throws NoSuchMethodException {
|
||||
RequestMappingInfo mappingInfo = RequestMappingInfo
|
||||
.paths(ApiConstants.API_PREFIX + path)
|
||||
.methods(RequestMethod.valueOf(method))
|
||||
.build();
|
||||
|
||||
HandlerMethod handlerMethodObject = new HandlerMethod(handler, handlerMethod);
|
||||
handlerMapping.registerMapping(mappingInfo, handlerMethodObject.getBean(), handlerMethodObject.getMethod());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package net.srt.handler;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MappingRequestHandler {
|
||||
Object invoke(HttpServletRequest request, String apiToken, Map<String, Object> pathVariables,
|
||||
Map<String, Object> requestParams, Map<String, Object> requestBodys);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package net.srt.handler;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingRequestHandlerExample {
|
||||
private final MappingRequestHandler handler;
|
||||
private Method method;
|
||||
|
||||
public MappingRequestHandlerExample(MappingRequestHandler handler) {
|
||||
this.handler = handler;
|
||||
try {
|
||||
method = MappingRequestHandler.class.getDeclaredMethod(
|
||||
"invoke", HttpServletRequest.class, String.class, Map.class, Map.class, Map.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void getHandlerAndMethod() {
|
||||
System.out.println("Handler: " + handler);
|
||||
System.out.println("Method: " + method);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package net.srt.query;
|
||||
|
||||
import lombok.Data;
|
||||
import net.srt.framework.common.query.Query;
|
||||
|
||||
@Data
|
||||
public class ApiConfigQuery extends Query {
|
||||
private Long groupId;
|
||||
private Long resourceId;
|
||||
private Long appId;
|
||||
private String name;
|
||||
private String path;
|
||||
private String contentType;
|
||||
private Integer status;
|
||||
private Integer sqlDbType;
|
||||
private Long databaseId;
|
||||
private Integer privates;
|
||||
private Integer openTrans;
|
||||
private Integer queryApply;
|
||||
private Integer ifMarket;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.srt.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import net.srt.framework.common.query.Query;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogQuery
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(description = "api日志")
|
||||
public class DataServiceApiLogQuery extends Query {
|
||||
private String ip;
|
||||
private String apiName;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package net.srt.service;
|
||||
|
||||
import cn.hutool.http.server.HttpServerResponse;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.query.ApiConfigQuery;
|
||||
import net.srt.vo.ApiConfigVo;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
public interface ApiConfigService extends BaseService<ApiConfigEntity> {
|
||||
String getIpPort();
|
||||
|
||||
PageResult<ApiConfigVo> page(ApiConfigQuery query);
|
||||
|
||||
void save(ApiConfigVo vo);
|
||||
|
||||
void update(ApiConfigVo vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
PageResult<ApiConfigVo> pageResource(ApiConfigQuery query);
|
||||
|
||||
List<ApiConfigEntity> listActiveByGroupId(Long id);
|
||||
|
||||
void online(Long id);
|
||||
|
||||
void offline(Long id);
|
||||
|
||||
String ipPort();
|
||||
|
||||
JdbcSelectResult sqlExecute(SqlDto dto);
|
||||
|
||||
void exportDocs(List<Long> ids, HttpServletResponse response);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package net.srt.service;
|
||||
|
||||
import net.srt.entity.ApiGroupEntity;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.vo.ApiGroupVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApiGroupService extends BaseService<ApiGroupEntity> {
|
||||
List<TreeNodeVo> listTree();
|
||||
|
||||
void save(ApiGroupVo vo);
|
||||
|
||||
void update(ApiGroupVo vo);
|
||||
|
||||
void delete(Long id);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package net.srt.service;
|
||||
|
||||
import net.srt.entity.DataServiceApiLogEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.query.DataServiceApiLogQuery;
|
||||
import net.srt.vo.DataServiceApiLogVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogService
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:31
|
||||
*/
|
||||
public interface DataServiceApiLogService extends BaseService<DataServiceApiLogEntity> {
|
||||
PageResult<DataServiceApiLogVo> dataPageList(DataServiceApiLogQuery query);
|
||||
|
||||
void removeId(List<Long> idList);
|
||||
}
|
|
@ -4,6 +4,7 @@ import net.srt.entity.DataServiceAppEntity;
|
|||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.BaseService;
|
||||
import net.srt.query.DataServiceAppQuery;
|
||||
import net.srt.vo.DataServiceApiAuthVo;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -23,9 +24,11 @@ public interface DataServiceAppService extends BaseService<DataServiceAppEntity>
|
|||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
void addAuth(DataServiceAppVo authVO);
|
||||
void addAuth(DataServiceApiAuthVo authVO);
|
||||
|
||||
void upAuth(DataServiceAppVo authVO);
|
||||
void upAuth(DataServiceApiAuthVo authVO);
|
||||
|
||||
void cancelAuth(Long authId);
|
||||
|
||||
String tokenGenerate(String appKey, String appSecret);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,266 @@
|
|||
package net.srt.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.api.ServerNames;
|
||||
import net.srt.convert.ApiConfigConvert;
|
||||
import net.srt.dao.ApiConfigDao;
|
||||
import net.srt.dao.ApiGroupDao;
|
||||
import net.srt.dto.SqlDto;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import net.srt.entity.ApiGroupEntity;
|
||||
import net.srt.framework.common.constant.Constant;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.srt.framework.security.user.SecurityUser;
|
||||
import net.srt.query.ApiConfigQuery;
|
||||
import net.srt.service.ApiConfigService;
|
||||
import net.srt.vo.ApiConfigVo;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
import srt.cloud.framework.dbswitch.core.model.JdbcSelectResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfigEntity> implements ApiConfigService {
|
||||
private final ApiGroupDao apiGroupDao;
|
||||
private final DiscoveryClient discoveryClient;
|
||||
private final ApiConfigDao apiConfigDao;
|
||||
private final Map<String, ApiConfigEntity> mappings = new ConcurrentHashMap<>();
|
||||
@Override
|
||||
public String getIpPort() {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||
return instances.get(0).getHost() + ":" + instances.get(0).getPort()+"/data-service/api/";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void online(Long id) {
|
||||
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
|
||||
if (apiConfigEntity != null) {
|
||||
apiConfigEntity.setStatus(1);
|
||||
apiConfigEntity.setReleaseTime(new Date());
|
||||
apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
|
||||
String routeKey = getRouteKeyByRequestTypeAndUrl(apiConfigEntity.getType(), apiConfigEntity.getPath());
|
||||
boolean isExists = checkIfExists(routeKey);
|
||||
|
||||
if (isExists) {
|
||||
ApiConfigEntity configEntity = mappings.get(routeKey);
|
||||
if (configEntity != null) { // 添加 null 判断
|
||||
offline(configEntity.getId()); // 修正方法调用为传入id
|
||||
// 从 mappings 中移除该 routeKey
|
||||
mappings.remove(routeKey);
|
||||
}
|
||||
} else {
|
||||
mappings.put(routeKey, apiConfigEntity);
|
||||
}
|
||||
apiConfigDao.updateById(apiConfigEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIfExists(String routeKey) {
|
||||
// 这里是全局的 mappings
|
||||
Map<String, ApiConfigEntity> globalMappings = getGlobalMappings();
|
||||
|
||||
return globalMappings.containsKey(routeKey);
|
||||
}
|
||||
|
||||
private Map<String, ApiConfigEntity> getGlobalMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
private String getRouteKeyByRequestTypeAndUrl(String type, String path) {
|
||||
return getRouteKey(type, path);
|
||||
}
|
||||
|
||||
private String getRouteKey(String type, String path) {
|
||||
return type.toUpperCase() + "_" + path.toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void offline(Long id) { // 修正参数类型为 Long id
|
||||
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
|
||||
if (apiConfigEntity != null) {
|
||||
apiConfigEntity.setStatus(0);
|
||||
apiConfigEntity.setReleaseTime(null);
|
||||
apiConfigEntity.setReleaseUserId(null);
|
||||
apiConfigDao.updateById(apiConfigEntity);
|
||||
}else{
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found");
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public void online(Long id) {
|
||||
// ApiConfigEntity apiConfigEntity = new ApiConfigEntity();
|
||||
// apiConfigEntity.setId(id);
|
||||
// apiConfigEntity.setStatus(1);
|
||||
// apiConfigEntity.setReleaseTime(new Date());
|
||||
// apiConfigEntity.setReleaseUserId(SecurityUser.getUserId());
|
||||
//
|
||||
// apiConfigDao.updateById(apiConfigEntity);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String ipPort() {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||
return instances.get(0).getHost() + ":" + instances.get(0).getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcSelectResult sqlExecute(SqlDto dto) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportDocs(List<Long> ids, HttpServletResponse response) {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||
ServiceInstance instance = instances.get(0);
|
||||
StringBuilder docs = new StringBuilder("## 接口文档\n---\n");
|
||||
List<ApiConfigEntity> apiConfigEntities = baseMapper.selectBatchIds(ids);
|
||||
for (ApiConfigEntity api : apiConfigEntities) {
|
||||
docs.append("### ").append(api.getName())
|
||||
.append("\n- IP地址:").append(instance.getHost())
|
||||
.append("\n- 端口:").append(instance.getPort())
|
||||
.append("\n- 接口地址:/data-service/api/").append(api.getPath())
|
||||
.append("\n- 请求方式:").append(api.getType())
|
||||
.append("\n- Content-Type:").append(api.getContentType())
|
||||
.append("\n- 是否需要鉴权:").append(api.getPrivates() == 1 ? "是" : "否");
|
||||
if (api.getPrivates() == 1) {
|
||||
docs.append("\n- 获取鉴权token:").append("/data-service/api/token/generate?appKey=您的appKey&appSecret=您的appToken");
|
||||
}
|
||||
docs.append("\n- 接口备注:").append(api.getNote())
|
||||
.append("\n- 请求参数示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getJsonParam()) ? api.getJsonParam() : "{}").append("\n```\n")
|
||||
.append("\n- 响应结果示例:").append("\n```json\n").append(StringUtil.isNotBlank(api.getResponseResult()) ? api.getResponseResult() : "{\"code\":0,\"msg\":\"success\",\"data\":[]}").append("\n```\n")
|
||||
.append("\n---\n");
|
||||
}
|
||||
response.setContentType("application/x-msdownload;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=API DOCS.md");
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = response.getOutputStream();
|
||||
os.write(docs.toString().getBytes(StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (os != null)
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ApiConfigVo> page(ApiConfigQuery query) {
|
||||
// 查询参数
|
||||
Map<String, Object> params = getParams(query);
|
||||
// 分页查询
|
||||
query.setOrder("dsac.id");
|
||||
IPage<ApiConfigEntity> page = getPage(query);
|
||||
params.put(Constant.PAGE, page);
|
||||
// 数据列表
|
||||
List<ApiConfigEntity> list = baseMapper.getAuthList(params);
|
||||
return new PageResult<>(ApiConfigConvert.INSTANCE.convertList(list), page.getTotal());
|
||||
}
|
||||
private LambdaQueryWrapper getWrapper(ApiConfigQuery query) {
|
||||
LambdaQueryWrapper<ApiConfigEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StringUtil.isNotBlank(query.getName()), ApiConfigEntity::getName, query.getName());
|
||||
wrapper.like(StringUtil.isNotBlank(query.getPath()), ApiConfigEntity::getPath, query.getPath());
|
||||
wrapper.eq(StringUtil.isNotBlank(query.getContentType()), ApiConfigEntity::getContentType, query.getContentType());
|
||||
wrapper.eq(query.getStatus()!= null, ApiConfigEntity::getStatus, query.getStatus());
|
||||
wrapper.eq(query.getSqlDbType() != null, ApiConfigEntity::getSqlDbType, query.getSqlDbType());
|
||||
wrapper.eq(query.getDatabaseId()!= null, ApiConfigEntity::getDatabaseId, query.getDatabaseId());
|
||||
wrapper.eq(query.getPrivates()!= null, ApiConfigEntity::getPrivates, query.getPrivates());
|
||||
wrapper.eq(query.getOpenTrans()!= null, ApiConfigEntity::getOpenTrans, query.getOpenTrans());
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
wrapper.orderByDesc(ApiConfigEntity::getCreateTime);
|
||||
wrapper.orderByDesc(ApiConfigEntity::getId);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ApiConfigVo vo) {
|
||||
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
|
||||
entity.setProjectId(getProjectId());
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ApiConfigVo vo) {
|
||||
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
|
||||
entity.setProjectId(getProjectId());
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ApiConfigVo> pageResource(ApiConfigQuery query) {
|
||||
// 查询参数
|
||||
Map<String, Object> params = getParams(query);
|
||||
IPage<ApiConfigEntity> page = getPage(query);
|
||||
params.put(Constant.PAGE, page);
|
||||
// 数据列表
|
||||
List<ApiConfigEntity> list = baseMapper.getResourceList(params);
|
||||
List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(list);
|
||||
for (ApiConfigVo apiConfigVo : apiConfigVos) {
|
||||
ApiGroupEntity groupEntity = apiGroupDao.selectById(apiConfigVo.getGroupId());
|
||||
apiConfigVo.setGroup(groupEntity != null ? groupEntity.getPath() : null);
|
||||
}
|
||||
return new PageResult<>(apiConfigVos, page.getTotal());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApiConfigEntity> listActiveByGroupId(Long id) {
|
||||
LambdaQueryWrapper<ApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ApiConfigEntity::getStatus, 1).eq(ApiConfigEntity::getGroupId, id).orderByDesc(ApiConfigEntity::getId);
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
return baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
private Map<String, Object> getParams(ApiConfigQuery query) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("ifMarket", query.getIfMarket());
|
||||
params.put("queryApply", query.getQueryApply());
|
||||
if (query.getQueryApply() != null && query.getQueryApply() == 1) {
|
||||
params.put("userId", SecurityUser.getUserId());
|
||||
}
|
||||
params.put("resourceId", query.getResourceId());
|
||||
params.put("groupId", query.getGroupId());
|
||||
params.put("appId", query.getAppId());
|
||||
params.put("name", query.getName());
|
||||
params.put("path", query.getPath());
|
||||
params.put("contentType", query.getContentType());
|
||||
params.put("status", query.getStatus());
|
||||
params.put("sqlDbType", query.getSqlDbType());
|
||||
params.put("databaseId", query.getDatabaseId());
|
||||
params.put("privates", query.getPrivates());
|
||||
params.put("openTrans", query.getOpenTrans());
|
||||
// 数据权限
|
||||
params.put(Constant.DATA_SCOPE, getDataScope("dsac", null, null, "project_id", false, true));
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package net.srt.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.constants.ApiGroupType;
|
||||
import net.srt.convert.ApiGroupConvert;
|
||||
import net.srt.dao.ApiGroupDao;
|
||||
import net.srt.entity.ApiConfigEntity;
|
||||
import net.srt.entity.ApiGroupEntity;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
import net.srt.framework.common.utils.BeanUtil;
|
||||
import net.srt.framework.common.utils.BuildTreeUtils;
|
||||
import net.srt.framework.common.utils.TreeNodeVo;
|
||||
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.srt.service.ApiConfigService;
|
||||
import net.srt.service.ApiGroupService;
|
||||
import net.srt.vo.ApiGroupVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEntity> implements ApiGroupService{
|
||||
private final ApiConfigService apiConfigService;
|
||||
@Override
|
||||
public List<TreeNodeVo> listTree() {
|
||||
List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
|
||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
}
|
||||
|
||||
private List<TreeNodeVo> getTreeNodeVos() {
|
||||
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
wrapper.orderByAsc(ApiGroupEntity::getOrderNo);
|
||||
List<ApiGroupEntity> 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 void save(ApiGroupVo vo) {
|
||||
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
entity.setProjectId(getProjectId());
|
||||
baseMapper.insert(entity); // 使用 insertSelective() 方法进行插入操作
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ApiGroupVo vo) {
|
||||
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
entity.setProjectId(getProjectId());
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
private String recursionPath(ApiGroupEntity groupEntity, String path) {
|
||||
if (StringUtil.isBlank(path)) {
|
||||
path = groupEntity.getName();
|
||||
}
|
||||
if (groupEntity.getParentId() != 0) {
|
||||
ApiGroupEntity parent = getById(groupEntity.getParentId());
|
||||
path = parent.getName() + "/" + path;
|
||||
return recursionPath(parent, path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
//查询有没有子节点
|
||||
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ApiGroupEntity::getParentId, id).last(" limit 1");
|
||||
ApiGroupEntity one = baseMapper.selectOne(wrapper);
|
||||
if (one != null) {
|
||||
throw new ServerException("存在子节点,不允许删除!");
|
||||
}
|
||||
//查询有没有api与之关联
|
||||
LambdaQueryWrapper<ApiConfigEntity> serviceApiConfigWrapper = new LambdaQueryWrapper<>();
|
||||
serviceApiConfigWrapper.eq(ApiConfigEntity::getGroupId, id).last(" limit 1");
|
||||
ApiConfigEntity apiConfigEntity = apiConfigService.getOne(serviceApiConfigWrapper);
|
||||
if (apiConfigEntity != null) {
|
||||
throw new ServerException("节点下有 api 与之关联,不允许删除!");
|
||||
}
|
||||
removeById(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package net.srt.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.convert.DataServiceApiLogConvert;
|
||||
import net.srt.dao.DataServiceApiLogDao;
|
||||
import net.srt.entity.DataServiceApiLogEntity;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.srt.query.DataServiceApiLogQuery;
|
||||
import net.srt.service.DataServiceApiLogService;
|
||||
import net.srt.vo.DataServiceApiLogVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLogServiceImpl
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:31
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataServiceApiLogServiceImpl extends BaseServiceImpl<DataServiceApiLogDao, DataServiceApiLogEntity> implements DataServiceApiLogService {
|
||||
@Override
|
||||
public PageResult<DataServiceApiLogVo> dataPageList(DataServiceApiLogQuery query) {
|
||||
IPage<DataServiceApiLogEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
||||
return new PageResult<>(DataServiceApiLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeId(List<Long> idList) {
|
||||
removeByIds(idList);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DataServiceApiLogEntity> getWrapper(DataServiceApiLogQuery query) {
|
||||
LambdaQueryWrapper<DataServiceApiLogEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StringUtil.isNotBlank(query.getIp()), DataServiceApiLogEntity::getIp, query.getIp())
|
||||
.like(StringUtil.isNotBlank(query.getApiName()), DataServiceApiLogEntity::getApiName, query.getApiName())
|
||||
.orderByDesc(DataServiceApiLogEntity::getCreateTime).orderByDesc(DataServiceApiLogEntity::getId);
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -4,8 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.srt.convert.DataServiceApiAuthConvert;
|
||||
import net.srt.convert.DataServiceAppConvert;
|
||||
import net.srt.dao.ApiConfigDao;
|
||||
import net.srt.dao.DataServiceApiAuthDao;
|
||||
import net.srt.dao.DataServiceAppDao;
|
||||
import net.srt.dto.AppToken;
|
||||
import net.srt.entity.DataServiceApiAuthEntity;
|
||||
import net.srt.entity.DataServiceAppEntity;
|
||||
import net.srt.framework.common.exception.ServerException;
|
||||
import net.srt.framework.common.page.PageResult;
|
||||
|
@ -13,7 +18,9 @@ import net.srt.framework.mybatis.service.impl.BaseServiceImpl;
|
|||
import net.srt.framework.security.user.SecurityUser;
|
||||
import net.srt.query.DataServiceAppQuery;
|
||||
import net.srt.service.DataServiceAppService;
|
||||
import net.srt.vo.DataServiceApiAuthVo;
|
||||
import net.srt.vo.DataServiceAppVo;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import srt.cloud.framework.dbswitch.common.util.StringUtil;
|
||||
|
||||
|
@ -30,6 +37,8 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao, DataServiceAppEntity> implements DataServiceAppService {
|
||||
private final DataServiceAppDao dataServiceAppDao;
|
||||
private final ApiConfigDao apiConfigDao;
|
||||
private final DataServiceApiAuthDao dataServiceApiAuthDao;
|
||||
@Override
|
||||
public PageResult<DataServiceAppVo> page(DataServiceAppQuery query) {
|
||||
IPage<DataServiceAppEntity> page=baseMapper.selectPage(getPage(query),null);
|
||||
|
@ -56,14 +65,18 @@ public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addAuth(DataServiceAppVo authVO) {
|
||||
public void addAuth(DataServiceApiAuthVo authVO) {
|
||||
authVO.setProjectId(getProjectId());
|
||||
dataServiceAppDao.insert(DataServiceAppConvert.INSTANCE.convert(authVO));
|
||||
DataServiceApiAuthEntity entity = DataServiceApiAuthConvert.INSTANCE.convert(authVO);
|
||||
dataServiceApiAuthDao.insert(entity);
|
||||
Long id = entity.getId();
|
||||
apiConfigDao.updateById(authVO.getApiId(),id);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upAuth(DataServiceAppVo authVO) {
|
||||
dataServiceAppDao.updateById(DataServiceAppConvert.INSTANCE.convert(authVO));
|
||||
public void upAuth(DataServiceApiAuthVo authVO) {
|
||||
dataServiceApiAuthDao.updateById(DataServiceApiAuthConvert.INSTANCE.convert(authVO));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,14 +84,42 @@ public class DataServiceAppServiceImpl extends BaseServiceImpl<DataServiceAppDao
|
|||
dataServiceAppDao.deleteById(authId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tokenGenerate(String appKey, String appSecret) {
|
||||
LambdaQueryWrapper<DataServiceAppEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(DataServiceAppEntity::getAppKey,appKey).last("limit 1");
|
||||
DataServiceAppEntity dataServiceAppEntity = baseMapper.selectOne(wrapper);
|
||||
if (dataServiceAppEntity==null){
|
||||
throw new RuntimeException("appKey不存在");
|
||||
}
|
||||
if (!appSecret.equals(dataServiceAppEntity.getAppSecret())){
|
||||
throw new ServerException("appSecret错误");
|
||||
}
|
||||
//生成token
|
||||
String token = RandomStringUtils.random(32, true, true);
|
||||
AppToken appToken = new AppToken();
|
||||
appToken.setToken(token);
|
||||
appToken.setAppKey(appKey);
|
||||
appToken.setAppId(dataServiceAppEntity.getId());
|
||||
if (dataServiceAppEntity.getExpireDuration()==0){
|
||||
appToken.setExpireAt(0L);
|
||||
} else if (dataServiceAppEntity.getExpireDuration()== -1) {
|
||||
appToken.setExpireAt(-1L);
|
||||
}else if (dataServiceAppEntity.getExpireDuration()>0){
|
||||
long l = System.currentTimeMillis() + dataServiceAppEntity.getExpireDuration() * 1000;
|
||||
appToken.setExpireAt(l);
|
||||
}
|
||||
return appToken.getToken();
|
||||
}
|
||||
|
||||
// private LambdaQueryWrapper<DataServiceAppEntity> getWrapper(DataServiceAppQuery query) {
|
||||
// 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;
|
||||
// }
|
||||
|
||||
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,145 @@
|
|||
package net.srt.utils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.security.Key;
|
||||
|
||||
/**
|
||||
* @ClassName : EncrypDES
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 09:31
|
||||
*/
|
||||
public class EncrypDES {
|
||||
|
||||
// 字符串默认键值
|
||||
private static String strDefaultKey = "inventec2020@#$%^&";
|
||||
|
||||
//加密工具
|
||||
private Cipher encryptCipher = null;
|
||||
|
||||
// 解密工具
|
||||
private Cipher decryptCipher = null;
|
||||
|
||||
/**
|
||||
* 默认构造方法,使用默认密钥
|
||||
*/
|
||||
public EncrypDES() throws Exception {
|
||||
this(strDefaultKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定密钥构造方法
|
||||
* @param strKey 指定的密钥
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public EncrypDES(String strKey) throws Exception {
|
||||
|
||||
// Security.addProvider(new com.sun.crypto.provider.SunJCE());
|
||||
Key key = getKey(strKey.getBytes());
|
||||
encryptCipher = Cipher.getInstance("DES");
|
||||
encryptCipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
decryptCipher = Cipher.getInstance("DES");
|
||||
decryptCipher.init(Cipher.DECRYPT_MODE, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813,和public static byte[]
|
||||
*
|
||||
* hexStr2ByteArr(String strIn) 互为可逆的转换过程
|
||||
*
|
||||
* @param arrB 需要转换的byte数组
|
||||
* @return 转换后的字符串
|
||||
* @throws Exception 本方法不处理任何异常,所有异常全部抛出
|
||||
*/
|
||||
public static String byteArr2HexStr(byte[] arrB) throws Exception {
|
||||
int iLen = arrB.length;
|
||||
// 每个byte用2个字符才能表示,所以字符串的长度是数组长度的2倍
|
||||
StringBuffer sb = new StringBuffer(iLen * 2);
|
||||
for (int i = 0; i < iLen; i++) {
|
||||
int intTmp = arrB[i];
|
||||
// 把负数转换为正数
|
||||
while (intTmp < 0) {
|
||||
intTmp = intTmp + 256;
|
||||
}
|
||||
// 小于0F的数需要在前面补0
|
||||
if (intTmp < 16) {
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(Integer.toString(intTmp, 16));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将表示16进制值的字符串转换为byte数组,和public static String byteArr2HexStr(byte[] arrB)
|
||||
* 互为可逆的转换过程
|
||||
* @param strIn 需要转换的字符串
|
||||
* @return 转换后的byte数组
|
||||
*/
|
||||
public static byte[] hexStr2ByteArr(String strIn) throws Exception {
|
||||
byte[] arrB = strIn.getBytes();
|
||||
int iLen = arrB.length;
|
||||
// 两个字符表示一个字节,所以字节数组长度是字符串长度除以2
|
||||
byte[] arrOut = new byte[iLen / 2];
|
||||
for (int i = 0; i < iLen; i = i + 2) {
|
||||
String strTmp = new String(arrB, i, 2);
|
||||
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
|
||||
}
|
||||
return arrOut;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 加密字节数组
|
||||
* @param arrB 需加密的字节数组
|
||||
* @return 加密后的字节数组
|
||||
*/
|
||||
public byte[] encrypt(byte[] arrB) throws Exception {
|
||||
return encryptCipher.doFinal(arrB);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密字符串
|
||||
* @param strIn 需加密的字符串
|
||||
* @return 加密后的字符串
|
||||
*/
|
||||
public String encrypt(String strIn) throws Exception {
|
||||
return byteArr2HexStr(encrypt(strIn.getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密字节数组
|
||||
* @param arrB 需解密的字节数组
|
||||
* @return 解密后的字节数组
|
||||
*/
|
||||
public byte[] decrypt(byte[] arrB) throws Exception {
|
||||
return decryptCipher.doFinal(arrB);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密字符串
|
||||
* @param strIn 需解密的字符串
|
||||
* @return 解密后的字符串
|
||||
*/
|
||||
public String decrypt(String strIn) throws Exception {
|
||||
return new String(decrypt(hexStr2ByteArr(strIn)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从指定字符串生成密钥,密钥所需的字节数组长度为8位 不足8位时后面补0,超出8位只取前8位
|
||||
* @param arrBTmp 构成该字符串的字节数组
|
||||
* @return 生成的密钥
|
||||
*/
|
||||
private Key getKey(byte[] arrBTmp) throws Exception {
|
||||
// 创建一个空的8位字节数组(默认值为0)
|
||||
byte[] arrB = new byte[8];
|
||||
// 将原始字节数组转换为8位
|
||||
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
|
||||
arrB[i] = arrBTmp[i];
|
||||
}
|
||||
// 生成密钥
|
||||
Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
|
||||
return key;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package net.srt.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.common.utils.DateUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 数据服务-api配置
|
||||
*
|
||||
* @author zrx 985134801@qq.com
|
||||
* @since 1.0.0 2023-01-28
|
||||
*/
|
||||
@Data
|
||||
public class ApiConfigVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Long id;
|
||||
private Long groupId;
|
||||
private String path;
|
||||
private String type;
|
||||
private String name;
|
||||
private String note;
|
||||
private String sqlText;
|
||||
private String sqlSeparator;
|
||||
private Integer sqlMaxRow;
|
||||
private String sqlParam;
|
||||
private String jsonParam;
|
||||
private String responseResult;
|
||||
private String contentType;
|
||||
private Integer status;
|
||||
private Date releaseTime;
|
||||
private Long releaseUserId;
|
||||
private Integer sqlDbType;
|
||||
private Long databaseId;
|
||||
private Integer privates;
|
||||
private Integer openTrans;
|
||||
private Long projectId;
|
||||
private Integer version;
|
||||
private Integer deleted;
|
||||
private Long creator;
|
||||
private Date createTime;
|
||||
private Long updater;
|
||||
private Date updateTime;
|
||||
private Integer requestedTimes;
|
||||
private Integer requestedSuccessTimes;
|
||||
private Integer requestedFailedTimes;
|
||||
private Long authId;
|
||||
private String group;
|
||||
private String groupPath;
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package net.srt.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ApiGroupVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Long id;
|
||||
private Long parentId;
|
||||
private Integer type;
|
||||
private String name;
|
||||
private String description;
|
||||
private Integer orderNo;
|
||||
private String path;
|
||||
private Long projectId;
|
||||
private Integer version;
|
||||
private Integer deleted;
|
||||
private Long creator;
|
||||
private Date createTime;
|
||||
private Long updater;
|
||||
private Date updateTime;
|
||||
}
|
|
@ -42,6 +42,8 @@ public class DataServiceApiAuthVo implements Serializable {
|
|||
@Schema(description = "所属项目id")
|
||||
private Long projectId;
|
||||
|
||||
private Long authId;
|
||||
|
||||
@Schema(description = "版本号")
|
||||
private Integer version;
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package net.srt.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.common.utils.DateUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName : DataServiceApiLog
|
||||
* @Description :
|
||||
* @Author : FJJ
|
||||
* @Date: 2023-12-25 11:05
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "api请求日志")
|
||||
public class DataServiceApiLogVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "url")
|
||||
private String url;
|
||||
|
||||
@Schema(description = "响应状态码")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "时长")
|
||||
private Long duration;
|
||||
|
||||
@Schema(description = "IP地址")
|
||||
private String ip;
|
||||
|
||||
@Schema(description = "app的id")
|
||||
private String appId;
|
||||
|
||||
@Schema(description = "api的id")
|
||||
private String apiId;
|
||||
|
||||
private String appName;
|
||||
private String apiName;
|
||||
|
||||
@Schema(description = "错误信息")
|
||||
private String error;
|
||||
|
||||
@Schema(description = "项目id")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "版本号")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "删除标识 0:正常 1:已删除")
|
||||
private Integer deleted;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private Long creator;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "更新者")
|
||||
private Long updater;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date updateTime;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package net.srt.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.common.utils.DateUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @BelongsProject: data-center
|
||||
* @BelongsPackage: net.srt.vo
|
||||
* @Author: yanqiang
|
||||
* @CreateTime: 2023-12-24 15:21
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Schema(description = "api日志")
|
||||
public class ServiceApiLogVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "url")
|
||||
private String url;
|
||||
|
||||
@Schema(description = "响应状态码")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "时长")
|
||||
private Long duration;
|
||||
|
||||
@Schema(description = "IP地址")
|
||||
private String ip;
|
||||
|
||||
@Schema(description = "app的id")
|
||||
private String appId;
|
||||
|
||||
@Schema(description = "api的id")
|
||||
private String apiId;
|
||||
|
||||
private String appName;
|
||||
private String apiName;
|
||||
|
||||
@Schema(description = "错误信息")
|
||||
private String error;
|
||||
|
||||
@Schema(description = "项目id")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "版本号")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "删除标识 0:正常 1:已删除")
|
||||
private Integer deleted;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private Long creator;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "更新者")
|
||||
private Long updater;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
|
||||
private Date updateTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package net.srt.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.srt.framework.common.utils.DateUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @BelongsProject: data-center
|
||||
* @BelongsPackage: net.srt.vo
|
||||
* @Author: yanqiang
|
||||
* @CreateTime: 2023-12-21 20:50
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Schema(description = "数据app")
|
||||
public class ServiceAppVo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String note;
|
||||
|
||||
@Schema(description = "appKey")
|
||||
private String appKey;
|
||||
|
||||
@Schema(description = "appSecret")
|
||||
private String appSecret;
|
||||
|
||||
@Schema(description = "过期时间")
|
||||
private String expireDesc;
|
||||
/**
|
||||
* 过期时间 -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;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="net.srt.dao.ApiConfigDao">
|
||||
<update id="updateById">
|
||||
update data_service_api_config set auth_id=#{apiId} where id=#{id}
|
||||
</update>
|
||||
<select id="getResourceList" resultType="net.srt.entity.ApiConfigEntity">
|
||||
<choose>
|
||||
<when test="queryApply!=null and queryApply==1">
|
||||
SELECT * FROM data_service_api_config
|
||||
WHERE id IN (SELECT mount_id FROM data_assets_resource_mount WHERE mount_type=2 AND resource_id=#{resourceId})
|
||||
AND deleted=0
|
||||
</when>
|
||||
<otherwise>
|
||||
SELECT
|
||||
dsac.*
|
||||
FROM
|
||||
data_service_api_config dsac
|
||||
INNER JOIN data_assets_resource_mount darm ON dsac.id = darm.mount_id
|
||||
WHERE
|
||||
darm.mount_type=2
|
||||
AND darm.resource_id=#{resourceId}
|
||||
AND dsac.deleted=0
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
<select id="getById" resultType="net.srt.entity.ApiConfigEntity">
|
||||
SELECT * FROM data_service_api_config WHERE id = #{id}
|
||||
</select>
|
||||
<select id="getAuthList" resultType="net.srt.entity.ApiConfigEntity">
|
||||
<choose>
|
||||
<when test="ifMarket != null and ifMarket==1">
|
||||
SELECT
|
||||
dsac.*,
|
||||
dsaa.id AS auth_id,
|
||||
dsag.path AS group_path
|
||||
FROM
|
||||
data_service_api_config dsac
|
||||
INNER JOIN data_service_api_group dsag ON dsac.group_id=dsag.id
|
||||
INNER JOIN data_service_api_auth1 dsaa ON dsac.id = dsaa.api_id
|
||||
WHERE
|
||||
dsaa.app_id=#{appId}
|
||||
AND dsac.deleted=0
|
||||
AND dsaa.deleted=0
|
||||
</when>
|
||||
<otherwise>
|
||||
SELECT
|
||||
dsac.*,
|
||||
dsaa.id AS auth_id
|
||||
FROM
|
||||
data_service_api_config dsac
|
||||
LEFT JOIN data_service_api_auth1 dsaa ON dsac.id = dsaa.api_id AND dsaa.app_id=#{appId}
|
||||
AND dsaa.deleted=0
|
||||
WHERE
|
||||
dsac.group_id = #{groupId}
|
||||
AND dsac.previlege=1
|
||||
AND dsac.deleted=0
|
||||
</otherwise>
|
||||
</choose>
|
||||
<if test="name != null and name.trim() != ''">
|
||||
AND dsac.name LIKE "%"#{name}"%"
|
||||
</if>
|
||||
<if test="path != null and path.trim() != ''">
|
||||
AND dsac.path LIKE "%"#{path}"%"
|
||||
</if>
|
||||
<if test="contentType != null and contentType.trim() != ''">
|
||||
AND dsac.content_type = #{contentType}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND dsac.status = #{status}
|
||||
</if>
|
||||
<if test="sqlDbType != null">
|
||||
AND dsac.sql_db_type = #{sqlDbType}
|
||||
</if>
|
||||
<if test="databaseId != null">
|
||||
AND dsac.database_id = #{databaseId}
|
||||
</if>
|
||||
<if test="previlege != null">
|
||||
AND dsac.previlege = #{previlege}
|
||||
</if>
|
||||
<if test="openTrans != null">
|
||||
AND dsac.open_trans = #{openTrans}
|
||||
</if>
|
||||
ORDER BY dsac.create_time DESC,dsac.id DESC
|
||||
</select>
|
||||
</mapper>
|
|
@ -5,7 +5,7 @@
|
|||
<mapper namespace="net.srt.dao.DataServiceAppDao">
|
||||
|
||||
|
||||
<select id="selectByApplyId" resultType="net.srt.entity.DataServiceAppEntity">
|
||||
SELECT dsa.* FROM data_service_app dsa INNER JOIN data_market_resource_apply dmra ON dsa.id=dmra.app_id WHERE dmra.id=#{applyId}
|
||||
</select>
|
||||
<!-- <select id="selectByApplyId" resultType="net.srt.entity.DataServiceAppEntity">-->
|
||||
<!-- SELECT dsa.* FROM data_service_app dsa INNER JOIN data_market_resource_apply dmra ON dsa.id=dmra.app_id WHERE dmra.id=#{applyId}-->
|
||||
<!-- </select>-->
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue