mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化流程查询以及多根节点构建树结构
This commit is contained in:
		@@ -10,7 +10,6 @@ import lombok.NoArgsConstructor;
 | 
			
		||||
import org.dromara.common.core.utils.reflect.ReflectUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
@@ -79,17 +78,10 @@ public class TreeBuildUtils extends TreeUtil {
 | 
			
		||||
            return CollUtil.newArrayList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 提取所有节点 ID,用于后续判断哪些节点为根节点(即 parentId 不在其中)
 | 
			
		||||
        Set<K> allIds = StreamUtils.toSet(list, getId);
 | 
			
		||||
        Set<K> rootParentIds = StreamUtils.toSet(list, getParentId);
 | 
			
		||||
        rootParentIds.removeAll(StreamUtils.toSet(list, getId));
 | 
			
		||||
 | 
			
		||||
        // 筛选出所有 parentId 不在 allIds 中的节点,这些节点的 parentId 可认为是根节点
 | 
			
		||||
        Set<K> rootParentIds = list.stream()
 | 
			
		||||
            .map(getParentId)
 | 
			
		||||
            .filter(Objects::nonNull)
 | 
			
		||||
            .filter(pid -> !allIds.contains(pid))
 | 
			
		||||
            .collect(Collectors.toSet());
 | 
			
		||||
 | 
			
		||||
        // 使用流处理,遍历每个顶级 parentId,构建对应树,并合并为一个列表返回
 | 
			
		||||
        // 构建每一个根 parentId 下的树,并合并成最终结果列表
 | 
			
		||||
        return rootParentIds.stream()
 | 
			
		||||
            .flatMap(rootParentId -> TreeUtil.build(list, rootParentId, parser).stream())
 | 
			
		||||
            .collect(Collectors.toList());
 | 
			
		||||
 
 | 
			
		||||
@@ -4,14 +4,13 @@ import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
 | 
			
		||||
import cn.idev.excel.annotation.ExcelProperty;
 | 
			
		||||
import io.github.linpeilie.annotations.AutoMapper;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import org.dromara.common.translation.annotation.Translation;
 | 
			
		||||
import org.dromara.workflow.common.constant.FlowConstant;
 | 
			
		||||
import org.dromara.workflow.domain.FlowCategory;
 | 
			
		||||
 | 
			
		||||
import java.io.Serial;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 流程分类视图对象 wf_category
 | 
			
		||||
@@ -34,13 +33,14 @@ public class FlowCategoryVo implements Serializable {
 | 
			
		||||
    private Long categoryId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 父级id
 | 
			
		||||
     * 父级分类id
 | 
			
		||||
     */
 | 
			
		||||
    private Long parentId;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 父类别名称
 | 
			
		||||
     * 父级分类名称
 | 
			
		||||
     */
 | 
			
		||||
    @Translation(type = FlowConstant.CATEGORY_ID_TO_NAME, mapper = "parentId")
 | 
			
		||||
    private String parentName;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -66,9 +66,4 @@ public class FlowCategoryVo implements Serializable {
 | 
			
		||||
    @ExcelProperty(value = "创建时间")
 | 
			
		||||
    private Date createTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 子菜单
 | 
			
		||||
     */
 | 
			
		||||
    private List<FlowCategoryVo> children = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
import org.dromara.common.core.constant.SystemConstants;
 | 
			
		||||
import org.dromara.common.core.exception.ServiceException;
 | 
			
		||||
import org.dromara.common.core.utils.*;
 | 
			
		||||
import org.dromara.common.core.utils.MapstructUtils;
 | 
			
		||||
import org.dromara.common.core.utils.ObjectUtils;
 | 
			
		||||
import org.dromara.common.core.utils.StringUtils;
 | 
			
		||||
import org.dromara.common.core.utils.TreeBuildUtils;
 | 
			
		||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
 | 
			
		||||
import org.dromara.common.satoken.utils.LoginHelper;
 | 
			
		||||
import org.dromara.warm.flow.core.service.DefService;
 | 
			
		||||
@@ -48,14 +51,7 @@ public class FlwCategoryServiceImpl implements IFlwCategoryService {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public FlowCategoryVo queryById(Long categoryId) {
 | 
			
		||||
        FlowCategoryVo category = baseMapper.selectVoById(categoryId);
 | 
			
		||||
        if (ObjectUtil.isNull(category)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
        FlowCategoryVo parentCategory = baseMapper.selectVoOne(new LambdaQueryWrapper<FlowCategory>()
 | 
			
		||||
            .select(FlowCategory::getCategoryName).eq(FlowCategory::getCategoryId, category.getParentId()));
 | 
			
		||||
        category.setParentName(ObjectUtils.notNullGetter(parentCategory, FlowCategoryVo::getCategoryName));
 | 
			
		||||
        return category;
 | 
			
		||||
        return baseMapper.selectVoById(categoryId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user