From 920c81e4cdadaeebe8726a28a1e9c89371c70f78 Mon Sep 17 00:00:00 2001 From: "jhforever.wang@estsh.com" Date: Thu, 23 Nov 2023 15:08:15 +0800 Subject: [PATCH] jx pcn plc pass step --- .../ext/mes/pcn/api/busi/jx/IJxPlcExtService.java | 40 +++++++++++++ .../serviceimpl/busi/jx/JxPlcExtService.java | 66 ++++++++++++++++++++++ .../jx/JxSnFinalInspectionModuleService.java | 14 +++++ .../busi/station/jx/JxSnLineOffModuleService.java | 14 +++++ .../busi/station/jx/JxSnLineOnModuleService.java | 14 +++++ .../station/jx/JxSnProcessingModuleService.java | 14 +++++ .../busi/step/jx/JxCenterPlcPassStepService.java | 45 ++++++++++++++- .../ext/mes/pcn/pojo/util/MesPcnExtConstWords.java | 6 +- 8 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java create mode 100644 modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java diff --git a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java new file mode 100644 index 0000000..0a9094f --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java @@ -0,0 +1,40 @@ +package cn.estsh.i3plus.ext.mes.pcn.api.busi.jx; + +import cn.estsh.i3plus.pojo.mes.bean.MesPlc; +import io.swagger.annotations.ApiOperation; + +/** + * @Author: wangjie + * @CreateDate: 2021/01/18 11:22 上午 + * @Description: + **/ +public interface IJxPlcExtService { + + /** + * 获取PLC信息 + * @param organizeCode 组织代码 + * @param plcCode PLC代码 + * @return 产品条码信息 + */ + @ApiOperation(value = "获取PLC信息", notes = "获取PLC信息") + MesPlc getPlcDb(String organizeCode, String plcCode); + + /** + * 读取PLC数据 + * @param plc PLC信息 + * @return PLC数据 + */ + @ApiOperation(value = "读取PLC数据", notes = "读取PLC数据") + Object doReadOpcParamValue(MesPlc plc); + + /** + * 写入PLC数据 + * @param plc PLC信息 + * @param value 数据 + * @return 结果 + */ + @ApiOperation(value = "写入PLC数据", notes = "写入PLC数据") + Boolean doWriteOpcParamValue(MesPlc plc, String value); + + +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java new file mode 100644 index 0000000..da7e30f --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java @@ -0,0 +1,66 @@ +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.jx; + +import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxPlcExtService; +import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import cn.estsh.i3plus.platform.plugin.opc.iservice.IOpcUAService; +import cn.estsh.i3plus.platform.plugin.opc.service.OpcUAService; +import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; +import cn.estsh.i3plus.pojo.hardswitch.bean.OpcUAParam; +import cn.estsh.i3plus.pojo.mes.bean.MesPlc; +import cn.estsh.i3plus.pojo.mes.repository.MesPlcRepository; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.text.MessageFormat; + +/** + * @Author: wangjie + * @CreateDate: 2021/01/18 11:41 上午 + * @Description: + **/ +@Slf4j +@Service +public class JxPlcExtService implements IJxPlcExtService { + + @Autowired + private MesPlcRepository plcRepository; + + @Override + public MesPlc getPlcDb(String organizeCode, String plcCode) { + if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(plcCode)) return null; + return plcRepository.getByProperty( + new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.PLC_CODE}, + new Object[]{organizeCode, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), plcCode}); + } + + @Override + public Object doReadOpcParamValue(MesPlc plc) { + IOpcUAService opcService = new OpcUAService(); + String tagAddress = MessageFormat.format("{0}.{1}.{2}", plc.getChannel(), plc.getDevice(), plc.getTagAddress()); + OpcUAParam opcParam = new OpcUAParam(); + opcParam.setServerUrl(plc.getOpcUrl()); + opcParam.setTagAddress(tagAddress); + opcParam.setNamespaceIndex(plc.getNameSpaceIndex()); + opcParam.setTagValueType(plc.getDataType()); + Object result = opcService.getOpcParamValue(opcParam); + opcService.disConnection(); + return result; + } + + @Override + public Boolean doWriteOpcParamValue(MesPlc plc, String value) { + IOpcUAService opcService = new OpcUAService(); + String tagAddress = MessageFormat.format("{0}.{1}.{2}", plc.getChannel(), plc.getDevice(), plc.getTagAddress()); + OpcUAParam opcParam = new OpcUAParam(); + opcParam.setServerUrl(plc.getOpcUrl()); + opcParam.setTagAddress(tagAddress); + opcParam.setNamespaceIndex(plc.getNameSpaceIndex()); + opcParam.setTagValueType(plc.getDataType()); + opcParam.setTagValue(value); + Boolean result = opcService.editOpcParamValue(opcParam); + opcService.disConnection(); + return result; + } +} \ No newline at end of file diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnFinalInspectionModuleService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnFinalInspectionModuleService.java index 1183471..818ae2f 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnFinalInspectionModuleService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnFinalInspectionModuleService.java @@ -236,4 +236,18 @@ public class JxSnFinalInspectionModuleService extends BaseModuleService { } } + public Object doHandlePlcData(StationRequestBean reqBean, String item, Integer flag, String plcData) { + switch (flag) { + case 1: + return redisMesPcn.getHash(getDataKey(reqBean), item); + case 2: + return redisMesPcn.putHash(getDataKey(reqBean), item, plcData, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue()); + case 3: + redisMesPcn.deleteHash(getDataKey(reqBean), item); + return true; + default: + return null; + } + } + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOffModuleService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOffModuleService.java index 96f0291..4a097a6 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOffModuleService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOffModuleService.java @@ -222,4 +222,18 @@ public class JxSnLineOffModuleService extends BaseModuleService { } } + public Object doHandlePlcData(StationRequestBean reqBean, String item, Integer flag, String plcData) { + switch (flag) { + case 1: + return redisMesPcn.getHash(getDataKey(reqBean), item); + case 2: + return redisMesPcn.putHash(getDataKey(reqBean), item, plcData, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue()); + case 3: + redisMesPcn.deleteHash(getDataKey(reqBean), item); + return true; + default: + return null; + } + } + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOnModuleService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOnModuleService.java index a4ba949..f06565b 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOnModuleService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnLineOnModuleService.java @@ -222,4 +222,18 @@ public class JxSnLineOnModuleService extends BaseModuleService { } } + public Object doHandlePlcData(StationRequestBean reqBean, String item, Integer flag, String plcData) { + switch (flag) { + case 1: + return redisMesPcn.getHash(getDataKey(reqBean), item); + case 2: + return redisMesPcn.putHash(getDataKey(reqBean), item, plcData, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue()); + case 3: + redisMesPcn.deleteHash(getDataKey(reqBean), item); + return true; + default: + return null; + } + } + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnProcessingModuleService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnProcessingModuleService.java index cff590f..070e1ab 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnProcessingModuleService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/station/jx/JxSnProcessingModuleService.java @@ -222,4 +222,18 @@ public class JxSnProcessingModuleService extends BaseModuleService { } } + public Object doHandlePlcData(StationRequestBean reqBean, String item, Integer flag, String plcData) { + switch (flag) { + case 1: + return redisMesPcn.getHash(getDataKey(reqBean), item); + case 2: + return redisMesPcn.putHash(getDataKey(reqBean), item, plcData, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue()); + case 3: + redisMesPcn.deleteHash(getDataKey(reqBean), item); + return true; + default: + return null; + } + } + } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxCenterPlcPassStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxCenterPlcPassStepService.java index 424d281..74098dc 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxCenterPlcPassStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxCenterPlcPassStepService.java @@ -1,14 +1,23 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.step.jx; +import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxPlcExtService; import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import cn.estsh.i3plus.mes.pcn.actor.shipping.dispatch.IFsmCommonService; +import cn.estsh.i3plus.mes.pcn.api.iservice.base.IModuleService; import cn.estsh.i3plus.mes.pcn.serviceimpl.base.BaseStepService; +import cn.estsh.i3plus.platform.common.util.MesPcnConstWords; +import cn.estsh.i3plus.pojo.mes.bean.MesPlc; 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 cn.estsh.impp.framework.boot.util.SpringContextsUtil; +import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; +import java.lang.reflect.Method; import java.util.StringJoiner; /** @@ -22,6 +31,12 @@ import java.util.StringJoiner; @Service("jxCenterPlcPassStepService") public class JxCenterPlcPassStepService extends BaseStepService { + @Autowired + private IFsmCommonService fsmCommonService; + + @Autowired + private IJxPlcExtService plcExtService; + @Override public StepResult execute(StationRequestBean reqBean) { @@ -33,7 +48,16 @@ public class JxCenterPlcPassStepService extends BaseStepService { Boolean forceCmd = reqBean.getDataMap().containsKey(forceCmdKey); if (forceCmd) reqBean.getDataMap().remove(forceCmdKey); - //通知PLC放行逻辑暂无 + fsmCommonService.checkWcpcMapForDoScan(reqBean); + String plcCode = fsmCommonService.getAndCheckWcpcMapIsContainsKey(reqBean, reqBean.getWcpcMap(), MesPcnExtConstWords.PLC_CODE_UC); + String plcPassValue = fsmCommonService.getAndCheckWcpcMapIsContainsKey(reqBean, reqBean.getWcpcMap(), MesPcnExtConstWords.PLC_PASS_VALUE); + if (StringUtils.isEmpty(plcCode) || StringUtils.isEmpty(plcPassValue)) foundExThrowNoShowMsg(); + + MesPlc plcDb = getPlcDb(reqBean, resultBean, plcCode); + if (null == plcDb) execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]工位参数[%s]值[%s]对应的PLC信息不存在!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), MesPcnExtConstWords.PLC_CODE_UC, plcCode)); + + if (!plcPassValue.equals("noplc") && !plcExtService.doWriteOpcParamValue(plcDb, plcPassValue)) + execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]%s放行失败:写入PLC[%s]值[%s]失败!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), !forceCmd ? MesPcnExtConstWords.EMPTY : "强制", plcCode, plcPassValue)); log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxCenterPlcPassStepService --- SUCCESS ---", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()); @@ -42,6 +66,25 @@ public class JxCenterPlcPassStepService extends BaseStepService { else return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean, "产线强制放行成功!"); } + private MesPlc getPlcDb(StationRequestBean reqBean, StationResultBean resultBean, String plcCode) { + String plcStr = (String) doHandlePlcData(reqBean, resultBean, plcCode, 1, null); + MesPlc plcDb = !StringUtils.isEmpty(plcStr) ? JSONObject.parseObject(plcStr, MesPlc.class) : plcExtService.getPlcDb(reqBean.getOrganizeCode(), plcCode); + if (StringUtils.isEmpty(plcStr) && null != plcDb) doHandlePlcData(reqBean, resultBean, plcCode, 2, JSONObject.toJSONString(plcDb)); + return plcDb; + } + + private Object doHandlePlcData(StationRequestBean reqBean, StationResultBean resultBean, String plcCode, Integer flag, String value) { + try { + IModuleService moduleService = (IModuleService) SpringContextsUtil.getBean(reqBean.getWcpcMap().get(MesPcnConstWords.MODULE_OBJECT)); + Method method = moduleService.getClass().getDeclaredMethod(MesPcnExtConstWords.doHandlePlcData, reqBean.getClass(), String.class, Integer.class, String.class); + method.setAccessible(true); + return method.invoke(moduleService, reqBean, new StringJoiner(MesPcnExtConstWords.COLON).add(MesPcnExtConstWords.PLC_CODE_UC).add(plcCode).toString(), flag, value); + } catch (Exception e) { + execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("执行展示组件内部方法[%s]参数[flag=%s,value=%s]出现异常:%s", MesPcnExtConstWords.doHandlePlcData, flag, value, e.getMessage())); + return null; + } + } + private String getManageCode(String manageCode, Integer length) { if (StringUtils.isEmpty(manageCode)) return null; String[] manageCodeArr = manageCode.split(MesPcnExtConstWords.AND); diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java index 0ed2c82..fc918c8 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/util/MesPcnExtConstWords.java @@ -264,6 +264,8 @@ public class MesPcnExtConstWords { //容器位置描述 public static final String LOCATION_DESC = "locationDesc"; //PLC代码 + public static final String PLC_CODE_UC = "PLC_CODE"; + //PLC代码 public static final String PLC_CODE = "plcCode"; //对象代码 public static final String OBJECT_CODE = "objectCode"; @@ -944,6 +946,7 @@ public class MesPcnExtConstWords { public static final String JX_SN_LINE_OFF_MODULE = "JX_SN_LINE_OFF_MODULE"; public static final String JX_SN_LINE_OFF_DATA = "JX_SN_LINE_OFF_DATA"; + public static final String doHandlePlcData = "doHandlePlcData"; public static final String doHandleBindKeyPartData = "doHandleBindKeyPartData"; public static final String doHandleSelectWorkOrderNo = "doHandleSelectWorkOrderNo"; public static final String doHandleCurExecWorkOrder = "doHandleCurExecWorkOrder"; @@ -1003,6 +1006,7 @@ public class MesPcnExtConstWords { //维修判定名称 public static final String REPAIR_JUDGE_NAME = "repairJudgeName"; - + //PLC放行值 + public static final String PLC_PASS_VALUE = "PLC_PASS_VALUE"; }