package com.casic.missiles.job.handler;

/**
 * @Description: 计量文件JobHandler
 * @Author: wangpeng
 * @Date: 2022/11/29 14:22
 */

import com.casic.missiles.mapper.meter.MeterFileMapper;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import static com.xxl.job.core.biz.model.ReturnT.SUCCESS;

@Slf4j
@Component
public class FileJobHandler {
    @Autowired
    private MeterFileMapper meterFileMapper;

    /**
     * 文件实施状态变更任务
     * 实施时间格式：yyyy-MM-dd
     * 当前时间 >= 实施时间 = 在使用（前提：非已废止）
     * 当前时间 < 实施时间 = 未使用（前提：非已废止）
     */
    @XxlJob(value = "fileEffectiveStatusHandler")
    public ReturnT<String> execute() throws Exception {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        log.info("========sync file effective status job begin");
        if(meterFileMapper.updateEffectiveStatusByTime() > 0){
            stopWatch.stop();
            log.info("file effective status changed, costTime:{}ms", stopWatch.getTotalTimeMillis());
        }
        log.info("========sync file effective status job end");
        return SUCCESS;
    }

}
