|
|
@ -26,11 +26,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Description : 发送加工参数
|
|
|
|
* @Description : 发送加工参数
|
|
|
@ -78,8 +76,11 @@ public class MesSendEquipParamsCmdStepService extends BaseStepService {
|
|
|
|
//获取生产线信息
|
|
|
|
//获取生产线信息
|
|
|
|
MesWorkCenter workCenter = productionProcessContext.getWorkCenter();
|
|
|
|
MesWorkCenter workCenter = productionProcessContext.getWorkCenter();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//搜集数据:根据数据关联键分组加工参数关联ID集合
|
|
|
|
|
|
|
|
Map<Integer, List<Long>> sourceIdMap2ForeignKey = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
//搜集加工参数关联ID集合 根据生产线类型区分
|
|
|
|
//搜集加工参数关联ID集合 根据生产线类型区分
|
|
|
|
List<Long> sourceIdList = getEquipmentProdParamCfgSourceIdList(productionProcessContext, prodRuleContextList, workCenter);
|
|
|
|
List<Long> sourceIdList = getEquipmentProdParamCfgSourceIdList(productionProcessContext, prodRuleContextList, workCenter, sourceIdMap2ForeignKey);
|
|
|
|
|
|
|
|
|
|
|
|
//根据来源ID查询设备加工参数信息
|
|
|
|
//根据来源ID查询设备加工参数信息
|
|
|
|
List<MesEquipmentProdParamCfg> equipmentProdParamCfgList = equipmentProdParamCfgService.getEquipmentProdParamCfgList(reqBean.getOrganizeCode(), sourceIdList);
|
|
|
|
List<MesEquipmentProdParamCfg> equipmentProdParamCfgList = equipmentProdParamCfgService.getEquipmentProdParamCfgList(reqBean.getOrganizeCode(), sourceIdList);
|
|
|
@ -123,7 +124,7 @@ public class MesSendEquipParamsCmdStepService extends BaseStepService {
|
|
|
|
productionPsOutContexts.stream().filter(i -> (null != i && !StringUtils.isEmpty(i.getForeignKey()) && i.getForeignKey().compareTo(o.getForeignKey()) == 0)).findFirst();
|
|
|
|
productionPsOutContexts.stream().filter(i -> (null != i && !StringUtils.isEmpty(i.getForeignKey()) && i.getForeignKey().compareTo(o.getForeignKey()) == 0)).findFirst();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doSendEquipParamsCmd(reqBean, resultBean, o, cellEquipContext, eppcMap2SourceId, evMap, productResult, productionPartContextOp, productionPsInContextOp, productionPsOutContextOp);
|
|
|
|
doSendEquipParamsCmd(reqBean, resultBean, o, sourceIdMap2ForeignKey.get(o.getForeignKey()), cellEquipContext, eppcMap2SourceId, evMap, productResult, productionPartContextOp, productionPsInContextOp, productionPsOutContextOp);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -131,10 +132,15 @@ public class MesSendEquipParamsCmdStepService extends BaseStepService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//搜集加工参数关联ID集合
|
|
|
|
//搜集加工参数关联ID集合
|
|
|
|
private List<Long> getEquipmentProdParamCfgSourceIdList(MesProductionProcessContext productionProcessContext, List<MesProdRuleContext> prodRuleContextList, MesWorkCenter workCenter) {
|
|
|
|
private List<Long> getEquipmentProdParamCfgSourceIdList(MesProductionProcessContext productionProcessContext, List<MesProdRuleContext> prodRuleContextList, MesWorkCenter workCenter, Map<Integer, List<Long>> sourceIdMap2ForeignKey) {
|
|
|
|
if (MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue() == workCenter.getCenterType()) {
|
|
|
|
if (MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue() == workCenter.getCenterType()) {
|
|
|
|
//非排序
|
|
|
|
//非排序
|
|
|
|
return prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPid()))).map(MesProdRuleContext::getPid).collect(Collectors.toList());
|
|
|
|
List<Long> sourceIdList = new ArrayList<>();
|
|
|
|
|
|
|
|
prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPid()))).forEach(o -> {
|
|
|
|
|
|
|
|
sourceIdMap2ForeignKey.put(o.getForeignKey(), Stream.of(o.getPid()).collect(Collectors.toList()));
|
|
|
|
|
|
|
|
sourceIdList.add(o.getPid());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return sourceIdList;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
//排序
|
|
|
|
//排序
|
|
|
|
List<Long> sourceIdList = null;
|
|
|
|
List<Long> sourceIdList = null;
|
|
|
@ -143,6 +149,7 @@ public class MesSendEquipParamsCmdStepService extends BaseStepService {
|
|
|
|
List<Long> itemIdList = prodRuleContext.getSortAssemblyDataContext().stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPid()))).map(MesProductionAssemblySortContext::getPid).collect(Collectors.toList());
|
|
|
|
List<Long> itemIdList = prodRuleContext.getSortAssemblyDataContext().stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPid()))).map(MesProductionAssemblySortContext::getPid).collect(Collectors.toList());
|
|
|
|
if (CollectionUtils.isEmpty(itemIdList)) continue;
|
|
|
|
if (CollectionUtils.isEmpty(itemIdList)) continue;
|
|
|
|
if (CollectionUtils.isEmpty(sourceIdList)) sourceIdList = new ArrayList<>();
|
|
|
|
if (CollectionUtils.isEmpty(sourceIdList)) sourceIdList = new ArrayList<>();
|
|
|
|
|
|
|
|
sourceIdMap2ForeignKey.put(prodRuleContext.getForeignKey(), itemIdList);
|
|
|
|
sourceIdList.addAll(itemIdList);
|
|
|
|
sourceIdList.addAll(itemIdList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sourceIdList;
|
|
|
|
return sourceIdList;
|
|
|
@ -150,57 +157,65 @@ public class MesSendEquipParamsCmdStepService extends BaseStepService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//发送设备加工参数
|
|
|
|
//发送设备加工参数
|
|
|
|
private void doSendEquipParamsCmd(StationRequestBean reqBean, StationResultBean resultBean, MesProdRuleContext prodRuleContext, MesCellEquipContext cellEquipContext,
|
|
|
|
private void doSendEquipParamsCmd(StationRequestBean reqBean, StationResultBean resultBean, MesProdRuleContext prodRuleContext, List<Long> sourceIdList, MesCellEquipContext cellEquipContext,
|
|
|
|
Map<Long, List<MesEquipmentProdParamCfg>> eppcMap2SourceId, Map<Long, MesEquipmentVariable> evMap, String productResult,
|
|
|
|
Map<Long, List<MesEquipmentProdParamCfg>> eppcMap2SourceId, Map<Long, MesEquipmentVariable> evMap, String productResult,
|
|
|
|
Optional<MesProductionPartContext> productionPartContextOp, Optional<MesProductionPsInContext> productionPsInContextOp, Optional<MesProductionPsOutContext> productionPsOutContextOp) {
|
|
|
|
Optional<MesProductionPartContext> productionPartContextOp, Optional<MesProductionPsInContext> productionPsInContextOp, Optional<MesProductionPsOutContext> productionPsOutContextOp) {
|
|
|
|
|
|
|
|
|
|
|
|
//当前加工规则的PID对应的设备加工参数
|
|
|
|
if (CollectionUtils.isEmpty(sourceIdList)) return;
|
|
|
|
List<MesEquipmentProdParamCfg> equipmentProdParamCfgList = eppcMap2SourceId.get(prodRuleContext.getPid());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(equipmentProdParamCfgList)) return;
|
|
|
|
for (Long sourceId : sourceIdList) {
|
|
|
|
|
|
|
|
|
|
|
|
MesProductionPartContext productionPartContext = (null != productionPartContextOp && productionPartContextOp.isPresent()) ? productionPartContextOp.get() : null;
|
|
|
|
if (StringUtils.isEmpty(sourceId)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
MesProductionPsInContext productionPsInContext = (null != productionPsInContextOp && productionPsInContextOp.isPresent()) ? productionPsInContextOp.get() : null;
|
|
|
|
//当前加工规则的PID对应的设备加工参数
|
|
|
|
|
|
|
|
List<MesEquipmentProdParamCfg> equipmentProdParamCfgList = eppcMap2SourceId.get(sourceId);
|
|
|
|
|
|
|
|
|
|
|
|
MesProductionPsOutContext productionPsOutContext = (null != productionPsOutContextOp && productionPsOutContextOp.isPresent()) ? productionPsOutContextOp.get() : null;
|
|
|
|
if (CollectionUtils.isEmpty(equipmentProdParamCfgList)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
//搜集发送规则并去重
|
|
|
|
MesProductionPartContext productionPartContext = (null != productionPartContextOp && productionPartContextOp.isPresent()) ? productionPartContextOp.get() : null;
|
|
|
|
List<String> matchRuleList = (equipmentProdParamCfgList.stream().filter(o -> null != o).map(o -> checkTransformUpperCase(o.getMatchRule())).collect(Collectors.toList())).stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String matchRule : matchRuleList) {
|
|
|
|
MesProductionPsInContext productionPsInContext = (null != productionPsInContextOp && productionPsInContextOp.isPresent()) ? productionPsInContextOp.get() : null;
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(matchRule)) continue;
|
|
|
|
MesProductionPsOutContext productionPsOutContext = (null != productionPsOutContextOp && productionPsOutContextOp.isPresent()) ? productionPsOutContextOp.get() : null;
|
|
|
|
|
|
|
|
|
|
|
|
Optional<MesEquipmentProdParamCfg> equipmentProdParamCfgOp = equipmentProdParamCfgList.stream().filter(o -> (null != o && checkTransformUpperCase(o.getMatchRule()).equals(matchRule) && evMap.containsKey(o.getEquipVariableId()))).findFirst();
|
|
|
|
//搜集发送规则并去重
|
|
|
|
|
|
|
|
List<String> matchRuleList = (equipmentProdParamCfgList.stream().filter(o -> null != o).map(o -> checkTransformUpperCase(o.getMatchRule())).collect(Collectors.toList())).stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
if (null == equipmentProdParamCfgOp || !equipmentProdParamCfgOp.isPresent()) continue;
|
|
|
|
for (String matchRule : matchRuleList) {
|
|
|
|
|
|
|
|
|
|
|
|
evMap.remove(equipmentProdParamCfgOp.get().getId());
|
|
|
|
if (StringUtils.isEmpty(matchRule)) continue;
|
|
|
|
|
|
|
|
|
|
|
|
//数据转换
|
|
|
|
Optional<MesEquipmentProdParamCfg> equipmentProdParamCfgOp = equipmentProdParamCfgList.stream().filter(o -> (null != o && checkTransformUpperCase(o.getMatchRule()).equals(matchRule) && evMap.containsKey(o.getEquipVariableId()))).findFirst();
|
|
|
|
String matchValue = transferValue(matchRule, reqBean, prodRuleContext, productResult, productionPartContext, productionPsInContext, productionPsOutContext);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(matchValue)) {
|
|
|
|
if (null == equipmentProdParamCfgOp || !equipmentProdParamCfgOp.isPresent()) continue;
|
|
|
|
this.sendMessage(reqBean, resultBean.writeDbLog(), String.format("发送设备加工参数:[%s]未匹配到业务数据", matchRule), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MesEquipmentVariable equipmentVariable = evMap.get(equipmentProdParamCfgOp.get().getEquipVariableId());
|
|
|
|
evMap.remove(equipmentProdParamCfgOp.get().getId());
|
|
|
|
if (null == equipmentVariable) {
|
|
|
|
|
|
|
|
this.sendMessage(reqBean, resultBean.writeDbLog(), String.format("发送设备加工参数:设备加工参数信息ID[%s]关联的设备数据变量ID[%s]未维护有效的设备数据变量信息!", equipmentProdParamCfgOp.get().getId(), equipmentProdParamCfgOp.get().getEquipVariableId()), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//写值
|
|
|
|
//数据转换
|
|
|
|
MesEquipVariableRwResult equipVariableRwResult = equipVariableRwExtService.writeVariable(matchValue, equipmentVariable, cellEquipContext.getKepwareFlag(equipmentVariable.getChannel()));
|
|
|
|
String matchValue = transferValue(matchRule, reqBean, prodRuleContext, productResult, productionPartContext, productionPsInContext, productionPsOutContext);
|
|
|
|
|
|
|
|
|
|
|
|
if (!equipVariableRwResult.getIsSuccessed()) {
|
|
|
|
if (StringUtils.isEmpty(matchValue)) {
|
|
|
|
this.sendMessage(reqBean, new StationResultBean().writeDbLog().checkRepeat(), String.format("设备[%s]:发送设备加工参数失败!原因:%s", cellEquipContext.getEquipmentName(), equipVariableRwResult.getMessage()), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
|
|
|
this.sendMessage(reqBean, resultBean.writeDbLog(), String.format("发送设备加工参数:[%s]未匹配到业务数据", matchRule), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.sendMessage(reqBean, new StationResultBean().writeDbLog(), String.format("设备[%s]:发送设备加工参数成功!%s", cellEquipContext.getEquipmentName(), equipVariableRwResult.getMessage()), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
|
|
|
|
MesEquipmentVariable equipmentVariable = evMap.get(equipmentProdParamCfgOp.get().getEquipVariableId());
|
|
|
|
|
|
|
|
if (null == equipmentVariable) {
|
|
|
|
|
|
|
|
this.sendMessage(reqBean, resultBean.writeDbLog(), String.format("发送设备加工参数:设备加工参数信息ID[%s]关联的设备数据变量ID[%s]未维护有效的设备数据变量信息!", equipmentProdParamCfgOp.get().getId(), equipmentProdParamCfgOp.get().getEquipVariableId()), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//写值
|
|
|
|
|
|
|
|
MesEquipVariableRwResult equipVariableRwResult = equipVariableRwExtService.writeVariable(matchValue, equipmentVariable, cellEquipContext.getKepwareFlag(equipmentVariable.getChannel()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!equipVariableRwResult.getIsSuccessed()) {
|
|
|
|
|
|
|
|
this.sendMessage(reqBean, new StationResultBean().writeDbLog().checkRepeat(), String.format("设备[%s]:发送设备加工参数失败!原因:%s", cellEquipContext.getEquipmentName(), equipVariableRwResult.getMessage()), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.sendMessage(reqBean, new StationResultBean().writeDbLog(), String.format("设备[%s]:发送设备加工参数成功!%s", cellEquipContext.getEquipmentName(), equipVariableRwResult.getMessage()), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|