| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package space.anyi.openAPI.controller;
- import cn.hutool.core.util.IdUtil;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import space.anyi.openAPI.model.PageVO;
- import space.anyi.openAPI.model.ResponseResult;
- import space.anyi.openAPI.model.commom.RequestID;
- import space.anyi.openAPI.model.interfaceInfo.InterfaceInfo;
- import space.anyi.openAPI.model.interfaceInfo.InterfaceStatus;
- import space.anyi.openAPI.model.interfaceInfo.dto.RequestAddInterfaceInfo;
- import space.anyi.openAPI.model.interfaceInfo.dto.RequestPageInterfaceInfo;
- import space.anyi.openAPI.model.interfaceInfo.dto.RequestUpdateInterfaceInfo;
- import space.anyi.openAPI.model.interfaceInfo.vo.InterfaceInfoVO;
- import space.anyi.openAPI.service.InterfaceInfoService;
- import space.anyi.openAPI.util.BeanCopyUtil;
- import space.anyi.openAPI.util.SecurityUtils;
- import javax.annotation.Resource;
- import java.util.List;
- import java.util.Objects;
- /**
- * @ProjectName: yangyi-open-api-platform
- * @FileName: InterfaceInfoController
- * @Author: 杨逸
- * @Data:2025/10/14 19:52
- * @Description:
- */
- @RestController
- @RequestMapping("/interfaceInfo")
- public class InterfaceInfoController {
- @Resource
- private InterfaceInfoService interfaceInfoService;
- @PostMapping
- @PreAuthorize("@ps.hasRole('管理员')")
- public ResponseResult add(@RequestBody RequestAddInterfaceInfo requestAddInterfaceInfo){
- long id = IdUtil.getSnowflake(1, 1).nextId();
- InterfaceInfo interfaceInfo = BeanCopyUtil.copyBean(requestAddInterfaceInfo, InterfaceInfo.class);
- interfaceInfo.setId(id);
- Long userId = SecurityUtils.getUserId();
- interfaceInfo.setUserId(userId);
- interfaceInfoService.save(interfaceInfo);
- return ResponseResult.okResult();
- }
- @DeleteMapping()
- @PreAuthorize("@ps.hasRole('管理员')")
- public ResponseResult delete(List<Long> ids){
- interfaceInfoService.removeByIds(ids);
- return ResponseResult.okResult();
- }
- @PutMapping
- @PreAuthorize("@ps.hasRole('管理员')")
- public ResponseResult update(@RequestBody RequestUpdateInterfaceInfo requestUpdateInterfaceInfo){
- InterfaceInfo interfaceInfo = BeanCopyUtil.copyBean(requestUpdateInterfaceInfo, InterfaceInfo.class);
- interfaceInfoService.updateById(interfaceInfo);
- return ResponseResult.okResult();
- }
- @GetMapping
- public ResponseResult list(RequestPageInterfaceInfo requestPageInterfaceInfo){
- PageVO pageVO = interfaceInfoService.listPage(requestPageInterfaceInfo);
- return ResponseResult.okResult(pageVO);
- }
- @PutMapping("/online")
- @PreAuthorize("@ps.hasRole('管理员')")
- public ResponseResult onlineInterface(@RequestBody RequestID requestID){
- //校验
- //接口是否存在
- InterfaceInfo interfaceInfo = interfaceInfoService.getById(requestID.getId());
- if (Objects.isNull(interfaceInfo)) {
- return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.INTERFACE_NOT_FOUND);
- }
- //是否为当前用户创建
- if (!SecurityUtils.getUserId().equals(interfaceInfo.getUserId())) {
- return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.NO_OPERATOR_AUTH);
- }
- //todo:是否可以调用
- //更新状态
- interfaceInfo.setStatus(InterfaceStatus.online.getStatus());
- interfaceInfoService.updateById(interfaceInfo);
- return ResponseResult.okResult();
- }
- @PutMapping("/offline")
- @PreAuthorize("@ps.hasRole('管理员')")
- public ResponseResult offlineInterface(@RequestBody RequestID requestID){
- //校验
- //接口是否存在
- InterfaceInfo interfaceInfo = interfaceInfoService.getById(requestID.getId());
- if (Objects.isNull(interfaceInfo)) {
- return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.INTERFACE_NOT_FOUND);
- }
- //是否为当前用户创建
- if (!SecurityUtils.getUserId().equals(interfaceInfo.getUserId())) {
- return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.NO_OPERATOR_AUTH);
- }
- //更新状态
- interfaceInfo.setStatus(InterfaceStatus.offline.getStatus());
- interfaceInfoService.updateById(interfaceInfo);
- return ResponseResult.okResult();
- }
- @PreAuthorize("@ps.hasRole('用户')")
- @GetMapping("/{id}")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", value = "接口信息id", required = true, dataType = "long", paramType = "path")
- })
- public ResponseResult getInterfaceInfoById(@PathVariable Long id){
- InterfaceInfo interfaceInfo = interfaceInfoService.getById(id);
- InterfaceInfoVO vo = BeanCopyUtil.copyBean(interfaceInfo, InterfaceInfoVO.class);
- return ResponseResult.okResult(vo);
- }
- }
|