From 4dc8a15cb1f1c7b8a70fce95f3f715b472302a9c Mon Sep 17 00:00:00 2001 From: wangwh <2397901735@qq.com> Date: Fri, 06 Sep 2024 18:20:26 +0800 Subject: [PATCH] 1、联合处置相关接口 2、查询办理结果接口 3、查询档案信息接口 4、修改督办相关接口等 --- dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 228 insertions(+), 6 deletions(-) diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java index 16e00d5..c681d15 100644 --- a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java +++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java @@ -1,25 +1,35 @@ package cn.huge.module.ctuser.service; +import cn.huge.base.common.dto.SelectTermDTO; 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.ctuser.dao.mapper.CtUnitMapper; +import cn.huge.module.ctuser.domain.po.CtDept; import cn.huge.module.ctuser.domain.po.CtUnit; +import cn.huge.module.ctuser.domain.po.CtUser; +import cn.huge.module.ctuser.domain.po.CtUserole; +import cn.huge.module.ctuser.dto.CtUnitWeChatCountDTO; +import cn.huge.module.cust.constant.RoleBaseEnum; +import cn.huge.module.cust.dto.CtUserDTO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; 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 javax.annotation.PostConstruct; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * @title: 客户组织信息表业务逻辑处理 @@ -39,6 +49,12 @@ @Autowired private UtilsClientImpl utilsClient; + + @Autowired + private CtDeptService ctDeptService; + + @Autowired + private CtUserService ctUserService; /** * 更新对象 @@ -116,11 +132,14 @@ */ public void saveCtUnit(CtUnit ctUnit){ try{ - Date nowDate = DateUtils.getMowDate(); + Date nowDate = DateUtils.getNowDate(); // 判断是否新增 if (IdUtils.checkNewId(ctUnit.getId())){ ctUnit.setId(utilsClient.getNewTimeId()); ctUnit.setCreateTime(nowDate); + }else { + // 1、更新单位信息时,更新调度规则指标目标组织名称 + mapper.updateDispNormCauseTargetUnitName(ctUnit.getUnitName(), ctUnit.getId()); } ctUnit.setUpdateTime(nowDate); this.saveOrUpdate(ctUnit); @@ -130,4 +149,207 @@ } } + /** + * 获取所有组织(包含所有下级子组织) + * + * @param custId 客户编号 + * @param firstId 某一级组织编号 + * @return List + */ + public List<CtUnit> listUnitTree(String custId, String firstId) { + QueryWrapper<CtUnit> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("cust_id", custId).orderByDesc("create_time"); + List<CtUnit> ctUnits = mapper.selectList(queryWrapper); + + // 获取所有的 CtDept 的数量 + QueryWrapper<CtDept> deptQueryWrapper = new QueryWrapper<>(); + deptQueryWrapper.in("unit_id", ctUnits.stream().map(CtUnit::getId).collect(Collectors.toList())); + List<CtDept> ctDepts = ctDeptService.list(deptQueryWrapper); + + // 将 CtDept 的数量存储在 Map 中 + Map<String, Long> ctDeptCountMap = ctDepts.stream() + .collect(Collectors.groupingBy(CtDept::getUnitId, Collectors.counting())); + + // 为每个 CtUnit 设置 CtDept 的数量 + for (CtUnit ctUnit : ctUnits) { + Long ctDeptsCount = ctDeptCountMap.getOrDefault(ctUnit.getId(), 0L); + ctUnit.setCountCtDept(ctDeptsCount.intValue()); + } + return this.createTree(ctUnits, firstId); + } + + /** + * 创建某一级组织下树形结构 + * + * @param ctUnitList 所有组织集合 + * @param firstId 某一级组织编号 + * @return List + */ + public List<CtUnit> createTree(List<CtUnit> ctUnitList, String firstId) { + List<CtUnit> firstMapList = new ArrayList<>(); + for (CtUnit ctUnit : ctUnitList) { + for (CtUnit currentParam : ctUnitList) { + if (currentParam.getId().equals(ctUnit.getParentId())) { + addToMBean(currentParam, ctUnit); + break; + } + } + } + //取第一级节点 + for (CtUnit unit : ctUnitList) { + if (StringUtils.isNotEmpty(firstId)) { + if (firstId.equals(unit.getId())) { + firstMapList.add(unit); + } + } else { + if (BaseConsts.ROOT.equals(unit.getParentId()) || StringUtils.isEmpty(unit.getParentId())) { + firstMapList.add(unit); + } + } + } + return firstMapList; + } + + /** + * 获取组织的子级组织 + * + * @param targetUnit 目标组织 + * @param currentUnit 子级组织 + */ + public void addToMBean(CtUnit targetUnit, CtUnit currentUnit) { + List<CtUnit> childListObj = targetUnit.getChildren(); + List<CtUnit> childList = null; + if (CollectionUtils.isEmpty(childListObj)) { + childList = new ArrayList(); + targetUnit.setChildren(childList); + } else { + childList = childListObj; + } + childList.add(currentUnit); + } + + /** + * 获取组织相关数据(包含组织下的部门) + * + * @param unitId 组织主键编号 + * @return + */ + public CtUnit getUnitAndDept(String unitId) { + + // 组织详情 + CtUnit ctUnit = mapper.selectById(unitId); + // 组织人员数量 + QueryWrapper<CtUser> userQueryWrapper = new QueryWrapper<>(); + userQueryWrapper.eq("unit_id", unitId); + Integer countCtUser = ctUserService.count(userQueryWrapper); + ctUnit.setCountCtUser(countCtUser); + // 未配岗人员(单位下) + userQueryWrapper.isNull("dept_id"); + List<CtUser> unMatchUsers = ctUserService.list(userQueryWrapper); + ctUnit.setUnMatchUsers(unMatchUsers); + // 部门详情 + QueryWrapper<CtDept> deptQueryWrapper = new QueryWrapper<>(); + deptQueryWrapper.eq("unit_id", unitId); + deptQueryWrapper.orderByDesc("create_time"); + List<CtDept> ctDepts = ctDeptService.list(deptQueryWrapper); + for (CtDept ctDept : ctDepts) { + // 部门 + userQueryWrapper.clear(); + userQueryWrapper.eq("dept_id", ctDept.getId()); + // 部门下成员 + List<CtUser> matchUsers = ctUserService.list(userQueryWrapper); + ctDept.setMatchUsers(matchUsers); + // 部门人员数量 + int countDeptUser = ctUserService.count(userQueryWrapper); + ctDept.setCountCtUser(countDeptUser); + } + List<CtDept> ctDeptTrees = ctDeptService.createTree(ctDepts, null); + ctUnit.setCtDepts(ctDeptTrees); + // 部门数量 + ctUnit.setCountCtDept(ctDepts.size()); + return ctUnit; + } + + /** + * 更新对象 + * + * @param ctUnit 对象 + */ + public void updateTerms(CtUnit ctUnit) { + mapper.updateTerms(ctUnit); + } + + /** + * 小程序统计机构数量 + * */ + public CtUnitWeChatCountDTO wechatCountUnit(){ + CtUnitWeChatCountDTO ctUnitWeChatCountDTO = new CtUnitWeChatCountDTO(); + QueryWrapper<CtUnit> unitQueryWrapper = new QueryWrapper<>(); + unitQueryWrapper.eq("unit_type", 1); + Integer zzUnitNum = mapper.selectCount(unitQueryWrapper); + if(ObjectUtils.isEmpty(zzUnitNum)){ + zzUnitNum = 0; + } + ctUnitWeChatCountDTO.setZzUnitNum(zzUnitNum); + List<Integer> unitTypeList = Arrays.asList(2,3,4,5); + QueryWrapper<CtUnit> unitQueryWrapper1 = new QueryWrapper<>(); + unitQueryWrapper1.in("unit_type", unitTypeList); + Integer tzUnitNum = mapper.selectCount(unitQueryWrapper1); + if(ObjectUtils.isEmpty(tzUnitNum)){ + tzUnitNum = 0; + } + ctUnitWeChatCountDTO.setTzUnitNum(tzUnitNum); + return ctUnitWeChatCountDTO; + } + + /** + * 按条件分页查询 + * + * @param userId 分页对象 + * @return Page + */ + public List<SelectTermDTO> unitChoose(String userId) { + // 获取当前登录用户 + CtUserDTO loginUser = ctUserService.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 = this.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()); + + 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); + + 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