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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionCustomContextStepService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step.MesCountDownShowStepService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseSwsService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.IShippingDispatchService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.function.IFsmModuleFunctionService;
import cn.estsh.i3plus.platform.common.util.MesPcnConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.mes.model.ButtonDynamicModel;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description : 工位参数按钮事件接口实现【解除锁定】
 **/
@Service
public class MesFunctionProductionUnlockService extends BaseSwsService implements IFsmModuleFunctionService {

    @Autowired
    private IMesProductionCustomContextStepService productionCustomContextStepService;

    @Autowired
    private IShippingDispatchService shippingDispatchService;

    @Override
    public Boolean doFunction(StationRequestBean reqBean, StationResultBean resultBean, ButtonDynamicModel buttonDynamicModel) {

        //删除上下文加工锁
        productionCustomContextStepService.removeProductionLockContext(reqBean);

        ((MesCountDownShowStepService) SpringContextsUtil.getBean("mesCountDownShowStepService")).checkCellProductionLockIsExist(reqBean, resultBean, false, false);

        this.sendMessage(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PICK.getValue()).scanInfo(buttonDynamicModel.getFunctionValue()),
                String.format("生产线[%s]工位[%s]%s成功!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), buttonDynamicModel.getButtonName()), MesPcnEnumUtil.STATION_BUSI_TYPE.MESSAGE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);

        reqBean.setClientInfo(shippingDispatchService.getActorClientInfo(reqBean));
        reqBean.setInterfaceType(MesPcnConstWords.SHIPPING);
        reqBean.setBusiType(MesPcnEnumUtil.ACTOR_RECEIVE_STRATEGY.WS_CMD_DO_SCAN.getCode());
        reqBean.setTriggerAutoFsm(true);

        shippingDispatchService.sendScanQueueIfNoQueue(reqBean, false, this.getClass().getSimpleName());

        return true;

    }

}
