174 lines
6.3 KiB
Java
174 lines
6.3 KiB
Java
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;
|
|
|
|
/**
|
|
* 分页查询接口配置列表
|
|
* @param query 查询条件
|
|
* @return 接口配置列表分页结果
|
|
*/
|
|
@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); // 调用service层方法获取分页结果
|
|
return Result.ok(page); // 封装返回结果并返回
|
|
}
|
|
//1
|
|
/**
|
|
* 根据resourceId分页获取接口配置列表
|
|
* @param query 查询条件
|
|
* @return 符合条件的接口配置列表的分页结果
|
|
*/
|
|
@GetMapping("page-resource")
|
|
@Operation(summary = "根据resourceId分页获取接口配置列表")
|
|
public Result<PageResult<ApiConfigVo>> pageResource(@Valid ApiConfigQuery query){
|
|
PageResult<ApiConfigVo> page = apiConfigService.pageResource(query); // 调用service层方法根据resourceId分页获取接口配置列表
|
|
return Result.ok(page); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 根据id获取接口配置信息
|
|
* @param id 接口配置id
|
|
* @return 对应id的接口配置信息
|
|
*/
|
|
@GetMapping("{id}")
|
|
@Operation(summary = "根据id获取接口配置信息")
|
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:info')")
|
|
public Result<ApiConfigVo> get(@PathVariable("id") Long id){
|
|
ApiConfigEntity entity=apiConfigService.getById(id); // 根据id获取接口配置实体对象
|
|
return Result.ok(ApiConfigConvert.INSTANCE.convert(entity)); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 保存接口配置信息
|
|
* @param vo 接口配置信息
|
|
* @return 保存结果
|
|
*/
|
|
@PostMapping
|
|
@Operation(summary = "保存接口配置信息")
|
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:save')")
|
|
public Result<String> save(@RequestBody ApiConfigVo vo) {
|
|
apiConfigService.save(vo); // 调用service层方法保存接口配置信息
|
|
return Result.ok(); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 修改接口配置信息
|
|
* @param vo 接口配置信息
|
|
* @return 修改结果
|
|
*/
|
|
@PutMapping
|
|
@Operation(summary = "修改接口配置信息")
|
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:update')")
|
|
public Result<String> update(@RequestBody ApiConfigVo vo){
|
|
apiConfigService.update(vo); // 调用service层方法修改接口配置信息
|
|
return Result.ok(); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 删除接口配置信息
|
|
* @param idList 待删除的接口配置id列表
|
|
* @return 删除结果
|
|
*/
|
|
@DeleteMapping
|
|
@Operation(summary = "删除接口配置信息")
|
|
@PreAuthorize("hasAnyAuthority('data-service:api-config:delete')")
|
|
public Result<String> delete(@RequestBody List<Long> idList){
|
|
apiConfigService.delete(idList); // 调用service层方法删除接口配置信息
|
|
return Result.ok(); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 获取服务的IP和端口号
|
|
* @return IP和端口号
|
|
*/
|
|
@GetMapping("getIpPort")
|
|
@Operation(summary = "获取服务的IP和端口号")
|
|
public Result<String> getIpPort() {
|
|
return Result.ok(apiConfigService.getIpPort()); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 获取服务的IP和端口号
|
|
* @return IP和端口号
|
|
*/
|
|
@GetMapping("/ip-port")
|
|
@Operation(summary = "获取服务的IP和端口号")
|
|
public Result<String> ipPort() {
|
|
return Result.ok(apiConfigService.ipPort()); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 上线指定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); // 调用service层方法上线指定id的接口配置
|
|
return Result.ok(); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 下线指定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); // 调用service层方法下线指定id的接口配置
|
|
return Result.ok(); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 执行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)); // 封装返回结果并返回
|
|
}
|
|
|
|
/**
|
|
* 导出指定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); // 调用service层方法导出API文档
|
|
}
|
|
|
|
}
|