SmartApplyController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.template.controller;
  2. import com.template.annotation.DESRespondSecret;
  3. import com.template.api.SmartApplyControllerAPI;
  4. import com.template.common.utils.paramUtils;
  5. import com.template.model.pojo.SmartApply;
  6. import com.template.model.pojo.SmartIdentity;
  7. import com.template.model.result.CommonResult;
  8. import com.template.model.result.PageUtils;
  9. import com.template.model.vo.ApplyVo;
  10. import com.template.model.vo.ApplysVo;
  11. import com.template.services.SmartApplyService;
  12. import com.template.services.SmartIdentityService;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.validation.BindingResult;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.stream.Collectors;
  21. /**
  22. * <p>
  23. * 前端控制器
  24. * </p>
  25. *
  26. * @author ceshi
  27. * @since 2023-12-04
  28. */
  29. @RestController
  30. //返回参数加密注解
  31. @DESRespondSecret
  32. public class SmartApplyController implements SmartApplyControllerAPI {
  33. @Autowired
  34. private SmartApplyService smartApplyService;
  35. @Autowired
  36. private SmartIdentityService smartIdentityService;
  37. /**
  38. * 查询应用管理
  39. *
  40. * @return
  41. */
  42. @Override
  43. @DESRespondSecret(validated = true)
  44. public CommonResult queryApplys() {
  45. List<ApplyVo> result = smartApplyService.queryApplys();
  46. return CommonResult.ok(result);
  47. }
  48. /**
  49. * 新增应用管理
  50. *
  51. * @param smartApply 应用管理数据
  52. * @param bindingResult
  53. * @return
  54. */
  55. @Override
  56. @DESRespondSecret(validated = true)
  57. public CommonResult insertSmartApply(SmartApply smartApply, BindingResult bindingResult) {
  58. if (bindingResult.hasErrors()) {
  59. String st = paramUtils.getParamError(bindingResult);
  60. return CommonResult.fail(st);
  61. }
  62. SmartApply data = smartApplyService.queryApplyByName(smartApply.getName());
  63. if (data != null) {
  64. return CommonResult.fail("该应用管理已存在");
  65. }
  66. int result = smartApplyService.insertSmartApply(smartApply);
  67. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  68. }
  69. /**
  70. * 更新应用管理
  71. *
  72. * @param sa 应用管理数据
  73. * @param bindingResult
  74. * @return
  75. */
  76. @Override
  77. @DESRespondSecret(validated = true)
  78. public CommonResult updateSmartApplyById(SmartApply sa, BindingResult bindingResult) {
  79. if (bindingResult.hasErrors()) {
  80. String st = paramUtils.getParamError(bindingResult);
  81. return CommonResult.fail(st);
  82. }
  83. SmartApply oldData = smartApplyService.getSmartById(sa.getId());
  84. if (oldData == null) {
  85. return CommonResult.fail("应用管理数据无效,修改失败");
  86. }
  87. if (sa.getName() != null && !sa.getName().equals(oldData.getName())) {
  88. //查看是否存在相同身份的数据
  89. SmartApply data = smartApplyService.queryApplyByName(sa.getName());
  90. if (data != null) {
  91. return CommonResult.fail("该应用管理已存在");
  92. }
  93. }
  94. int result = smartApplyService.updateSmartApply(sa);
  95. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  96. }
  97. /**
  98. * 应用管理分页数据查询
  99. *
  100. * @param currentPage 当前页数
  101. * @param pageCount 一页数据条数
  102. * @param name 查询名称
  103. * @return
  104. */
  105. @Override
  106. @DESRespondSecret(validated = true)
  107. public CommonResult queryPageSmartApplys(int currentPage, int pageCount, String name) {
  108. PageUtils<SmartApply> result = smartApplyService.queryPageSmartApplys(currentPage, pageCount, name);
  109. return CommonResult.ok(result);
  110. }
  111. @Override
  112. @DESRespondSecret(validated = true)
  113. public CommonResult deleteSmartApplyById(int id) {
  114. SmartApply data = smartApplyService.getSmartById(id);
  115. if (data == null) {
  116. return CommonResult.fail("当前数据不存在,删除失败!");
  117. }
  118. //查看被删除的应用管理有没有绑定身份数据 有的话提示无法删除
  119. List<SmartIdentity> identitys = smartIdentityService.querySmartIdentityDatas(id);
  120. if (identitys != null && identitys.size() > 0) {
  121. String name = StringUtils.join(identitys.stream().map(SmartIdentity::getName).collect(Collectors.toList()), ',');
  122. return CommonResult.fail("当前应用数据已绑定" + name + "身份,请先解绑");
  123. }
  124. int result = smartApplyService.deleteSmartApplyById(id);
  125. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  126. }
  127. @Override
  128. @DESRespondSecret(validated = true)
  129. public CommonResult queryAppletApplys() {
  130. List<ApplysVo> result = new ArrayList<>();
  131. List<SmartApply> applys = smartApplyService.queryAppletApplys();
  132. for (SmartApply apply : applys) {
  133. ApplysVo data = new ApplysVo();
  134. data.setId(apply.getId());
  135. data.setPath(apply.getRoute());
  136. data.setTitle(apply.getName());
  137. data.setUrl(apply.getLogo());
  138. result.add(data);
  139. }
  140. return CommonResult.ok(result);
  141. }
  142. }