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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.jx.IJxProdBindRecordExtService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.base.BaseStepService;
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
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;

/**
 * @Description : 嘉兴下线关键件解绑工步
 * @Reference :
 * @Author : wangjie
 * @CreateDate : 2019-07-11
 * @Modify:
 **/
@Slf4j
@Service("jxSnLineOffUnBindKeyPartStepService")
public class JxSnLineOffUnBindKeyPartStepService extends BaseStepService {

    @Autowired
    private IJxProdBindRecordExtService prodBindRecordExtService;

    @Override
    public StepResult execute(StationRequestBean reqBean) {

        log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnLineOffUnBindKeyPartStepService --- START --- ", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode());

        StationResultBean resultBean = new StationResultBean();

        Integer count = prodBindRecordExtService.doUnBindKeyPartList(reqBean.getOrganizeCode(), reqBean.getUserInfo(), reqBean.getWorkOrderNo(), reqBean.getSerialNumber(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode());

        log.info("工厂{}生产线{}工位{}: --- STEP EXECUTE --- JxSnLineOffUnBindKeyPartStepService --- SUCCESS ---", reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode());

        return execDynamicsCompleteAndSendMsgReturn(reqBean, resultBean, StepResult.getSuccessComplete(), true,
                MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT, String.format("当前产品[%s]已被标记为出货检验还线品,源关键件信息[%s条]均已完成解绑!", reqBean.getProductSn(), count));
    }

}
