IpInterfaceController.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package com.hr.controller;
  2. import com.github.pagehelper.PageInfo;
  3. import com.hr.param.AccountInterfaceParam;
  4. import com.hr.param.InterfaceConfigParam;
  5. import com.hr.param.IpInterfaceParam;
  6. import com.hr.param.SwitchStatusParam;
  7. import com.hr.service.IpTokenInterfaceService;
  8. import com.hr.service.IpInterfaceService;
  9. import com.hr.vo.*;
  10. import com.yy.basedevelop.common.data.BasePageResult;
  11. import com.yy.basedevelop.common.data.BaseReturnDto;
  12. import com.yy.basedevelop.common.http.config.TokenUtil;
  13. import com.yy.basedevelop.dto.LoginUser;
  14. import io.swagger.v3.oas.annotations.Operation;
  15. import io.swagger.v3.oas.annotations.tags.Tag;
  16. import org.apache.commons.lang3.RandomStringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.data.domain.Page;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.util.List;
  21. /**
  22. * 接口管理
  23. * @author : longhoo
  24. * @date : 2025-10-10
  25. */
  26. @RestController
  27. @RequestMapping("/ipInterface")
  28. @Tag(name = "接口管理")
  29. public class IpInterfaceController {
  30. @Autowired
  31. private IpInterfaceService ipInterfaceService;
  32. @Autowired
  33. private IpTokenInterfaceService ipTokenInterfaceService;
  34. /**
  35. * 分页查询
  36. *
  37. * @param ipInterfaceParam 筛选条件
  38. * @return 查询结果
  39. */
  40. @Operation(summary = "分页查询")
  41. @GetMapping("/list")
  42. public BasePageResult<IpInterfaceVO> paginQuery(IpInterfaceParam ipInterfaceParam){
  43. BasePageResult<IpInterfaceVO> ipAccountPOS = ipInterfaceService.paginQuery(ipInterfaceParam, ipInterfaceParam.getPageNum(), ipInterfaceParam.getPageSize());
  44. return ipAccountPOS;
  45. }
  46. /**
  47. * 新增数据
  48. *
  49. * @param ipInterfaceParam 实例对象
  50. * @return 实例对象
  51. */
  52. @Operation(summary = "新增/更新数据")
  53. @PostMapping("/saveOrUpdate")
  54. public BaseReturnDto<IpAccountVO> saveOrUpdate(@RequestBody IpInterfaceParam ipInterfaceParam){
  55. LoginUser user= TokenUtil.getUser();
  56. ipInterfaceService.saveOrUpdate(ipInterfaceParam,user.getUsername(),user.getUserid());
  57. return BaseReturnDto.success();
  58. }
  59. /**
  60. * 通过主键删除数据
  61. *
  62. * @param id 主键
  63. * @return 是否成功
  64. */
  65. @Operation(summary = "通过主键删除数据")
  66. @DeleteMapping("/delete/{id}")
  67. public BaseReturnDto<Boolean> deleteById(@PathVariable Long id){
  68. return BaseReturnDto.success(ipInterfaceService.deleteById(id));
  69. }
  70. /**
  71. * 修改状态
  72. * @param switchStatusParam 主键
  73. * @return 是否成功
  74. */
  75. @Operation(summary = "修改状态")
  76. @PostMapping("/switchStatus")
  77. public BaseReturnDto<Boolean> switchStatus(@RequestBody SwitchStatusParam switchStatusParam){
  78. return BaseReturnDto.success(ipInterfaceService.switchStatus(switchStatusParam));
  79. }
  80. /**
  81. * 接口下拉列表
  82. * @return 列表
  83. */
  84. @Operation(summary = "接口下拉列表")
  85. @PostMapping("/optionList")
  86. public BaseReturnDto<List<NameValueVO>> optionList(){
  87. return BaseReturnDto.success(ipInterfaceService.optionList());
  88. }
  89. /**
  90. * 账号配置接口
  91. */
  92. @Operation(summary = "账号配置接口")
  93. @PostMapping("/interfaceConfig")
  94. public BaseReturnDto interfaceConfig(@RequestBody InterfaceConfigParam param){
  95. LoginUser user = TokenUtil.getUser();
  96. ipTokenInterfaceService.interfaceConfig(param,user);
  97. return BaseReturnDto.success();
  98. }
  99. /**
  100. * 生成 token
  101. */
  102. @Operation(summary = "生成 token")
  103. @PostMapping("/token/generate")
  104. public BaseReturnDto<SecretVO> generateToken(){
  105. SecretVO vo = new SecretVO();
  106. String secret = RandomStringUtils.random(64, "0123456789abcdef");
  107. String token = RandomStringUtils.random(32, "0123456789abcdef");
  108. vo.setToken(token);
  109. vo.setSecret(secret);
  110. return BaseReturnDto.success(vo);
  111. }
  112. /**
  113. * 删除账号接口配置
  114. */
  115. @Operation(summary = "删除账号关联的接口")
  116. @DeleteMapping("/delAccountInterface/{id}")
  117. public BaseReturnDto delAccountInterface(@PathVariable Long id){
  118. LoginUser user = TokenUtil.getUser();
  119. ipTokenInterfaceService.delAccountInterface(id,user);
  120. return BaseReturnDto.success();
  121. }
  122. /**
  123. * 查询账号下关联的接口列表
  124. */
  125. @Operation(summary = "查询账号下关联的接口列表")
  126. @PostMapping("/account/ref/list")
  127. public BasePageResult<AccountInterfaceVO> accountInterfaceList(@RequestBody AccountInterfaceParam pageParam){
  128. BasePageResult<AccountInterfaceVO> result = ipTokenInterfaceService.accountInterfaceList(pageParam);
  129. return result;
  130. }
  131. /**
  132. * 账号关联接口修改接口状态
  133. * @param switchStatusParam 主键
  134. * @return 是否成功
  135. */
  136. @Operation(summary = "修改状态")
  137. @PostMapping("/account/interface/ref/switchStatus")
  138. public BaseReturnDto<Boolean> accountInterfaceRefSwitch(@RequestBody SwitchStatusParam switchStatusParam){
  139. return BaseReturnDto.success(ipTokenInterfaceService.switchStatus(switchStatusParam));
  140. }
  141. }