发送指令 bug 处理 可能存在多个点位

tags/yfai-pcn-ext-v1.0
王杰 11 months ago
parent 14aa4fde0b
commit 1cfac89842

@ -82,12 +82,10 @@ public class MesEquipmentRwExtService implements IMesEquipVariableRwExtService {
params.put(MesPcnExtConstWords.CLIENT_HANDLE, equipVariableRwModel.getClientHandle().toString());
params.put(MesPcnExtConstWords.CHANNEL, equipVariableRwModel.getChannel());
params.put(MesPcnExtConstWords.EQUIPMENT_ID, equipVariableRwModel.getEquipId().toString());
LOGGER.info("设备数据变量写值开始-> 地址:{}, params={}", equipVariableRwModel.getWriteRequestUrl(), params);
String data = HttpClientTool.doHttpUrl(CommonEnumUtil.HTTP_METHOD_TYPE.POST, false, equipVariableRwModel.getWriteRequestUrl(), params, null, null);
LOGGER.info("设备数据变量写值返回-> data:{} ", data);
if (!StringUtils.isEmpty(data)) return JsonUtilTool.decode(data, MesEquipVariableRwResult.class);
else return result.noSuccessed().message(String.format("设备数据变量写值失败! 数据信息:[%s]!", JSONObject.toJSONString(equipVariableRwModel)));
if (!StringUtils.isEmpty(data)) return JsonUtilTool.decode(data, MesEquipVariableRwResult.class).obj(JSONObject.toJSONString(equipVariableRwModel));
else return result.noSuccessed().message(String.format("设备数据变量写值失败! CLIENT_HANDLE[%s] CHANNEL[%s] EQUIPMENT_ID[%s] VALUE[%s]",
equipVariableRwModel.getClientHandle(), equipVariableRwModel.getChannel(), equipVariableRwModel.getEquipId(), equipVariableRwModel.getValue())).obj(JSONObject.toJSONString(equipVariableRwModel));
}

@ -0,0 +1,75 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProduceSnExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCell;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
import cn.estsh.i3plus.pojo.mes.model.StepResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @Description : 线
* @Author : wangjie
**/
@Slf4j
@Service("mesProdCraftRouteCheckStepService")
public class MesProdCraftRouteCheckStepService extends BaseStepService {
@Autowired
private IMesProductionProcessContextStepService productionProcessContextStepService;
@Autowired
private IMesProductionDispatchContextStepService productionDispatchContextStepService;
@Autowired
private IMesProduceSnExtService produceSnExtService;
@Override
public StepResult execute(StationRequestBean reqBean) {
StationResultBean resultBean = new StationResultBean();
StepResult stepResult = StepResult.getSuccessComplete();
//获取上下文信息
MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean);
//获取生产过程上下文对象有异常信息 抛出异常
if (!productionProcessContext.getSuccess()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage());
//存储生产过程上下文对象
productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext);
//从上下文中取出生产线对象
MesWorkCenter workCenter = productionProcessContext.getWorkCenter();
//从上下文中取出工位对象
MesWorkCell workCell = productionProcessContext.getWorkCell();
return stepResult;
}
}

@ -25,6 +25,7 @@ import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @Description :
@ -86,23 +87,28 @@ public class MesSendInitializationCmdStepService extends BaseStepService {
productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext);
//发送数据给设备的数据变量
return execSendInitializationCmd(reqBean, resultBean, stepParamMap, stepResult, cellEquipContext, equipmentVariableCfgList.get(0), equipmentVariableList.get(0), cellEquipContext.getKepwareFlag(equipmentVariableList.get(0).getChannel()));
return execSendInitializationCmd(reqBean, resultBean, stepParamMap, stepResult, cellEquipContext, equipmentVariableCfgList, equipmentVariableList, cellEquipContext.getKepwareFlag(equipmentVariableList.get(0).getChannel()));
}
private StepResult execSendInitializationCmd(StationRequestBean reqBean, StationResultBean resultBean, Optional<Map<String, MesProdRouteOptParam>> stepParamMap, StepResult stepResult,
MesCellEquipContext cellEquipContext, MesEquipmentVariableCfg equipmentVariableCfg, MesEquipmentVariable equipmentVariable, String kepwareFlag) {
MesCellEquipContext cellEquipContext, List<MesEquipmentVariableCfg> equipmentVariableCfgList, List<MesEquipmentVariable> equipmentVariableList, String kepwareFlag) {
//最大重试次数[工步参数]
Integer maxRetryTimes = getMaxRetryTimes(stepParamMap);
MesEquipVariableRwResult equipVariableRwResult;
MesEquipVariableRwResult equipVariableRwResult = null;
Map<String, List<MesEquipmentVariableCfg>> categoryLevelTwoMap = equipmentVariableCfgList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesEquipmentVariableCfg::getCategoryLevelTwo));
for (int i = 1; i <= maxRetryTimes; i ++) {
//写值
equipVariableRwResult = equipVariableRwExtService.writeVariable(equipmentVariableCfg, equipmentVariable, kepwareFlag);
this.sendMessage(reqBean, resultBean, JSONObject.toJSONString(equipVariableRwResult), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
for (MesEquipmentVariable equipmentVariable : equipmentVariableList) {
equipVariableRwResult = equipVariableRwExtService.writeVariable(categoryLevelTwoMap.get(equipmentVariable.getCategoryLevelTwo()).get(0), equipmentVariable, kepwareFlag);
this.sendMessage(reqBean, resultBean, JSONObject.toJSONString(equipVariableRwResult), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
if (!equipVariableRwResult.getIsSuccessed()) break;
}
if (!equipVariableRwResult.getIsSuccessed() && equipVariableRwResult.getIsNoCfg()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("设备[%s]:初始化指令发送失败!原因:%s", cellEquipContext.getEquipmentCode(), equipVariableRwResult.getMessage()));

@ -25,6 +25,7 @@ import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @Description :
@ -89,20 +90,53 @@ public class MesSendProcessCmdStepService extends BaseStepService {
productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext);
//发送数据给设备的数据变量
MesEquipVariableRwResult equipVariableRwResult = equipVariableRwExtService.writeVariable(equipmentVariableCfgList.get(0), equipmentVariableList.get(0), cellEquipContext.getKepwareFlag(equipmentVariableList.get(0).getChannel()));
this.sendMessage(reqBean, resultBean, JSONObject.toJSONString(equipVariableRwResult), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
return execSendProcessCmd(reqBean, resultBean, stepParamMap, stepResult, cellEquipContext, equipmentVariableCfgList, equipmentVariableList, cellEquipContext.getKepwareFlag(equipmentVariableList.get(0).getChannel()));
if (!equipVariableRwResult.getIsSuccessed() && equipVariableRwResult.getIsNoCfg()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("设备[%s]:初始化指令发送失败!原因:%s", cellEquipContext.getEquipmentCode(), equipVariableRwResult.getMessage()));
}
private StepResult execSendProcessCmd(StationRequestBean reqBean, StationResultBean resultBean, Optional<Map<String, MesProdRouteOptParam>> stepParamMap, StepResult stepResult,
MesCellEquipContext cellEquipContext, List<MesEquipmentVariableCfg> equipmentVariableCfgList, List<MesEquipmentVariable> equipmentVariableList, String kepwareFlag) {
//最大重试次数[工步参数]
Integer maxRetryTimes = getMaxRetryTimes(stepParamMap);
MesEquipVariableRwResult equipVariableRwResult = null;
Map<String, List<MesEquipmentVariableCfg>> categoryLevelTwoMap = equipmentVariableCfgList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesEquipmentVariableCfg::getCategoryLevelTwo));
for (int i = 1; i <= maxRetryTimes; i ++) {
//写值
for (MesEquipmentVariable equipmentVariable : equipmentVariableList) {
equipVariableRwResult = equipVariableRwExtService.writeVariable(categoryLevelTwoMap.get(equipmentVariable.getCategoryLevelTwo()).get(0), equipmentVariable, kepwareFlag);
this.sendMessage(reqBean, resultBean, JSONObject.toJSONString(equipVariableRwResult), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
if (!equipVariableRwResult.getIsSuccessed()) break;
}
//保存设备当前一轮工序的发送允许加工指令, 写接口逻辑参考值
if (equipVariableRwResult.getIsSuccessed()) productionDispatchContextStepService.saveSendProcessCmdContext(reqBean, equipmentVariableCfgList.get(0).getValue());
if (!equipVariableRwResult.getIsSuccessed() && equipVariableRwResult.getIsNoCfg()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("设备[%s]:允许加工指令发送失败!原因:%s", cellEquipContext.getEquipmentCode(), equipVariableRwResult.getMessage()));
if (!equipVariableRwResult.getIsSuccessed())
execThreadSleepAndSendTaskCompleteAndThrowEx(reqBean, resultBean.writeDbLog(), stepResult.isCompleted(false).msg(String.format("设备[%s]:允许加工指令发送失败!原因:%s", cellEquipContext.getEquipmentCode(), equipVariableRwResult.getMessage())),
MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT, stepParamMap, MesPcnExtConstWords.READ_FAILURE_SLEEP, MesPcnExtConstWords.READ_FAILURE_SLEEP_DEFAULT_TIME);
if (equipVariableRwResult.getIsSuccessed()) return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, String.format("设备[%s]:允许加工指令发送成功!", cellEquipContext.getEquipmentCode()));
return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, String.format("设备[%s]:允许加工指令发送成功!", cellEquipContext.getEquipmentCode()));
execNonCompleteAndSendMsg(reqBean, resultBean.writeDbLog(), stepResult, String.format("设备[%s]:允许加工指令发送失败!累计次数[%s]!原因:%s", cellEquipContext.getEquipmentCode(), i, equipVariableRwResult.getMessage()));
//每失败一次 睡眠
if (i != maxRetryTimes) threadSleep(stepParamMap, MesPcnExtConstWords.READ_FAILURE_SLEEP, MesPcnExtConstWords.READ_FAILURE_SLEEP_DEFAULT_TIME);
}
execSendTaskCompleteAndThrowEx(reqBean, stepResult, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
return stepResult;
}
//最大重试次数[工步参数]
private Integer getMaxRetryTimes(Optional<Map<String, MesProdRouteOptParam>> stepParamMap) {
Integer maxRetryTimes = null;
try {
maxRetryTimes = (null != stepParamMap && stepParamMap.isPresent() && stepParamMap.get().containsKey(MesPcnExtConstWords.MAX_RETRY_TIMES)) ? Integer.valueOf(stepParamMap.get().get(MesPcnExtConstWords.MAX_RETRY_TIMES).getParamValue()) : null;
} catch (NumberFormatException e) {
}
return !StringUtils.isEmpty(maxRetryTimes) ? maxRetryTimes : MesPcnExtConstWords.MAX_RETRY_TIMES_DEFAULT;
}
}

Loading…
Cancel
Save