package org.jeecg.modules.eam.service.impl; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import org.jeecg.common.api.vo.CommonGenericTree; import org.jeecg.modules.eam.entity.PrecisionParametersCategory; import org.jeecg.modules.eam.mapper.PrecisionParametersCategoryMapper; import org.jeecg.modules.eam.service.IPrecisionParametersCategoryService; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Description: mom_eam_precision_parameters_category * @Author: jeecg-boot * @Date: 2023-03-14 * @Version: V1.0 */ @Service public class PrecisionParametersCategoryServiceImpl extends ServiceImpl implements IPrecisionParametersCategoryService { @Override public List loadTree() { List precisionParametersCategoryList = this.lambdaQuery().eq(PrecisionParametersCategory::getDelFlag, "0").list(); List commonGenericTrees = loadTree(precisionParametersCategoryList); return commonGenericTrees; } @SuppressWarnings("unchecked") public List loadTree(List precisionParametersCategoryList) { @SuppressWarnings("unused") PrecisionParametersCategory precisionParametersCategory = new PrecisionParametersCategory(); List list = new ArrayList<>(); Map map = new HashMap<>(); Map map2 = new HashMap<>(); Map map3 = new HashMap<>(); Map map4 = new HashMap<>(); Map map5 = new HashMap<>(); Map map6 = new HashMap<>(); Map map7 = new HashMap<>(); CommonGenericTree node = new CommonGenericTree<>(); node.setKey("-1"); node.setValue("-1"); node.setTitle("精度参数分类"); node.setRField1(""); node.setRField2(""); node.setDisabled(false); node.setEntity(new PrecisionParametersCategory()); list.add(node); if (CollectionUtils.isNotEmpty(list)) { CommonGenericTree pcNode; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (precisionType.getParentId().equals("-1")) { pcNode = new CommonGenericTree<>(); pcNode.setKey(precisionType.getId()); pcNode.setTitle(precisionType.getNum() + "/" + precisionType.getName()); pcNode.setParentId(node.getKey()); pcNode.setIcon(""); pcNode.setType(0); pcNode.setValue(precisionType.getId()); pcNode.setDisabled(false); pcNode.setRField1(precisionType.getNum()); pcNode.setRField2(precisionType.getName()); pcNode.setEntity(precisionType); node.addChildren(pcNode); map.put(precisionType.getId(), pcNode); } } CommonGenericTree childNode; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map.containsKey(precisionType.getParentId())) { pcNode = map.get(precisionType.getParentId()); childNode = new CommonGenericTree<>(); childNode.setKey(precisionType.getId()); childNode.setTitle(precisionType.getNum() + "/" + precisionType.getName()); childNode.setParentId(precisionType.getParentId()); childNode.setIcon(""); childNode.setType(0); childNode.setValue(precisionType.getId()); childNode.setDisabled(false); childNode.setRField1(precisionType.getNum()); childNode.setRField2(precisionType.getName()); childNode.setEntity(precisionType); pcNode.addChildren(childNode); map2.put(precisionType.getId(), childNode); } } if(map2.size()>0){ CommonGenericTree child2Node; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map2.containsKey(precisionType.getParentId())) { pcNode = map2.get(precisionType.getParentId()); child2Node = new CommonGenericTree<>(); child2Node.setKey(precisionType.getId()); child2Node.setTitle(precisionType.getNum() + "/" + precisionType.getName()); child2Node.setParentId(precisionType.getParentId()); child2Node.setIcon(""); child2Node.setType(0); child2Node.setValue(precisionType.getId()); child2Node.setDisabled(false); child2Node.setRField1(precisionType.getNum()); child2Node.setRField2(precisionType.getName()); child2Node.setEntity(precisionType); pcNode.addChildren(child2Node); map3.put(precisionType.getId(), child2Node); } } if(map3.size()>0){ CommonGenericTree child3Node; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map3.containsKey(precisionType.getParentId())) { pcNode = map3.get(precisionType.getParentId()); child3Node = new CommonGenericTree<>(); child3Node.setKey(precisionType.getId()); child3Node.setTitle(precisionType.getNum() + "/" + precisionType.getName()); child3Node.setParentId(precisionType.getParentId()); child3Node.setIcon(""); child3Node.setType(0); child3Node.setValue(precisionType.getId()); child3Node.setDisabled(false); child3Node.setRField1(precisionType.getNum()); child3Node.setRField2(precisionType.getName()); child3Node.setEntity(precisionType); pcNode.addChildren(child3Node); map4.put(precisionType.getId(), child3Node); } } if(map4.size()>0){ CommonGenericTree child4Node; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map4.containsKey(precisionType.getParentId())) { pcNode = map4.get(precisionType.getParentId()); child4Node = new CommonGenericTree<>(); child4Node.setKey(precisionType.getId()); child4Node.setTitle(precisionType.getNum() + "/" + precisionType.getName()); child4Node.setParentId(precisionType.getParentId()); child4Node.setIcon(""); child4Node.setType(0); child4Node.setValue(precisionType.getId()); child4Node.setDisabled(false); child4Node.setRField1(precisionType.getNum()); child4Node.setRField2(precisionType.getName()); child4Node.setEntity(precisionType); pcNode.addChildren(child4Node); map5.put(precisionType.getId(), child4Node); } } if(map5.size()>0){ CommonGenericTree child5Node; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map5.containsKey(precisionType.getParentId())) { pcNode = map5.get(precisionType.getParentId()); child5Node = new CommonGenericTree<>(); child5Node.setKey(precisionType.getId()); child5Node.setTitle(precisionType.getNum() + "/" + precisionType.getName()); child5Node.setParentId(precisionType.getParentId()); child5Node.setIcon(""); child5Node.setType(0); child5Node.setValue(precisionType.getId()); child5Node.setDisabled(false); child5Node.setRField1(precisionType.getNum()); child5Node.setRField2(precisionType.getName()); child5Node.setEntity(precisionType); pcNode.addChildren(child5Node); map6.put(precisionType.getId(), child5Node); } } if(map6.size()>0){ CommonGenericTree child6Node; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map6.containsKey(precisionType.getParentId())) { pcNode = map6.get(precisionType.getParentId()); child6Node = new CommonGenericTree<>(); child6Node.setKey(precisionType.getId()); child6Node.setTitle(precisionType.getNum() + "/" + precisionType.getName()); child6Node.setParentId(precisionType.getParentId()); child6Node.setIcon(""); child6Node.setType(0); child6Node.setValue(precisionType.getId()); child6Node.setDisabled(false); child6Node.setRField1(precisionType.getNum()); child6Node.setRField2(precisionType.getName()); child6Node.setEntity(precisionType); pcNode.addChildren(child6Node); map7.put(precisionType.getId(), child6Node); } } if(map7.size()>0){ CommonGenericTree child7Node; for (PrecisionParametersCategory precisionType : precisionParametersCategoryList) { if (map.containsKey(precisionType.getParentId())) { pcNode = map7.get(precisionType.getParentId()); child7Node = new CommonGenericTree<>(); child7Node.setKey(precisionType.getId()); child7Node.setTitle(precisionType.getNum() + "/" + precisionType.getName()); child7Node.setParentId(precisionType.getParentId()); child7Node.setIcon(""); child7Node.setType(0); child7Node.setValue(precisionType.getId()); child7Node.setDisabled(false); child7Node.setRField1(precisionType.getNum()); child7Node.setRField2(precisionType.getName()); child7Node.setEntity(precisionType); // pcNode.addChildren(child7Node); // map7.put(cause.getId(), child7Node); } } } } } } } } } return list; } }