测试API模块提交
parent
ce78b4e3fd
commit
1b2ac94b2d
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -25,95 +25,149 @@ import java.util.List;
|
|||
public class ApiConfigController {
|
||||
private final ApiConfigService apiConfigService;
|
||||
|
||||
/**
|
||||
* 分页查询接口配置列表
|
||||
* @param query 查询条件
|
||||
* @return 接口配置列表分页结果
|
||||
*/
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@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);
|
||||
PageResult<ApiConfigVo> page = apiConfigService.page(query); // 调用service层方法获取分页结果
|
||||
return Result.ok(page); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据resourceId分页获取接口配置列表
|
||||
* @param query 查询条件
|
||||
* @return 符合条件的接口配置列表的分页结果
|
||||
*/
|
||||
@GetMapping("page-resource")
|
||||
@Operation(summary = "根据resourceId分页获取")
|
||||
@Operation(summary = "根据resourceId分页获取接口配置列表")
|
||||
public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){
|
||||
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query);
|
||||
|
||||
return Result.ok(page);
|
||||
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query); // 调用service层方法根据resourceId分页获取接口配置列表
|
||||
return Result.ok(page); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
// @GetMapping("{id}")
|
||||
// @Operation(summary = "信息")
|
||||
// public ResponseEntity<?> get(@PathVariable("id") Long id) {
|
||||
// ApiConfigEntity entity = apiConfigService.getById(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");
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 根据id获取接口配置信息
|
||||
* @param id 接口配置id
|
||||
* @return 对应id的接口配置信息
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "信息")
|
||||
@Operation(summary = "根据id获取接口配置信息")
|
||||
@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));
|
||||
ApiConfigEntity entity=apiConfigService.getById(id); // 根据id获取接口配置实体对象
|
||||
return Result.ok(ApiConfigConvert.INSTANCE.convert(entity)); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存接口配置信息
|
||||
* @param vo 接口配置信息
|
||||
* @return 保存结果
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@Operation(summary = "保存接口配置信息")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:save')")
|
||||
public Result<String> save(@RequestBody ApiConfigVo vo) {
|
||||
apiConfigService.save(vo);
|
||||
return Result.ok();
|
||||
apiConfigService.save(vo); // 调用service层方法保存接口配置信息
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口配置信息
|
||||
* @param vo 接口配置信息
|
||||
* @return 修改结果
|
||||
*/
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@Operation(summary = "修改接口配置信息")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:update')")
|
||||
public Result<String> update(@RequestBody ApiConfigVo vo){
|
||||
apiConfigService.update(vo);
|
||||
return Result.ok();
|
||||
apiConfigService.update(vo); // 调用service层方法修改接口配置信息
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口配置信息
|
||||
* @param idList 待删除的接口配置id列表
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping
|
||||
@Operation(summary = "删除")
|
||||
@Operation(summary = "删除接口配置信息")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:delete')")
|
||||
public Result<String> delete(@RequestBody List<Long> idList){
|
||||
apiConfigService.delete(idList);
|
||||
return Result.ok();
|
||||
apiConfigService.delete(idList); // 调用service层方法删除接口配置信息
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务的IP和端口号
|
||||
* @return IP和端口号
|
||||
*/
|
||||
@GetMapping("getIpPort")
|
||||
@Operation(summary = "获取服务的IP和端口号")
|
||||
public Result<String> getIpPort() {
|
||||
return Result.ok(apiConfigService.getIpPort());
|
||||
return Result.ok(apiConfigService.getIpPort()); // 封装返回结果并返回
|
||||
}
|
||||
@Operation(summary = "获取服务的ip和端口号")
|
||||
|
||||
/**
|
||||
* 获取服务的IP和端口号
|
||||
* @return IP和端口号
|
||||
*/
|
||||
@GetMapping("/ip-port")
|
||||
@Operation(summary = "获取服务的IP和端口号")
|
||||
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")
|
||||
@Operation(summary = "上线指定id的接口配置")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:online')")
|
||||
public Result<String> online(@PathVariable Long id) {
|
||||
apiConfigService.online(id);
|
||||
return Result.ok();
|
||||
apiConfigService.online(id); // 调用service层方法上线指定id的接口配置
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
@Operation(summary = "下线")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')")
|
||||
|
||||
/**
|
||||
* 下线指定id的接口配置
|
||||
* @param id 待下线的接口配置id
|
||||
* @return 下线结果
|
||||
*/
|
||||
@PutMapping("/{id}/offline")
|
||||
@Operation(summary = "下线指定id的接口配置")
|
||||
@PreAuthorize("hasAnyAuthority('data-service:api-config:offline')")
|
||||
public Result<String> offline(@PathVariable Long id){
|
||||
apiConfigService.offline(id);
|
||||
return Result.ok();
|
||||
apiConfigService.offline(id); // 调用service层方法下线指定id的接口配置
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
@Operation(summary = "执行sql")
|
||||
/**
|
||||
* 执行SQL查询
|
||||
* @param dto SQL查询参数
|
||||
* @return SQL查询结果
|
||||
*/
|
||||
@PostMapping("/sql/execute")
|
||||
@Operation(summary = "执行SQL查询")
|
||||
public Result<JdbcSelectResult> sqlExecute(@RequestBody SqlDto dto) {
|
||||
return Result.ok(apiConfigService.sqlExecute(dto));
|
||||
return Result.ok(apiConfigService.sqlExecute(dto)); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
@Operation(summary = "导出 api 文档")
|
||||
/**
|
||||
* 导出指定id列表对应的API文档
|
||||
* @param ids 待导出API文档的id列表
|
||||
* @param response HTTP响应对象
|
||||
*/
|
||||
@PostMapping(value = "/export-docs")
|
||||
@Operation(summary = "导出API文档")
|
||||
public void exportDocs(@RequestBody List<Long> ids, HttpServletResponse response) {
|
||||
apiConfigService.exportDocs(ids, response);
|
||||
apiConfigService.exportDocs(ids, response); // 调用service层方法导出API文档
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,42 +28,66 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class ApiGroupController {
|
||||
private final ApiGroupService apiGroupService;
|
||||
/**
|
||||
* 查询文件分组树
|
||||
* @return 文件分组树的列表结果
|
||||
*/
|
||||
@GetMapping("api-group")
|
||||
@Operation(summary = "查询文件分组树")
|
||||
public Result<List<TreeNodeVo>> listTree() {
|
||||
return Result.ok(apiGroupService.listTree());
|
||||
return Result.ok(apiGroupService.listTree()); // 调用service层方法查询文件分组树并返回结果
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取文件分组信息
|
||||
* @param id 文件分组id
|
||||
* @return 对应id的文件分组信息
|
||||
*/
|
||||
@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));
|
||||
ApiGroupEntity entity = apiGroupService.getById(id); // 根据id获取文件分组实体对象
|
||||
return Result.ok(ApiGroupConvert.INSTANCE.convert(entity)); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存文件分组信息
|
||||
* @param vo 文件分组信息
|
||||
* @return 保存结果
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "保存")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:save')")
|
||||
public Result<String> save(@RequestBody ApiGroupVo vo) {
|
||||
apiGroupService.save(vo);
|
||||
return Result.ok();
|
||||
apiGroupService.save(vo); // 调用service层方法保存文件分组信息
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文件分组信息
|
||||
* @param vo 文件分组信息
|
||||
* @return 修改结果
|
||||
*/
|
||||
@PutMapping
|
||||
@Operation(summary = "修改")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:update')")
|
||||
public Result<String> update(@RequestBody @Valid ApiGroupVo vo) {
|
||||
apiGroupService.update(vo);
|
||||
return Result.ok();
|
||||
apiGroupService.update(vo); // 调用service层方法修改文件分组信息
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件分组信息
|
||||
* @param id 待删除的文件分组id
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除")
|
||||
@PreAuthorize("hasAuthority('data-service:api-group:delete')")
|
||||
public Result<String> delete(@PathVariable Long id) {
|
||||
apiGroupService.delete(id);
|
||||
return Result.ok();
|
||||
apiGroupService.delete(id); // 调用service层方法删除文件分组信息
|
||||
return Result.ok(); // 封装返回结果并返回
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,4 +81,5 @@ public class DataServiceAppController {
|
|||
dataServiceAppService.cancelAuth(authId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,37 +12,164 @@ import java.util.Date;
|
|||
@Data
|
||||
public class ApiConfigDto implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 数据库主键id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文件分组id
|
||||
*/
|
||||
private Long groupId;
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 文件类型,如:sql、http等
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 文件备注
|
||||
*/
|
||||
private String note;
|
||||
|
||||
/**
|
||||
* SQL语句内容
|
||||
*/
|
||||
private String sqlText;
|
||||
|
||||
/**
|
||||
* SQL语句分隔符
|
||||
*/
|
||||
private String sqlSeparator;
|
||||
|
||||
/**
|
||||
* SQL最大行数
|
||||
*/
|
||||
private Integer sqlMaxRow;
|
||||
|
||||
/**
|
||||
* SQL语句参数
|
||||
*/
|
||||
private String sqlParam;
|
||||
|
||||
/**
|
||||
* JSON参数
|
||||
*/
|
||||
private String jsonParam;
|
||||
|
||||
/**
|
||||
* HTTP响应结果
|
||||
*/
|
||||
private String responseResult;
|
||||
|
||||
/**
|
||||
* 内容类型
|
||||
*/
|
||||
private String contentType;
|
||||
|
||||
/**
|
||||
* 状态,1启用,0禁用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
private Date releaseTime;
|
||||
|
||||
/**
|
||||
* 发布用户id
|
||||
*/
|
||||
private Long releaseUserId;
|
||||
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
private Integer sqlDbType;
|
||||
|
||||
/**
|
||||
* 数据库id
|
||||
*/
|
||||
private Long databaseId;
|
||||
|
||||
/**
|
||||
* 是否私有文件,1是,0否
|
||||
*/
|
||||
private Integer privates;
|
||||
|
||||
/**
|
||||
* 开启事务,1是,0否
|
||||
*/
|
||||
private Integer openTrans;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 是否删除,1是,0否
|
||||
*/
|
||||
private Integer deleted;
|
||||
|
||||
/**
|
||||
* 创建者id
|
||||
*/
|
||||
private Long creator;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新者id
|
||||
*/
|
||||
private Long updater;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 请求次数
|
||||
*/
|
||||
private Integer requestedTimes;
|
||||
|
||||
/**
|
||||
* 请求成功次数
|
||||
*/
|
||||
private Integer requestedSuccessTimes;
|
||||
|
||||
/**
|
||||
* 请求失败次数
|
||||
*/
|
||||
private Integer requestedFailedTimes;
|
||||
|
||||
/**
|
||||
* 授权id
|
||||
*/
|
||||
private Long authId;
|
||||
|
||||
/**
|
||||
* 分组名
|
||||
*/
|
||||
private String group;
|
||||
|
||||
}
|
||||
|
|
|
@ -10,8 +10,24 @@ import java.io.Serializable;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AppToken implements Serializable {
|
||||
/**
|
||||
* 应用id
|
||||
*/
|
||||
private Long appId;
|
||||
|
||||
/**
|
||||
* 应用密钥
|
||||
*/
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* 访问令牌
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 过期时间戳
|
||||
*/
|
||||
private Long expireAt;
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,44 @@ import lombok.Data;
|
|||
|
||||
@Data
|
||||
public class SqlDto {
|
||||
/**
|
||||
* 数据库类型
|
||||
*/
|
||||
private Integer sqlDbType;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* SQL语句
|
||||
*/
|
||||
private String statement;
|
||||
|
||||
/**
|
||||
* SQL语句分隔符
|
||||
*/
|
||||
private String sqlSeparator;
|
||||
|
||||
/**
|
||||
* 数据库id
|
||||
*/
|
||||
private Long databaseId;
|
||||
|
||||
/**
|
||||
* 是否开启事务,1是,0否
|
||||
*/
|
||||
private Integer openTrans;
|
||||
|
||||
/**
|
||||
* JSON参数
|
||||
*/
|
||||
private String jsonParams;
|
||||
|
||||
/**
|
||||
* SQL最大行数
|
||||
*/
|
||||
private Integer sqlMaxRow;
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,10 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
|
|||
private final DiscoveryClient discoveryClient;
|
||||
private final ApiConfigDao apiConfigDao;
|
||||
private final Map<String, ApiConfigEntity> mappings = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* 获取服务实例的IP和端口
|
||||
* @return IP和端口
|
||||
*/
|
||||
@Override
|
||||
public String getIpPort() {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(ServerNames.GATEWAY_SERVER_NAME);
|
||||
|
@ -51,7 +55,10 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将API配置设置为上线状态并更新路由映射
|
||||
* @param id API配置ID
|
||||
*/
|
||||
public void online(Long id) {
|
||||
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
|
||||
if (apiConfigEntity != null) {
|
||||
|
@ -93,36 +100,41 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
|
|||
private String getRouteKey(String type, String path) {
|
||||
return type.toUpperCase() + "_" + path.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将API配置设置为下线状态
|
||||
* @param id API配置ID
|
||||
*/
|
||||
@Override
|
||||
public void offline(Long id) { // 修正参数类型为 Long id
|
||||
public void offline(Long id) {
|
||||
// 根据id获取API配置实体对象
|
||||
ApiConfigEntity apiConfigEntity = apiConfigDao.getById(id);
|
||||
if (apiConfigEntity != null) {
|
||||
// 将API配置实体对象的状态设置为下线
|
||||
apiConfigEntity.setStatus(0);
|
||||
apiConfigEntity.setReleaseTime(null);
|
||||
apiConfigEntity.setReleaseUserId(null);
|
||||
// 更新API配置实体对象
|
||||
apiConfigDao.updateById(apiConfigEntity);
|
||||
}else{
|
||||
} else {
|
||||
// 如果没有找到对应的API配置实体对象,抛出404异常
|
||||
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
|
||||
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;
|
||||
|
@ -168,12 +180,21 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询API配置
|
||||
* @param query 查询条件
|
||||
* @return API配置分页结果
|
||||
*/
|
||||
@Override
|
||||
public PageResult<ApiConfigVo> page(ApiConfigQuery query) {
|
||||
// 执行分页查询,并获取分页对象
|
||||
IPage<ApiConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
||||
return new PageResult<>(ApiConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
|
||||
// 将实体对象列表转换为VO对象列表
|
||||
List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(page.getRecords());
|
||||
// 返回VO对象列表和总记录数构成的分页结果对象
|
||||
return new PageResult<>(apiConfigVos, page.getTotal());
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper getWrapper(ApiConfigQuery query) {
|
||||
LambdaQueryWrapper<ApiConfigEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StringUtil.isNotBlank(query.getName()), ApiConfigEntity::getName, query.getName());
|
||||
|
@ -190,17 +211,32 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
|
|||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增API配置
|
||||
* @param vo API配置VO对象
|
||||
*/
|
||||
@Override
|
||||
public void save(ApiConfigVo vo) {
|
||||
// 将VO对象转换为实体对象
|
||||
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
|
||||
// 设置项目ID
|
||||
entity.setProjectId(getProjectId());
|
||||
// 执行插入操作
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新API配置
|
||||
* @param vo API配置VO对象
|
||||
*/
|
||||
@Override
|
||||
public void update(ApiConfigVo vo) {
|
||||
// 将VO对象转换为实体对象
|
||||
ApiConfigEntity entity = ApiConfigConvert.INSTANCE.convert(vo);
|
||||
// 设置项目ID
|
||||
entity.setProjectId(getProjectId());
|
||||
// 执行更新操作
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
|
@ -209,31 +245,52 @@ public class ApiConfigServiceImpl extends BaseServiceImpl<ApiConfigDao, ApiConfi
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询API资源
|
||||
* @param query 查询条件
|
||||
* @return API资源分页结果
|
||||
*/
|
||||
@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);
|
||||
// 将数据列表转换为VO对象列表
|
||||
List<ApiConfigVo> apiConfigVos = ApiConfigConvert.INSTANCE.convertList(list);
|
||||
// 遍历VO对象列表,设置所属组信息
|
||||
for (ApiConfigVo apiConfigVo : apiConfigVos) {
|
||||
ApiGroupEntity groupEntity = apiGroupDao.selectById(apiConfigVo.getGroupId());
|
||||
apiConfigVo.setGroup(groupEntity != null ? groupEntity.getPath() : null);
|
||||
}
|
||||
// 返回VO对象列表和总记录数构成的分页结果对象
|
||||
return new PageResult<>(apiConfigVos, page.getTotal());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据组ID获取有效的API配置列表
|
||||
* @param id 组ID
|
||||
* @return API配置列表
|
||||
*/
|
||||
@Override
|
||||
public List<ApiConfigEntity> listActiveByGroupId(Long id) {
|
||||
// 创建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);
|
||||
// 执行查询并返回结果列表
|
||||
return baseMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Object> getParams(ApiConfigQuery query) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("ifMarket", query.getIfMarket());
|
||||
|
|
|
@ -25,43 +25,78 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEntity> implements ApiGroupService{
|
||||
private final ApiConfigService apiConfigService;
|
||||
/**
|
||||
* 获取API分组树形结构列表
|
||||
* @return API分组树形结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<TreeNodeVo> listTree() {
|
||||
// 查询所有API分组实体对象,并转换为树节点VO对象列表
|
||||
List<TreeNodeVo> treeNodeVos = getTreeNodeVos();
|
||||
// 构建树形结构,并返回根节点列表
|
||||
return BuildTreeUtils.buildTree(treeNodeVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取API分组树节点VO对象列表
|
||||
* @return API分组树节点VO对象列表
|
||||
*/
|
||||
private List<TreeNodeVo> getTreeNodeVos() {
|
||||
LambdaQueryWrapper<ApiGroupEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
dataScopeWithoutOrgId(wrapper);
|
||||
wrapper.orderByAsc(ApiGroupEntity::getOrderNo);
|
||||
dataScopeWithoutOrgId(wrapper); // 加入数据权限过滤
|
||||
wrapper.orderByAsc(ApiGroupEntity::getOrderNo); // 按orderNo升序排序
|
||||
List<ApiGroupEntity> apiGroupEntities = baseMapper.selectList(wrapper);
|
||||
// 将实体对象列表转换为VO对象列表
|
||||
return BeanUtil.copyListProperties(apiGroupEntities, TreeNodeVo::new, (oldItem, newItem) -> {
|
||||
// 设置节点名称
|
||||
newItem.setLabel(oldItem.getName());
|
||||
// 设置节点值
|
||||
newItem.setValue(oldItem.getId());
|
||||
newItem.setDisabled(oldItem.getType() == 1);
|
||||
if (newItem.getPath().contains("/")) {
|
||||
newItem.setDisabled(oldItem.getType() == 1); // 如果是虚拟节点,设置禁用状态
|
||||
if (newItem.getPath().contains("/")) { // 设置父级节点路径
|
||||
newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增API分组
|
||||
* @param vo API分组VO对象
|
||||
*/
|
||||
@Override
|
||||
public void save(ApiGroupVo vo) {
|
||||
// 将VO对象转换为实体对象
|
||||
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
|
||||
// 递归生成路径
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
// 设置项目ID
|
||||
entity.setProjectId(getProjectId());
|
||||
// 执行插入操作
|
||||
baseMapper.insert(entity); // 使用 insertSelective() 方法进行插入操作
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新API分组
|
||||
* @param vo API分组VO对象
|
||||
*/
|
||||
@Override
|
||||
public void update(ApiGroupVo vo) {
|
||||
// 将VO对象转换为实体对象
|
||||
ApiGroupEntity entity = ApiGroupConvert.INSTANCE.convert(vo);
|
||||
// 递归生成路径
|
||||
entity.setPath(recursionPath(entity, null));
|
||||
// 设置项目ID
|
||||
entity.setProjectId(getProjectId());
|
||||
// 执行更新操作
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成API分组路径
|
||||
* @param groupEntity 分组实体对象
|
||||
* @param path 父级路径
|
||||
* @return 完整路径
|
||||
*/
|
||||
private String recursionPath(ApiGroupEntity groupEntity, String path) {
|
||||
if (StringUtil.isBlank(path)) {
|
||||
path = groupEntity.getName();
|
||||
|
@ -74,22 +109,28 @@ public class ApiGroupServiceImpl extends BaseServiceImpl<ApiGroupDao, ApiGroupEn
|
|||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除API分组
|
||||
* @param id API分组ID
|
||||
*/
|
||||
@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与之关联
|
||||
// 查询是否有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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ spring:
|
|||
nacos:
|
||||
discovery:
|
||||
server-addr: 101.34.77.101:8848
|
||||
# 命名空间,默认:public
|
||||
namespace: 09dff3e2-9790-4d4f-beb6-9baeb01ae040
|
||||
# 命名空间,默认:public、
|
||||
namespace: a60b2ca1-a8c6-47ae-94f1-741105674655
|
||||
service: ${spring.application.name}
|
||||
group: srt2.0
|
||||
config:
|
||||
|
|
Loading…
Reference in New Issue