package cn.cecep.talroad.task;

import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.enums.StatisticsTypeEnum;
import cn.cecep.talroad.service.analysis.ISRaOverRateGasService;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@Api(tags = "超标率分析-气污染要素")
@RestController
@RequestMapping("/over/gas/task")
public class SRaOverRateGasTaskController extends BasesController {
    @Autowired
    private ISRaOverRateGasService sRaOverRateGasService;


    @ApiOperation(value = "月统计")
    @GetMapping("/month")
    public AjaxResults<Boolean> month() {
        Date lastMonth = DateUtils.addDateMonths(new Date(),-1);
        final DateTime endTime = DateUtil.endOfMonth(lastMonth);
        final DateTime startTime = DateUtil.beginOfMonth(lastMonth);
        return AjaxResults.success(sRaOverRateGasService.periodTask(StatisticsTypeEnum.MONTH,DateUtils.parseDateToStr("yyyy-MM",startTime.toJdkDate()),startTime,endTime));
    }

    @ApiOperation(value = "季统计")
    @GetMapping("/quarter")
    public AjaxResults<Boolean> quarter() {
        Date lastMonth = DateUtils.addDateMonths(new Date(),-1);
        final DateTime endTime = DateUtil.endOfQuarter(lastMonth);
        final DateTime startTime = DateUtil.beginOfQuarter(lastMonth);
        return AjaxResults.success(sRaOverRateGasService.periodTask(StatisticsTypeEnum.QUARTER,DateUtils.parseDateToStr("yyyy",startTime)+startTime.quarter(),startTime,endTime));
    }


    @ApiOperation(value = "年统计")
    @GetMapping("/year")
    public AjaxResults<Boolean> year() {
        Date lastMonth = DateUtils.addDateMonths(new Date(),-1);
        final DateTime endTime = DateUtil.endOfYear(lastMonth);
        final DateTime startTime = DateUtil.beginOfYear(lastMonth);
        return AjaxResults.success(sRaOverRateGasService.periodTask(StatisticsTypeEnum.YEAR,DateUtils.parseDateToStr("yyyy",startTime.toJdkDate()),startTime,endTime));
    }
}
