package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.step.ep;

import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.station.ep.EpPutPalletModuleService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.ep.EpPutPalletPlcDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.IShippingDispatchService;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.IStepCommonMethodService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.base.BaseStepService;
import cn.estsh.i3plus.mes.pcn.util.LocaleUtil;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.platform.common.util.MesPcnConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesPlc;
import cn.estsh.i3plus.pojo.mes.bean.MesProdRouteOptParam;
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.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.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Description : 工步业务-EP装托PLC模式读取产品信息工步
 * @Reference :
 * @Author : wangjie
 * @CreateDate : 2019-07-11
 * @Modify:
 **/
@Slf4j
@Service("epPutPalletPlcWorkReadProdStepService")
public class EpPutPalletPlcWorkReadProdStepService extends BaseStepService {

    @Autowired
    private EpPutPalletModuleService putPalletModuleService;

    @Autowired
    private IStepCommonMethodService stepCommonMethodService;

    @Autowired
    private MesPlcRepository plcRepository;

    @Autowired
    private IShippingDispatchService shippingDispatchService;

    //失败回到结束，成功进入检验PLC数据状态点，PLC_WORK进入满托校验状态点
    @Override
    public StepResult execute(StationRequestBean reqBean) {
        log.info("EpPutPalletPlcWorkReadProdStepService[execute] 参数：{}", reqBean);

        StationResultBean resultBean = new StationResultBean();
        String err;

        Map<String, MesProdRouteOptParam> stepParamMap = stepCommonMethodService.getStepCfgInfo(reqBean);
        if (CollectionUtils.isEmpty(stepParamMap)) {
            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]未配置必要工步参数[%s][%s][%s][%s][%s][%s][%s][%s][%s]"),
                    MesPcnExtConstWords.EP_PLC_PUT_PALLET_PROD_HAND_SHAKE_SIGNAL, MesPcnExtConstWords.EP_PLC_PUT_PALLET_PROD_DATA,
                    MesPcnExtConstWords.EP_PCN_PUT_PALLET_PROD_HAND_SHAKE_SIGNAL, MesPcnExtConstWords.EP_PCN_PUT_PALLET_PROD_DATA,
                    MesPcnExtConstWords.EP_PLC_PUT_PALLET_COMPLETE_HAND_SHAKE_SIGNAL, MesPcnExtConstWords.EP_PLC_PUT_PALLET_COMPLETE_DATA,
                    MesPcnExtConstWords.EP_PCN_PUT_PALLET_COMPLETE_HAND_SHAKE_SIGNAL, MesPcnExtConstWords.EP_PCN_PUT_PALLET_COMPLETE_DATA,
                    MesPcnExtConstWords.FORCE_SPEC_STEP_CODE);
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            foundExThrowNoShowMsg();
        }

        EpPutPalletPlcDataModel curExecPackageNoModel = (EpPutPalletPlcDataModel) putPalletModuleService.doHandleCacheCurExecPackageNo(reqBean, 1, null);
        if (null != curExecPackageNoModel && curExecPackageNoModel.getBoo()) {
            StepResult stepResult = StepResult.getNonComplete();
            stepResult.setNextTriggerEvent(MesPcnExtEnumUtil.EP_PUT_PALLET_PROD_TYPE.PLC_WORK.name());
            return stepResult;
        }

        EpPutPalletPlcDataModel plcDateModel = (EpPutPalletPlcDataModel) putPalletModuleService.doHandleCurPlcData(reqBean, 1, null);
        if (null != plcDateModel && !plcDateModel.getIsCheck()) {
            //获取到未被验证的PLC的产品组或完托组数据,直接进入下一个检验状态点
            return StepResult.getSuccessComplete();
        }

        String forceSpecStepCode = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.FORCE_SPEC_STEP_CODE, reqBean, resultBean);

        String plcProdHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PLC_PUT_PALLET_PROD_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        String plcProdData = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PLC_PUT_PALLET_PROD_DATA, reqBean, resultBean);
        String plcCompleteHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PLC_PUT_PALLET_COMPLETE_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        String plcCompleteData = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PLC_PUT_PALLET_COMPLETE_DATA, reqBean, resultBean);

        String pcnProdHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PCN_PUT_PALLET_PROD_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        String pcnProdData = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PCN_PUT_PALLET_PROD_DATA, reqBean, resultBean);
        String pcnCompleteHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PCN_PUT_PALLET_COMPLETE_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        String pcnCompleteData = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.EP_PCN_PUT_PALLET_COMPLETE_DATA, reqBean, resultBean);

        MesPlc plcProdHandShakeSignalPlc = getPlc(plcProdHandShakeSignal, MesPcnExtConstWords.EP_PLC_PUT_PALLET_PROD_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        MesPlc plcProdDataPlc = getPlc(plcProdData, MesPcnExtConstWords.EP_PLC_PUT_PALLET_PROD_DATA, reqBean, resultBean);
        MesPlc plcCompleteHandShakeSignalPlc = getPlc(plcCompleteHandShakeSignal, MesPcnExtConstWords.EP_PLC_PUT_PALLET_COMPLETE_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        MesPlc plcCompleteDataPlc = getPlc(plcCompleteData, MesPcnExtConstWords.EP_PLC_PUT_PALLET_COMPLETE_DATA, reqBean, resultBean);

        MesPlc pcnProdHandShakeSignalPlc = getPlc(pcnProdHandShakeSignal, MesPcnExtConstWords.EP_PCN_PUT_PALLET_PROD_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        MesPlc pcnProdDataPlc = getPlc(pcnProdData, MesPcnExtConstWords.EP_PCN_PUT_PALLET_PROD_DATA, reqBean, resultBean);
        MesPlc pcnCompleteHandShakeSignalPlc = getPlc(pcnCompleteHandShakeSignal, MesPcnExtConstWords.EP_PCN_PUT_PALLET_COMPLETE_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        MesPlc pcnCompleteDataPlc = getPlc(pcnCompleteData, MesPcnExtConstWords.EP_PCN_PUT_PALLET_COMPLETE_DATA, reqBean, resultBean);

        Integer value1, value3;
        String value2, value4;
        Boolean boo1, boo2;
        //判断当前是否存在握手
        Integer curExcePlcTask = (Integer) putPalletModuleService.doHandleCurExecPlcTask(reqBean, 1, null);
        if (!StringUtils.isEmpty(curExcePlcTask)) {
            if (CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == curExcePlcTask) {
                //产品握手
                try {
                    value1 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(plcProdHandShakeSignalPlc).toString());
                    value2 = (String) putPalletModuleService.doReadOpcParamValue(plcProdDataPlc);
                    value3 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(pcnProdHandShakeSignalPlc).toString());
                    value4 = (String) putPalletModuleService.doReadOpcParamValue(pcnProdDataPlc);

                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步][CUR_EXEC_PLC_TASK]PCN读取产品组PLC地址位[%s][%s][%s][%s]值分别为[%s][%s][%s][%s]"),
                            plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress(), pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress(), value1, value2, value3, value4);
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                } catch (Exception e) {
//                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取产品组PLC地址位发生异常:[%s]"), e.getMessage());
//                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s][%s][%s]发生异常:[%s]"),
                            plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress(), pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress(), e.getMessage());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return StepResult.getNonComplete(err);
                }
                if (StringUtils.isEmpty(value1) || StringUtils.isEmpty(value2) || StringUtils.isEmpty(value3) || StringUtils.isEmpty(value4)) {
//                    err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取产品组PLC地址位存在空数据,请检查");
//                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s][%s][%s]存在空数据,请检查"),
                            plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress(), pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return StepResult.getNonComplete(err);
                }
                if (value1 == 0 && value2.equals("0")) {
                    err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品组数据PLC地址已复位成功");
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

                    try {
                        if (!value3.equals("0")) {
                            boo1 = putPalletModuleService.doWriteOpcParamValue(pcnProdHandShakeSignalPlc, "0");
                        } else {
                            boo1 = true;
                        }
                        if (!value4.equals("0")) {
                            boo2 = putPalletModuleService.doWriteOpcParamValue(pcnProdDataPlc, "0");
                        } else {
                            boo2 = true;
                        }
                    } catch (Exception e) {
//                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN复位产品组PLC地址位值为[0]时发生异常:[%s]"), e.getMessage());
//                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN复位产品组PLC地址位[%s][%s]值为[0]时发生异常:[%s]"),
                                pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress(), e.getMessage());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    }
                    if (boo1 && boo2) {
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN复位产品组PLC地址位[%s][%s]值为[0]成功"),
                                pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

                        putPalletModuleService.doHandleCurExecPlcTask(reqBean, 3, null);
                        putPalletModuleService.doHandleCurPlcData(reqBean, 3, null);

                        if (null != plcDateModel && plcDateModel.getBoo() && plcDateModel.getIsCheck() &&
                                !StringUtils.isEmpty(plcDateModel.getCtNo()) && !StringUtils.isEmpty(plcDateModel.getPackageNo())) {

                            if (null == curExecPackageNoModel ||
                                    (!curExecPackageNoModel.getPackageNo().equals(plcDateModel.getPackageNo()) || null == curExecPackageNoModel.getPutPalletModuleModel())) {
                                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "产品握手成功!但缓存缺失有效的[CUR_EXEC_PACKAGE_NO]数据,本次产品指令执行失败");
                                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                                return StepResult.getNonComplete(err);
                            }

                            EpPutPalletPlcDataModel curCtNoModel = (EpPutPalletPlcDataModel) putPalletModuleService.doHandleCurCtNo(reqBean, 1, null);
                            if (null == curCtNoModel || !curCtNoModel.getCtNo().equals(plcDateModel.getCtNo())) {
                                curCtNoModel = new EpPutPalletPlcDataModel();
                                curCtNoModel.setCtNo(plcDateModel.getCtNo());
                                curCtNoModel.setBoo(true);
                                curCtNoModel.setReadDatetime(TimeTool.getNowTime(true));
                                putPalletModuleService.doHandleCurCtNo(reqBean, 2, curCtNoModel);
                            } else {
                                if (!curCtNoModel.getBoo()) {
                                    curCtNoModel.setBoo(true);
                                    putPalletModuleService.doHandleCurCtNo(reqBean, 2, curCtNoModel);
                                }
                            }

                            if ((Boolean) putPalletModuleService.doHandlePackageDataByCtNo(reqBean, plcDateModel.getCtNo(), 2, curExecPackageNoModel.getPutPalletModuleModel())) {
                                curExecPackageNoModel.setBoo(true);
                                putPalletModuleService.doHandleCacheCurExecPackageNo(reqBean, 2, curExecPackageNoModel);

                                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "产品握手成功!即将执行满托校验...");
                                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                                StepResult stepResult = StepResult.getNonComplete();
                                stepResult.setNextTriggerEvent(MesPcnExtEnumUtil.EP_PUT_PALLET_PROD_TYPE.PLC_WORK.name());
                                return stepResult;
                            } else {
                                putPalletModuleService.doHandleCacheCurExecPackageNo(reqBean, 3, null);
                                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "产品握手成功!但缓存数据[CUR_EXEC_PACKAGE_NO]执行装托失败,本次产品指令执行失败");
                                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                                return StepResult.getNonComplete(err);
                            }
                        }

                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品握手成功!产品异常,本次产品指令执行失败");
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    } else {
//                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN复位产品组PLC地址位值为[0]失败");
//                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN复位产品组PLC地址位[%s][%s]值为[0]失败"),
                                pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    }
                } else {
                    if (value3 == 0 && value4.equals("0")) {
                        putPalletModuleService.doHandleCurExecPlcTask(reqBean, 3, null);
                        putPalletModuleService.doHandleCurPlcData(reqBean, 3, null);
                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品组数据位存在数据,但PCN对应的数据位值是0,已删除[CUR_EXEC_PLC_TASK]缓存,将重新获取数据");
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                        return StepResult.getNonComplete(err);
                    } else {
                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]监听产品组数据PLC地址复位中...");
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                        return StepResult.getNonComplete(err);
                    }
                }
            } else {
                //完托握手
                try {
                    value1 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(plcCompleteHandShakeSignalPlc).toString());
                    value2 = (String) putPalletModuleService.doReadOpcParamValue(plcCompleteDataPlc);
                    value3 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(pcnCompleteHandShakeSignalPlc).toString());
                    value4 = (String) putPalletModuleService.doReadOpcParamValue(pcnCompleteDataPlc);

                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步][CUR_EXEC_PLC_TASK]PCN读取完托组PLC地址位[%s][%s][%s][%s]值分别为[%s][%s][%s][%s]"),
                            plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress(), pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress(), value1, value2, value3, value4);
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                } catch (Exception e) {
//                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取完托组PLC地址位发生异常:[%s]"), e.getMessage());
//                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取完托组PLC地址位[%s][%s][%s][%s]发生异常:[%s]"),
                            plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress(), pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress(), e.getMessage());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return StepResult.getNonComplete(err);
                }
                if (StringUtils.isEmpty(value1) || StringUtils.isEmpty(value2) || StringUtils.isEmpty(value3) || StringUtils.isEmpty(value4)) {
//                    err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取完托组PLC地址位存在空数据,请检查");
//                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取完托组PLC地址位[%s][%s][%s][%s]存在空数据,请检查"),
                            plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress(), pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return StepResult.getNonComplete(err);
                }
                if (value1 == 0 && value2.equals("0")) {
                    err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托组数据PLC地址已复位成功");
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

                    try {
                        if (!value3.equals("0")) {
                            boo1 = putPalletModuleService.doWriteOpcParamValue(pcnCompleteHandShakeSignalPlc, "0");
                        } else {
                            boo1 = true;
                        }
                        if (!value4.equals("0")) {
                            boo2 = putPalletModuleService.doWriteOpcParamValue(pcnCompleteDataPlc, "0");
                        } else {
                            boo2 = true;
                        }
                    } catch (Exception e) {
//                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN复位完托组PLC地址位值为[0]时发生异常:[%s]"), e.getMessage());
//                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN复位完托组PLC地址位[%s][%s]值为[0]时发生异常:[%s]"),
                                pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress(), e.getMessage());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    }
                    if (boo1 && boo2) {
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN复位完托组PLC地址位[%s][%s]值为[0]成功"),
                                pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

                        putPalletModuleService.doHandleCurExecPlcTask(reqBean, 3, null);
                        putPalletModuleService.doHandleCurPlcData(reqBean, 3, null);

                        if (null != plcDateModel && plcDateModel.getBoo() && plcDateModel.getIsCheck() &&
                                StringUtils.isEmpty(plcDateModel.getCtNo()) && StringUtils.isEmpty(plcDateModel.getPackageNo())) {
                            //执行强制装托
                            reqBean.setClientInfo(shippingDispatchService.getActorClientInfo(reqBean));
                            reqBean.setInterfaceType(MesPcnConstWords.SHIPPING);
                            reqBean.setBusiType(MesPcnConstWords.WS_CMD_DO_SCAN);
                            reqBean.setForceSpecStepCode(forceSpecStepCode);
                            shippingDispatchService.doSendScanQueueNextExec(reqBean);
                            err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "完托握手成功!即将执行强制完成装托...");
                            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                            foundExThrowNoShowMsg();
                        }
                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托握手成功!托盘异常,本次完托指令执行失败");
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    } else {
//                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN复位完托组PLC地址位值为[0]失败");
//                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN复位完托组PLC地址位[%s][%s]值为[0]失败"),
                                pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    }
                } else {
                    if (value3 == 0 && value4.equals("0")) {
                        putPalletModuleService.doHandleCurExecPlcTask(reqBean, 3, null);
                        putPalletModuleService.doHandleCurPlcData(reqBean, 3, null);
                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托组数据位存在数据,但PCN对应的数据位值是0,已删除[CUR_EXEC_PLC_TASK]缓存,将重新获取数据");
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                        return StepResult.getNonComplete(err);
                    } else {
                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]监听完托组数据PLC地址复位中...");
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                        return StepResult.getNonComplete(err);
                    }
                }
            }
        }

        String cmdPlcPutPallet = (String) putPalletModuleService.doHandleCmdPlcPutPallet(reqBean, 1, null);
        //没有必要完托信号,先获取产品组,再获取完托组
        if (StringUtils.isEmpty(cmdPlcPutPallet)) {
            //产品组
            try {
                value1 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(plcProdHandShakeSignalPlc).toString());
                value2 = (String) putPalletModuleService.doReadOpcParamValue(plcProdDataPlc);
                value3 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(pcnProdHandShakeSignalPlc).toString());
                value4 = (String) putPalletModuleService.doReadOpcParamValue(pcnProdDataPlc);

                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s][%s][%s]值分别为[%s][%s][%s][%s]"),
                        plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress(), pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress(), value1, value2, value3, value4);
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            } catch (Exception e) {
//                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取产品组PLC地址位发生异常:[%s]"), e.getMessage());
//                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s][%s][%s]发生异常:[%s]"),
                        plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress(), pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress(), e.getMessage());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }
            if (StringUtils.isEmpty(value1) || StringUtils.isEmpty(value2) || StringUtils.isEmpty(value3) || StringUtils.isEmpty(value4)) {
//                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取产品组PLC地址位存在空数据,请检查");
//                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s][%s][%s]存在空数据,请检查"),
                        plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress(), pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }
            if (value1 == 1 && !value2.equals("0")) {
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品组数据PLC地址已写入成功");
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

                if (value3 != 0 && !value4.equals("0")) {
                    err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品组数据位存在数据,但PCN对应的数据位不是复位状态,即将尝试先复位,后重新获取数据");
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);

                    try {
                        boo1 = putPalletModuleService.doWriteOpcParamValue(pcnProdHandShakeSignalPlc, "0");
                        boo2 = putPalletModuleService.doWriteOpcParamValue(pcnProdDataPlc, "0");
                    } catch (Exception e) {
//                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "产品组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位值为[0]时发生异常:[%s]"), e.getMessage());
//                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位[%s][%s]值为[0]时发生异常:[%s]"),
                                pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress(), e.getMessage());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    }
                    if (!boo1 || !boo2) {
//                        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "产品组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位值为[0]时失败");
//                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]产品组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位[%s][%s]值为[0]时失败"),
                                pcnProdHandShakeSignalPlc.getTagAddress(), pcnProdDataPlc.getTagAddress());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return StepResult.getNonComplete(err);
                    }
                } else {
                    String[] prodDataArr = value2.split(MesPcnExtConstWords.COMMA);
                    if (null == prodDataArr || prodDataArr.length != 2) {
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s]未获取到有效的产品组数据,持续监听中..."),
                                plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress());
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                        //接着获取完托组
                    } else {
                        putPalletModuleService.doHandleCurExecPlcTask(reqBean, 2, CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
                        plcDateModel = new EpPutPalletPlcDataModel();
                        plcDateModel.setCtNo(prodDataArr[0]);
                        plcDateModel.setPackageNo(prodDataArr[1]);
                        plcDateModel.setReadDatetime(TimeTool.getNowTime(true));
                        plcDateModel.setBoo(false);
                        plcDateModel.setIsCheck(false);
                        putPalletModuleService.doHandleCurPlcData(reqBean, 2, plcDateModel);

                        return StepResult.getSuccessComplete();
                    }
                }
            } else {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取产品组PLC地址位[%s][%s]未获取到有效的产品组数据,持续监听中..."),
                        plcProdHandShakeSignalPlc.getTagAddress(), plcProdDataPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                //接着获取完托组
            }
        }

        //完托组
        try {
            value1 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(plcCompleteHandShakeSignalPlc).toString());
            value2 = (String) putPalletModuleService.doReadOpcParamValue(plcCompleteDataPlc);
            value3 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(pcnCompleteHandShakeSignalPlc).toString());
            value4 = (String) putPalletModuleService.doReadOpcParamValue(pcnCompleteDataPlc);

            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取完托组PLC地址位[%s][%s][%s][%s]值分别为[%s][%s][%s][%s]"),
                    plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress(), pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress(), value1, value2, value3, value4);
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
        } catch (Exception e) {
//            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取完托组PLC地址位发生异常:[%s]"), e.getMessage());
//            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取完托组PLC地址位[%s][%s][%s][%s]发生异常:[%s]"),
                    plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress(), pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress(), e.getMessage());
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            return StepResult.getNonComplete(err);
        }
        if (StringUtils.isEmpty(value1) || StringUtils.isEmpty(value2) || StringUtils.isEmpty(value3) || StringUtils.isEmpty(value4)) {
//            err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN读取完托组PLC地址位存在空数据,请检查");
//            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取完托组PLC地址位[%s][%s][%s][%s]存在空数据,请检查"),
                    plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress(), pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress());
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            return StepResult.getNonComplete(err);
        }

        if (value1 == 1 && !value2.equals("0")) {
            err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托组数据PLC地址已写入成功");
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

            if (value3 != 0 && !value4.equals("0")) {
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托组数据位存在数据,但PCN对应的数据位不是复位状态,即将尝试先复位,后重新获取数据");
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);

                try {
                    boo1 = putPalletModuleService.doWriteOpcParamValue(pcnCompleteHandShakeSignalPlc, "0");
                    boo2 = putPalletModuleService.doWriteOpcParamValue(pcnCompleteDataPlc, "0");
                } catch (Exception e) {
//                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "完托组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位值为[0]时发生异常:[%s]"), e.getMessage());
//                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位[%s][%s]值为[0]时发生异常:[%s]"),
                            pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress(), e.getMessage());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return StepResult.getNonComplete(err);
                }
                if (!boo1 || !boo2) {
//                    err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "完托组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位值为[0]时失败");
//                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]完托组数据位存在数据,但PCN对应的数据位不是复位状态,尝试复位PLC地址位[%s][%s]值为[0]时失败"),
                            pcnCompleteHandShakeSignalPlc.getTagAddress(), pcnCompleteDataPlc.getTagAddress());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return StepResult.getNonComplete(err);
                }
            } else {
                putPalletModuleService.doHandleCurExecPlcTask(reqBean, 2, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());

                plcDateModel = new EpPutPalletPlcDataModel();
                plcDateModel.setReadDatetime(TimeTool.getNowTime(true));
                plcDateModel.setBoo(false);
                plcDateModel.setIsCheck(false);
                putPalletModuleService.doHandleCurPlcData(reqBean, 2, plcDateModel);
                return StepResult.getSuccessComplete();
            }
        } else {
            if (StringUtils.isEmpty(cmdPlcPutPallet)) {
//                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN正在监听PLC地址位中的产品组或完托组数据...");
//                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]PCN读取完托组PLC地址位[%s][%s]未获取到有效的完托组数据,持续监听中..."),
                        plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            } else {
//                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "当前容器已满托!PCN正在监听完托组PLC地址位中的完托组数据...");
//                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]当前容器已满托!PCN读取完托组PLC地址位[%s][%s]未获取到有效的完托组数据,持续监听中..."),
                        plcCompleteHandShakeSignalPlc.getTagAddress(), plcCompleteDataPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            }
            return StepResult.getNonComplete(err);
        }

        err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]持续监听中...");
        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
        return StepResult.getNonComplete(err);
    }

    private String getValueByStepParamMap(Map<String, MesProdRouteOptParam> stepParamMap, String code, StationRequestBean reqBean, StationResultBean resultBean) {
        String value = null;
        if (!CollectionUtils.isEmpty(stepParamMap) && stepParamMap.containsKey(code)
                && !StringUtils.isEmpty(stepParamMap.get(code).getParamValue())) {
            value = stepParamMap.get(code).getParamValue();
        }
        if (StringUtils.isEmpty(value)) {
            String err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[装托PLC模式读取产品信息工步]未配置必要工步参数[%s]"), code);
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            foundExThrowNoShowMsg();
        }
        return value;
    }

    public MesPlc getPlc(String paramValue, String code, StationRequestBean reqBean, StationResultBean resultBean) {
        MesPlc plc = (MesPlc) putPalletModuleService.doHandleCachePlc(reqBean, 1, code, null);
        if (null == plc) {
            plc = plcRepository.getByProperty(
                    new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.PLC_CODE},
                    new Object[]{reqBean.getOrganizeCode(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), paramValue});
            if (null != plc) {
                putPalletModuleService.doHandleCachePlc(reqBean, 2, code, plc);
            } else {
                String err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PLC[%s]在数据库不存在"), paramValue);
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                foundExThrowNoShowMsg();
            }
        }
        return plc;
    }

}
