package com.tofly.xrtygis.handle.statistical;

import com.tofly.xrtygis.custom.util.DateTimeUtil;
import com.tofly.xrtygis.service.IndicatorCorrectionService;
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 java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;

@Component
@Slf4j
public class DmaStatisticalHandler {
    @Autowired
    private IndicatorCorrectionService indicatorCorrectionService;

    /**
     * DMA分区各项指标数据统计(每天)
     * @param param
     * @return
     */
    @XxlJob("leakageRateCalculate")
    public ReturnT<String> leakageRateCalculate(String param) {
        long l = System.currentTimeMillis();
       // LocalDate firstDayOfCurrentMonth = DateTimeUtil.getFirstDayOfCurrentMonth();
       // Date date = DateTimeUtil.localDateToDate(firstDayOfCurrentMonth);
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        //indicatorCorrectionService.leakageRateCalculate(date);
        indicatorCorrectionService.leakageRateCalculateDay(calendar.getTime());
        long l1 = System.currentTimeMillis();
        log.info("同步结束DMA各项每月数据统计,用时{}mm",l1-l);
        return ReturnT.SUCCESS;
    }
}
