¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.system.util; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.model.MdcProductionTreeModel; |
| | | import org.jeecg.modules.system.model.ProductionIdModel; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 对åºäº§çº¿ç表ï¼å¤çå¹¶æ¥æ¾æ ç»ææ°æ® |
| | | * |
| | | * @author: LiuS |
| | | * @create: 2023-03-23 14:46 |
| | | */ |
| | | public class FindsProductionsChildrenUtil { |
| | | |
| | | /** |
| | | * queryTreeListçåæ¹æ³ ====1===== |
| | | * è¯¥æ¹æ³æ¯så°MdcProductionç±»åçlistéåè½¬æ¢æMdcProductionTreeModelç±»åçéå |
| | | */ |
| | | public static List<MdcProductionTreeModel> wrapTreeDataToTreeList(List<MdcProduction> recordList) { |
| | | List<ProductionIdModel> idList = new ArrayList<>(); |
| | | List<MdcProductionTreeModel> records = new ArrayList<>(); |
| | | for (int i = 0; i < recordList.size(); i++) { |
| | | MdcProduction mdcProduction = recordList.get(i); |
| | | if (StrUtil.isEmpty(mdcProduction.getDescription())){ |
| | | mdcProduction.setDescription(""); |
| | | } |
| | | records.add(new MdcProductionTreeModel(mdcProduction)); |
| | | } |
| | | List<MdcProductionTreeModel> tree = findChildren(records, idList); |
| | | setEmptyChildrenAsNull(tree); |
| | | return tree; |
| | | } |
| | | |
| | | /** |
| | | * queryTreeListçåæ¹æ³ ====1===== |
| | | * è¯¥æ¹æ³æ¯æ¾å°å¹¶å°è£
顶级ç¶ç±»çèç¹å°TreeListéå |
| | | */ |
| | | public static List<MdcProductionTreeModel> findChildren(List<MdcProductionTreeModel> recordList, List<ProductionIdModel> productionIdList) { |
| | | List<MdcProductionTreeModel> treeList = new ArrayList<>(); |
| | | for (int i = 0; i < recordList.size(); i++) { |
| | | MdcProductionTreeModel branch = recordList.get(i); |
| | | if (oConvertUtils.isEmpty(branch.getParentId())) { |
| | | treeList.add(branch); |
| | | ProductionIdModel productionIdModel = new ProductionIdModel().convert(branch); |
| | | productionIdList.add(productionIdModel); |
| | | } |
| | | } |
| | | getGrandChildren(treeList, recordList, productionIdList); |
| | | return treeList; |
| | | } |
| | | |
| | | /** |
| | | * queryTreeListçåæ¹æ³====3==== |
| | | *è¯¥æ¹æ³æ¯æ¾å°é¡¶çº§ç¶ç±»ä¸çææåèç¹éåå¹¶å°è£
å°TreeListéå |
| | | */ |
| | | private static void getGrandChildren(List<MdcProductionTreeModel> treeList, List<MdcProductionTreeModel> recordList, List<ProductionIdModel> idList) { |
| | | for (int i = 0; i < treeList.size(); i++) { |
| | | MdcProductionTreeModel model = treeList.get(i); |
| | | ProductionIdModel idModel = idList.get(i); |
| | | for (int i1 = 0; i1 < recordList.size(); i1++) { |
| | | MdcProductionTreeModel m = recordList.get(i1); |
| | | if (m.getParentId() != null && m.getParentId().equals(model.getId())) { |
| | | model.getChildren().add(m); |
| | | ProductionIdModel pim = new ProductionIdModel().convert(m); |
| | | idModel.setSelectable(false); |
| | | idModel.getChildren().add(pim); |
| | | } |
| | | } |
| | | getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * queryTreeListçåæ¹æ³ ====4==== |
| | | * è¯¥æ¹æ³æ¯å°åèç¹ä¸ºç©ºçListéå设置为Nullå¼ |
| | | */ |
| | | private static void setEmptyChildrenAsNull(List<MdcProductionTreeModel> treeList) { |
| | | for (int i = 0; i < treeList.size(); i++) { |
| | | MdcProductionTreeModel model = treeList.get(i); |
| | | if (model.getChildren().size() == 0) { |
| | | model.setChildren(null); |
| | | model.setLeaf(true); |
| | | } else { |
| | | setEmptyChildrenAsNull(model.getChildren()); |
| | | model.setLeaf(false); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·å DepartIdModel |
| | | */ |
| | | public static List<ProductionIdModel> wrapTreeDataToProductionIdTreeList(List<MdcProduction> recordList) { |
| | | List<ProductionIdModel> idList = new ArrayList<>(); |
| | | List<MdcProductionTreeModel> records = new ArrayList<>(); |
| | | for (int i = 0; i < recordList.size(); i++) { |
| | | MdcProduction mdcProduction = recordList.get(i); |
| | | records.add(new MdcProductionTreeModel(mdcProduction)); |
| | | } |
| | | findChildren(records, idList); |
| | | return idList; |
| | | } |
| | | } |