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

import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.station.yf.YfManyCellMonitorModuleService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.base.BaseStepService;
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.StringUtils;

@Slf4j
@Service("yfManyCellScanStepService")
public class YfManyCellScanStepService extends BaseStepService {

    @Autowired
    private YfManyCellMonitorModuleService manyCellMonitorModuleService;

    @Override
    public StepResult guide(StationRequestBean reqBean) {
        return execSuccessCompleteAndSendGuideReturn(reqBean, new StationResultBean(), "请扫描产品条码!");
    }

    @Override
    public StepResult execute(StationRequestBean reqBean) {

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

        StationResultBean resultBean = new StationResultBean();

        if (StringUtils.isEmpty(reqBean.getScanInfo())) execSendGuideAndThrowEx(reqBean, resultBean, "请扫描产品条码!");

        manyCellMonitorModuleService.addSerialNumber(reqBean, reqBean.getScanInfo());

        reqBean.setSerialNumber(reqBean.getScanInfo());

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

        return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean, String.format("产品条码[%s]扫描成功! 请进行加工操作!", reqBean.getSerialNumber()));
    }

}
