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

import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.WorkCenterContainerLocationService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.station.SxPutPalletModuleService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesWorkCenterContainerLocation;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxPutPalletPlcDataModel;
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.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.pojo.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesContainer;
import cn.estsh.i3plus.pojo.mes.bean.MesPartContainerCapacity;
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 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.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Description : 工步业务-本体装托PLC模式读取容器代码工步
 * @Reference :
 * @Author : wangjie
 * @CreateDate : 2019-07-11
 * @Modify:
 **/
@Slf4j
@Service("sxPutPalletPlcWorkReadCtNoStepService")
public class SxPutPalletPlcWorkReadCtNoStepService extends BaseStepService {

    @Autowired
    private SxPutPalletModuleService putPalletModuleService;

    @Autowired
    private IStepCommonMethodService stepCommonMethodService;

    @Autowired
    private SxPutPalletInitProdTypeStepService putPalletInitProdTypeStepService;

    @Autowired
    private WorkCenterContainerLocationService workCenterContainerLocationService;

    @Override
    public StepResult execute(StationRequestBean reqBean) {
        log.info("SxPutPalletPlcWorkReadCtNoStepService[execute] 参数：{}", reqBean);

        StationResultBean resultBean = new StationResultBean();
        String err;

        SxPutPalletPlcDataModel curCtNoModel = (SxPutPalletPlcDataModel) putPalletModuleService.doHandleCurCtNo(reqBean, 1, null);
        if (null != curCtNoModel && curCtNoModel.getBoo()) {

            //判断是否需要重新获取标准容量
            Integer ctQty = (Integer) putPalletModuleService.doHandleCurCtQty(reqBean, 1, null);
            if (StringUtils.isEmpty(ctQty) || ctQty.compareTo(0) == 0) {
                String curPartNo = (String) putPalletModuleService.doHandleCurPartNo(reqBean, 1, null);

                MesContainer container = workCenterContainerLocationService.getContainerByCtNo(reqBean.getOrganizeCode(), curCtNoModel.getCtNo());
                if (null == container) {
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PLC重新获取标准容量:当前缓存的容器代码[%s]无效"), curCtNoModel.getCtNo());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    putPalletModuleService.doHandleCurCtNo(reqBean, 3, null);
                    return StepResult.getNonComplete(err);
                }
                if (String.valueOf(MesPcnEnumUtil.MES_CONTAINER_STATUS.OCCUPY.getValue()).equals(container.getUseStatus())) {
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PLC重新获取标准容量:当前缓存的容器代码[%s]的当前状态为[占用]"), container.getCtNo());
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    putPalletModuleService.doHandleCurCtNo(reqBean, 3, null);
                    return StepResult.getNonComplete(err);
                }
                MesPartContainerCapacity partContainerCapacity = workCenterContainerLocationService.getPartContainerCapacity(reqBean.getOrganizeCode(), container.getCtCode(), curPartNo);
                if (null != partContainerCapacity) {
                    if (StringUtils.isEmpty(partContainerCapacity.getCtQty()) || partContainerCapacity.getCtQty().compareTo(0) == 0) {
                        err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(),
                                "PLC重新获取标准容量:当前缓存的容器代码[%s]对应的容器类型[%s]与物料编码[%s]在产品容器容量配置信息中未配置容量"), container.getCtNo(), container.getCtCode(), curPartNo);
                        this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        putPalletModuleService.doHandleCurCtNo(reqBean, 3, null);
                        return StepResult.getNonComplete(err);
                    }
                    putPalletModuleService.doHandleCurCtQty(reqBean, 2, partContainerCapacity.getCtQty());
                } else {
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PLC重新获取标准容量:当前缓存的容器代码[%s]对应的容器类型[%s]与物料编码[%s]未配置产品容器容量信息"),
                            container.getCtNo(), container.getCtCode(), curPartNo);
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    putPalletModuleService.doHandleCurCtNo(reqBean, 3, null);
                    return StepResult.getNonComplete(err);
                }
            }

            return StepResult.getSuccessComplete();
        }

        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]"),
                    MesPcnExtConstWords.PLC_LEFT_LOCATION_HAND_SHAKE_SIGNAL, MesPcnExtConstWords.PLC_LEFT_LOCATION_CT_NO, MesPcnExtConstWords.PCN_LEFT_LOCATION_HAND_SHAKE_SIGNAL,
                    MesPcnExtConstWords.PLC_RIGHT_LOCATION_HAND_SHAKE_SIGNAL, MesPcnExtConstWords.PLC_RIGHT_LOCATION_CT_NO, MesPcnExtConstWords.PCN_RIGHT_LOCATION_HAND_SHAKE_SIGNAL);
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            foundExThrowNoShowMsg();
        }

        Integer locationType = null;
        String curLockLocationNo = (String) putPalletModuleService.doHandleCurLockLocationNo(reqBean, 1, null);
        List<MesWorkCenterContainerLocation> locationList = (List<MesWorkCenterContainerLocation>) putPalletModuleService.doHandleSelectLocationList(reqBean, 1, null);
        Optional<MesWorkCenterContainerLocation> wcclOptional = locationList.stream().filter(o -> (null != o && o.getCtLocationNo().equals(curLockLocationNo))).findFirst();
        if (null != wcclOptional && wcclOptional.isPresent()) {
            locationType = wcclOptional.get().getLocationType();
        }

        String plcLocationHandShakeSignal, plcLocationCtNo, pcnLocationHandShakeSignal;
        MesPlc plcLocationHandShakeSignalPlc, plcLocationCtNoPlc, pcnLocationHandShakeSignalPlc;
        if (MesPcnExtEnumUtil.WORK_CENTER_CT_LOCATION_TYPE.LEFT.getValue() == locationType) {
            plcLocationHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.PLC_LEFT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);
            plcLocationCtNo = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.PLC_LEFT_LOCATION_CT_NO, reqBean, resultBean);
            pcnLocationHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.PCN_LEFT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);

            plcLocationHandShakeSignalPlc = putPalletInitProdTypeStepService.getPlc(plcLocationHandShakeSignal, MesPcnExtConstWords.PLC_LEFT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);
            plcLocationCtNoPlc = putPalletInitProdTypeStepService.getPlc(plcLocationCtNo, MesPcnExtConstWords.PLC_LEFT_LOCATION_CT_NO, reqBean, resultBean);
            pcnLocationHandShakeSignalPlc = putPalletInitProdTypeStepService.getPlc(pcnLocationHandShakeSignal, MesPcnExtConstWords.PCN_LEFT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        } else {
            plcLocationHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.PLC_RIGHT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);
            plcLocationCtNo = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.PLC_RIGHT_LOCATION_CT_NO, reqBean, resultBean);
            pcnLocationHandShakeSignal = getValueByStepParamMap(stepParamMap, MesPcnExtConstWords.PCN_RIGHT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);

            plcLocationHandShakeSignalPlc = putPalletInitProdTypeStepService.getPlc(plcLocationHandShakeSignal, MesPcnExtConstWords.PLC_RIGHT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);
            plcLocationCtNoPlc = putPalletInitProdTypeStepService.getPlc(plcLocationCtNo, MesPcnExtConstWords.PLC_RIGHT_LOCATION_CT_NO, reqBean, resultBean);
            pcnLocationHandShakeSignalPlc = putPalletInitProdTypeStepService.getPlc(pcnLocationHandShakeSignal, MesPcnExtConstWords.PCN_RIGHT_LOCATION_HAND_SHAKE_SIGNAL, reqBean, resultBean);
        }


        Integer value1, value3;
        String value2;
        try {
            value1 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(plcLocationHandShakeSignalPlc).toString());
            value2 = (String) putPalletModuleService.doReadOpcParamValue(plcLocationCtNoPlc);
            value3 = Integer.valueOf(putPalletModuleService.doReadOpcParamValue(pcnLocationHandShakeSignalPlc).toString());
        } 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]"),
                    plcLocationHandShakeSignalPlc.getTagAddress(), plcLocationCtNoPlc.getTagAddress(),
                    pcnLocationHandShakeSignalPlc.getTagAddress(), e.getMessage());
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            return StepResult.getNonComplete(err);
        }

        Boolean boo;
        if (value1 == 0 && value2.equals("0") && value3 == 0) {
            try {
                boo = putPalletModuleService.doWriteOpcParamValue(pcnLocationHandShakeSignalPlc, "1");
            } catch (Exception e) {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN修改PLC地址位值为[1]时发生异常:[%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]值为[1]时发生异常:[%s]"),
                        pcnLocationHandShakeSignalPlc.getTagAddress(), e.getMessage());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }
            if (!boo) {
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN修改PLC地址位值为[1]时失败");
                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]值为[1]时失败"),
                        pcnLocationHandShakeSignalPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            } else {
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "正在监听PLC读取容器代码...");
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[本体装托PLC模式读取容器代码工步]PCN修改PLC地址位[%s]值为[1]成功,正在监听PLC读取容器代码..."),
                        pcnLocationHandShakeSignalPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "正在监听PLC读取容器代码...");
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            }
            return StepResult.getNonComplete(err);
        } else if (value1 != 0 && !value2.equals("0") && value3 == 1) {
            curCtNoModel = new SxPutPalletPlcDataModel();
            curCtNoModel.setCtNo(value2);
            curCtNoModel.setBoo(false);
            curCtNoModel.setReadDatetime(TimeTool.getNowTime(true));
            putPalletModuleService.doHandleCurCtNo(reqBean, 2, curCtNoModel);
            try {
                boo = putPalletModuleService.doWriteOpcParamValue(pcnLocationHandShakeSignalPlc, "2");
            } catch (Exception e) {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN修改PLC地址位值为[2]时发生异常:[%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]值为[2]时发生异常:[%s]"),
                        pcnLocationHandShakeSignalPlc.getTagAddress(), e.getMessage());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }
            if (!boo) {
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PCN修改PLC地址位值为[2]时失败");
                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]值为[2]时失败"),
                        pcnLocationHandShakeSignalPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            } else {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "已经读取到PLC中的容器代码[%s],正在监听PLC复位..."), value2);
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[本体装托PLC模式读取容器代码工步]PCN修改PLC地址位[%s]值为[2]成功,已经读取到PLC中的容器代码[%s],正在监听PLC复位..."),
                        pcnLocationHandShakeSignalPlc.getTagAddress(), value2);
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "已经读取到PLC中的容器代码[%s],正在监听PLC复位..."), value2);
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            }
            return StepResult.getNonComplete(err);
        } else if (value1 == 0 && value2.equals("0") && value3 == 2) {
            try {
                boo = putPalletModuleService.doWriteOpcParamValue(pcnLocationHandShakeSignalPlc, "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]值为[0]时发生异常:[%s]"),
                        pcnLocationHandShakeSignalPlc.getTagAddress(), e.getMessage());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }
            if (!boo) {
                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]值为[0]时失败"),
                        pcnLocationHandShakeSignalPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            } else {
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PLC地址位复位成功");
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[本体装托PLC模式读取容器代码工步]PCN修改PLC地址位[%s]值为[0]成功,PLC地址位复位成功"),
                        pcnLocationHandShakeSignalPlc.getTagAddress());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
                err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "PLC地址位复位成功");
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            }

            curCtNoModel = (SxPutPalletPlcDataModel) putPalletModuleService.doHandleCurCtNo(reqBean, 1, null);

            MesContainer container = workCenterContainerLocationService.getContainerByCtNo(reqBean.getOrganizeCode(), curCtNoModel.getCtNo());
            if (null == container) {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "容器代码[%s]无效"), curCtNoModel.getCtNo());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }

            if (String.valueOf(MesPcnEnumUtil.MES_CONTAINER_STATUS.OCCUPY.getValue()).equals(container.getUseStatus())) {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "容器代码[%s]当前状态[占用]"), container.getCtNo());
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                return StepResult.getNonComplete(err);
            }

            String curPartNo = (String) putPalletModuleService.doHandleCurPartNo(reqBean, 1, null);
            MesPartContainerCapacity partContainerCapacity = workCenterContainerLocationService.getPartContainerCapacity(reqBean.getOrganizeCode(), container.getCtCode(), curPartNo);
            if (null != partContainerCapacity) {
                if (StringUtils.isEmpty(partContainerCapacity.getCtQty()) || partContainerCapacity.getCtQty().compareTo(0) == 0) {
                    err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(),
                            "容器代码[%s]对应的容器类型[%s]与物料编码[%s]在产品容器容量配置信息中未配置容量"), container.getCtNo(), container.getCtCode(), curPartNo);
                    this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    putPalletModuleService.doHandleCurCtNo(reqBean, 3, null);
                    return StepResult.getNonComplete(err);
                }
                putPalletModuleService.doHandleCurCtQty(reqBean, 2, partContainerCapacity.getCtQty());
            } else {
                err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "容器代码[%s]对应的容器类型[%s]与物料编码[%s]未配置产品容器容量信息"),
                        container.getCtNo(), container.getCtCode(), curPartNo);
                this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                putPalletModuleService.doHandleCurCtNo(reqBean, 3, null);
                return StepResult.getNonComplete(err);
            }

            curCtNoModel.setBoo(true);
            putPalletModuleService.doHandleCurCtNo(reqBean, 2, curCtNoModel);

            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "容器代码[%s]扫描成功!"), curCtNoModel.getCtNo());
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            return StepResult.getSuccessComplete();
        } else {
            err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "正在监听中...");
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "[本体装托PLC模式读取容器代码工步]正在监听PLC地址位读取容器代码...");
            this.sendMessage(reqBean, resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            return StepResult.getNonComplete();
        }

    }

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


}
