diff --git a/srt-data-development/src/main/java/net/srt/Hadoop/controller/HadoopController.java b/srt-data-development/src/main/java/net/srt/Hadoop/controller/HadoopController.java index b4ff453..6b32ab7 100644 --- a/srt-data-development/src/main/java/net/srt/Hadoop/controller/HadoopController.java +++ b/srt-data-development/src/main/java/net/srt/Hadoop/controller/HadoopController.java @@ -42,7 +42,7 @@ public class HadoopController { } /** - * 删除 + * 修改 * @param HadoopAddDto * @return */ diff --git a/srt-data-development/src/main/java/net/srt/Hadoop/convert/HadoopConvert.java b/srt-data-development/src/main/java/net/srt/Hadoop/convert/HadoopConvert.java index 05d33d7..8e57ed1 100644 --- a/srt-data-development/src/main/java/net/srt/Hadoop/convert/HadoopConvert.java +++ b/srt-data-development/src/main/java/net/srt/Hadoop/convert/HadoopConvert.java @@ -1,11 +1,6 @@ package net.srt.Hadoop.convert; -import net.srt.Fink.convert.FinkConvert; -import net.srt.Fink.dto.FinkAddDto; -import net.srt.Fink.entity.FinkEntity; -import net.srt.Fink.vo.FinkVo; import net.srt.Hadoop.dto.HadoopAddDto; -import net.srt.Hadoop.dto.HadoopDto; import net.srt.Hadoop.entity.HadoopEntity; import net.srt.Hadoop.vo.HadoopVo; import org.mapstruct.Mapper; diff --git a/srt-data-development/src/main/java/net/srt/disposition/service/impl/DataProductionServiceImpl.java b/srt-data-development/src/main/java/net/srt/disposition/service/impl/DataProductionServiceImpl.java index ee3b990..82bba9a 100644 --- a/srt-data-development/src/main/java/net/srt/disposition/service/impl/DataProductionServiceImpl.java +++ b/srt-data-development/src/main/java/net/srt/disposition/service/impl/DataProductionServiceImpl.java @@ -14,8 +14,12 @@ import net.srt.disposition.entity.DataProductionTreeEntity; import net.srt.disposition.mapper.DataProductionMapper; import net.srt.disposition.service.DataProductionService; import net.srt.disposition.vo.DataProductionTreeVo; +import net.srt.framework.common.utils.BeanUtil; +import net.srt.framework.common.utils.BuildTreeUtils; +import net.srt.framework.common.utils.TreeNodeVo; import net.srt.framework.mybatis.service.impl.BaseServiceImpl; import org.springframework.stereotype.Service; +import srt.cloud.framework.dbswitch.common.util.StringUtil; import java.util.ArrayList; import java.util.List; @@ -24,36 +28,70 @@ import java.util.List; public class DataProductionServiceImpl extends BaseServiceImpl implements DataProductionService { @Override public List dataTreeList() { - ArrayList dataProductionTreeVoArrayList = new ArrayList<>(); - List dataProductionTreeEntities = baseMapper.selectList(null); - for (DataProductionTreeEntity dataProductionTreeEntity : dataProductionTreeEntities) { - List dataProductionTreeVos=findDataProductTreeVoList(dataProductionTreeEntity); - DataProductionTreeVo convert = DataProductionTreeConvert.INSTANCE.convert(dataProductionTreeEntity); - convert.setDataProductionTreeVos(dataProductionTreeVos); - dataProductionTreeVoArrayList.add(convert); - } - return dataProductionTreeVoArrayList; + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.orderByAsc(DataProductionTreeEntity::getOrderNo); + List dataFileCategoryEntities = baseMapper.selectList(wrapper); + List treeNodeVos = BeanUtil.copyListProperties(dataFileCategoryEntities, DataProductionTreeVo::new, (oldItem, newItem) -> { + newItem.setLabel(oldItem.getName()); + if (newItem.getPath().contains("/")) { + newItem.setParentPath(newItem.getPath().substring(0, newItem.getPath().lastIndexOf("/"))); + } + }); + return buildTree(treeNodeVos); } - private List findDataProductTreeVoList(DataProductionTreeEntity dataProductionTreeEntity) { - QueryWrapper dataProductionTreeEntityQueryWrapper = new QueryWrapper<>(); - dataProductionTreeEntityQueryWrapper.eq("parent_id",dataProductionTreeEntity.getId()); - List dataProductionTreeEntities = baseMapper.selectList(dataProductionTreeEntityQueryWrapper); - List convert = DataProductionTreeConvert.INSTANCE.convert(dataProductionTreeEntities); - return convert; + public static List buildTree(List nodeVos) { + List resultVos = new ArrayList<>(10); + for (DataProductionTreeVo node : nodeVos) { + // 一级菜单parentId为0 + if (node.getParentId() == 0) { + resultVos.add(node); + } + } + // 为一级菜单设置子菜单,getChild是递归调用的 + for (DataProductionTreeVo node : resultVos) { + node.setDataProductionTreeVos(getChild(node.getId(), nodeVos)); + } + return resultVos; + } + + + private static List getChild(Integer id, List nodeVos) { + // 子菜单 + List childList = new ArrayList<>(10); + for (DataProductionTreeVo node : nodeVos) { + // 遍历所有节点,将父菜单id与传过来的id比较 + if (node.getParentId() != 0) { + if (node.getParentId().equals(id)) { + childList.add(node); + } + } + } + // 把子菜单的子菜单再循环一遍 + for (DataProductionTreeVo node : childList) { + node.setDataProductionTreeVos(getChild(node.getId(), nodeVos)); + } + return childList; } @Override public void add(DataProductionTreeDto dataProductionTreeDto) { - DataProductionTreeEntity convert = DataProductionTreeConvert.INSTANCE.convert(dataProductionTreeDto); - if (convert.getParentPath()!=null && !convert.getParentPath().equals("")){ - String path=convert.getParentPath()+"/"+convert.getName(); - convert.setPath(path); - baseMapper.insert(convert); + DataProductionTreeEntity entity = DataProductionTreeConvert.INSTANCE.convert(dataProductionTreeDto); + entity.setPath(recursionPath(entity, null)); + entity.setProjectId(getProjectId()); + baseMapper.insert(entity); + } + + private String recursionPath(DataProductionTreeEntity categoryEntity, String path) { + if (StringUtil.isBlank(path)) { + path = categoryEntity.getName(); } - convert.setLabel(convert.getName()); - convert.setPath(convert.getName()); - baseMapper.insert(convert); + if (categoryEntity.getParentId() != 0) { + DataProductionTreeEntity parent = getById(categoryEntity.getParentId()); + path = parent.getName() + "/" + path; + return recursionPath(parent, path); + } + return path; } }