From 0817f426f3ff66c6ab07f81d17e77be106b9c622 Mon Sep 17 00:00:00 2001 From: liyj <1003249715@qq.com> Date: Mon, 26 Aug 2024 14:26:59 +0800 Subject: [PATCH] 代码生成器优化 --- dyh-service/dyh-cust/src/main/java/cn/huge/module/ctuser/service/CtDeptService.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 53 insertions(+), 4 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 5cf56f2..f58e0f7 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,19 +4,21 @@ 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; -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.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @@ -26,7 +28,7 @@ * @Description 客户部门表业务逻辑处理 * @company hugeinfo * @author liyj - * @Time 2024-08-17 15:30:57 + * @Time 2024-08-19 20:04:19 * @version 1.0.0 */ @Slf4j @@ -116,7 +118,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 +132,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