From e282e3bb247adc903e201e85239a504548efa7c6 Mon Sep 17 00:00:00 2001 From: wangwh <2397901735@qq.com> Date: Tue, 10 Sep 2024 14:26:20 +0800 Subject: [PATCH] 1、修改查询下级所有组织接口 2、首页相关接口 --- dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUserService.java | 190 ++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 184 insertions(+), 6 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 d986d95..888c322 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 @@ -19,6 +19,7 @@ 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; @@ -35,11 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; -import java.util.ArrayList; -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: 客户用户表业务逻辑处理 @@ -360,7 +359,7 @@ if (IdUtils.checkNewId(ctUser.getId())) { ctUser.setId(utilsClient.getNewTimeId()); ctUser.setCreateTime(nowDate); - ctUser.setDeleteStatus(BaseConsts.DELETE_STATUS_1); + ctUser.setDeleteStatus(BaseConsts.DELETE_STATUS_0); ctUser.setJoinWay(UserBaseConsts.JOIN_WAY_1); ctUser.setRealStatus(UserBaseConsts.REAL_STATUS_0); ctUser.setStatus(UserBaseConsts.USER_STATUS_1); @@ -380,7 +379,7 @@ ctAccount.setAcc(ctUser.getAcc()); ctAccount.setCipher(DigestUtils.md5DigestAsHex(ctUserSaveDTO.getCipher().getBytes())); ctAccount.setCipherOpen(ctUserSaveDTO.getCipher()); - ctAccount.setDeleteStatus(BaseConsts.DELETE_STATUS_1); + ctAccount.setDeleteStatus(BaseConsts.DELETE_STATUS_0); ctAccount.setCreateTime(nowDate); ctAccount.setCipherTime(nowDate); ctAccount.setUpdateTime(nowDate); @@ -520,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