WelcomeAccountController.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package com.template.controller;
  2. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  3. import com.template.annotation.AWelcomeLevelLog;
  4. import com.template.annotation.AWelcomeLog;
  5. import com.template.annotation.AWelcomeLogMode;
  6. import com.template.annotation.AWelcomeTypeLog;
  7. import com.template.api.WelcomeAccountControllerAPI;
  8. import com.template.common.utils.AesUtils;
  9. import com.template.model.pojo.WelcomeAccount;
  10. import com.template.model.pojo.WelcomeOrg;
  11. import com.template.model.pojo.WelcomeRole;
  12. import com.template.model.result.CommonResult;
  13. import com.template.model.result.PageUtils;
  14. import com.template.model.vo.AccountAuthorityVo;
  15. import com.template.model.vo.WelcomeAccountVo;
  16. import com.template.services.WelcomeAccountService;
  17. import com.template.services.WelcomeOrgService;
  18. import com.template.services.WelcomeRoleService;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. /**
  25. * <p>
  26. * 前端控制器
  27. * </p>
  28. *
  29. * @author ceshi
  30. * @since 2025-06-13
  31. */
  32. @RestController
  33. public class WelcomeAccountController implements WelcomeAccountControllerAPI {
  34. @Autowired
  35. WelcomeAccountService welcomeAccountService;
  36. @Autowired
  37. WelcomeOrgService welcomeOrgService;
  38. @Autowired
  39. WelcomeRoleService welcomeRoleService;
  40. @Override
  41. @AWelcomeLog("新增用户管理")
  42. @AWelcomeTypeLog("新增")
  43. @AWelcomeLogMode("用户管理")
  44. @AWelcomeLevelLog("信息")
  45. public CommonResult saveAccount(WelcomeAccount welcomeAccount) {
  46. String account = welcomeAccount.getAccount();
  47. // 将密码加密
  48. String password = welcomeAccount.getPassword();
  49. String encPassword = AesUtils.encrypt(password);
  50. welcomeAccount.setPassword(encPassword);
  51. WelcomeAccount dataByAccount = welcomeAccountService.getDataByAccount(account);
  52. if (ObjectUtils.isNotEmpty(dataByAccount)) {
  53. return CommonResult.fail("已存在该账号");
  54. }
  55. welcomeAccountService.insertWelcomeAccount(welcomeAccount);
  56. return CommonResult.ok();
  57. }
  58. @Override
  59. @AWelcomeLog("删除用户管理")
  60. @AWelcomeTypeLog("删除")
  61. @AWelcomeLogMode("用户管理")
  62. @AWelcomeLevelLog("警告")
  63. public CommonResult deleteAccount(Integer accountId) {
  64. boolean result = welcomeAccountService.removeById(accountId);
  65. return result ? CommonResult.ok() : CommonResult.fail();
  66. }
  67. @Override
  68. @AWelcomeLog("编辑用户管理")
  69. @AWelcomeTypeLog("编辑")
  70. @AWelcomeLogMode("用户管理")
  71. @AWelcomeLevelLog("信息")
  72. public CommonResult updateAccount(WelcomeAccount welcomeAccount) {
  73. String account = welcomeAccount.getAccount();
  74. // 将密码加密
  75. String password = welcomeAccount.getPassword();
  76. String encPassword = AesUtils.encrypt(password);
  77. welcomeAccount.setPassword(encPassword);
  78. WelcomeAccount dataByAccount = welcomeAccountService.getDataByAccount(account);
  79. if (ObjectUtils.isNotEmpty(dataByAccount)) {
  80. Integer id = dataByAccount.getId();
  81. Integer id1 = welcomeAccount.getId();
  82. if (!id.equals(id1)) {
  83. return CommonResult.fail("已存在该账号");
  84. }
  85. }
  86. welcomeAccountService.updateWelcomeAccount(welcomeAccount);
  87. return CommonResult.ok();
  88. }
  89. @Override
  90. public CommonResult listAccount(int currentPage, int pageCount,Integer status,String keyWord,String startTime,String endTime) {
  91. PageUtils<WelcomeAccountVo> pageUtils= welcomeAccountService.listAccount(currentPage,pageCount,status,keyWord,startTime,endTime);
  92. List<WelcomeAccountVo> list = pageUtils.getList();
  93. for (WelcomeAccountVo record : list) {
  94. String collegeId = record.getCollegeId();
  95. List<WelcomeOrg> checkOrgList= new ArrayList<>();
  96. if (ObjectUtils.isNotEmpty(collegeId)) {
  97. List<String> checkOrg= Arrays.asList(collegeId.split(","));
  98. for(int i=0;i<checkOrg.size();i++){
  99. WelcomeOrg welcomeOrg= welcomeOrgService.getById(checkOrg.get(i));
  100. if (welcomeOrg!=null){
  101. checkOrgList.add(welcomeOrg);
  102. }
  103. }
  104. record.setWelcomeOrgList(checkOrgList);
  105. }
  106. if (ObjectUtils.isNotEmpty(record.getRoleId())) {
  107. WelcomeRole byId = welcomeRoleService.getById(record.getRoleId());
  108. record.setWelcomeRole(byId);
  109. }
  110. String password = record.getPassword();
  111. String decrypt = AesUtils.decrypt(password);
  112. record.setPassword(decrypt);
  113. }
  114. return CommonResult.ok(pageUtils);
  115. }
  116. @Override
  117. public CommonResult getAccountAuthority(Integer accountId) {
  118. WelcomeAccount welcomeAccount = welcomeAccountService.getById(accountId);
  119. if (ObjectUtils.isEmpty(welcomeAccount)) {
  120. return CommonResult.fail("无该账号");
  121. }
  122. Integer roleId = welcomeAccount.getRoleId();
  123. if (ObjectUtils.isEmpty(roleId)) {
  124. return CommonResult.fail("无角色权限");
  125. }
  126. String collegeId = welcomeAccount.getCollegeId();
  127. if (ObjectUtils.isEmpty(collegeId)) {
  128. return CommonResult.fail("无管理部门");
  129. }
  130. WelcomeRole welcomeRole = welcomeRoleService.getById(roleId);
  131. if (ObjectUtils.isEmpty(welcomeRole)) {
  132. return CommonResult.fail("无该角色");
  133. }
  134. List<String> checkOrg= Arrays.asList(collegeId.split(","));
  135. List<WelcomeOrg> checkOrgList= new ArrayList<>();
  136. for(int i=0;i<checkOrg.size();i++){
  137. WelcomeOrg welcomeOrg= welcomeOrgService.getById(checkOrg.get(i));
  138. if (welcomeOrg!=null){
  139. checkOrgList.add(welcomeOrg);
  140. }
  141. }
  142. AccountAuthorityVo vo = new AccountAuthorityVo();
  143. vo.setWelcomeRole(welcomeRole);
  144. vo.setWelcomeOrgList(checkOrgList);
  145. return CommonResult.ok(vo);
  146. }
  147. }