SmartAuthorGroupController.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. System.out.println(")))" + 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[] newUserId = userId.split(",");
  451. List<String> userList = Arrays.asList(newUserId);
  452. Set<String> set = new HashSet<>(userList);
  453. if (userList.size() != set.size()) {
  454. return CommonResult.fail("请勿选择重复用户");
  455. }
  456. QueryWrapper<SmartAuthority> queryWrapperA = new QueryWrapper<>();
  457. List<String> typeList = Arrays.asList(newUserId);
  458. queryWrapperA.in("user_id", typeList);
  459. queryWrapperA.eq("deleted", 0);
  460. queryWrapperA.ne("group_id", sa.getId());
  461. List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapperA);
  462. if (querySmart.size() > 0) {
  463. return CommonResult.fail("该用户已分配其他权限组");
  464. }
  465. QueryWrapper<SmartAuthority> queryWrapperA2 = new QueryWrapper<>();
  466. queryWrapperA2.eq("deleted", 0);
  467. queryWrapperA2.eq("group_id", sa.getId());
  468. List<SmartAuthority> oldUser = smartAuthorityService.getAuthorByKey(queryWrapperA2);
  469. List<Integer> oldUserId = oldUser.stream().map(SmartAuthority::getUserId).collect(Collectors.toList());
  470. QueryWrapper<SmartUser> queryWrapperB = new QueryWrapper<>();
  471. List<String> users = Arrays.asList(newUserId);
  472. queryWrapperB.in("id", users);
  473. queryWrapperB.eq("deleted", 0);
  474. List<SmartUser> ulist = smartUserService.list(queryWrapperB);
  475. if (!userId.equals("") && (ulist.isEmpty() || ulist.size()!=newUserId.length)){
  476. return CommonResult.fail("有用户已删除");
  477. }
  478. if (!oldUserId.isEmpty()){
  479. for (int i = 0; i < oldUserId.size(); i++) {
  480. System.out.println("-----"+oldUserId.get(i));
  481. if (!userList.contains(String.valueOf(oldUserId.get(i)))) {
  482. QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
  483. queryWrapper1.eq("deleted", 0);
  484. queryWrapper1.eq("user_id", oldUserId.get(i));
  485. List<SmartAuthority> smartAuthority1 = smartAuthorityService.getAuthorByKey(queryWrapper1);
  486. if (smartAuthority1.size() > 0) {
  487. SmartAuthority smartAuthority = smartAuthority1.get(0);
  488. smartAuthority.setDeleted(1);
  489. smartAuthorityService.updateSmartAuthority(smartAuthority);
  490. }
  491. }
  492. }
  493. }
  494. for (int i = 0; i < newUserId.length; i++) {
  495. if (!newUserId[i].equals("")){
  496. QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
  497. queryWrapper2.eq("deleted", 0);
  498. queryWrapper2.eq("user_id", Integer.parseInt(newUserId[i]));
  499. List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper2);
  500. if (smartAuthoritys.size() <= 0) {
  501. SmartAuthority smartAuthority = new SmartAuthority();
  502. smartAuthority.setUserId(Integer.parseInt(newUserId[i]));
  503. smartAuthority.setGroupId(sa.getId());
  504. smartAuthority.setDepartmentView("");
  505. smartAuthority.setDepartmentManage("");
  506. smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  507. smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
  508. smartAuthority.setCreateUser("admin");
  509. smartAuthority.setUpdateUser("admin");
  510. smartAuthority.setDeleted(0);
  511. smartAuthorityService.insertSmartAuthority(smartAuthority);
  512. }
  513. }
  514. }
  515. sa.setUserId(userId);
  516. int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
  517. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  518. }
  519. /**
  520. * 操作菜单权限
  521. *
  522. * @param
  523. * @param
  524. * @return
  525. */
  526. @Override
  527. @PassToken
  528. @DESRespondSecret(validated = true)
  529. public CommonResult operateSmartAuthorGroupApply(Integer id, String applyId) {
  530. if (id==null){
  531. return CommonResult.fail("id不能为空");
  532. }
  533. if (applyId==null){
  534. applyId="";
  535. }
  536. SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
  537. if (sa==null){
  538. return CommonResult.fail("当前权限组不存在");
  539. }
  540. sa.setApplyId(applyId);
  541. int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
  542. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  543. }
  544. @PassToken
  545. @Override
  546. @DESRespondSecret(validated = false)
  547. public CommonResult getSmartAuthorGroupManager(String groupId) {
  548. List<SmartAuthorGroupManager> list = smartAuthorGroupService.getSmartAuthorGroupManager(groupId);
  549. return CommonResult.ok(list);
  550. }
  551. @PassToken
  552. @Override
  553. public CommonResult operateSmartAuthorDepartment(JSONObject jsonObject) {
  554. Integer id = jsonObject.getInteger("id");
  555. String departmentView = jsonObject.getString("departmentView");
  556. String departmentManage = jsonObject.getString("departmentManage");
  557. if (id==null){
  558. return CommonResult.fail("请传入ID");
  559. }
  560. SmartAuthority smartAuthority = smartAuthorityService.getSmartById(id);
  561. if (departmentView!=null ){
  562. smartAuthority.setDepartmentView(departmentView);
  563. }
  564. if (departmentManage!=null){
  565. smartAuthority.setDepartmentManage(departmentManage);
  566. }
  567. smartAuthorityService.updateSmartAuthority(smartAuthority);
  568. return CommonResult.ok("修改成功");
  569. }
  570. @PassToken
  571. @Override
  572. @DESRespondSecret(validated = false)
  573. public CommonResult getSmartAuthorGroupMenu(Integer id) {
  574. SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(id);
  575. if (smartAuthorGroup==null || smartAuthorGroup.getDeleted()==1){
  576. return CommonResult.fail("当前权限组已删除");
  577. }
  578. String[] applyIds = smartAuthorGroup.getApplyId().split(",");
  579. QueryWrapper<SmartMenu> queryWrapper2 = new QueryWrapper<>();
  580. queryWrapper2.eq("deleted", 0);
  581. List<String> applyId_ = Arrays.asList(applyIds);
  582. queryWrapper2.in("id", applyId_);
  583. List<SmartMenu> list2 = smartMenuService.list(queryWrapper2);
  584. return CommonResult.ok(list2);
  585. }
  586. @PassToken
  587. @Override
  588. public CommonResult updateSmartAuthorGroupName(JSONObject jsonObject) {
  589. Integer id = jsonObject.getInteger("id");
  590. String name = jsonObject.getString("name");
  591. if (id==null || name==null){
  592. return CommonResult.fail("请传入参数");
  593. }
  594. SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(id);
  595. if (smartAuthorGroup==null || smartAuthorGroup.getDeleted()==1){
  596. return CommonResult.fail("该权限组已删除");
  597. }
  598. smartAuthorGroup.setName(name);
  599. smartAuthorGroupService.updateSmartAuthorGroup(smartAuthorGroup);
  600. return CommonResult.ok("修改成功");
  601. }
  602. @PassToken
  603. @Override
  604. @DESRespondSecret(validated = false)
  605. public CommonResult queryUserAuthor(String userId,String userHead) {
  606. if (userId==null || userId.equals("")){
  607. userId = AesUtils.decrypt(userHead);
  608. }
  609. String[] userids = userId.split(",");
  610. QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
  611. queryWrapper1.eq("deleted", 0);
  612. queryWrapper1.in("user_id", Arrays.asList(userids));
  613. List<SmartAuthority> userAuthor = smartAuthorityService.getAuthorByKey(queryWrapper1);
  614. if (userAuthor.size() <= 0) {
  615. return CommonResult.ok(new ArrayList<>());
  616. }
  617. List<JSONObject> allList = new ArrayList<>();
  618. for (int i = 0; i < userAuthor.size(); i++) {
  619. SmartAuthority smartAuthority = userAuthor.get(i);
  620. JSONObject jsonObject = new JSONObject();
  621. jsonObject.put("userId", smartAuthority.getUserId());
  622. Integer groupId = smartAuthority.getGroupId();
  623. SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(groupId);
  624. QueryWrapper<SmartDepartment> queryWrapper2 = new QueryWrapper<>();
  625. queryWrapper2.eq("deleted", 0);
  626. List<String> viewDepart = Arrays.asList(smartAuthority.getDepartmentView().split(","));
  627. queryWrapper2.in("id", viewDepart);
  628. List<SmartDepartment> list1 = smartDepartmentService.list(queryWrapper2);
  629. QueryWrapper<SmartDepartment> queryWrapper3 = new QueryWrapper<>();
  630. queryWrapper3.eq("deleted", 0);
  631. List<String> manageDepart = Arrays.asList(smartAuthority.getDepartmentManage().split(","));
  632. queryWrapper3.in("id", manageDepart);
  633. List<SmartDepartment> list2 = smartDepartmentService.list(queryWrapper3);
  634. jsonObject.put("departmentViewAuthor", list1);
  635. jsonObject.put("departmentManageAuthor", list2);
  636. if (smartAuthorGroup != null && smartAuthorGroup.getDeleted() == 0) {
  637. QueryWrapper<SmartMenu> queryWrapper4 = new QueryWrapper<>();
  638. queryWrapper4.eq("deleted", 0);
  639. List<String> menuList = Arrays.asList(smartAuthorGroup.getApplyId().split(","));
  640. queryWrapper4.in("id", menuList);
  641. List<SmartMenu> list3 = smartMenuService.list(queryWrapper4);
  642. jsonObject.put("treAuthor", list3);
  643. } else {
  644. jsonObject.put("treAuthor", new ArrayList<>());
  645. }
  646. allList.add(jsonObject);
  647. }
  648. return CommonResult.ok(allList);
  649. }
  650. /**
  651. * 查看权限列表
  652. *
  653. * @return
  654. */
  655. @Override
  656. @PassToken
  657. @DESRespondSecret(validated = true)
  658. public CommonResult querySmartAuthorGroup(Integer authorGroupId) {
  659. List<SmartAuthorGroup> smartAuthorGroups = smartAuthorGroupService.getAuthorGroupList();
  660. List<AuthorListGroup> authorListGroupList = null;
  661. if (smartAuthorGroups.size() > 0) {
  662. authorListGroupList = smartAuthorGroupService.queryCommentTreeRecords(authorGroupId, smartAuthorGroups);
  663. }
  664. return CommonResult.ok(authorListGroupList);
  665. }
  666. @Override
  667. @DESRespondSecret(validated = true)
  668. public CommonResult deleteSmartAuthorGroupById(int id) {
  669. SmartAuthorGroup data = smartAuthorGroupService.getSmartById(id);
  670. if (data == null) {
  671. return CommonResult.fail("当前数据不存在,删除失败!");
  672. }
  673. int result = smartAuthorGroupService.deleteSmartAuthorGroupById(id);
  674. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  675. }
  676. }