From 5dedf6c30f0864ae7c4fd3c47c74b057f2360156 Mon Sep 17 00:00:00 2001
From: zhouxiantao <1026371446@qq.com>
Date: Tue, 03 Sep 2024 10:07:54 +0800
Subject: [PATCH] 小程序开发
---
dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtUnitService.java | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 170 insertions(+), 7 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 6b35afe..6f83f64 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
@@ -3,30 +3,35 @@
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.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.dto.CtUnitWeChatCountDTO;
+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: 客户组织信息表业务逻辑处理
* @Description 客户组织信息表业务逻辑处理
* @company hugeinfo
* @author liyj
- * @Time 2024-08-17 15:30:57
+ * @Time 2024-08-19 20:04:19
* @version 1.0.0
*/
@Slf4j
@@ -39,6 +44,12 @@
@Autowired
private UtilsClientImpl utilsClient;
+
+ @Autowired
+ private CtDeptService ctDeptService;
+
+ @Autowired
+ private CtUserService ctUserService;
/**
* 更新对象
@@ -116,7 +127,7 @@
*/
public void saveCtUnit(CtUnit ctUnit){
try{
- Date nowDate = DateUtils.getMowDate();
+ Date nowDate = DateUtils.getNowDate();
// 判断是否新增
if (IdUtils.checkNewId(ctUnit.getId())){
ctUnit.setId(utilsClient.getNewTimeId());
@@ -130,4 +141,156 @@
}
}
+ /**
+ * 获取所有组织(包含所有下级子组织)
+ *
+ * @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;
+ }
}
--
Gitblit v1.8.0