package org.jeecg.modules.mdc.util;
|
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
|
import org.jeecg.modules.system.entity.MdcProduction;
|
import org.jeecg.modules.system.model.MdcProductionTreeModel;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 产线设备树
|
* @author: LiuS
|
* @create: 2023-04-03 15:59
|
*/
|
public class FindsEquipmentProductionUtil {
|
|
/**
|
* 获取 MdcEquipmentTree
|
*/
|
public static List<MdcEquipmentTree> wrapEquipmentProductionTreeList(List<MdcProduction> recordList) {
|
List<MdcEquipmentTree> idList = new ArrayList<>();
|
List<MdcProductionTreeModel> records = new ArrayList<>();
|
for (MdcProduction mdcProduction : recordList) {
|
records.add(new MdcProductionTreeModel(mdcProduction));
|
}
|
getChildren(records, idList);
|
setEmptyChildrenAsNull(idList);
|
return idList;
|
}
|
|
/**
|
* 该方法是找到并封装顶级父类的节点到TreeList集合
|
*/
|
private static void getChildren(List<MdcProductionTreeModel> recordList, List<MdcEquipmentTree> idList) {
|
List<MdcProductionTreeModel> treeList = new ArrayList<>();
|
for (MdcProductionTreeModel mdcProductionTreeModel : recordList) {
|
if (oConvertUtils.isEmpty(mdcProductionTreeModel.getParentId())) {
|
mdcProductionTreeModel.setType(1);
|
treeList.add(mdcProductionTreeModel);
|
idList.add(new MdcEquipmentTree().convertByProduction(mdcProductionTreeModel));
|
}
|
}
|
getGrandChildren(treeList, recordList, idList);
|
}
|
|
/**
|
*该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
|
*/
|
private static void getGrandChildren(List<MdcProductionTreeModel> treeList, List<MdcProductionTreeModel> recordList, List<MdcEquipmentTree> idList) {
|
for (int i = 0; i < treeList.size(); i++) {
|
MdcProductionTreeModel model = treeList.get(i);
|
MdcEquipmentTree mdcEquipmentTree = 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);
|
m.setType(1);
|
mdcEquipmentTree.getChildren().add(new MdcEquipmentTree().convertByProduction(m));
|
}
|
}
|
getGrandChildren(treeList.get(i).getChildren(), recordList, idList.get(i).getChildren());
|
}
|
}
|
|
/**
|
* 该方法是将子节点为空的List集合设置为Null值
|
*/
|
private static void setEmptyChildrenAsNull(List<MdcEquipmentTree> idList) {
|
for (MdcEquipmentTree mdcEquipmentTree : idList) {
|
if (mdcEquipmentTree.getChildren().isEmpty()) {
|
mdcEquipmentTree.setLeaf(true);
|
} else {
|
setEmptyChildrenAsNull(mdcEquipmentTree.getChildren());
|
mdcEquipmentTree.setLeaf(false);
|
}
|
}
|
}
|
}
|