package cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataJobService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/2/2 16:44
 **/
@Slf4j
@DisallowConcurrentExecution
@ApiOperation("第三方DB数据采集定时任务")
public class SxThirdPartyDbCollectDataJob implements Job {

    @Autowired
    private ISxThirdPartyDbCollectDataJobService thirdPartyDbCollectDataJobService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {

        Object param = jobExecutionContext.getJobDetail().getJobDataMap().get(MesPcnExtConstWords.PARAM);
        if (StringUtils.isEmpty(param)) return;

        log.info("第三方DB数据采集 --- JOB --- PARAM:{}", param.toString());

        String[] paramArr = param.toString().split(MesPcnExtConstWords.COMMA);

        if (paramArr.length != 2) return;

        log.info("工厂{}第三方DB数据采集 --- JOB START --- PARAM:{}", paramArr[0], param.toString());

        long startTime = System.currentTimeMillis();

        thirdPartyDbCollectDataJobService.doThirdPartyDbCollectData(paramArr[0], paramArr[1], MesPcnExtConstWords.JOB);

        long endTime = System.currentTimeMillis();

        log.info("工厂{}第三方DB数据采集 --- JOB END --- 耗时: {} ms", paramArr[0], endTime - startTime);

    }
}
