From f974bf528f0fd1f7316bdb3f06be8004e8db9f15 Mon Sep 17 00:00:00 2001
From: wangwh <2397901735@qq.com>
Date: Wed, 21 Aug 2024 17:24:07 +0800
Subject: [PATCH] 用户中心部分迁移1
---
dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 52 insertions(+), 1 deletions(-)
diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java
index 4ebcf35..3853f43 100644
--- a/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java
+++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java
@@ -4,9 +4,12 @@
import cn.huge.base.common.utils.DateUtils;
import cn.huge.base.common.utils.IdUtils;
import cn.huge.module.client.api.impl.UtilsClientImpl;
+import cn.huge.module.constant.BaseConsts;
import cn.huge.module.ctuser.dao.mapper.CtDeptMapper;
import cn.huge.module.ctuser.domain.po.CtDept;
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;
@@ -17,6 +20,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -116,7 +120,7 @@
*/
public void saveCtDept(CtDept ctDept){
try{
- Date nowDate = DateUtils.getMowDate();
+ Date nowDate = DateUtils.getNowDate();
// 判断是否新增
if (IdUtils.checkNewId(ctDept.getId())){
ctDept.setId(utilsClient.getNewTimeId());
@@ -130,4 +134,51 @@
}
}
+ /**
+ * 创建某一级部门下树形结构
+ * @param ctDeptList 所有部门集合
+ * @param firstId 某一级组织编号
+ * @return List
+ */
+ public List<CtDept> createTree(List<CtDept> ctDeptList, String firstId) {
+ List<CtDept> firstMapList= new ArrayList<>();
+ for (CtDept ctDept: ctDeptList ){
+ for(CtDept deptParam: ctDeptList ) {
+ if (deptParam.getId().equals(ctDept.getParentId())) {
+ addToMBean(deptParam, ctDept);
+ break;
+ }
+ }
+ }
+ //取第一级节点
+ for (CtDept dept: ctDeptList ){
+ if (StringUtils.isNotEmpty(firstId)){
+ if (firstId.equals(dept.getId())) {
+ firstMapList.add(dept);
+ }
+ }else{
+ if (BaseConsts.ROOT.equals(dept.getParentId()) || StringUtils.isEmpty(dept.getParentId())) {
+ firstMapList.add(dept);
+ }
+ }
+ }
+ return firstMapList;
+ }
+
+ /**
+ * 获取部门的子级部门
+ * @param targetUnit 目标部门
+ * @param currentUnit 子级部门
+ */
+ public void addToMBean(CtDept targetUnit, CtDept currentUnit){
+ List<CtDept> childListObj = targetUnit.getChildren();
+ List<CtDept> childList = null;
+ if(CollectionUtils.isEmpty(childListObj)) {
+ childList = new ArrayList();
+ targetUnit.setChildren(childList);
+ }else{
+ childList = childListObj;
+ }
+ childList.add(currentUnit);
+ }
}
--
Gitblit v1.8.0