SmartAuthorGroupController.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.template.annotation.DESRespondSecret;
  5. import com.template.annotation.PassToken;
  6. import com.template.api.SmartAuthorGroupControllerAPI;
  7. import com.template.common.utils.AesUtils;
  8. import com.template.common.utils.TimeExchange2;
  9. import com.template.common.utils.TreeRecordsUtil;
  10. import com.template.common.utils.UUIDUtil;
  11. import com.template.model.pojo.*;
  12. import com.template.model.result.CommonResult;
  13. import com.template.model.weixin.AuthorAndGroup;
  14. import com.template.model.weixin.AuthorAndGroup2;
  15. import com.template.model.weixin.AuthorListGroup;
  16. import com.template.model.weixin.userAuthor;
  17. import com.template.services.*;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.text.ParseException;
  21. import java.util.*;
  22. import java.util.stream.Collectors;
  23. /**
  24. * <p>
  25. * 前端控制器
  26. * </p>
  27. *
  28. * @author ceshi
  29. * @since 2023-12-04
  30. */
  31. @RestController
  32. //返回参数加密注解
  33. @DESRespondSecret
  34. public class SmartAuthorGroupController implements SmartAuthorGroupControllerAPI {
  35. @Autowired
  36. private SmartAuthorGroupService smartAuthorGroupService;
  37. @Autowired
  38. public SmartAuthorityService smartAuthorityService;
  39. @Autowired
  40. public SmartUserService smartUserService;
  41. @Autowired
  42. public SmartDepartmentService smartDepartmentService;
  43. @Autowired
  44. public SmartMenuService smartMenuService;
  45. /**
  46. * 新增权限组
  47. *
  48. * @param
  49. * @param
  50. * @return
  51. */
  52. @Override
  53. @PassToken
  54. @DESRespondSecret(validated = true)
  55. public CommonResult insertSmartAuthorGroup(JSONObject jsonObject, Integer samePower) throws ParseException {
  56. if (samePower == null) {
  57. return CommonResult.fail("samePower不能为空");
  58. }
  59. // 所有管理员权限一样
  60. if (samePower == 1) {
  61. AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
  62. SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
  63. sa.setId((int) UUIDUtil.generateID());
  64. String[] userId = sa.getUserId().split(",");
  65. // 相关判断
  66. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  67. queryWrapper.eq("deleted", "0");
  68. queryWrapper.eq("parent_id", sa.getParentId());
  69. queryWrapper.eq("name", sa.getName());
  70. List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
  71. if (querySmartGroup.size() > 0) {
  72. return CommonResult.fail("该管理员已存在,请勿重复添加");
  73. }
  74. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  75. List<String> typeList = Arrays.asList(userId);
  76. queryWrapper2.in("user_id", typeList);
  77. queryWrapper2.eq("deleted", "0");
  78. List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
  79. if (querySmart.size() > 0) {
  80. return CommonResult.fail("该用户已分配其他权限组");
  81. }
  82. Set<String> set = new HashSet<>(typeList);
  83. if (typeList.size() != set.size()) {
  84. return CommonResult.fail("请勿选择重复用户");
  85. }
  86. for (int i = 0; i < userId.length; i++) {
  87. SmartAuthority smartAuthority = new SmartAuthority();
  88. smartAuthority.setUserId(Integer.parseInt(userId[i]));
  89. smartAuthority.setGroupId(sa.getId());
  90. smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
  91. smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
  92. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  93. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  94. smartAuthority.setCreateUser("admin");
  95. smartAuthority.setUpdateUser("admin");
  96. smartAuthority.setDeleted(0);
  97. smartAuthorityService.insertSmartAuthority(smartAuthority);
  98. }
  99. sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  100. sa.setCreateUser("admin");
  101. sa.setUpdateUser("admin");
  102. sa.setDeleted(0);
  103. int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
  104. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  105. }
  106. // 每个管理员权限不一样
  107. if (samePower == 2) {
  108. AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
  109. SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
  110. sa.setId((int) UUIDUtil.generateID());
  111. List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
  112. // 相关查询
  113. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  114. queryWrapper.eq("deleted", 0);
  115. queryWrapper.eq("parent_id", sa.getParentId());
  116. queryWrapper.eq("name", sa.getName());
  117. List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
  118. if (querySmartGroup.size() > 0) {
  119. return CommonResult.fail("该管理员已存在,请勿重复添加");
  120. }
  121. List<Integer> uid = userAuthors.stream().map(userAuthor::getUserId).collect(Collectors.toList());
  122. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  123. queryWrapper2.in("user_id", uid);
  124. queryWrapper2.eq("deleted", 0);
  125. List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
  126. if (querySmart.size() > 0) {
  127. return CommonResult.fail("该用户已分配其他权限组");
  128. }
  129. Set<Integer> set = new HashSet<>(uid);
  130. if (uid.size() != set.size()) {
  131. return CommonResult.fail("请勿选择重复用户");
  132. }
  133. for (int i = 0; i < userAuthors.size(); i++) {
  134. SmartAuthority smartAuthority = new SmartAuthority();
  135. smartAuthority.setUserId(userAuthors.get(i).getUserId());
  136. smartAuthority.setGroupId(sa.getId());
  137. smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
  138. smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
  139. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  140. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  141. smartAuthority.setCreateUser("admin");
  142. smartAuthority.setUpdateUser("admin");
  143. smartAuthority.setDeleted(0);
  144. smartAuthorityService.insertSmartAuthority(smartAuthority);
  145. }
  146. sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  147. sa.setCreateUser("admin");
  148. sa.setUpdateUser("admin");
  149. sa.setDeleted(0);
  150. int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
  151. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  152. }
  153. return CommonResult.errorMsg("参数格式错误");
  154. }
  155. /**
  156. * 更新权限组
  157. *
  158. * @param
  159. * @param
  160. * @return
  161. */
  162. @Override
  163. @PassToken
  164. @DESRespondSecret(validated = true)
  165. public CommonResult updateSmartAuthorGroup(JSONObject jsonObject, Integer samePower) throws ParseException {
  166. if (samePower == null) {
  167. return CommonResult.errorMsg("samePower不能为空");
  168. }
  169. // 所有管理员权限一样
  170. if (samePower == 1) {
  171. AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
  172. SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
  173. String[] userId = sa.getUserId().split(",");
  174. // 相关判断
  175. QueryWrapper<SmartAuthorGroup> queryWrapperA = new QueryWrapper<>();
  176. queryWrapperA.eq("deleted", 0);
  177. queryWrapperA.eq("id", sa.getId());
  178. List<SmartAuthorGroup> querySmartGroupA = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperA);
  179. if (querySmartGroupA.size() <= 0) {
  180. return CommonResult.fail("该条信息已删除");
  181. }
  182. QueryWrapper<SmartAuthorGroup> queryWrapperB = new QueryWrapper<>();
  183. queryWrapperB.eq("deleted", 0);
  184. queryWrapperB.eq("id", sa.getParentId());
  185. List<SmartAuthorGroup> querySmartGroupB = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperB);
  186. if (querySmartGroupB.size() <= 0 && sa.getParentId() != 0) {
  187. return CommonResult.fail("父ID不存在");
  188. }
  189. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  190. queryWrapper.eq("deleted", 0);
  191. queryWrapper.eq("parent_id", sa.getParentId());
  192. queryWrapper.eq("name", sa.getName());
  193. queryWrapper.ne("id", sa.getId());
  194. List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
  195. if (querySmartGroup.size() > 0) {
  196. return CommonResult.fail("该管理员已存在,请勿重复修改");
  197. }
  198. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  199. List<String> typeList = Arrays.asList(userId);
  200. queryWrapper2.in("user_id", typeList);
  201. queryWrapper2.eq("deleted", 0);
  202. queryWrapper2.ne("group_id", sa.getId());
  203. List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
  204. if (querySmart.size() > 0) {
  205. return CommonResult.fail("该用户已分配其他权限组");
  206. }
  207. Set<String> set = new HashSet<>(typeList);
  208. if (typeList.size() != set.size()) {
  209. return CommonResult.fail("请勿选择重复用户");
  210. }
  211. String[] old_userId = querySmartGroupA.get(0).getUserId().split(",");
  212. for (int i = 0; i < old_userId.length; i++) {
  213. if (!typeList.contains(old_userId[i])) {
  214. QueryWrapper<SmartAuthority> queryWrapperC = new QueryWrapper<>();
  215. queryWrapperC.eq("deleted", 0);
  216. queryWrapperC.eq("user_id", Integer.parseInt(old_userId[i]));
  217. List<SmartAuthority> smartAuthorityC = smartAuthorityService.getAuthorByKey(queryWrapperC);
  218. if (smartAuthorityC.size() > 0) {
  219. SmartAuthority smartAuthority = smartAuthorityC.get(0);
  220. smartAuthority.setDeleted(1);
  221. logger.info(")))" + smartAuthority.getId());
  222. smartAuthorityService.updateSmartAuthority(smartAuthority);
  223. }
  224. }
  225. }
  226. for (int i = 0; i < userId.length; i++) {
  227. QueryWrapper<SmartAuthority> queryWrapper3 = new QueryWrapper<>();
  228. queryWrapper3.eq("deleted", 0);
  229. queryWrapper3.eq("user_id", Integer.parseInt(userId[i]));
  230. List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper3);
  231. if (smartAuthoritys.size() > 0) {
  232. SmartAuthority smartAuthority = smartAuthoritys.get(0);
  233. smartAuthority.setGroupId(sa.getId());
  234. smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
  235. smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
  236. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  237. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  238. smartAuthority.setCreateUser("admin");
  239. smartAuthority.setUpdateUser("admin");
  240. smartAuthority.setDeleted(0);
  241. smartAuthorityService.updateSmartAuthority(smartAuthority);
  242. } else {
  243. SmartAuthority smartAuthority = new SmartAuthority();
  244. smartAuthority.setUserId(Integer.parseInt(userId[i]));
  245. smartAuthority.setGroupId(sa.getId());
  246. smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
  247. smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
  248. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  249. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  250. smartAuthority.setCreateUser("admin");
  251. smartAuthority.setUpdateUser("admin");
  252. smartAuthority.setDeleted(0);
  253. smartAuthorityService.insertSmartAuthority(smartAuthority);
  254. }
  255. }
  256. int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
  257. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  258. }
  259. // 每个管理员权限不一样
  260. if (samePower == 2) {
  261. AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
  262. SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
  263. List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
  264. // 相关查询
  265. QueryWrapper<SmartAuthorGroup> queryWrapperA = new QueryWrapper<>();
  266. queryWrapperA.eq("deleted", 0);
  267. queryWrapperA.eq("id", sa.getId());
  268. List<SmartAuthorGroup> querySmartGroupA = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperA);
  269. if (querySmartGroupA.size() <= 0) {
  270. return CommonResult.fail("该条信息已删除");
  271. }
  272. QueryWrapper<SmartAuthorGroup> queryWrapperB = new QueryWrapper<>();
  273. queryWrapperB.eq("deleted", 0);
  274. queryWrapperB.eq("id", sa.getParentId());
  275. List<SmartAuthorGroup> querySmartGroupB = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperB);
  276. if (querySmartGroupB.size() <= 0 && sa.getParentId() != 0) {
  277. return CommonResult.fail("父ID不存在");
  278. }
  279. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  280. queryWrapper.eq("deleted", 0);
  281. queryWrapper.eq("parent_id", sa.getParentId());
  282. queryWrapper.eq("name", sa.getName());
  283. queryWrapper.ne("id", sa.getId());
  284. List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
  285. if (querySmartGroup.size() > 0) {
  286. return CommonResult.fail("该管理员已存在,请勿重复添加");
  287. }
  288. List<Integer> uid = userAuthors.stream().map(userAuthor::getUserId).collect(Collectors.toList());
  289. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  290. queryWrapper2.in("user_id", uid);
  291. queryWrapper2.eq("deleted", 0);
  292. queryWrapper2.ne("group_id", sa.getId());
  293. List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
  294. if (querySmart.size() > 0) {
  295. return CommonResult.fail("该用户已分配其他权限组");
  296. }
  297. Set<Integer> set = new HashSet<>(uid);
  298. if (uid.size() != set.size()) {
  299. return CommonResult.fail("请勿选择重复用户");
  300. }
  301. String[] old_userId = querySmartGroupA.get(0).getUserId().split(",");
  302. for (int i = 0; i < old_userId.length; i++) {
  303. if (!uid.contains(Integer.parseInt(old_userId[i]))) {
  304. QueryWrapper<SmartAuthority> queryWrapperC = new QueryWrapper<>();
  305. queryWrapperC.eq("deleted", 0);
  306. queryWrapperC.eq("user_id", Integer.parseInt(old_userId[i]));
  307. List<SmartAuthority> smartAuthorityC = smartAuthorityService.getAuthorByKey(queryWrapperC);
  308. if (smartAuthorityC.size() > 0) {
  309. SmartAuthority smartAuthority = smartAuthorityC.get(0);
  310. smartAuthority.setDeleted(1);
  311. smartAuthorityService.updateSmartAuthority(smartAuthority);
  312. }
  313. }
  314. }
  315. String userid = "";
  316. for (int i = 0; i < userAuthors.size(); i++) {
  317. if (i == userAuthors.size() - 1) {
  318. userid += userAuthors.get(i).getUserId();
  319. } else {
  320. userid += userAuthors.get(i).getUserId() + ",";
  321. }
  322. QueryWrapper<SmartAuthority> queryWrapper3 = new QueryWrapper<>();
  323. queryWrapper3.eq("deleted", 0);
  324. queryWrapper3.eq("user_id", userAuthors.get(i).getUserId());
  325. List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper3);
  326. if (smartAuthoritys.size() > 0) {
  327. SmartAuthority smartAuthority = smartAuthoritys.get(0);
  328. smartAuthority.setUserId(userAuthors.get(i).getUserId());
  329. smartAuthority.setGroupId(sa.getId());
  330. smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
  331. smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
  332. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  333. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  334. smartAuthority.setCreateUser("admin");
  335. smartAuthority.setUpdateUser("admin");
  336. smartAuthority.setDeleted(userAuthors.get(i).getDeleted());
  337. smartAuthorityService.updateSmartAuthority(smartAuthority);
  338. } else {
  339. SmartAuthority smartAuthority = new SmartAuthority();
  340. smartAuthority.setUserId(userAuthors.get(i).getUserId());
  341. smartAuthority.setGroupId(sa.getId());
  342. smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
  343. smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
  344. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  345. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  346. smartAuthority.setCreateUser("admin");
  347. smartAuthority.setUpdateUser("admin");
  348. smartAuthority.setDeleted(0);
  349. smartAuthorityService.insertSmartAuthority(smartAuthority);
  350. }
  351. }
  352. sa.setUserId(userid);
  353. int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
  354. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  355. }
  356. return CommonResult.errorMsg("参数格式错误");
  357. }
  358. /**
  359. * 新增权限组
  360. *
  361. * @param
  362. * @param
  363. * @return
  364. */
  365. @Override
  366. @PassToken
  367. @DESRespondSecret(validated = true)
  368. public CommonResult addSmartAuthorGroup(JSONObject jsonObject) throws ParseException {
  369. AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
  370. SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
  371. sa.setId((int) UUIDUtil.generateID());
  372. // 相关判断
  373. QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
  374. queryWrapper.eq("deleted", "0");
  375. queryWrapper.eq("parent_id", sa.getParentId());
  376. queryWrapper.eq("name", sa.getName());
  377. List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
  378. if (querySmartGroup.size() > 0) {
  379. return CommonResult.fail("该管理员已存在,请勿重复添加");
  380. }
  381. sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  382. sa.setCreateUser("admin");
  383. sa.setUpdateUser("admin");
  384. sa.setDeleted(0);
  385. int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
  386. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  387. }
  388. /**
  389. * 删除权限组
  390. *
  391. * @param
  392. * @param
  393. * @return
  394. */
  395. @Override
  396. @PassToken
  397. @DESRespondSecret(validated = true)
  398. public CommonResult delSmartAuthorGroup(Integer id) {
  399. QueryWrapper<SmartAuthorGroup> queryWrapper1 = new QueryWrapper<>();
  400. queryWrapper1.eq("parent_id", id);
  401. queryWrapper1.eq("deleted",0);
  402. List<SmartAuthorGroup> list1 = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper1);
  403. SmartAuthorGroup rns = new SmartAuthorGroup();
  404. rns.setId(id);
  405. rns.setDeleted(1);
  406. int result = smartAuthorGroupService.updateSmartAuthorGroup(rns);
  407. SmartAuthority smartAuthority = new SmartAuthority();
  408. smartAuthority.setDeleted(1);
  409. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  410. queryWrapper2.eq("group_id", id);
  411. boolean m = smartAuthorityService.update(smartAuthority,queryWrapper2);
  412. SmartAuthorGroup rns2 = new SmartAuthorGroup();
  413. rns2.setDeleted(1);
  414. QueryWrapper<SmartAuthorGroup> queryWrapper3 = new QueryWrapper<>();
  415. queryWrapper3.eq("parent_id", id);
  416. boolean result2 = smartAuthorGroupService.update(rns2, queryWrapper3);
  417. SmartAuthority smartAuthority2 = new SmartAuthority();
  418. smartAuthority2.setDeleted(1);
  419. QueryWrapper<SmartAuthority> queryWrapper4 = new QueryWrapper<>();
  420. List<Integer> gid = list1.stream().map(SmartAuthorGroup::getId).collect(Collectors.toList());
  421. queryWrapper4.in("group_id", gid);
  422. queryWrapper4.eq("deleted",0);
  423. boolean m2 = smartAuthorityService.update(smartAuthority2,queryWrapper4);
  424. return result > 0 && result2 && m && m2 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  425. }
  426. /**
  427. * 操作管理员
  428. *
  429. * @param
  430. * @param
  431. * @return
  432. */
  433. @Override
  434. @PassToken
  435. @DESRespondSecret(validated = true)
  436. public CommonResult operateSmartAuthorGroupUser(Integer id, String userId) throws ParseException {
  437. if (id==null){
  438. return CommonResult.fail("id不能为空");
  439. }
  440. if (userId==null){
  441. userId="";
  442. }
  443. SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
  444. if (sa==null){
  445. return CommonResult.fail("当前权限组不存在");
  446. }
  447. if (sa.getUserId()==null){
  448. sa.setUserId("");
  449. }
  450. String[] oldUserId = sa.getUserId().split(",");
  451. String[] newUserId = userId.split(",");
  452. List<String> userList = Arrays.asList(newUserId);
  453. Set<String> set = new HashSet<>(userList);
  454. if (userList.size() != set.size()) {
  455. return CommonResult.fail("请勿选择重复用户");
  456. }
  457. QueryWrapper<SmartAuthority> queryWrapperA = new QueryWrapper<>();
  458. List<String> typeList = Arrays.asList(newUserId);
  459. queryWrapperA.in("user_id", typeList);
  460. queryWrapperA.eq("deleted", 0);
  461. queryWrapperA.ne("group_id", sa.getId());
  462. List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapperA);
  463. if (querySmart.size() > 0) {
  464. return CommonResult.fail("该用户已分配其他权限组");
  465. }
  466. QueryWrapper<SmartUser> queryWrapperB = new QueryWrapper<>();
  467. List<String> users = Arrays.asList(newUserId);
  468. queryWrapperB.in("id", users);
  469. queryWrapperB.eq("deleted", 0);
  470. List<SmartUser> ulist = smartUserService.list(queryWrapperB);
  471. if (!userId.equals("") && (ulist.isEmpty() || ulist.size()!=newUserId.length)){
  472. return CommonResult.fail("有用户已删除");
  473. }
  474. for (int i = 0; i < oldUserId.length; i++) {
  475. if (!oldUserId[i].equals("") && !userList.contains(oldUserId[i])) {
  476. QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
  477. queryWrapper1.eq("deleted", 0);
  478. queryWrapper1.eq("user_id", Integer.parseInt(oldUserId[i]));
  479. List<SmartAuthority> smartAuthority1 = smartAuthorityService.getAuthorByKey(queryWrapper1);
  480. if (smartAuthority1.size() > 0) {
  481. SmartAuthority smartAuthority = smartAuthority1.get(0);
  482. smartAuthority.setDeleted(1);
  483. smartAuthorityService.updateSmartAuthority(smartAuthority);
  484. }
  485. }
  486. }
  487. for (int i = 0; i < newUserId.length; i++) {
  488. if (!newUserId[i].equals("")){
  489. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  490. queryWrapper2.eq("deleted", 0);
  491. queryWrapper2.eq("user_id", Integer.parseInt(newUserId[i]));
  492. List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper2);
  493. if (smartAuthoritys.size() <= 0) {
  494. SmartAuthority smartAuthority = new SmartAuthority();
  495. smartAuthority.setUserId(Integer.parseInt(newUserId[i]));
  496. smartAuthority.setGroupId(sa.getId());
  497. smartAuthority.setDepartmentView("");
  498. smartAuthority.setDepartmentManage("");
  499. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  500. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  501. smartAuthority.setCreateUser("admin");
  502. smartAuthority.setUpdateUser("admin");
  503. smartAuthority.setDeleted(0);
  504. smartAuthorityService.insertSmartAuthority(smartAuthority);
  505. }
  506. }
  507. }
  508. sa.setUserId(userId);
  509. int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
  510. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  511. }
  512. /**
  513. * 操作菜单权限
  514. *
  515. * @param
  516. * @param
  517. * @return
  518. */
  519. @Override
  520. @PassToken
  521. @DESRespondSecret(validated = true)
  522. public CommonResult operateSmartAuthorGroupApply(Integer id, String applyId) {
  523. if (id==null){
  524. return CommonResult.fail("id不能为空");
  525. }
  526. if (applyId==null){
  527. applyId="";
  528. }
  529. SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
  530. if (sa==null){
  531. return CommonResult.fail("当前权限组不存在");
  532. }
  533. sa.setApplyId(applyId);
  534. int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
  535. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  536. }
  537. @PassToken
  538. @Override
  539. @DESRespondSecret(validated = false)
  540. public CommonResult getSmartAuthorGroupManager(String groupId) {
  541. List<SmartAuthorGroupManager> list = smartAuthorGroupService.getSmartAuthorGroupManager(groupId);
  542. return CommonResult.ok(list);
  543. }
  544. @PassToken
  545. @Override
  546. public CommonResult operateSmartAuthorDepartment(JSONObject jsonObject) {
  547. Integer id = jsonObject.getInteger("id");
  548. String departmentView = jsonObject.getString("departmentView");
  549. String departmentManage = jsonObject.getString("departmentManage");
  550. if (id==null){
  551. return CommonResult.fail("请传入ID");
  552. }
  553. SmartAuthority smartAuthority = smartAuthorityService.getSmartById(id);
  554. if (departmentView!=null ){
  555. smartAuthority.setDepartmentView(departmentView);
  556. }
  557. if (departmentManage!=null){
  558. smartAuthority.setDepartmentManage(departmentManage);
  559. }
  560. smartAuthorityService.updateSmartAuthority(smartAuthority);
  561. return CommonResult.ok("修改成功");
  562. }
  563. @PassToken
  564. @Override
  565. @DESRespondSecret(validated = false)
  566. public CommonResult getSmartAuthorGroupMenu(Integer id) {
  567. SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(id);
  568. if (smartAuthorGroup==null || smartAuthorGroup.getDeleted()==1){
  569. return CommonResult.fail("当前权限组已删除");
  570. }
  571. String[] applyIds = smartAuthorGroup.getApplyId().split(",");
  572. QueryWrapper<SmartMenu> queryWrapper2 = new QueryWrapper<>();
  573. queryWrapper2.eq("deleted", 0);
  574. List<String> applyId_ = Arrays.asList(applyIds);
  575. queryWrapper2.in("id", applyId_);
  576. List<SmartMenu> list2 = smartMenuService.list(queryWrapper2);
  577. return CommonResult.ok(list2);
  578. }
  579. @PassToken
  580. @Override
  581. public CommonResult updateSmartAuthorGroupName(JSONObject jsonObject) {
  582. Integer id = jsonObject.getInteger("id");
  583. String name = jsonObject.getString("name");
  584. if (id==null || name==null){
  585. return CommonResult.fail("请传入参数");
  586. }
  587. SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(id);
  588. if (smartAuthorGroup==null || smartAuthorGroup.getDeleted()==1){
  589. return CommonResult.fail("该权限组已删除");
  590. }
  591. smartAuthorGroup.setName(name);
  592. smartAuthorGroupService.updateSmartAuthorGroup(smartAuthorGroup);
  593. return CommonResult.ok("修改成功");
  594. }
  595. @PassToken
  596. @Override
  597. @DESRespondSecret(validated = false)
  598. public CommonResult queryUserAuthor(String userId,String userhead) {
  599. if (userId==null || userId.equals("")){
  600. userId = AesUtils.decrypt(userhead);
  601. }
  602. String[] userids = userId.split(",");
  603. QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
  604. queryWrapper1.eq("deleted", 0);
  605. queryWrapper1.in("user_id", Arrays.asList(userids));
  606. List<SmartAuthority> userAuthor = smartAuthorityService.getAuthorByKey(queryWrapper1);
  607. if (userAuthor.size() <= 0) {
  608. return CommonResult.ok(new ArrayList<>());
  609. }
  610. List<JSONObject> allList = new ArrayList<>();
  611. for (int i = 0; i < userAuthor.size(); i++) {
  612. SmartAuthority smartAuthority = userAuthor.get(i);
  613. JSONObject jsonObject = new JSONObject();
  614. jsonObject.put("userId", smartAuthority.getUserId());
  615. Integer groupId = smartAuthority.getGroupId();
  616. SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(groupId);
  617. QueryWrapper<SmartDepartment> queryWrapper2 = new QueryWrapper<>();
  618. queryWrapper2.eq("deleted", 0);
  619. List<String> viewDepart = Arrays.asList(smartAuthority.getDepartmentView().split(","));
  620. queryWrapper2.in("id", viewDepart);
  621. List<SmartDepartment> list1 = smartDepartmentService.list(queryWrapper2);
  622. QueryWrapper<SmartDepartment> queryWrapper3 = new QueryWrapper<>();
  623. queryWrapper3.eq("deleted", 0);
  624. List<String> manageDepart = Arrays.asList(smartAuthority.getDepartmentManage().split(","));
  625. queryWrapper3.in("id", manageDepart);
  626. List<SmartDepartment> list2 = smartDepartmentService.list(queryWrapper3);
  627. jsonObject.put("departmentViewAuthor", list1);
  628. jsonObject.put("departmentManageAuthor", list2);
  629. if (smartAuthorGroup != null && smartAuthorGroup.getDeleted() == 0) {
  630. QueryWrapper<SmartMenu> queryWrapper4 = new QueryWrapper<>();
  631. queryWrapper4.eq("deleted", 0);
  632. List<String> menuList = Arrays.asList(smartAuthorGroup.getApplyId().split(","));
  633. queryWrapper4.in("id", menuList);
  634. List<SmartMenu> list3 = smartMenuService.list(queryWrapper4);
  635. jsonObject.put("treAuthor", list3);
  636. } else {
  637. jsonObject.put("treAuthor", new ArrayList<>());
  638. }
  639. allList.add(jsonObject);
  640. }
  641. return CommonResult.ok(allList);
  642. }
  643. /**
  644. * 查看权限列表
  645. *
  646. * @return
  647. */
  648. @Override
  649. @PassToken
  650. @DESRespondSecret(validated = true)
  651. public CommonResult querySmartAuthorGroup(Integer authorGroupId) {
  652. List<SmartAuthorGroup> smartAuthorGroups = smartAuthorGroupService.getAuthorGroupList();
  653. List<AuthorListGroup> authorListGroupList = null;
  654. if (smartAuthorGroups.size() > 0) {
  655. authorListGroupList = smartAuthorGroupService.queryCommentTreeRecords(authorGroupId, smartAuthorGroups);
  656. }
  657. return CommonResult.ok(authorListGroupList);
  658. }
  659. @Override
  660. @DESRespondSecret(validated = true)
  661. public CommonResult deleteSmartAuthorGroupById(int id) {
  662. SmartAuthorGroup data = smartAuthorGroupService.getSmartById(id);
  663. if (data == null) {
  664. return CommonResult.fail("当前数据不存在,删除失败!");
  665. }
  666. int result = smartAuthorGroupService.deleteSmartAuthorGroupById(id);
  667. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  668. }
  669. }