jx pcn plc pass step

dev
王杰 1 year ago
parent 8761faceb6
commit 920c81e4cd

@ -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);
}

@ -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;
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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;
}
}
}

@ -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);

@ -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";
}

Loading…
Cancel
Save