package com.sundot.airport.web.controller.system;

import cn.hutool.core.util.StrUtil;
import com.sundot.airport.check.service.ICheckLargeScreenService;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.core.domain.BaseLargeScreenQueryParamDto;
import com.sundot.airport.common.core.domain.SysAnalysisReportDateRangeDto;
import com.sundot.airport.common.core.domain.SysAnalysisReportParamDto;
import com.sundot.airport.common.core.domain.SysCheckAnalysisReportCheckProblemDistributionDto;
import com.sundot.airport.common.core.domain.SysCheckAnalysisReportDto;
import com.sundot.airport.common.enums.DateRangeQueryTypeEnum;
import com.sundot.airport.common.utils.DateRangeQueryUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 质控分析报告
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/analysisReport")
public class SysCheckAnalysisReportController extends BaseController {

    @Autowired
    private ICheckLargeScreenService checkLargeScreenService;

    /**
     * 质控活动
     */
    @PostMapping("/check")
    public AjaxResult checkAnalysisReport(@RequestBody SysAnalysisReportParamDto paramDto) {
        List<SysAnalysisReportDateRangeDto> dateRangeList = new ArrayList<>();
        if (StrUtil.equals(DateRangeQueryTypeEnum.YEAR.getCode(), paramDto.getDateRangeQueryType())) {
            dateRangeList.add(DateRangeQueryUtils.getPreviousYearRange(paramDto.getYear()));
            dateRangeList.add(DateRangeQueryUtils.getYearRange(paramDto.getYear(), null));
        } else if (StrUtil.equals(DateRangeQueryTypeEnum.QUARTER.getCode(), paramDto.getDateRangeQueryType())) {
            dateRangeList.add(DateRangeQueryUtils.getLastYearSameQuarterRange(paramDto.getYear(), paramDto.getQuarter()));
            dateRangeList.add(DateRangeQueryUtils.getPreviousQuarterRange(paramDto.getYear(), paramDto.getQuarter()));
            dateRangeList.add(DateRangeQueryUtils.getQuarterRange(paramDto.getYear(), paramDto.getQuarter(), null));
        } else if (StrUtil.equals(DateRangeQueryTypeEnum.MONTH.getCode(), paramDto.getDateRangeQueryType())) {
            dateRangeList.add(DateRangeQueryUtils.getLastYearSameMonthRange(paramDto.getYear(), paramDto.getMonth()));
            dateRangeList.add(DateRangeQueryUtils.getPreviousMonthRange(paramDto.getYear(), paramDto.getMonth()));
            dateRangeList.add(DateRangeQueryUtils.getMonthRange(paramDto.getYear(), paramDto.getMonth(), null));
        }
        paramDto.setDateRangeList(dateRangeList);
        SysCheckAnalysisReportDto result = checkLargeScreenService.checkAnalysisReport(paramDto);
        return success(result);
    }

    /**
     * 质控活动-问题分布统计
     */
    @GetMapping("/checkProblemDistribution")
    public AjaxResult checkAnalysisReportCheckProblemDistributionDto(BaseLargeScreenQueryParamDto paramDto) {
        SysCheckAnalysisReportCheckProblemDistributionDto result = checkLargeScreenService.getCheckProblemDistribution(paramDto);
        return success(result);
    }

}
