120 lines
3.4 KiB
Java
120 lines
3.4 KiB
Java
package net.srt.controller;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import lombok.AllArgsConstructor;
|
|
import net.srt.dto.ApiConfigDto;
|
|
import net.srt.entity.ApiConfigEntity;
|
|
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.ApiConfigService;
|
|
import net.srt.vo.ApiConfig;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.validation.Valid;
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping("/api-config")
|
|
@AllArgsConstructor
|
|
public class ApiConfigController {
|
|
|
|
private final ApiConfigService apiConfigService;
|
|
|
|
|
|
|
|
/**
|
|
* 查询文件分组树
|
|
*
|
|
* @return 结果列表
|
|
*/
|
|
@GetMapping("/api-group")
|
|
@Operation(summary = "查询文件分组树")
|
|
public Result<List<TreeNodeVo>> listTree() {
|
|
return Result.ok(apiConfigService.listTree());
|
|
}
|
|
|
|
/**
|
|
* 分页查询API配置
|
|
* @param query API配置查询对象
|
|
* @return 分页结果
|
|
*/
|
|
@GetMapping("/page")
|
|
@Operation(summary = "分页")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:page')")
|
|
public Result<PageResult<ApiConfig>> page(@Valid ApiConfigQuery query) {
|
|
PageResult<ApiConfig> page = apiConfigService.page(query);
|
|
|
|
return Result.ok(page);
|
|
}
|
|
|
|
/**
|
|
* 获取IP和端口信息
|
|
*
|
|
* @return 返回IP和端口信息
|
|
*/
|
|
@GetMapping("/getIpPort")
|
|
public Result<String> getIpPort() {
|
|
return Result.ok(apiConfigService.getIpPort());
|
|
}
|
|
|
|
/**
|
|
* 根据ID获取API配置信息
|
|
*
|
|
* @param id API配置ID
|
|
* @return API配置实体对象
|
|
*/
|
|
@GetMapping("/{id}")
|
|
@Operation(summary = "查看")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:info')")
|
|
public Result<ApiConfigEntity> get(@PathVariable("id") Long id) {
|
|
ApiConfigEntity apiConfig = apiConfigService.getByI(id);
|
|
|
|
return Result.ok(apiConfig);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
@Operation(summary = "修改")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:update')")
|
|
public Result<ApiConfigEntity> update(@PathVariable Long id, @RequestBody @Valid ApiConfigEntity vo) {
|
|
apiConfigService.update(id,vo);
|
|
return Result.ok();
|
|
}
|
|
@PutMapping("/{id}/offline")
|
|
@Operation(summary = "下线")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:update')")
|
|
public Result<ApiConfigEntity> xia(@PathVariable Long id) {
|
|
apiConfigService.xia(id);
|
|
return Result.ok();
|
|
}
|
|
|
|
@PutMapping("/{id}/online")
|
|
@Operation(summary = "上线")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:update')")
|
|
public Result<ApiConfigEntity> shang(@PathVariable Long id) {
|
|
apiConfigService.shang(id);
|
|
return Result.ok();
|
|
}
|
|
|
|
|
|
@PostMapping
|
|
@Operation(summary = "新增")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:save')")
|
|
public Result<String> insert(@RequestBody ApiConfig vo) {
|
|
apiConfigService.sav(vo);
|
|
return Result.ok();
|
|
}
|
|
|
|
@DeleteMapping
|
|
@Operation(summary = "删除")
|
|
@PreAuthorize("hasAuthority('data-service:api-config:delete')")
|
|
public Result<String> delete(@RequestBody List<Long> idList) {
|
|
apiConfigService.removeByI(idList);
|
|
return Result.ok();
|
|
}
|
|
|
|
|
|
}
|