SmartApplyController.java 5.0 KB

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