package org.jeecg.modules.eam.wrapper;
|
|
import org.jeecg.modules.eam.entity.Area;
|
import org.jeecg.modules.eam.entity.ProductionLine;
|
import org.jeecg.modules.eam.entity.Site;
|
import org.jeecg.modules.eam.vo.CommonCascade;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import java.util.*;
|
|
public class SiteAreaCascadeWrapper {
|
|
/**
|
* 获取工厂车间两级级联数据 必须选择到产线
|
*
|
* @param siteList
|
* @param areaList
|
* @return
|
*/
|
public static List<CommonCascade> loadCascade(List<Site> siteList, List<Area> areaList) {
|
List<CommonCascade> list = loadCascadeBase(siteList, areaList, null);
|
List<CommonCascade> result = new ArrayList<>();
|
for (CommonCascade c : list) {
|
if (c.hasChildren()) {
|
result.add(c);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 必须要选择到产线三级级联结构
|
*
|
* @param siteList
|
* @param areaList
|
* @return
|
*/
|
public static List<CommonCascade> loadCascade(List<Site> siteList, List<Area> areaList,
|
List<ProductionLine> lineList) {
|
List<CommonCascade> list = loadCascadeBase(siteList, areaList, lineList);
|
// 过滤工厂下没有车间 车间下没有产线的数据
|
List<CommonCascade> result = new ArrayList<>();
|
for (CommonCascade c : list) {
|
if (c.hasChildren()) {
|
List<CommonCascade> children = c.getChildren();
|
List<CommonCascade> dList = new ArrayList<>();
|
for (CommonCascade d : children) {
|
if (d.hasChildren()) {
|
dList.add(d);
|
}
|
}
|
if (!dList.isEmpty()) {
|
c.setChildren(dList);
|
result.add(c);
|
}
|
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 获取工厂车间产线三级级联数据 返回全数据 不做过滤
|
*
|
* @param siteList
|
* @param areaList
|
* @param lineList
|
* @return
|
*/
|
public static List<CommonCascade> loadCascadeBase(List<Site> siteList, List<Area> areaList,
|
List<ProductionLine> productionLineList) {
|
List<CommonCascade> commonCascadeList = new ArrayList<CommonCascade>();
|
if (CollectionUtils.isNotEmpty(siteList) || CollectionUtils.isNotEmpty(areaList)) {
|
Map<String, CommonCascade> siteMap = new HashMap<>();
|
Map<String, CommonCascade> areaMap = new HashMap<>();
|
CommonCascade siteNode;
|
CommonCascade areaNode;
|
CommonCascade productionLineNode;
|
for (Site site : siteList) {
|
siteNode = new CommonCascade();
|
siteNode = siteNode.setValue(site.getId()).setLabel(site.getName());
|
commonCascadeList.add(siteNode);
|
siteMap.put(site.getId(), siteNode);
|
}
|
for (Area area : areaList) {
|
if (siteMap.containsKey(area.getSiteId())) {
|
siteNode = siteMap.get(area.getSiteId());
|
areaNode = new CommonCascade();
|
areaNode = areaNode.setValue(area.getId()).setLabel(area.getName());
|
siteNode.addChildren(areaNode);
|
areaMap.put(area.getId(), areaNode);
|
}
|
}
|
// 返回两级数据
|
if (CollectionUtils.isNotEmpty(productionLineList)) {
|
for (ProductionLine productionLine : productionLineList) {
|
if (areaMap.containsKey(productionLine.getAreaId())) {
|
areaNode = areaMap.get(productionLine.getAreaId());
|
productionLineNode = new CommonCascade();
|
productionLineNode = productionLineNode.setValue(productionLine.getId())
|
.setLabel(productionLine.getName());
|
areaNode.addChildren(productionLineNode);
|
}
|
}
|
}
|
}
|
return commonCascadeList;
|
}
|
|
}
|