From 47fa44a60a9dffee1e122a72b61badc36726b300 Mon Sep 17 00:00:00 2001 From: liyj <1003249715@qq.com> Date: Tue, 10 Sep 2024 16:29:02 +0800 Subject: [PATCH] 1、角色权限整改 --- dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java | 498 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 463 insertions(+), 35 deletions(-) diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java index 80c5f99..5411841 100644 --- a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java +++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java @@ -1,39 +1,44 @@ package cn.huge.module.ctuser.service; +import cn.huge.base.common.dto.SelectTermDTO; import cn.huge.base.common.exception.MethodException; import cn.huge.base.common.exception.ServiceException; import cn.huge.base.common.utils.DateUtils; import cn.huge.base.common.utils.IdUtils; import cn.huge.base.common.utils.ObjectUtils; +import cn.huge.base.common.utils.SelectTermUtils; import cn.huge.module.client.api.impl.UtilsClientImpl; import cn.huge.module.constant.BaseConsts; +import cn.huge.module.ctrole.domain.po.CtRole; +import cn.huge.module.ctrole.service.CtRoleService; import cn.huge.module.ctuser.dao.mapper.CtUserMapper; -import cn.huge.module.ctuser.domain.po.CtUnit; -import cn.huge.module.ctuser.domain.po.CtUser; +import cn.huge.module.ctuser.domain.po.*; +import cn.huge.module.ctuser.dto.CtUserSaveDTO; +import cn.huge.module.cust.constant.RoleBaseEnum; import cn.huge.module.cust.constant.UserBaseConsts; import cn.huge.module.cust.dto.CtUserDTO; import cn.huge.module.redis.constant.RedisKeyConsts; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Maps; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; -import javax.annotation.PostConstruct; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @title: 客户用户表业务逻辑处理 @@ -53,15 +58,21 @@ @Autowired private CtUserMapper mapper; + @Autowired + private CtAccountService ctAccountService; + @Autowired + private CtUnitService ctUnitService; + @Autowired + private CtUseroleService ctUseroleService; + @Autowired + private CtRoleService ctRoleService; + @Autowired + private CtUsepostService ctUsepostService; + @Autowired + private CtDeptService ctDeptService; @Autowired private UtilsClientImpl utilsClient; - - @Autowired - private CtUnitService ctUnitService; - - @Autowired - private CtUseroleService ctUseroleService; /** * 更新对象 @@ -188,24 +199,7 @@ } /** - * web端-人员信息管理-新增/新用户信息 - * @param ctUser - * @param userId - */ - public void webSaveCtUser(CtUser ctUser, String userId) { - try { - // 获取当前登录用户 - CtUser loginUser = this.getByIdFromRedis(userId); - Date nowDate = DateUtils.getNowDate(); - - } catch (Exception e) { - log.error("service方法[CtUserService.webSaveCtUser]调用异常:" + e, e); - throw new MethodException(e.getMessage()); - } - } - - /** - * 重写根据id获取用户 + * 重写根据id获取用户(id带有角色信息,如:1001&01) * @param userId 登录用户编号 * @return Object */ @@ -218,6 +212,265 @@ loginUserId = userId; } return mapper.selectById(loginUserId); + } + + /** + * web端-获取人员信息列表查询条件 + * @param userId 当前登录用户编号 + * @return + */ + public Map<String, Object> webListSelectTerm(String userId){ + try { + Map<String, Object> result = Maps.newHashMap(); + // 获取当前登录用户 + CtUserDTO loginUser = this.clientGetUserAll(userId); + // 组织条件 + List<CtUnit> ctUnits = ctUnitService.list(); + List<SelectTermDTO> unitSelectTerms = new ArrayList<>(); + for (CtUnit ctUnit : ctUnits) { + SelectTermDTO unitSelectTerm = new SelectTermDTO(); + unitSelectTerm.setValue(ctUnit.getId()); + unitSelectTerm.setLabel(ctUnit.getUnitName()); + unitSelectTerm.setParentId(ctUnit.getParentId()); + unitSelectTerms.add(unitSelectTerm); + + // 部门条件 + QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>(); + ctDeptQueryWrapper.eq("unit_id", ctUnit.getId()); + List<CtDept> ctDepts = ctDeptService.list(ctDeptQueryWrapper); + if (CollectionUtils.isNotEmpty(ctDepts)) { + List<SelectTermDTO> deptSelectTerms = new ArrayList<>(); + for (CtDept ctDept : ctDepts) { + SelectTermDTO deptSelectTerm = new SelectTermDTO(); + deptSelectTerm.setValue(ctDept.getId()); + deptSelectTerm.setLabel(ctDept.getName()); + deptSelectTerm.setParentId(ctDept.getParentId()); + deptSelectTerms.add(deptSelectTerm); + } + List<SelectTermDTO> depts = SelectTermUtils.createTreeByRoot(deptSelectTerms); + unitSelectTerm.setChainList(depts); + } + } + result.put("units", SelectTermUtils.createTreeByFirst(unitSelectTerms, loginUser.getUnitId())); + + // 角色条件 + QueryWrapper<CtRole> ctRoleQueryWrapper = new QueryWrapper<>(); + ctRoleQueryWrapper.eq("unit_id", loginUser.getUnitId()); + //判断是否为村居(村居不应该有调委会管理员角色) + QueryWrapper<CtUnit> ctUnitQueryWrapper1 = new QueryWrapper<>(); + ctUnitQueryWrapper1.eq("id", loginUser.getUnitId()).eq("cust_id", loginUser.getCustId()) + .select("unit_type"); + CtUnit ctUnit = ctUnitService.getOne(ctUnitQueryWrapper1); + if (ctUnit.getUnitType() == UserBaseConsts.UNIT_TYPE_4) { + ctRoleQueryWrapper.ne("role_code", RoleBaseEnum.ROLE_1.getIndex()); + } + List<CtRole> ctRoleList = ctRoleService.list(ctRoleQueryWrapper); + List<SelectTermDTO> roleSelectTerms = new ArrayList<>(); + for (CtRole ctRole : ctRoleList) { + SelectTermDTO selectTerm = new SelectTermDTO(); + selectTerm.setValue(ctRole.getRoleCode()); + selectTerm.setLabel(ctRole.getName()); + roleSelectTerms.add(selectTerm); + } + result.put("roles", roleSelectTerms); + return result; + }catch (Exception e){ + log.error("[CtUserService.webListSelectTerm]调用失败,异常信息:"+e, e); + throw new ServiceException("CtUserService.webListSelectTerm", e); + } + } + + /** + * web端-人员信息管理-人员列表 + * @param page 分页对象 + * @param terms 条件 + * @return Page + */ + public Map<String, Object> webPageQuery(int page, int size, Map<String, Object> terms, String userId){ + try { + // 获取当前登录用户 + CtUserDTO loginUser = this.clientGetUserAll(userId); + Map<String, Object> result = Maps.newHashMap(); + // todo 角色数据权限 + + Sort sort = Sort.by(Sort.Direction.DESC, "t1.create_time"); + PageRequest pageRequest = PageRequest.of(page - 1, size, sort); + Page<CtUser> ctUserPage = this.pageUserAndRole(pageRequest, terms); + QueryWrapper<CtAccount> accountQueryWrapper = new QueryWrapper<>(); + QueryWrapper<CtUserole> ctUseroleQueryWrapper = new QueryWrapper<>(); + QueryWrapper<CtUsepost> ctUsepostQueryWrapper = new QueryWrapper<>(); + for (CtUser ctUser : ctUserPage) { + accountQueryWrapper.clear(); + // 密码 + accountQueryWrapper.eq("acc_type", UserBaseConsts.ACC_TYPE_1); + accountQueryWrapper.eq("user_id", ctUser.getId()); + CtAccount ctAccount = ctAccountService.getOne(accountQueryWrapper); + if (ObjectUtils.isNotEmpty(ctAccount)) { + ctUser.setAcc(ctAccount.getAcc()); + ctUser.setCipher(ctAccount.getCipherOpen()); + } + // 角色 + ctUseroleQueryWrapper.clear(); + ctUseroleQueryWrapper.eq("user_id", ctUser.getId()); + List<CtUserole> ctUseroleList = ctUseroleService.list(ctUseroleQueryWrapper); + if (ObjectUtils.isNotEmpty(ctUseroleList)) { + for (CtUserole ctUserole : ctUseroleList) { + ctUserole.setRoleId(ctUserole.getRoleCode()); + } + ctUser.setCtUseroleList(ctUseroleList); + } + // 岗位 + ctUsepostQueryWrapper.clear(); + ctUsepostQueryWrapper.eq("user_id", ctUser.getId()); + List<CtUsepost> ctUsepostList = ctUsepostService.list(ctUsepostQueryWrapper); + if (ObjectUtils.isNotEmpty(ctUsepostList)) { + ctUser.setCtUsepostList(ctUsepostList); + } + } + result.put("ctUserPage", ctUserPage); + terms = Maps.newHashMap(); + // 生效名额 + terms.put("status", UserBaseConsts.USER_STATUS_1); + // todo 角色数据权限 + + long countZzStatus = this.countTerms(terms); + result.put("countZzStatus", countZzStatus); + return result; + }catch (Exception e){ + log.error("[CtUserService.webPageQuery]调用失败,异常信息:"+e, e); + throw new ServiceException("CtUserService.webPageQuery", e); + } + } + + /** + * web端-人员信息管理-新增/新用户信息 + * @param ctUserSaveDTO 提交用户信息 + * @param userId 当前登录用户编号 + */ + public void webSaveCtUser(CtUserSaveDTO ctUserSaveDTO, String userId) { + try { + // 获取当前登录用户 + CtUser loginUser = this.getById(userId); + Date nowDate = DateUtils.getNowDate(); + // 判断是否新增 + CtUser ctUser = new CtUser(); + BeanUtils.copyProperties(ctUserSaveDTO, ctUser); + ctUser.setUpdateTime(nowDate); + if (IdUtils.checkNewId(ctUser.getId())) { + ctUser.setId(utilsClient.getNewTimeId()); + ctUser.setCreateTime(nowDate); + ctUser.setDeleteStatus(BaseConsts.DELETE_STATUS_0); + ctUser.setJoinWay(UserBaseConsts.JOIN_WAY_1); + ctUser.setRealStatus(UserBaseConsts.REAL_STATUS_0); + ctUser.setStatus(UserBaseConsts.USER_STATUS_1); + ctUser.setCustId(loginUser.getCustId()); + mapper.insert(ctUser); + + // 创建账号 + CtAccount ctAccount = ctAccountService.getByAccAndType(ctUser.getAcc(), UserBaseConsts.ACC_TYPE_1); + if (ObjectUtils.isNotEmpty(ctAccount)) { + throw new ServiceException("账号已存在,请重新输入!"); + } else { + ctAccount = new CtAccount(); + ctAccount.setCustId(ctUser.getCustId()); + ctAccount.setId(utilsClient.getNewTimeId()); + ctAccount.setUserId(ctUser.getId()); + ctAccount.setAccType(UserBaseConsts.ACC_TYPE_1); + ctAccount.setAcc(ctUser.getAcc()); + ctAccount.setCipher(DigestUtils.md5DigestAsHex(ctUserSaveDTO.getCipher().getBytes())); + ctAccount.setCipherOpen(ctUserSaveDTO.getCipher()); + ctAccount.setDeleteStatus(BaseConsts.DELETE_STATUS_0); + ctAccount.setCreateTime(nowDate); + ctAccount.setCipherTime(nowDate); + ctAccount.setUpdateTime(nowDate); + ctAccountService.save(ctAccount); + } + + // 保存角色 + List<CtUserole> ctUseroleList = ctUserSaveDTO.getCtUseroleList(); + for (CtUserole ctUserole : ctUseroleList) { + ctUserole.setId(utilsClient.getNewTimeId()); + ctUserole.setUserId(ctUser.getId()); + CtRole ctRole = ctRoleService.getByUnitIdAndRoleId(ctUser.getUnitId(), ctUserole.getRoleId()); + ctUserole.setRoleId(ctRole.getId()); + ctUserole.setRoleCode(ctRole.getRoleCode()); + ctUserole.setCustId(ctUser.getCustId()); + ctUserole.setCreateTime(nowDate); + ctUserole.setUpdateTime(nowDate); + ctUseroleService.save(ctUserole); + } + + // 岗位 + List<CtUsepost> ctUsepostList = ctUserSaveDTO.getCtUsepostList(); + if (ObjectUtils.isNotEmpty(ctUsepostList)) { + for (CtUsepost ctUsepost : ctUsepostList) { + ctUsepost.setId(utilsClient.getNewTimeId()); + ctUsepost.setUserId(ctUser.getId()); + ctUsepost.setUnitId(ctUser.getUnitId()); + ctUsepost.setDeptId(ctUser.getDeptId()); + ctUsepost.setMatchType(UserBaseConsts.MATCH_TYPE_1); + ctUsepost.setCustId(ctUser.getCustId()); + ctUsepost.setCreateTime(nowDate); + ctUsepost.setUpdateTime(nowDate); + ctUsepostService.save(ctUsepost); + } + } + } else { + // 修改用户信息 + mapper.updateById(ctUser); + + // 修改账号信息 + CtAccount ctAccount = ctAccountService.getByUserIdAndType(ctUser.getId(), UserBaseConsts.ACC_TYPE_1); + if (!ctAccount.getAcc().equals(ctUser.getAcc())) { + CtAccount oldAccount = ctAccountService.getByAccAndType(ctUser.getAcc(), UserBaseConsts.ACC_TYPE_1); + if (ObjectUtils.isNotEmpty(oldAccount)) { + throw new MethodException("修改后的账号已存在,请重新输入!"); + } else { + ctAccount.setAcc(ctUser.getAcc()); + } + } + ctAccount.setCipher(DigestUtils.md5DigestAsHex(ctUserSaveDTO.getCipher().getBytes())); + ctAccount.setCipherOpen(ctUserSaveDTO.getCipher()); + ctAccount.setCipherTime(nowDate); + ctAccount.setUpdateTime(nowDate); + ctAccountService.updateById(ctAccount); + + // 修改角色信息 + ctUseroleService.deleteByUserId(ctUser.getId()); + List<CtUserole> ctUseroleList = ctUserSaveDTO.getCtUseroleList(); + for (CtUserole ctUserole : ctUseroleList) { + ctUserole.setId(utilsClient.getNewTimeId()); + ctUserole.setUserId(ctUser.getId()); + ctUserole.setCustId(ctUser.getCustId()); + CtRole ctRole = ctRoleService.getByUnitIdAndRoleId(ctUser.getUnitId(), ctUserole.getRoleId()); + ctUserole.setRoleId(ctRole.getId()); + ctUserole.setRoleCode(ctRole.getRoleCode()); + ctUserole.setCreateTime(nowDate); + ctUserole.setUpdateTime(nowDate); + ctUseroleService.save(ctUserole); + } + + // 修改岗位信息 + ctUsepostService.deleteByUserId(ctUser.getId()); + List<CtUsepost> ctUsepostList = ctUserSaveDTO.getCtUsepostList(); + if (ObjectUtils.isNotEmpty(ctUsepostList)) { + for (CtUsepost ctUsepost : ctUsepostList) { + ctUsepost.setId(utilsClient.getNewTimeId()); + ctUsepost.setUserId(ctUser.getId()); + ctUsepost.setUnitId(ctUser.getUnitId()); + ctUsepost.setDeptId(ctUser.getDeptId()); + ctUsepost.setMatchType(UserBaseConsts.MATCH_TYPE_1); + ctUsepost.setCustId(ctUser.getCustId()); + ctUsepost.setCreateTime(nowDate); + ctUsepost.setUpdateTime(nowDate); + ctUsepostService.save(ctUsepost); + } + } + } + } catch (Exception e) { + log.error("service方法[CtUserService.webSaveCtUser]调用异常:" + e, e); + throw new MethodException(e.getMessage()); + } } /** @@ -251,12 +504,8 @@ // 用户信息 CtUser ctUser = mapper.selectById(loginUserId); if (ObjectUtils.isNotEmpty(ctUser)){ - CtUnit ctUnit = ctUnitService.getById(ctUser.getUnitId()); CtUserDTO ctUserDTO = new CtUserDTO(); BeanUtils.copyProperties(ctUser, ctUserDTO); - if(ObjectUtils.isNotEmpty(ctUnit)){ - ctUserDTO.setUnitType(ctUnit.getUnitType()); - } // 角色代码 if (StringUtils.isEmpty(loginRoleCode)) { List<String> roleCodeList = ctUseroleService.listRoleCode(loginUserId); @@ -270,4 +519,183 @@ return null; } } + + /** + * 批量删除 + * @param data 批量id对象 + */ + public void removeListId(List<String> data) { + for (String id : data) { + // 查询人员信息 + CtUser ctUser = this.getById(id); + // 删除人员 + this.removeById(id); + // 删除账号 + UpdateWrapper<CtAccount> ctAccountUpdateWrapper = new UpdateWrapper(); + ctAccountUpdateWrapper.eq("user_id", ctUser.getId()); + ctAccountService.remove(ctAccountUpdateWrapper); + // 删除人员岗位 + UpdateWrapper<CtUsepost> ctUsepostUpdateWrapper = new UpdateWrapper(); + ctUsepostUpdateWrapper.eq("user_id", ctUser.getId()); + ctUsepostService.remove(ctUsepostUpdateWrapper); + // 删除人员角色 + UpdateWrapper<CtUserole> ctUseroleUpdateWrapper = new UpdateWrapper(); + ctUseroleUpdateWrapper.eq("user_id", ctUser.getId()); + ctUseroleService.remove(ctUseroleUpdateWrapper); + //更新部门和组织的调解专长和范围 + this.updateField("unit", ctUser.getUnitId()); + this.updateField("dept", ctUser.getDeptId()); + } + } + + private void updateField(String tag, String targetId){ + QueryWrapper query = new QueryWrapper(); + if("unit".equals(tag)){ + query.eq("unit_id", targetId); + }else if("dept".equals(tag)){ + query.eq("dept_id", targetId); + } + List<CtUser> ctUser1 = mapper.selectList(query); + Set<String> setGoodField = new HashSet<>(); + Set<String> setGoodFieldName = new HashSet<>(); + Set<String> setCanField = new HashSet<>(); + Set<String> setCanFieldName = new HashSet<>(); + String goodField = new String(); + String goodFieldName = new String(); + String canField = new String(); + String canFieldName = new String(); + if(CollectionUtils.isNotEmpty(ctUser1)){ + for(CtUser ctUsers1: ctUser1){ + if (StringUtils.isNotEmpty(ctUsers1.getGoodField())) { + setGoodField.addAll(Stream.of(ctUsers1.getGoodField().split(",")).collect(Collectors.toSet())); + setGoodFieldName.addAll(Stream.of(ctUsers1.getGoodFieldName().split(",")).collect(Collectors.toSet())); + } + if (StringUtils.isNotEmpty(ctUsers1.getCanField())) { + setCanField.addAll(Stream.of(ctUsers1.getCanField().split(",")).collect(Collectors.toSet())); + setCanFieldName.addAll(Stream.of(ctUsers1.getCanFieldName().split(",")).collect(Collectors.toSet())); + } + } + goodField = String.join(",", setGoodField); + goodFieldName = String.join(",", setGoodFieldName); + canField = String.join(",", setCanField); + canFieldName = String.join(",", setCanFieldName); + } + if("unit".equals(tag)){ + CtUnit ctUnit = new CtUnit(); + ctUnit.setId(targetId); + ctUnit.setGoodField(goodField); + ctUnit.setGoodFieldName(goodFieldName); + ctUnit.setCanField(canField); + ctUnit.setCanFieldName(canFieldName); + ctUnit.setUpdateTime(DateUtils.getNowDate()); + ctUnitService.updateTerms(ctUnit); + }else if("dept".equals(tag)){ + CtDept ctDept = new CtDept(); + ctDept.setId(targetId); + ctDept.setGoodField(goodField); + ctDept.setGoodFieldName(goodFieldName); + ctDept.setCanField(canField); + ctDept.setCanFieldName(canFieldName); + ctDept.setUpdateTime(DateUtils.getNowDate()); + ctDeptService.updateCtDept(ctDept); + } + } + + /** + * 根据部门和角色查询 + * @param deptIdList 部门编号 + * @param roleCode 角色代码 + * @return List<SelectTermDTO> + */ + public List<CtUser> listUserByDeptRoleList(List<String> deptIdList, String roleCode){ + return mapper.listUserByDeptRoleList(deptIdList, roleCode); + } + + /** + * 按条件分页查询 + * + * @param userId 分页对象 + * @param roleCode 条件 + * @return Page + */ + public List<SelectTermDTO> userChoose(String userId, String roleCode) { + // 获取当前登录用户 + CtUserDTO loginUser = clientGetUserAll(userId); + // 组织条件 + QueryWrapper<CtUnit> ctUnitQueryWrapper = new QueryWrapper<>(); + if (RoleBaseEnum.checkAdminPower(loginUser)){ + ctUnitQueryWrapper.eq("cust_id", loginUser.getCustId()).select("id", "unit_name", "parent_id"); + }else { + ctUnitQueryWrapper.eq("id", loginUser.getUnitId()).select("id", "unit_name", "parent_id"); + } + List<CtUnit> ctUnitList = ctUnitService.list(ctUnitQueryWrapper); + List<SelectTermDTO> unitSelectTerms = new ArrayList<>(); + + List<String> unitIdList= ctUnitList.stream().map(CtUnit::getId).collect(Collectors.toList()); + // 部门条件 + QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>(); + ctDeptQueryWrapper.in("unit_id", unitIdList).select("id", "unit_id", "name", "parent_id"); + List<CtDept> ctDeptList = ctDeptService.list(ctDeptQueryWrapper); + List<String> deptIdList = ctDeptList.stream().map(CtDept::getId).collect(Collectors.toList()); + + // 人员条件 + List<CtUser> ctUsers = null; + if (StringUtils.isNotEmpty(roleCode)){ + ctUsers = listUserByDeptRoleList(deptIdList, roleCode); + }else { + QueryWrapper<CtUser> ctUserQueryWrapper = new QueryWrapper<>(); + ctUserQueryWrapper.in("dept_id", deptIdList).select("id", "true_name", "dept_id"); + ctUsers = this.list(ctUserQueryWrapper); + } + List<String> userIdList = ctUsers.stream().map(CtUser::getId).collect(Collectors.toList()); + QueryWrapper<CtUserole> ctUserQueryWrapper = new QueryWrapper<>(); + ctUserQueryWrapper.in("user_id", userIdList).select("user_id", "role_name"); + List<CtUserole> roleList = ctUseroleService.list(ctUserQueryWrapper); + + for(CtUnit ctUnit: ctUnitList){ + SelectTermDTO unitSelectTerm = new SelectTermDTO(); + unitSelectTerm.setValue(ctUnit.getId()); + unitSelectTerm.setLabel(ctUnit.getUnitName()); + unitSelectTerm.setParentId(ctUnit.getParentId()); + unitSelectTerm.setCheckable(false); + List<SelectTermDTO> deptSelectTerms = new ArrayList<>(); + for(CtDept ctDept : ctDeptList){ + if(ctUnit.getId().equals(ctDept.getUnitId())){ + SelectTermDTO deptSelectTerm = new SelectTermDTO(); + deptSelectTerm.setValue(ctDept.getId()); + deptSelectTerm.setLabel(ctDept.getName()); + deptSelectTerm.setParentId(ctDept.getParentId()); + deptSelectTerm.setCheckable(false); + + if (CollectionUtils.isNotEmpty(ctUsers)) { + List<SelectTermDTO> userSelectTerms = new ArrayList<>(); + + for(CtUser ctUser : ctUsers){ + if(ctUser.getDeptId().equals(ctDept.getId())){ + List<CtUserole> ctUseroleList = new ArrayList<>(); + for(CtUserole ctUserole: roleList){ + if(ctUser.getId().equals(ctUserole.getUserId())){ + ctUseroleList.add(ctUserole); + } + } + SelectTermDTO userSelectTerm = new SelectTermDTO(); + userSelectTerm.setValue(ctUser.getId()); + userSelectTerm.setCheckable(true); + String roleName = ctUseroleList.stream().map(CtUserole::getRoleName).collect(Collectors.joining(",")); + userSelectTerm.setLabel(ctUser.getTrueName()+"("+roleName+")"); + userSelectTerms.add(userSelectTerm); + } + } + List<SelectTermDTO> users = SelectTermUtils.createTreeByRoot(userSelectTerms); + deptSelectTerm.setChildren(users); + } + deptSelectTerms.add(deptSelectTerm); + } + List<SelectTermDTO> depts = SelectTermUtils.createTreeByRoot(deptSelectTerms); + unitSelectTerm.setChildren(depts); + } + unitSelectTerms.add(unitSelectTerm); + } + return SelectTermUtils.createTreeByFirst(unitSelectTerms, loginUser.getUnitId()); + } } -- Gitblit v1.8.0