From c05d148bb0942e7424f8f72d377cc366a33a9e01 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期二, 26 十一月 2024 12:25:55 +0800 Subject: [PATCH] 流程类型tree接口 --- business/src/main/java/com/ycl/service/impl/FlowableTypeServiceImpl.java | 69 ++++++++++++++++++++++++++++++++-- 1 files changed, 64 insertions(+), 5 deletions(-) diff --git a/business/src/main/java/com/ycl/service/impl/FlowableTypeServiceImpl.java b/business/src/main/java/com/ycl/service/impl/FlowableTypeServiceImpl.java index 1996b65..63aaca0 100644 --- a/business/src/main/java/com/ycl/service/impl/FlowableTypeServiceImpl.java +++ b/business/src/main/java/com/ycl/service/impl/FlowableTypeServiceImpl.java @@ -1,17 +1,14 @@ package com.ycl.service.impl; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ycl.common.base.Result; import com.ycl.domain.entity.FlowableType; -import com.ycl.framework.utils.PageUtil; import com.ycl.mapper.FlowableTypeMapper; import com.ycl.service.FlowableTypeService; import lombok.RequiredArgsConstructor; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; -import org.springframework.util.Assert; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; @@ -24,4 +21,66 @@ public List<FlowableType> selectTypeList(FlowableType flowableType) { return baseMapper.selectTypeList(flowableType); } + + @Override + public List<FlowableType> buildTreeSelect(List<FlowableType> list) { + List<FlowableType> returnList = new ArrayList<FlowableType>(); + List<Integer> tempList = list.stream().map(FlowableType::getId).collect(Collectors.toList()); + for (Iterator<FlowableType> iterator = list.iterator(); iterator.hasNext();) + { + FlowableType type = (FlowableType) iterator.next(); + // 濡傛灉鏄《绾ц妭鐐�, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣 + if (!tempList.contains(type.getParentId())) + { + recursionFn(list, type); + returnList.add(type); + } + } + if (returnList.isEmpty()) + { + returnList = list; + } + return returnList; + } + + private void recursionFn(List<FlowableType> list, FlowableType t) + { + // 寰楀埌瀛愯妭鐐瑰垪琛� + List<FlowableType> childList = getChildList(list, t); + t.setChildren(childList); + for (FlowableType tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 寰楀埌瀛愯妭鐐瑰垪琛� + */ + private List<FlowableType> getChildList(List<FlowableType> list, FlowableType t) + { + List<FlowableType> tlist = new ArrayList<FlowableType>(); + Iterator<FlowableType> it = list.iterator(); + while (it.hasNext()) + { + FlowableType n = (FlowableType) it.next(); + if (n.getParentId().longValue() == t.getId().longValue()) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 鍒ゆ柇鏄惁鏈夊瓙鑺傜偣 + */ + private boolean hasChild(List<FlowableType> list, FlowableType t) + { + return getChildList(list, t).size() > 0; + } + } -- Gitblit v1.8.0