package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi.bu3;

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxProdDataToSoftAdapterStrategyService;
import cn.estsh.i3plus.ext.mes.pojo.model.bu3.SxProdDataToSoftAdapterDataModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;

@Slf4j
public class SxProdDataToSoftAdapterStrategyWatchService implements ISxProdDataToSoftAdapterStrategyService {

    private ISxProdDataToSoftAdapterStrategyService strategyService;

    public SxProdDataToSoftAdapterStrategyWatchService(ISxProdDataToSoftAdapterStrategyService strategyService) {
        this.strategyService = strategyService;
    }

    @Override
    public SxProdDataToSoftAdapterDataModel exec(SxProdDataToSoftAdapterDataModel data) {

        StopWatch stopWatch = new StopWatch();

        stopWatch.start();

        log.info("MES工厂{}DATE{}执行生产数据回传软适配JOB --- EXEC STRATEGY_CLASS[{}] --- WATCH START --- THREAD:[{}]", data.getOrganizeCode(), data.getDate(), data.getClassName(), data.getCurrentThreadName());

        try {

            strategyService.exec(data);

        } finally {

            stopWatch.stop();

            log.info("MES工厂{}DATE{}执行生产数据回传软适配JOB --- EXEC STRATEGY_CLASS[{}] --- WATCH END --- 耗时:[{}] --- THREAD:[{}]", data.getOrganizeCode(), data.getDate(), data.getClassName(), stopWatch.getTotalTimeMillis(), data.getCurrentThreadName());

        }

        return data;
    }
}
