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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IShiftExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IShiftProdCenterRecordService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.ISxWorkOrderExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IWorkCenterExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IProduceSnTravelExtService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesManulExecuteOutTravel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProduceSnTravelExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesWorkCenterExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesWorkOrderExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesManulExecuteOutTravelRepository;
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.actor.shipping.dispatch.IFsmCommonService;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.IShippingDispatchService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.base.BaseModuleService;
import cn.estsh.i3plus.mes.pcn.util.LocaleUtil;
import cn.estsh.i3plus.mes.pcn.util.PojoAttrUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.util.MesPcnConstWords;
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.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.hardswitch.bean.OpcUAParam;
import cn.estsh.i3plus.pojo.mes.bean.MesPlc;
import cn.estsh.i3plus.pojo.mes.bean.MesShift;
import cn.estsh.i3plus.pojo.mes.bean.MesStateMachineStatus;
import cn.estsh.i3plus.pojo.mes.model.AttrBean;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
import cn.estsh.i3plus.pojo.mes.repository.MesPlcRepository;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ImppRedis;
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 javax.annotation.Resource;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description : 展示组件：本体包装前置组件(生成包装条码)
 * @Reference :
 * @Author :wangjie
 * @CreateDate : 2020-06-26 11:18 上午
 * @Modify:
 **/
@Slf4j
@Service("sxNoumenonSnPopUpOnlineModuleService")
public class SxNoumenonSnPopUpOnlineModuleService extends BaseModuleService {

    @Autowired
    private IProduceSnTravelExtService produceSnTravelExtService;

    @Autowired
    private ISxWorkOrderExtService workOrderExtService;

    @Autowired
    private IWorkCenterExtService workCenterExtService;

    @Autowired
    private IShiftExtService shiftExtService;

    @Autowired
    private IShiftProdCenterRecordService shiftProdCenterRecordService;

    @Autowired
    private IShippingDispatchService shippingDispatchService;

    @Autowired
    private IFsmCommonService fsmCommonService;

    @Autowired
    private MesPlcRepository plcRepository;

    @Autowired
    private MesManulExecuteOutTravelRepository manulExecuteOutRepository;

    @Resource(name = MesPcnExtConstWords.REDIS_RES_PCN)
    private ImppRedis redisMesPcn;

    private static final String LAST_SELECT_ORDER = "LAST_SELECT_ORDER";

    private static final String NOUMENON_SN_ONLINE_DATA = "NOUMENON_SN_ONLINE_DATA";

    @Override
    public void init(StationRequestBean reqBean) {
        StationResultBean resultBean = new StationResultBean();
        String err;

        resultBean.setBusiType(MesPcnEnumUtil.STATION_BUSI_TYPE.MODULE_CONTENT.getValue());
        resultBean.setDataType(MesPcnEnumUtil.STATION_DATA_TYPE.CUSTOM.getValue());
        resultBean.setCustomPageName(MesPcnExtConstWords.NOUMENON_SN_POP_UP_ONLINE_MODULE);
        //resultBean.setCustomPageName(MesPcnExtConstWords.NOUMENON_PACKAGE_MODULE);

        //resultBean.setDataAttrList(packDataAttrList(reqBean));
        resultBean.setSpecialDisplayData(getStepColIndent(reqBean));

        MesWorkCenterExt workCenterExt = workCenterExtService.getWorkCenterExtByWorkCenterCode(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode());
        if (null == workCenterExt || (StringUtils.isEmpty(workCenterExt.getShiftCode()) || StringUtils.isEmpty(workCenterExt.getWorkTime()))) {
            this.sendMessage(reqBean, resultBean);
            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "生产线[%s]未启动班次"), reqBean.getWorkCenterCode());
            this.sendMessage(reqBean,  resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                    .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                    .setErrorDetail("生产线[%s]未启动班次", reqBean.getWorkCenterCode())
                    .build();
        }
        MesShift shiftDb = shiftExtService.getShiftByShiftCodeAndCenterCode(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), workCenterExt.getShiftCode());
        if (null == shiftDb) {
            this.sendMessage(reqBean, resultBean);
            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "生产线[%s]未关联班次代码[%s]"), reqBean.getWorkCenterCode(), workCenterExt.getShiftCode());
            this.sendMessage(reqBean,  resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                    .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION.getCode())
                    .setErrorDetail("生产线[%s]未关联班次代码[%s]", reqBean.getWorkCenterCode(), workCenterExt.getShiftCode())
                    .build();
        }
        String workTime = shiftProdCenterRecordService.getWorkTime(shiftDb.getStartTime(), shiftDb.getEndTime());
        if (StringUtils.isEmpty(workTime) || !workTime.equals(workCenterExt.getWorkTime())) {
            this.sendMessage(reqBean, resultBean);
            err = String.format(LocaleUtil.transferLanguage(reqBean.getUserInfo(), "生产线[%s]需要重新启动班次"), reqBean.getWorkCenterCode());
            this.sendMessage(reqBean,  resultBean, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                    .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION.getCode())
                    .setErrorDetail("生产线[%s]需要重新启动班次", reqBean.getWorkCenterCode())
                    .build();
        }
        if (StringUtils.isEmpty(reqBean.getWorkOrderNo())) {
            this.sendMessage(reqBean, resultBean);
            err = LocaleUtil.transferLanguage(reqBean.getUserInfo(), "请选择工单");
            this.sendMessage(reqBean,  null, err, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                    .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION.getCode())
                    .setErrorDetail("请选择工单")
                    .build();
        }

        List<MesProduceSnTravelExt> produceSnTravelExtList = produceSnTravelExtService.getProduceSnTravelExtListByOrderNo(
                reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), reqBean.getWorkOrderNo());

        int snCount = CollectionUtils.isEmpty(produceSnTravelExtList) ? 0 : produceSnTravelExtList.size();

        MesWorkOrderExt workOrderExt = workOrderExtService.getWorkOrderExtByOrderNo(reqBean.getOrganizeCode(), reqBean.getWorkOrderNo());
        if (null == workOrderExt || MesPcnExtEnumUtil.WORK_ORDER_STATUS.OPEN.getValue() != workOrderExt.getWorkOrderStatus() ||
                MesPcnExtEnumUtil.WORK_ORDER_TYPE.REWORK_ORDER.getValue() == workOrderExt.getWorkOrderType()) {
            this.sendMessage(reqBean, resultBean);
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                    .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION.getCode())
                    .setErrorDetail("工单[%s]不能在此工位操作", reqBean.getWorkOrderNo())
                    .build();

        } else if (snCount >= workOrderExt.getQty().intValue()) {
            this.sendMessage(reqBean, resultBean);
            throw ImppExceptionBuilder.newInstance()
                    .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                    .setErrorCode(ImppExceptionEnum.BUSINESS_EXCEPTION.getCode())
                    .setErrorDetail("工单[%s]已达绑定数量,不能在此工位操作", reqBean.getWorkOrderNo())
                    .build();
        }

        Map<String, String> wcpcMap = fsmCommonService.getCachedWorkCellParam(reqBean);
        reqBean.setWorkOrderNo(wcpcMap.get("WORK_ORDER_NO"));
        doHandleSelectWorkOrderNo(reqBean, 2, wcpcMap.get("WORK_ORDER_NO"));

        resultBean.setResultMap(packResultMap(workOrderExt, produceSnTravelExtList));

        this.sendMessage(reqBean, resultBean);
    }

    private Map<String, Object> packResultMap(MesWorkOrderExt workOrderExt, List<MesProduceSnTravelExt> produceSnTravelExtList) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put(MesPcnExtConstWords.WORK_ORDER_NO, workOrderExt.getOrderNo());
        resultMap.put(MesPcnExtConstWords.WORK_ORDER_TYPE_NAME, MesPcnExtEnumUtil.WORK_ORDER_TYPE.valueOfDescription(workOrderExt.getWorkOrderType()));
        resultMap.put(MesPcnExtConstWords.PART_NO, workOrderExt.getPartNo());
        resultMap.put(MesPcnExtConstWords.PART_NAME, workOrderExt.getPartNameRdd());
        resultMap.put(MesPcnExtConstWords.QTY, workOrderExt.getQty());
        resultMap.put(MesPcnExtConstWords.COMPLETE_QTY, CollectionUtils.isEmpty(produceSnTravelExtList) ? 0 : produceSnTravelExtList.size());
        return resultMap;
    }

    private List<AttrBean> packDataAttrList(StationRequestBean reqBean) {
        List<AttrBean> attrBeanList = new ArrayList<>();
        PojoAttrUtil.loadPojoAttrs(attrBeanList, MesPcnExtConstWords.SERIAL_NUMBER, LocaleUtil.transferLanguage(reqBean.getUserInfo(), "产品条码"));
        PojoAttrUtil.loadPojoAttrs(attrBeanList, MesPcnExtConstWords.PACKAGENO, LocaleUtil.transferLanguage(reqBean.getUserInfo(), "包装条码"));
        PojoAttrUtil.loadPojoAttrs(attrBeanList, MesPcnExtConstWords.CREATE_DATE_TIME, LocaleUtil.transferLanguage(reqBean.getUserInfo(), "扫描时间"));
        return attrBeanList;
    }

    private String getLastSelectOrderKey(StationRequestBean reqBean) {
        return getCacheKey(reqBean, LAST_SELECT_ORDER);
    }

    @Override
    public boolean execute(StationRequestBean reqBean) {
        return true;
    }

    @Override
    public boolean execStateModule(StationRequestBean reqBean, List<MesStateMachineStatus> states, Map<String, String> wcpcMap) {
        log.info(" sxNoumenonSnPopUpOnlineModuleService ---  wcpcMap:{}", wcpcMap);
        init(reqBean);
        return true;
    }

    public synchronized Object doHandleManageCode(StationRequestBean reqBean, Integer flag, String value) {
        switch (flag) {
            case 1:
                return redisMesPcn.getHash(getCacheKey(reqBean, MesPcnExtConstWords.CUR_MANAGE_CODE), MesPcnExtConstWords.CUR_MANAGE_CODE);
            case 2:
                return redisMesPcn.putHash(getCacheKey(reqBean, MesPcnExtConstWords.CUR_MANAGE_CODE), MesPcnExtConstWords.CUR_MANAGE_CODE, value, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue());
            case 3:
                redisMesPcn.deleteHash(getCacheKey(reqBean, MesPcnExtConstWords.CUR_MANAGE_CODE), MesPcnExtConstWords.CUR_MANAGE_CODE);
                return true;
            default:
                return null;
        }
    }

    private String getDataKey(StationRequestBean reqBean) {
        return new StringJoiner(MesPcnExtConstWords.COLON)
                .add(reqBean.getOrganizeCode()).add(NOUMENON_SN_ONLINE_DATA).add(reqBean.getWorkCenterCode()).toString();
    }

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

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

    public Boolean doReadOpcParamValueIsEquDefaultVal(MesPlc plc, String defaultVal, Boolean isEqu) {
        Object plcValue = doReadOpcParamValue(plc);
        if (StringUtils.isEmpty(plcValue)) {
            return false;
        }
        if (isEqu) {
            if (plcValue.toString().equals(defaultVal)) {
                return true;
            } else {
                return false;
            }
        } else {
            if (plcValue.toString().equals(defaultVal)) {
                return false;
            } else {
                return true;
            }
        }
    }

    public void putLastSelectOrder(StationRequestBean reqBean) {
        redisMesPcn.putObject(getLastSelectOrderKey(reqBean), reqBean.getWorkOrderNo(), MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue());
    }

    @Override
    public boolean doFunction(StationRequestBean reqBean) {
        Boolean result = false;
        Map<String, Object> dataMap = reqBean.getDataMap();
        String command = (String) dataMap.get(MesPcnExtConstWords.COMMAND);
        Object value = dataMap.get(MesPcnExtConstWords.VALUE);
        if (StringUtils.isEmpty(command)) {
            this.sendMessage(reqBean,  null, "后端未获取到业务功能指令", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
            return result;
        }

        switch (command) {
            case MesPcnExtConstWords.CMD_WORK_ORDER :
                if (StringUtils.isEmpty(value)) {
                    this.sendMessage(reqBean,  null, "请选择启动状态的工单", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return result;
                }

                String selectWorkOrderNo = (String) doHandleSelectWorkOrderNo(reqBean, 1, null);
                if (!StringUtils.isEmpty(selectWorkOrderNo) && selectWorkOrderNo.equals(value)) return result;
                if (StringUtils.isEmpty(selectWorkOrderNo)) {
                    if ((Boolean) doHandleSelectWorkOrderNo(reqBean, 2, value.toString())) {
                        result = true;
                    }
                    else {
                        this.sendMessage(reqBean,  null, String.format("切换的生产工单[%s]缓存失败,请重试", value), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                        return result;
                    }
                }
                break;
            case MesPcnExtConstWords.EXECUTE_OUT:
                if (StringUtils.isEmpty(value)) {
                    this.sendMessage(reqBean,  null, "入参缺少强制放行的工步代码", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return result;
                }

                Map<String, String> wcpcMap = fsmCommonService.getCachedWorkCellParam(reqBean);
                String plcCode = wcpcMap.get("PLC_CODE");
                String executeOutPwd = wcpcMap.get("EXECUTE_OUT_PWD");

                if (StringUtils.isEmpty(executeOutPwd)) {
                    this.sendMessage(reqBean,  null, "当前工位未维护强制放行密码", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return result;
                }

                if (StringUtils.isEmpty(plcCode)) {
                    this.sendMessage(reqBean,  null, "当前工位未维护PLC代码", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return result;
                }

                List<String> executeOutPwdList = Arrays.stream(executeOutPwd.split(MesPcnExtConstWords.COMMA)).collect(Collectors.toList());
                if (!executeOutPwdList.contains(value)) {
                    this.sendMessage(reqBean,  null, "强制密码错误", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return result;
                }

                MesPlc plc = getPlc(reqBean.getOrganizeCode(), plcCode);
                if (plc == null) {
                    this.sendMessage(reqBean,  null, String.format("PLC代码[%s]不存在", plcCode), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
                    return result;
                }
                Boolean writeResult = doWriteOpcParamValue(plc, "1");

                // 手动强制执行履行
                MesManulExecuteOutTravel manulExecuteOutTravel = new MesManulExecuteOutTravel();
                manulExecuteOutTravel.setPartNo(reqBean.getPartNo());
                manulExecuteOutTravel.setPartNameRdd(reqBean.getPartName());
                manulExecuteOutTravel.setProcessCode(reqBean.getProcessCode());
                manulExecuteOutTravel.setSerialNumber(reqBean.getSerialNumber());
                manulExecuteOutTravel.setWorkCellCode(reqBean.getWorkCellCode());
                manulExecuteOutTravel.setWorkCenterCode(reqBean.getWorkCenterCode());
                manulExecuteOutTravel.setWorkOrderNo(reqBean.getWorkOrderNo());
                ConvertBean.serviceModelInitialize(manulExecuteOutTravel, reqBean.getUserInfo());
                manulExecuteOutRepository.save(manulExecuteOutTravel);

                log.info("SxNoumenonSnPopUpOnlineModuleService --- 放行结果：{} ", writeResult);

                result = true;
                break;
            default:
                break;
        }

        if (!result) this.sendMessage(reqBean,  null, "操作太频繁", MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT);
        else {
            //跳过工序
            reqBean.setClientInfo(shippingDispatchService.getActorClientInfo(reqBean));
            reqBean.setInterfaceType(MesPcnConstWords.SHIPPING);
            reqBean.setBusiType(MesPcnConstWords.WS_CMD_DO_SCAN);
            reqBean.setForceJumpProcess(true);
            shippingDispatchService.doSendScanQueueNextExec(reqBean);
        }
        return result;
    }

    public MesPlc getPlc(String organizeCode, String plcCode) {

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

    public synchronized Object doHandleSelectWorkOrderNo(StationRequestBean reqBean, Integer flag, String selectWorkOrderNo) {
        switch (flag) {
            case 1:
                return redisMesPcn.getHash(getDataKey(reqBean), MesPcnExtConstWords.CMD_WORK_ORDER);
            case 2:
                return redisMesPcn.putHash(getDataKey(reqBean), MesPcnExtConstWords.CMD_WORK_ORDER, selectWorkOrderNo, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue());
            case 3:
                redisMesPcn.deleteHash(getDataKey(reqBean), MesPcnExtConstWords.CMD_WORK_ORDER);
                return true;
            default:
                return null;
        }
    }

    public synchronized Object doHandleCurExecWorkOrder(StationRequestBean reqBean, Integer flag, String curExecWorkOrder) {
        switch (flag) {
            case 1:
                return redisMesPcn.getHash(getDataKey(reqBean), MesPcnExtConstWords.CUR_EXEC_WORK_ORDER);
            case 2:
                return redisMesPcn.putHash(getDataKey(reqBean), MesPcnExtConstWords.CUR_EXEC_WORK_ORDER, curExecWorkOrder, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue());
            case 3:
                redisMesPcn.deleteHash(getDataKey(reqBean), MesPcnExtConstWords.CUR_EXEC_WORK_ORDER);
                return true;
            default:
                return null;
        }
    }

    public synchronized Object doHandleSelectWorkOrderType(StationRequestBean reqBean, Integer flag, String selectWorkOrderType) {
        switch (flag) {
            case 1:
                return redisMesPcn.getHash(getDataKey(reqBean), MesPcnExtConstWords.CMD_WORK_ORDER_TYPE);
            case 2:
                return redisMesPcn.putHash(getDataKey(reqBean), MesPcnExtConstWords.CMD_WORK_ORDER_TYPE, selectWorkOrderType, MesPcnEnumUtil.EXPIRE_TIME.NEVER.getValue());
            case 3:
                redisMesPcn.deleteHash(getDataKey(reqBean), MesPcnExtConstWords.CMD_WORK_ORDER_TYPE);
                return true;
            default:
                return null;
        }
    }


}
