package com.zcxk.charge.xxl.jobs;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.zcxk.charge.core.dao.MonitorDataMapper;
import com.zcxk.charge.xxl.service.impl.DataAlarmDayJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author Administrator
 * @create 2020-05-18 14:07
 */
@Slf4j
@Component
public  class MonitorDataReportByMonthJob implements Serializable {

    private static final long serialVersionUID = 3336891083300321324L;

    @Resource
    private MonitorDataMapper monitorDataMapper;

    @Resource
    private DataAlarmDayJobService dataAlarmDayJobService;

    @XxlJob("monitorDataReportByMonthJob")
    public ReturnT<String> execute(String string) {
        try{
            log.info("月报报任务开始执行");
            getMonitorDataByDay();
            dataAlarmDayJobService.execute();
            log.info("月报任务执行结束");
        }catch (Exception e){
            e.printStackTrace();
            log.info("月报任务执行异常，{}", e.getMessage());
        }
        return ReturnT.SUCCESS;
    }

    public void getMonitorDataByDay() {
        //取前一天的时间
        LocalDateTime dateTime = LocalDateTime.now().plusDays(-1);
        //保存日报表数据
        monitorDataMapper.batchInsertMonthReport(dateTime.getYear(),dateTime.getMonthValue(),dateTime.getDayOfMonth());
    }

}