| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
- package com.template.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.template.annotation.DESRespondSecret;
- import com.template.annotation.PassToken;
- import com.template.api.SmartAuthorGroupControllerAPI;
- import com.template.common.utils.AesUtils;
- import com.template.common.utils.TimeExchange2;
- import com.template.common.utils.TreeRecordsUtil;
- import com.template.common.utils.UUIDUtil;
- import com.template.model.pojo.*;
- import com.template.model.result.CommonResult;
- import com.template.model.weixin.AuthorAndGroup;
- import com.template.model.weixin.AuthorAndGroup2;
- import com.template.model.weixin.AuthorListGroup;
- import com.template.model.weixin.userAuthor;
- import com.template.services.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.RestController;
- import java.text.ParseException;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author ceshi
- * @since 2023-12-04
- */
- @RestController
- //返回参数加密注解
- @DESRespondSecret
- public class SmartAuthorGroupController implements SmartAuthorGroupControllerAPI {
- @Autowired
- private SmartAuthorGroupService smartAuthorGroupService;
- @Autowired
- public SmartAuthorityService smartAuthorityService;
- @Autowired
- public SmartUserService smartUserService;
- @Autowired
- public SmartDepartmentService smartDepartmentService;
- @Autowired
- public SmartMenuService smartMenuService;
- /**
- * 新增权限组
- *
- * @param
- * @param
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult insertSmartAuthorGroup(JSONObject jsonObject, Integer samePower) throws ParseException {
- if (samePower == null) {
- return CommonResult.fail("samePower不能为空");
- }
- // 所有管理员权限一样
- if (samePower == 1) {
- AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
- SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
- sa.setId((int) UUIDUtil.generateID());
- String[] userId = sa.getUserId().split(",");
- // 相关判断
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("deleted", "0");
- queryWrapper.eq("parent_id", sa.getParentId());
- queryWrapper.eq("name", sa.getName());
- List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
- if (querySmartGroup.size() > 0) {
- return CommonResult.fail("该管理员已存在,请勿重复添加");
- }
- QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
- List<String> typeList = Arrays.asList(userId);
- queryWrapper2.in("user_id", typeList);
- queryWrapper2.eq("deleted", "0");
- List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
- if (querySmart.size() > 0) {
- return CommonResult.fail("该用户已分配其他权限组");
- }
- Set<String> set = new HashSet<>(typeList);
- if (typeList.size() != set.size()) {
- return CommonResult.fail("请勿选择重复用户");
- }
- for (int i = 0; i < userId.length; i++) {
- SmartAuthority smartAuthority = new SmartAuthority();
- smartAuthority.setUserId(Integer.parseInt(userId[i]));
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
- smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(0);
- smartAuthorityService.insertSmartAuthority(smartAuthority);
- }
- sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- sa.setCreateUser("admin");
- sa.setUpdateUser("admin");
- sa.setDeleted(0);
- int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
- }
- // 每个管理员权限不一样
- if (samePower == 2) {
- AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
- SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
- sa.setId((int) UUIDUtil.generateID());
- List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
- // 相关查询
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("deleted", 0);
- queryWrapper.eq("parent_id", sa.getParentId());
- queryWrapper.eq("name", sa.getName());
- List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
- if (querySmartGroup.size() > 0) {
- return CommonResult.fail("该管理员已存在,请勿重复添加");
- }
- List<Integer> uid = userAuthors.stream().map(userAuthor::getUserId).collect(Collectors.toList());
- QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.in("user_id", uid);
- queryWrapper2.eq("deleted", 0);
- List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
- if (querySmart.size() > 0) {
- return CommonResult.fail("该用户已分配其他权限组");
- }
- Set<Integer> set = new HashSet<>(uid);
- if (uid.size() != set.size()) {
- return CommonResult.fail("请勿选择重复用户");
- }
- for (int i = 0; i < userAuthors.size(); i++) {
- SmartAuthority smartAuthority = new SmartAuthority();
- smartAuthority.setUserId(userAuthors.get(i).getUserId());
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
- smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(0);
- smartAuthorityService.insertSmartAuthority(smartAuthority);
- }
- sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- sa.setCreateUser("admin");
- sa.setUpdateUser("admin");
- sa.setDeleted(0);
- int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
- }
- return CommonResult.errorMsg("参数格式错误");
- }
- /**
- * 更新权限组
- *
- * @param
- * @param
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult updateSmartAuthorGroup(JSONObject jsonObject, Integer samePower) throws ParseException {
- if (samePower == null) {
- return CommonResult.errorMsg("samePower不能为空");
- }
- // 所有管理员权限一样
- if (samePower == 1) {
- AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
- SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
- String[] userId = sa.getUserId().split(",");
- // 相关判断
- QueryWrapper<SmartAuthorGroup> queryWrapperA = new QueryWrapper<>();
- queryWrapperA.eq("deleted", 0);
- queryWrapperA.eq("id", sa.getId());
- List<SmartAuthorGroup> querySmartGroupA = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperA);
- if (querySmartGroupA.size() <= 0) {
- return CommonResult.fail("该条信息已删除");
- }
- QueryWrapper<SmartAuthorGroup> queryWrapperB = new QueryWrapper<>();
- queryWrapperB.eq("deleted", 0);
- queryWrapperB.eq("id", sa.getParentId());
- List<SmartAuthorGroup> querySmartGroupB = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperB);
- if (querySmartGroupB.size() <= 0 && sa.getParentId() != 0) {
- return CommonResult.fail("父ID不存在");
- }
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("deleted", 0);
- queryWrapper.eq("parent_id", sa.getParentId());
- queryWrapper.eq("name", sa.getName());
- queryWrapper.ne("id", sa.getId());
- List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
- if (querySmartGroup.size() > 0) {
- return CommonResult.fail("该管理员已存在,请勿重复修改");
- }
- QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
- List<String> typeList = Arrays.asList(userId);
- queryWrapper2.in("user_id", typeList);
- queryWrapper2.eq("deleted", 0);
- queryWrapper2.ne("group_id", sa.getId());
- List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
- if (querySmart.size() > 0) {
- return CommonResult.fail("该用户已分配其他权限组");
- }
- Set<String> set = new HashSet<>(typeList);
- if (typeList.size() != set.size()) {
- return CommonResult.fail("请勿选择重复用户");
- }
- String[] old_userId = querySmartGroupA.get(0).getUserId().split(",");
- for (int i = 0; i < old_userId.length; i++) {
- if (!typeList.contains(old_userId[i])) {
- QueryWrapper<SmartAuthority> queryWrapperC = new QueryWrapper<>();
- queryWrapperC.eq("deleted", 0);
- queryWrapperC.eq("user_id", Integer.parseInt(old_userId[i]));
- List<SmartAuthority> smartAuthorityC = smartAuthorityService.getAuthorByKey(queryWrapperC);
- if (smartAuthorityC.size() > 0) {
- SmartAuthority smartAuthority = smartAuthorityC.get(0);
- smartAuthority.setDeleted(1);
- logger.info(")))" + smartAuthority.getId());
- smartAuthorityService.updateSmartAuthority(smartAuthority);
- }
- }
- }
- for (int i = 0; i < userId.length; i++) {
- QueryWrapper<SmartAuthority> queryWrapper3 = new QueryWrapper<>();
- queryWrapper3.eq("deleted", 0);
- queryWrapper3.eq("user_id", Integer.parseInt(userId[i]));
- List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper3);
- if (smartAuthoritys.size() > 0) {
- SmartAuthority smartAuthority = smartAuthoritys.get(0);
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
- smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(0);
- smartAuthorityService.updateSmartAuthority(smartAuthority);
- } else {
- SmartAuthority smartAuthority = new SmartAuthority();
- smartAuthority.setUserId(Integer.parseInt(userId[i]));
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
- smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(0);
- smartAuthorityService.insertSmartAuthority(smartAuthority);
- }
- }
- int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- // 每个管理员权限不一样
- if (samePower == 2) {
- AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
- SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
- List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
- // 相关查询
- QueryWrapper<SmartAuthorGroup> queryWrapperA = new QueryWrapper<>();
- queryWrapperA.eq("deleted", 0);
- queryWrapperA.eq("id", sa.getId());
- List<SmartAuthorGroup> querySmartGroupA = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperA);
- if (querySmartGroupA.size() <= 0) {
- return CommonResult.fail("该条信息已删除");
- }
- QueryWrapper<SmartAuthorGroup> queryWrapperB = new QueryWrapper<>();
- queryWrapperB.eq("deleted", 0);
- queryWrapperB.eq("id", sa.getParentId());
- List<SmartAuthorGroup> querySmartGroupB = smartAuthorGroupService.getAuthorGroupByKey(queryWrapperB);
- if (querySmartGroupB.size() <= 0 && sa.getParentId() != 0) {
- return CommonResult.fail("父ID不存在");
- }
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("deleted", 0);
- queryWrapper.eq("parent_id", sa.getParentId());
- queryWrapper.eq("name", sa.getName());
- queryWrapper.ne("id", sa.getId());
- List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
- if (querySmartGroup.size() > 0) {
- return CommonResult.fail("该管理员已存在,请勿重复添加");
- }
- List<Integer> uid = userAuthors.stream().map(userAuthor::getUserId).collect(Collectors.toList());
- QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.in("user_id", uid);
- queryWrapper2.eq("deleted", 0);
- queryWrapper2.ne("group_id", sa.getId());
- List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapper2);
- if (querySmart.size() > 0) {
- return CommonResult.fail("该用户已分配其他权限组");
- }
- Set<Integer> set = new HashSet<>(uid);
- if (uid.size() != set.size()) {
- return CommonResult.fail("请勿选择重复用户");
- }
- String[] old_userId = querySmartGroupA.get(0).getUserId().split(",");
- for (int i = 0; i < old_userId.length; i++) {
- if (!uid.contains(Integer.parseInt(old_userId[i]))) {
- QueryWrapper<SmartAuthority> queryWrapperC = new QueryWrapper<>();
- queryWrapperC.eq("deleted", 0);
- queryWrapperC.eq("user_id", Integer.parseInt(old_userId[i]));
- List<SmartAuthority> smartAuthorityC = smartAuthorityService.getAuthorByKey(queryWrapperC);
- if (smartAuthorityC.size() > 0) {
- SmartAuthority smartAuthority = smartAuthorityC.get(0);
- smartAuthority.setDeleted(1);
- smartAuthorityService.updateSmartAuthority(smartAuthority);
- }
- }
- }
- String userid = "";
- for (int i = 0; i < userAuthors.size(); i++) {
- if (i == userAuthors.size() - 1) {
- userid += userAuthors.get(i).getUserId();
- } else {
- userid += userAuthors.get(i).getUserId() + ",";
- }
- QueryWrapper<SmartAuthority> queryWrapper3 = new QueryWrapper<>();
- queryWrapper3.eq("deleted", 0);
- queryWrapper3.eq("user_id", userAuthors.get(i).getUserId());
- List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper3);
- if (smartAuthoritys.size() > 0) {
- SmartAuthority smartAuthority = smartAuthoritys.get(0);
- smartAuthority.setUserId(userAuthors.get(i).getUserId());
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
- smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(userAuthors.get(i).getDeleted());
- smartAuthorityService.updateSmartAuthority(smartAuthority);
- } else {
- SmartAuthority smartAuthority = new SmartAuthority();
- smartAuthority.setUserId(userAuthors.get(i).getUserId());
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
- smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(0);
- smartAuthorityService.insertSmartAuthority(smartAuthority);
- }
- }
- sa.setUserId(userid);
- int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- return CommonResult.errorMsg("参数格式错误");
- }
- /**
- * 新增权限组
- *
- * @param
- * @param
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult addSmartAuthorGroup(JSONObject jsonObject) throws ParseException {
- AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
- SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
- sa.setId((int) UUIDUtil.generateID());
- // 相关判断
- QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("deleted", "0");
- queryWrapper.eq("parent_id", sa.getParentId());
- queryWrapper.eq("name", sa.getName());
- List<SmartAuthorGroup> querySmartGroup = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper);
- if (querySmartGroup.size() > 0) {
- return CommonResult.fail("该管理员已存在,请勿重复添加");
- }
- sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- sa.setCreateUser("admin");
- sa.setUpdateUser("admin");
- sa.setDeleted(0);
- int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
- }
- /**
- * 删除权限组
- *
- * @param
- * @param
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult delSmartAuthorGroup(Integer id) {
- QueryWrapper<SmartAuthorGroup> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("parent_id", id);
- queryWrapper1.eq("deleted",0);
- List<SmartAuthorGroup> list1 = smartAuthorGroupService.getAuthorGroupByKey(queryWrapper1);
- SmartAuthorGroup rns = new SmartAuthorGroup();
- rns.setId(id);
- rns.setDeleted(1);
- int result = smartAuthorGroupService.updateSmartAuthorGroup(rns);
- SmartAuthority smartAuthority = new SmartAuthority();
- smartAuthority.setDeleted(1);
- QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.eq("group_id", id);
- boolean m = smartAuthorityService.update(smartAuthority,queryWrapper2);
- SmartAuthorGroup rns2 = new SmartAuthorGroup();
- rns2.setDeleted(1);
- QueryWrapper<SmartAuthorGroup> queryWrapper3 = new QueryWrapper<>();
- queryWrapper3.eq("parent_id", id);
- boolean result2 = smartAuthorGroupService.update(rns2, queryWrapper3);
- SmartAuthority smartAuthority2 = new SmartAuthority();
- smartAuthority2.setDeleted(1);
- QueryWrapper<SmartAuthority> queryWrapper4 = new QueryWrapper<>();
- List<Integer> gid = list1.stream().map(SmartAuthorGroup::getId).collect(Collectors.toList());
- queryWrapper4.in("group_id", gid);
- queryWrapper4.eq("deleted",0);
- boolean m2 = smartAuthorityService.update(smartAuthority2,queryWrapper4);
- return result > 0 && result2 && m && m2 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
- }
- /**
- * 操作管理员
- *
- * @param
- * @param
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult operateSmartAuthorGroupUser(Integer id, String userId) throws ParseException {
- if (id==null){
- return CommonResult.fail("id不能为空");
- }
- if (userId==null){
- userId="";
- }
- SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
- if (sa==null){
- return CommonResult.fail("当前权限组不存在");
- }
- if (sa.getUserId()==null){
- sa.setUserId("");
- }
- String[] oldUserId = sa.getUserId().split(",");
- String[] newUserId = userId.split(",");
- List<String> userList = Arrays.asList(newUserId);
- Set<String> set = new HashSet<>(userList);
- if (userList.size() != set.size()) {
- return CommonResult.fail("请勿选择重复用户");
- }
- QueryWrapper<SmartAuthority> queryWrapperA = new QueryWrapper<>();
- List<String> typeList = Arrays.asList(newUserId);
- queryWrapperA.in("user_id", typeList);
- queryWrapperA.eq("deleted", 0);
- queryWrapperA.ne("group_id", sa.getId());
- List<SmartAuthority> querySmart = smartAuthorityService.getAuthorByKey(queryWrapperA);
- if (querySmart.size() > 0) {
- return CommonResult.fail("该用户已分配其他权限组");
- }
- QueryWrapper<SmartUser> queryWrapperB = new QueryWrapper<>();
- List<String> users = Arrays.asList(newUserId);
- queryWrapperB.in("id", users);
- queryWrapperB.eq("deleted", 0);
- List<SmartUser> ulist = smartUserService.list(queryWrapperB);
- if (!userId.equals("") && (ulist.isEmpty() || ulist.size()!=newUserId.length)){
- return CommonResult.fail("有用户已删除");
- }
- for (int i = 0; i < oldUserId.length; i++) {
- if (!oldUserId[i].equals("") && !userList.contains(oldUserId[i])) {
- QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("deleted", 0);
- queryWrapper1.eq("user_id", Integer.parseInt(oldUserId[i]));
- List<SmartAuthority> smartAuthority1 = smartAuthorityService.getAuthorByKey(queryWrapper1);
- if (smartAuthority1.size() > 0) {
- SmartAuthority smartAuthority = smartAuthority1.get(0);
- smartAuthority.setDeleted(1);
- smartAuthorityService.updateSmartAuthority(smartAuthority);
- }
- }
- }
- for (int i = 0; i < newUserId.length; i++) {
- if (!newUserId[i].equals("")){
- QueryWrapper<SmartAuthority> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.eq("deleted", 0);
- queryWrapper2.eq("user_id", Integer.parseInt(newUserId[i]));
- List<SmartAuthority> smartAuthoritys = smartAuthorityService.getAuthorByKey(queryWrapper2);
- if (smartAuthoritys.size() <= 0) {
- SmartAuthority smartAuthority = new SmartAuthority();
- smartAuthority.setUserId(Integer.parseInt(newUserId[i]));
- smartAuthority.setGroupId(sa.getId());
- smartAuthority.setDepartmentView("");
- smartAuthority.setDepartmentManage("");
- smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(), "yyyy-MM-dd HH:mm:ss"));
- smartAuthority.setCreateUser("admin");
- smartAuthority.setUpdateUser("admin");
- smartAuthority.setDeleted(0);
- smartAuthorityService.insertSmartAuthority(smartAuthority);
- }
- }
- }
- sa.setUserId(userId);
- int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- /**
- * 操作菜单权限
- *
- * @param
- * @param
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult operateSmartAuthorGroupApply(Integer id, String applyId) {
- if (id==null){
- return CommonResult.fail("id不能为空");
- }
- if (applyId==null){
- applyId="";
- }
- SmartAuthorGroup sa = smartAuthorGroupService.getSmartById(id);
- if (sa==null){
- return CommonResult.fail("当前权限组不存在");
- }
- sa.setApplyId(applyId);
- int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
- return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
- }
- @PassToken
- @Override
- @DESRespondSecret(validated = false)
- public CommonResult getSmartAuthorGroupManager(String groupId) {
- List<SmartAuthorGroupManager> list = smartAuthorGroupService.getSmartAuthorGroupManager(groupId);
- return CommonResult.ok(list);
- }
- @PassToken
- @Override
- public CommonResult operateSmartAuthorDepartment(JSONObject jsonObject) {
- Integer id = jsonObject.getInteger("id");
- String departmentView = jsonObject.getString("departmentView");
- String departmentManage = jsonObject.getString("departmentManage");
- if (id==null){
- return CommonResult.fail("请传入ID");
- }
- SmartAuthority smartAuthority = smartAuthorityService.getSmartById(id);
- if (departmentView!=null ){
- smartAuthority.setDepartmentView(departmentView);
- }
- if (departmentManage!=null){
- smartAuthority.setDepartmentManage(departmentManage);
- }
- smartAuthorityService.updateSmartAuthority(smartAuthority);
- return CommonResult.ok("修改成功");
- }
- @PassToken
- @Override
- @DESRespondSecret(validated = false)
- public CommonResult getSmartAuthorGroupMenu(Integer id) {
- SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(id);
- if (smartAuthorGroup==null || smartAuthorGroup.getDeleted()==1){
- return CommonResult.fail("当前权限组已删除");
- }
- String[] applyIds = smartAuthorGroup.getApplyId().split(",");
- QueryWrapper<SmartMenu> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.eq("deleted", 0);
- List<String> applyId_ = Arrays.asList(applyIds);
- queryWrapper2.in("id", applyId_);
- List<SmartMenu> list2 = smartMenuService.list(queryWrapper2);
- return CommonResult.ok(list2);
- }
- @PassToken
- @Override
- public CommonResult updateSmartAuthorGroupName(JSONObject jsonObject) {
- Integer id = jsonObject.getInteger("id");
- String name = jsonObject.getString("name");
- if (id==null || name==null){
- return CommonResult.fail("请传入参数");
- }
- SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(id);
- if (smartAuthorGroup==null || smartAuthorGroup.getDeleted()==1){
- return CommonResult.fail("该权限组已删除");
- }
- smartAuthorGroup.setName(name);
- smartAuthorGroupService.updateSmartAuthorGroup(smartAuthorGroup);
- return CommonResult.ok("修改成功");
- }
- @PassToken
- @Override
- @DESRespondSecret(validated = false)
- public CommonResult queryUserAuthor(String userId,String userhead) {
- if (userId==null || userId.equals("")){
- userId = AesUtils.decrypt(userhead);
- }
- String[] userids = userId.split(",");
- QueryWrapper<SmartAuthority> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.eq("deleted", 0);
- queryWrapper1.in("user_id", Arrays.asList(userids));
- List<SmartAuthority> userAuthor = smartAuthorityService.getAuthorByKey(queryWrapper1);
- if (userAuthor.size() <= 0) {
- return CommonResult.ok(new ArrayList<>());
- }
- List<JSONObject> allList = new ArrayList<>();
- for (int i = 0; i < userAuthor.size(); i++) {
- SmartAuthority smartAuthority = userAuthor.get(i);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("userId", smartAuthority.getUserId());
- Integer groupId = smartAuthority.getGroupId();
- SmartAuthorGroup smartAuthorGroup = smartAuthorGroupService.getSmartById(groupId);
- QueryWrapper<SmartDepartment> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.eq("deleted", 0);
- List<String> viewDepart = Arrays.asList(smartAuthority.getDepartmentView().split(","));
- queryWrapper2.in("id", viewDepart);
- List<SmartDepartment> list1 = smartDepartmentService.list(queryWrapper2);
- QueryWrapper<SmartDepartment> queryWrapper3 = new QueryWrapper<>();
- queryWrapper3.eq("deleted", 0);
- List<String> manageDepart = Arrays.asList(smartAuthority.getDepartmentManage().split(","));
- queryWrapper3.in("id", manageDepart);
- List<SmartDepartment> list2 = smartDepartmentService.list(queryWrapper3);
- jsonObject.put("departmentViewAuthor", list1);
- jsonObject.put("departmentManageAuthor", list2);
- if (smartAuthorGroup != null && smartAuthorGroup.getDeleted() == 0) {
- QueryWrapper<SmartMenu> queryWrapper4 = new QueryWrapper<>();
- queryWrapper4.eq("deleted", 0);
- List<String> menuList = Arrays.asList(smartAuthorGroup.getApplyId().split(","));
- queryWrapper4.in("id", menuList);
- List<SmartMenu> list3 = smartMenuService.list(queryWrapper4);
- jsonObject.put("treAuthor", list3);
- } else {
- jsonObject.put("treAuthor", new ArrayList<>());
- }
- allList.add(jsonObject);
- }
- return CommonResult.ok(allList);
- }
- /**
- * 查看权限列表
- *
- * @return
- */
- @Override
- @PassToken
- @DESRespondSecret(validated = true)
- public CommonResult querySmartAuthorGroup(Integer authorGroupId) {
- List<SmartAuthorGroup> smartAuthorGroups = smartAuthorGroupService.getAuthorGroupList();
- List<AuthorListGroup> authorListGroupList = null;
- if (smartAuthorGroups.size() > 0) {
- authorListGroupList = smartAuthorGroupService.queryCommentTreeRecords(authorGroupId, smartAuthorGroups);
- }
- return CommonResult.ok(authorListGroupList);
- }
- @Override
- @DESRespondSecret(validated = true)
- public CommonResult deleteSmartAuthorGroupById(int id) {
- SmartAuthorGroup data = smartAuthorGroupService.getSmartById(id);
- if (data == null) {
- return CommonResult.fail("当前数据不存在,删除失败!");
- }
- int result = smartAuthorGroupService.deleteSmartAuthorGroupById(id);
- return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
- }
- }
|