package org.jeecg.modules.mdc.util;
|
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.base.entity.Factory;
|
import org.jeecg.modules.mdc.model.MdcEquipmentTree;
|
import org.jeecg.modules.mdc.model.FactoryTreeModel;
|
import org.jeecg.modules.mdc.model.MdcProductionTreeModel;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 产线设备树
|
* @author: LiuS
|
* @create: 2023-04-03 15:59
|
*/
|
public class FindsEquipmentFactoryUtil {
|
|
/**
|
* 获取 MdcEquipmentTree
|
*/
|
public static List<MdcEquipmentTree> wrapEquipmentFactoryTreeList(List<Factory> recordList) {
|
List<MdcEquipmentTree> idList = new ArrayList<>();
|
List<FactoryTreeModel> records = new ArrayList<>();
|
for (Factory factory : recordList) {
|
records.add(new FactoryTreeModel(factory));
|
}
|
getChildren(records, idList);
|
setEmptyChildrenAsNull(idList);
|
return idList;
|
}
|
|
/**
|
* 该方法是找到并封装顶级父类的节点到TreeList集合
|
*/
|
private static void getChildren(List<FactoryTreeModel> recordList, List<MdcEquipmentTree> idList) {
|
List<FactoryTreeModel> treeList = new ArrayList<>();
|
for (FactoryTreeModel factoryTreeModel : recordList) {
|
if (oConvertUtils.isEmpty(factoryTreeModel.getParentId())) {
|
factoryTreeModel.setType(1);
|
treeList.add(factoryTreeModel);
|
idList.add(new MdcEquipmentTree().convertByFactory(factoryTreeModel));
|
}
|
}
|
getGrandChildren(treeList, recordList, idList);
|
}
|
|
/**
|
*该方法是找到顶级父类下的所有子节点集合并封装到TreeList集合
|
*/
|
private static void getGrandChildren(List<FactoryTreeModel> treeList, List<FactoryTreeModel> recordList, List<MdcEquipmentTree> idList) {
|
for (int i = 0; i < treeList.size(); i++) {
|
FactoryTreeModel model = treeList.get(i);
|
MdcEquipmentTree mdcEquipmentTree = idList.get(i);
|
for (int i1 = 0; i1 < recordList.size(); i1++) {
|
FactoryTreeModel 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().convertByFactory(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);
|
}
|
}
|
}
|
}
|