测试API模块提交

dev
liyongbin 2023-12-26 21:44:05 +08:00
parent ce78b4e3fd
commit 1b2ac94b2d
10 changed files with 436 additions and 105 deletions

View File

@ -1,21 +0,0 @@
package net.srt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @ClassName : ${NAME}
* @Description : ${description}
* @Author : FJJ
* @Date: 2023-12-22 20:44
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class ServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
}

View File

@ -25,95 +25,149 @@ import java.util.List;
public class ApiConfigController { public class ApiConfigController {
private final ApiConfigService apiConfigService; private final ApiConfigService apiConfigService;
/**
*
* @param query
* @return
*/
@GetMapping("page") @GetMapping("page")
@Operation(summary = "分页") @Operation(summary = "分页查询接口配置列表")
@PreAuthorize("hasAuthority('data-service:api-config:page')") @PreAuthorize("hasAuthority('data-service:api-config:page')")
public Result<PageResult<ApiConfigVo>> page(@Valid ApiConfigQuery query) { public Result<PageResult<ApiConfigVo>> page(@Valid ApiConfigQuery query) {
PageResult<ApiConfigVo> page = apiConfigService.page(query); PageResult<ApiConfigVo> page = apiConfigService.page(query); // 调用service层方法获取分页结果
return Result.ok(page); // 封装返回结果并返回
return Result.ok(page);
} }
/**
* resourceId
* @param query
* @return
*/
@GetMapping("page-resource") @GetMapping("page-resource")
@Operation(summary = "根据resourceId分页获取") @Operation(summary = "根据resourceId分页获取接口配置列表")
public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){ public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query); PageResult<ApiConfigVo> page = apiConfigService.pageResource(query); // 调用service层方法根据resourceId分页获取接口配置列表
return Result.ok(page); // 封装返回结果并返回
return Result.ok(page);
} }
// @GetMapping("{id}") /**
// @Operation(summary = "信息") * id
// public ResponseEntity<?> get(@PathVariable("id") Long id) { * @param id id
// ApiConfigEntity entity = apiConfigService.getById(id); * @return id
// if (entity != null && entity.getStatus() == 1) { */
// return ResponseEntity.ok(ApiConfigConvert.INSTANCE.convert(entity));
// } else {
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Resource not found");
// }
// }
@GetMapping("{id}") @GetMapping("{id}")
@Operation(summary = "信息") @Operation(summary = "根据id获取接口配置信息")
@PreAuthorize("hasAnyAuthority('data-service:api-config:info')") @PreAuthorize("hasAnyAuthority('data-service:api-config:info')")
public Result<ApiConfigVo> get(@PathVariable("id") Long id){ public Result<ApiConfigVo> get(@PathVariable("id") Long id){
ApiConfigEntity entity=apiConfigService.getById(id); ApiConfigEntity entity=apiConfigService.getById(id); // 根据id获取接口配置实体对象
return Result.ok(ApiConfigConvert.INSTANCE.convert(entity)); return Result.ok(ApiConfigConvert.INSTANCE.convert(entity)); // 封装返回结果并返回
} }
/**
*
* @param vo
* @return
*/
@PostMapping @PostMapping
@Operation(summary = "保存") @Operation(summary = "保存接口配置信息")
@PreAuthorize("hasAnyAuthority('data-service:api-config:save')") @PreAuthorize("hasAnyAuthority('data-service:api-config:save')")
public Result<String> save(@RequestBody ApiConfigVo vo) { public Result<String> save(@RequestBody ApiConfigVo vo) {
apiConfigService.save(vo); apiConfigService.save(vo); // 调用service层方法保存接口配置信息
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
/**
*
* @param vo
* @return
*/
@PutMapping @PutMapping
@Operation(summary = "修改") @Operation(summary = "修改接口配置信息")
@PreAuthorize("hasAnyAuthority('data-service:api-config:update')") @PreAuthorize("hasAnyAuthority('data-service:api-config:update')")
public Result<String> update(@RequestBody ApiConfigVo vo){ public Result<String> update(@RequestBody ApiConfigVo vo){
apiConfigService.update(vo); apiConfigService.update(vo); // 调用service层方法修改接口配置信息
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
/**
*
* @param idList id
* @return
*/
@DeleteMapping @DeleteMapping
@Operation(summary = "删除") @Operation(summary = "删除接口配置信息")
@PreAuthorize("hasAnyAuthority('data-service:api-config:delete')") @PreAuthorize("hasAnyAuthority('data-service:api-config:delete')")
public Result<String> delete(@RequestBody List<Long> idList){ public Result<String> delete(@RequestBody List<Long> idList){
apiConfigService.delete(idList); apiConfigService.delete(idList); // 调用service层方法删除接口配置信息
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
/**
* IP
* @return IP
*/
@GetMapping("getIpPort") @GetMapping("getIpPort")
@Operation(summary = "获取服务的IP和端口号")
public Result<String> getIpPort() { public Result<String> getIpPort() {
return Result.ok(apiConfigService.getIpPort()); return Result.ok(apiConfigService.getIpPort()); // 封装返回结果并返回
} }
@Operation(summary = "获取服务的ip和端口号")
/**
* IP
* @return IP
*/
@GetMapping("/ip-port") @GetMapping("/ip-port")
@Operation(summary = "获取服务的IP和端口号")
public Result<String> ipPort() { public Result<String> ipPort() {
return Result.ok(apiConfigService.ipPort()); return Result.ok(apiConfigService.ipPort()); // 封装返回结果并返回
} }
@Operation(summary = "上线")
@PreAuthorize("hasAnyAuthority('data-service:api-config:online')") /**
* 线id
* @param id 线id
* @return 线
*/
@PutMapping("/{id}/online") @PutMapping("/{id}/online")
@Operation(summary = "上线指定id的接口配置")
@PreAuthorize("hasAnyAuthority('data-service:api-config:online')")
public Result<String> online(@PathVariable Long id) { public Result<String> online(@PathVariable Long id) {
apiConfigService.online(id); apiConfigService.online(id); // 调用service层方法上线指定id的接口配置
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
@Operation(summary = "下线")
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')") /**
* 线id
* @param id 线id
* @return 线
*/
@PutMapping("/{id}/offline") @PutMapping("/{id}/offline")
@Operation(summary = "下线指定id的接口配置")
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')")
public Result<String> offline(@PathVariable Long id){ public Result<String> offline(@PathVariable Long id){
apiConfigService.offline(id); apiConfigService.offline(id); // 调用service层方法下线指定id的接口配置
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
@Operation(summary = "执行sql") /**
* SQL
* @param dto SQL
* @return SQL
*/
@PostMapping("/sql/execute") @PostMapping("/sql/execute")
@Operation(summary = "执行SQL查询")
public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto dto) { public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto dto) {
return Result.ok(apiConfigService.sqlExecute(dto)); return Result.ok(apiConfigService.sqlExecute(dto)); // 封装返回结果并返回
} }
@Operation(summary = "导出 api 文档") /**
* idAPI
* @param ids APIid
* @param response HTTP
*/
@PostMapping(value = "/export-docs") @PostMapping(value = "/export-docs")
@Operation(summary = "导出API文档")
public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) { public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) {
apiConfigService.exportDocs(ids, response); apiConfigService.exportDocs(ids, response); // 调用service层方法导出API文档
} }
} }

View File

@ -28,42 +28,66 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class ApiGroupController { public class ApiGroupController {
private final ApiGroupService apiGroupService; private final ApiGroupService apiGroupService;
/**
*
* @return
*/
@GetMapping("api-group") @GetMapping("api-group")
@Operation(summary = "查询文件分组树") @Operation(summary = "查询文件分组树")
public Result<List<TreeNodeVo>> listTree() { public Result<List<TreeNodeVo>> listTree() {
return Result.ok(apiGroupService.listTree()); return Result.ok(apiGroupService.listTree()); // 调用service层方法查询文件分组树并返回结果
} }
/**
* id
* @param id id
* @return id
*/
@GetMapping("{id}") @GetMapping("{id}")
@Operation(summary = "信息") @Operation(summary = "信息")
@PreAuthorize("hasAuthority('data-service:api-group:info')") @PreAuthorize("hasAuthority('data-service:api-group:info')")
public Result<ApiGroupVo> get(@PathVariable("id") Long id){ public Result<ApiGroupVo> get(@PathVariable("id") Long id){
ApiGroupEntity entity = apiGroupService.getById(id); ApiGroupEntity entity = apiGroupService.getById(id); // 根据id获取文件分组实体对象
return Result.ok(ApiGroupConvert.INSTANCE.convert(entity)); // 封装返回结果并返回
return Result.ok(ApiGroupConvert.INSTANCE.convert(entity));
} }
/**
*
* @param vo
* @return
*/
@PostMapping @PostMapping
@Operation(summary = "保存") @Operation(summary = "保存")
@PreAuthorize("hasAuthority('data-service:api-group:save')") @PreAuthorize("hasAuthority('data-service:api-group:save')")
public Result<String> save(@RequestBody ApiGroupVo vo) { public Result<String> save(@RequestBody ApiGroupVo vo) {
apiGroupService.save(vo); apiGroupService.save(vo); // 调用service层方法保存文件分组信息
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
/**
*
* @param vo
* @return
*/
@PutMapping @PutMapping
@Operation(summary = "修改") @Operation(summary = "修改")
@PreAuthorize("hasAuthority('data-service:api-group:update')") @PreAuthorize("hasAuthority('data-service:api-group:update')")
public Result<String> update(@RequestBody @Valid ApiGroupVo vo) { public Result<String> update(@RequestBody @Valid ApiGroupVo vo) {
apiGroupService.update(vo); apiGroupService.update(vo); // 调用service层方法修改文件分组信息
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
/**
*
* @param id id
* @return
*/
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@Operation(summary = "删除") @Operation(summary = "删除")
@PreAuthorize("hasAuthority('data-service:api-group:delete')") @PreAuthorize("hasAuthority('data-service:api-group:delete')")
public Result<String> delete(@PathVariable Long id) { public Result<String> delete(@PathVariable Long id) {
apiGroupService.delete(id); apiGroupService.delete(id); // 调用service层方法删除文件分组信息
return Result.ok(); return Result.ok(); // 封装返回结果并返回
} }
} }

View File

@ -81,4 +81,5 @@ public class DataServiceAppController {
dataServiceAppService.cancelAuth(authId); dataServiceAppService.cancelAuth(authId);
return Result.ok(); return Result.ok();
} }
} }

View File

@ -12,37 +12,164 @@ import java.util.Date;
@Data @Data
public class ApiConfigDto implements Serializable { public class ApiConfigDto implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
* id
*/
private Long id; private Long id;
/**
* id
*/
private Long groupId; private Long groupId;
/**
*
*/
private String path; private String path;
/**
* sqlhttp
*/
private String type; private String type;
/**
*
*/
private String name; private String name;
/**
*
*/
private String note; private String note;
/**
* SQL
*/
private String sqlText; private String sqlText;
/**
* SQL
*/
private String sqlSeparator; private String sqlSeparator;
/**
* SQL
*/
private Integer sqlMaxRow; private Integer sqlMaxRow;
/**
* SQL
*/
private String sqlParam; private String sqlParam;
/**
* JSON
*/
private String jsonParam; private String jsonParam;
/**
* HTTP
*/
private String responseResult; private String responseResult;
/**
*
*/
private String contentType; private String contentType;
/**
* 10
*/
private Integer status; private Integer status;
/**
*
*/
private Date releaseTime; private Date releaseTime;
/**
* id
*/
private Long releaseUserId; private Long releaseUserId;
/**
*
*/
private Integer sqlDbType; private Integer sqlDbType;
/**
* id
*/
private Long databaseId; private Long databaseId;
/**
* 10
*/
private Integer privates; private Integer privates;
/**
* 10
*/
private Integer openTrans; private Integer openTrans;
/**
* id
*/
private Long projectId; private Long projectId;
/**
*
*/
private Integer version; private Integer version;
/**
* 10
*/
private Integer deleted; private Integer deleted;
/**
* id
*/
private Long creator; private Long creator;
/**
*
*/
private Date createTime; private Date createTime;
/**
* id
*/
private Long updater; private Long updater;
/**
*
*/
private Date updateTime; private Date updateTime;
/**
*
*/
private Integer requestedTimes; private Integer requestedTimes;
/**
*
*/
private Integer requestedSuccessTimes; private Integer requestedSuccessTimes;
/**
*
*/
private Integer requestedFailedTimes; private Integer requestedFailedTimes;
/**
* id
*/
private Long authId; private Long authId;
/**
*
*/
private String group; private String group;
} }

View File

@ -10,8 +10,24 @@ import java.io.Serializable;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class AppToken implements Serializable { public class AppToken implements Serializable {
/**
* id
*/
private Long appId; private Long appId;
/**
*
*/
private String appKey; private String appKey;
/**
* 访
*/
private String token; private String token;
/**
*
*/
private Long expireAt; private Long expireAt;
} }

View File

@ -4,12 +4,44 @@ import lombok.Data;
@Data @Data
public class SqlDto { public class SqlDto {
/**
*
*/
private Integer sqlDbType; private Integer sqlDbType;
/**
* id
*/
private Long projectId; private Long projectId;
/**
* SQL
*/
private String statement; private String statement;
/**
* SQL
*/
private String sqlSeparator; private String sqlSeparator;
/**
* id
*/
private Long databaseId; private Long databaseId;
/**
* 10
*/
private Integer openTrans; private Integer openTrans;
/**
* JSON
*/
private String jsonParams; private String jsonParams;
/**
* SQL
*/
private Integer sqlMaxRow; private Integer sqlMaxRow;
} }

View File

@ -43,6 +43,10 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
private final DiscoveryClient discoveryClient; private final DiscoveryClient discoveryClient;
private final ApiConfigDao apiConfigDao; private final ApiConfigDao apiConfigDao;
private final Map<String, ApiConfigEntity> mappings = new ConcurrentHashMap<>(); private final Map<String, ApiConfigEntity> mappings = new ConcurrentHashMap<>();
/**
* IP
* @return IP
*/
@Override @Override
public String getIpPort() { public String getIpPort() {
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME); List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
@ -51,7 +55,10 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
/**
* API线
* @param id APIID
*/
public void online(Long id) { public void online(Long id) {
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id); ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
if (apiConfigEntity != null) { if (apiConfigEntity != null) {
@ -93,36 +100,41 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
private String getRouteKey(String type, String path) { private String getRouteKey(String type, String path) {
return type.toUpperCase() + "_" + path.toLowerCase(); return type.toUpperCase() + "_" + path.toLowerCase();
} }
/**
* API线
* @param id APIID
*/
@Override @Override
public void offline(Long id) { // 修正参数类型为 Long id public void offline(Long id) {
// 根据id获取API配置实体对象
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id); ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
if (apiConfigEntity != null) { if (apiConfigEntity != null) {
// 将API配置实体对象的状态设置为下线
apiConfigEntity.setStatus(0); apiConfigEntity.setStatus(0);
apiConfigEntity.setReleaseTime(null); apiConfigEntity.setReleaseTime(null);
apiConfigEntity.setReleaseUserId(null); apiConfigEntity.setReleaseUserId(null);
// 更新API配置实体对象
apiConfigDao.updateById(apiConfigEntity); apiConfigDao.updateById(apiConfigEntity);
}else{ } else {
// 如果没有找到对应的API配置实体对象抛出404异常
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found"); 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);
// }
/**
* IP
* @return IP
*/
@Override @Override
public String ipPort() { public String ipPort() {
// 获取网关服务实例列表
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME); List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
// 获取第一个网关服务实例的主机和端口,并返回拼接后的字符串
return instances.get(0).getHost() + ":" + instances.get(0).getPort(); return instances.get(0).getHost() + ":" + instances.get(0).getPort();
} }
@Override @Override
public JdbcSelectResult sqlExecute(SqlDto dto) { public JdbcSelectResult sqlExecute(SqlDto dto) {
return null; return null;
@ -168,12 +180,21 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
} }
} }
/**
* API
* @param query
* @return API
*/
@Override @Override
public PageResult<ApiConfigVo> page(ApiConfigQuery query) { public PageResult<ApiConfigVo> page(ApiConfigQuery query) {
// 执行分页查询,并获取分页对象
IPage<ApiConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query)); IPage<ApiConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
// 将实体对象列表转换为VO对象列表
return new PageResult<>(ApiConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal()); List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(page.getRecords());
// 返回VO对象列表和总记录数构成的分页结果对象
return new PageResult<>(apiConfigVos, page.getTotal());
} }
private LambdaQueryWrapper getWrapper(ApiConfigQuery query) { private LambdaQueryWrapper getWrapper(ApiConfigQuery query) {
LambdaQueryWrapper<ApiConfigEntity> wrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<ApiConfigEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StringUtil.isNotBlank(query.getName()), ApiConfigEntity::getName, query.getName()); wrapper.like(StringUtil.isNotBlank(query.getName()), ApiConfigEntity::getName, query.getName());
@ -190,17 +211,32 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
return wrapper; return wrapper;
} }
/**
* API
* @param vo APIVO
*/
@Override @Override
public void save(ApiConfigVo vo) { public void save(ApiConfigVo vo) {
// 将VO对象转换为实体对象
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo); ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
// 设置项目ID
entity.setProjectId(getProjectId()); entity.setProjectId(getProjectId());
// 执行插入操作
baseMapper.insert(entity); baseMapper.insert(entity);
} }
/**
* API
* @param vo APIVO
*/
@Override @Override
public void update(ApiConfigVo vo) { public void update(ApiConfigVo vo) {
// 将VO对象转换为实体对象
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo); ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
// 设置项目ID
entity.setProjectId(getProjectId()); entity.setProjectId(getProjectId());
// 执行更新操作
updateById(entity); updateById(entity);
} }
@ -209,31 +245,52 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
removeByIds(idList); removeByIds(idList);
} }
/**
* API
* @param query
* @return API
*/
@Override @Override
public PageResult<ApiConfigVo> pageResource(ApiConfigQuery query) { public PageResult<ApiConfigVo> pageResource(ApiConfigQuery query) {
// 查询参数 // 获取查询参数
Map<String, Object> params = getParams(query); Map<String, Object> params = getParams(query);
// 获取分页对象
IPage<ApiConfigEntity> page = getPage(query); IPage<ApiConfigEntity> page = getPage(query);
params.put(Constant.PAGE, page); params.put(Constant.PAGE, page);
// 数据列表 // 查询数据列表
List<ApiConfigEntity> list = baseMapper.getResourceList(params); List<ApiConfigEntity> list = baseMapper.getResourceList(params);
// 将数据列表转换为VO对象列表
List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(list); List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(list);
// 遍历VO对象列表设置所属组信息
for (ApiConfigVo apiConfigVo : apiConfigVos) { for (ApiConfigVo apiConfigVo : apiConfigVos) {
ApiGroupEntity groupEntity = apiGroupDao.selectById(apiConfigVo.getGroupId()); ApiGroupEntity groupEntity = apiGroupDao.selectById(apiConfigVo.getGroupId());
apiConfigVo.setGroup(groupEntity != null ? groupEntity.getPath() : null); apiConfigVo.setGroup(groupEntity != null ? groupEntity.getPath() : null);
} }
// 返回VO对象列表和总记录数构成的分页结果对象
return new PageResult<>(apiConfigVos, page.getTotal()); return new PageResult<>(apiConfigVos, page.getTotal());
} }
/**
* IDAPI
* @param id ID
* @return API
*/
@Override @Override
public List<ApiConfigEntity> listActiveByGroupId(Long id) { public List<ApiConfigEntity> listActiveByGroupId(Long id) {
// 创建LambdaQueryWrapper对象
LambdaQueryWrapper<ApiConfigEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ApiConfigEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ApiConfigEntity::getStatus, 1).eq(ApiConfigEntity::getGroupId, id).orderByDesc(ApiConfigEntity::getId); // 设置查询条件状态为1有效组ID为指定ID并按照ID降序排序
wrapper.eq(ApiConfigEntity::getStatus, 1)
.eq(ApiConfigEntity::getGroupId, id)
.orderByDesc(ApiConfigEntity::getId);
// 应用数据范围控制排除组织ID
dataScopeWithoutOrgId(wrapper); dataScopeWithoutOrgId(wrapper);
// 执行查询并返回结果列表
return baseMapper.selectList(wrapper); return baseMapper.selectList(wrapper);
} }
private Map<String, Object> getParams(ApiConfigQuery query) { private Map<String, Object> getParams(ApiConfigQuery query) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("ifMarket", query.getIfMarket()); params.put("ifMarket", query.getIfMarket());

View File

@ -25,43 +25,78 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEntity> implements ApiGroupService{ public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEntity> implements ApiGroupService{
private final ApiConfigService apiConfigService; private final ApiConfigService apiConfigService;
/**
* API
* @return API
*/
@Override @Override
public List<TreeNodeVo> listTree() { public List<TreeNodeVo> listTree() {
// 查询所有API分组实体对象并转换为树节点VO对象列表
List<TreeNodeVo> treeNodeVos = getTreeNodeVos(); List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
// 构建树形结构,并返回根节点列表
return BuildTreeUtils.buildTree(treeNodeVos); return BuildTreeUtils.buildTree(treeNodeVos);
} }
/**
* APIVO
* @return APIVO
*/
private List<TreeNodeVo> getTreeNodeVos() { private List<TreeNodeVo> getTreeNodeVos() {
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
dataScopeWithoutOrgId(wrapper); dataScopeWithoutOrgId(wrapper); // 加入数据权限过滤
wrapper.orderByAsc(ApiGroupEntity::getOrderNo); wrapper.orderByAsc(ApiGroupEntity::getOrderNo); // 按orderNo升序排序
List<ApiGroupEntity> apiGroupEntities = baseMapper.selectList(wrapper); List<ApiGroupEntity> apiGroupEntities = baseMapper.selectList(wrapper);
// 将实体对象列表转换为VO对象列表
return BeanUtil.copyListProperties(apiGroupEntities, TreeNodeVo::new, (oldItem, newItem) -> { return BeanUtil.copyListProperties(apiGroupEntities, TreeNodeVo::new, (oldItem, newItem) -> {
// 设置节点名称
newItem.setLabel(oldItem.getName()); newItem.setLabel(oldItem.getName());
// 设置节点值
newItem.setValue(oldItem.getId()); newItem.setValue(oldItem.getId());
newItem.setDisabled(oldItem.getType() == 1); newItem.setDisabled(oldItem.getType() == 1); // 如果是虚拟节点,设置禁用状态
if (newItem.getPath().contains("/")) { if (newItem.getPath().contains("/")) { // 设置父级节点路径
newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/"))); newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/")));
} }
}); });
} }
/**
* API
* @param vo APIVO
*/
@Override @Override
public void save(ApiGroupVo vo) { public void save(ApiGroupVo vo) {
// 将VO对象转换为实体对象
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo); ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
// 递归生成路径
entity.setPath(recursionPath(entity, null)); entity.setPath(recursionPath(entity, null));
// 设置项目ID
entity.setProjectId(getProjectId()); entity.setProjectId(getProjectId());
// 执行插入操作
baseMapper.insert(entity); // 使用 insertSelective() 方法进行插入操作 baseMapper.insert(entity); // 使用 insertSelective() 方法进行插入操作
} }
/**
* API
* @param vo APIVO
*/
@Override @Override
public void update(ApiGroupVo vo) { public void update(ApiGroupVo vo) {
// 将VO对象转换为实体对象
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo); ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
// 递归生成路径
entity.setPath(recursionPath(entity, null)); entity.setPath(recursionPath(entity, null));
// 设置项目ID
entity.setProjectId(getProjectId()); entity.setProjectId(getProjectId());
// 执行更新操作
updateById(entity); updateById(entity);
} }
/**
* API
* @param groupEntity
* @param path
* @return
*/
private String recursionPath(ApiGroupEntity groupEntity, String path) { private String recursionPath(ApiGroupEntity groupEntity, String path) {
if (StringUtil.isBlank(path)) { if (StringUtil.isBlank(path)) {
path = groupEntity.getName(); path = groupEntity.getName();
@ -74,22 +109,28 @@ public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEn
return path; return path;
} }
/**
* IDAPI
* @param id APIID
*/
@Override @Override
public void delete(Long id) { public void delete(Long id) {
//查询有没有子节点 // 查询是否存在子节点
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ApiGroupEntity::getParentId, id).last(" limit 1"); wrapper.eq(ApiGroupEntity::getParentId, id).last(" limit 1");
ApiGroupEntity one = baseMapper.selectOne(wrapper); ApiGroupEntity one = baseMapper.selectOne(wrapper);
if (one != null) { if (one != null) {
throw new ServerException("存在子节点,不允许删除!"); throw new ServerException("存在子节点,不允许删除!");
} }
//查询有没有api与之关联 // 查询是否有API配置与之关联
LambdaQueryWrapper<ApiConfigEntity> serviceApiConfigWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ApiConfigEntity> serviceApiConfigWrapper = new LambdaQueryWrapper<>();
serviceApiConfigWrapper.eq(ApiConfigEntity::getGroupId, id).last(" limit 1"); serviceApiConfigWrapper.eq(ApiConfigEntity::getGroupId, id).last(" limit 1");
ApiConfigEntity apiConfigEntity = apiConfigService.getOne(serviceApiConfigWrapper); ApiConfigEntity apiConfigEntity = apiConfigService.getOne(serviceApiConfigWrapper);
if (apiConfigEntity != null) { if (apiConfigEntity != null) {
throw new ServerException("节点下有 api 与之关联,不允许删除!"); throw new ServerException("节点下有 api 与之关联,不允许删除!");
} }
// 执行删除操作
removeById(id); removeById(id);
} }
} }

View File

@ -14,8 +14,8 @@ spring:
nacos: nacos:
discovery: discovery:
server-addr: 101.34.77.101:8848 server-addr: 101.34.77.101:8848
# 命名空间默认public # 命名空间默认public
namespace: 09dff3e2-9790-4d4f-beb6-9baeb01ae040 namespace: a60b2ca1-a8c6-47ae-94f1-741105674655
service: ${spring.application.name} service: ${spring.application.name}
group: srt2.0 group: srt2.0
config: config: