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

import com.sundot.airport.check.domain.CheckLargeScreenCommonDto;
import com.sundot.airport.check.domain.CheckLargeScreenCorrectionDto;
import com.sundot.airport.check.domain.CheckLargeScreenCorrectionPortraitDto;
import com.sundot.airport.check.domain.CheckLargeScreenCorrectionQueryParamDto;
import com.sundot.airport.check.domain.CheckLargeScreenHomePageDto;
import com.sundot.airport.check.domain.CheckLargeScreenInspectionExecuteDto;
import com.sundot.airport.check.domain.CheckLargeScreenPlanOverviewDto;
import com.sundot.airport.check.domain.CheckLargeScreenPlanQueryParamDto;
import com.sundot.airport.check.domain.CheckLargeScreenProblemDto;
import com.sundot.airport.check.domain.CheckLargeScreenProblemQueryParamDto;
import com.sundot.airport.check.domain.CheckLargeScreenProblemTrendDto;
import com.sundot.airport.check.domain.CheckTask;
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.CheckLargeScreenHomePageRankingDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 巡检大屏Controller
 *
 * @author ruoyi
 * @date 2025-09-07
 */
@RestController
@RequestMapping("/check/largeScreen")
public class CheckLargeScreenController extends BaseController {

    @Autowired
    private ICheckLargeScreenService checkLargeScreenService;

    /**
     * 巡检计划-计划安排总览
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/planOverview")
    public AjaxResult planOverview(CheckLargeScreenPlanQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenPlanOverviewDto> result = checkLargeScreenService.planOverview(dto, source);
        return success(result);
    }

    /**
     * 巡检计划-日常任务检查指标累积分布
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/planDistribution")
    public AjaxResult planDistribution(CheckLargeScreenPlanQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenCommonDto> result = checkLargeScreenService.planDistribution(dto, source);
        return success(result);
    }

    /**
     * 巡检计划-任务明细统计表
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/planStatistics")
    public AjaxResult planStatistics(CheckLargeScreenPlanQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckTask> result = checkLargeScreenService.planStatistics(dto, source);
        return success(result);
    }

    /**
     * 问题发现-总体问题分布
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/problemDistribution")
    public AjaxResult problemDistribution(CheckLargeScreenProblemQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenProblemDto> result = checkLargeScreenService.problemDistribution(dto, source);
        return success(result);
    }

    /**
     * 问题发现-问题分布对比
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/problemComparison")
    public AjaxResult problemComparison(CheckLargeScreenProblemQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenProblemDto> result = checkLargeScreenService.problemComparison(dto, source);
        return success(result);
    }

    /**
     * 问题发现-通道面貌-问题对比
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/problemComparisonTwo")
    public AjaxResult problemComparisonTwo(CheckLargeScreenProblemQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenProblemDto> result = checkLargeScreenService.problemComparisonTwo(dto, source);
        return success(result);
    }

    /**
     * 问题发现-通道面貌-问题趋势
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/problemTrend")
    public AjaxResult problemTrend(CheckLargeScreenProblemQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenProblemTrendDto> result = checkLargeScreenService.problemTrend(dto, source);
        return success(result);
    }

    /**
     * 问题整改-整改状态总计
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/correction")
    public AjaxResult correction(CheckLargeScreenCorrectionQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        CheckLargeScreenCorrectionDto result = checkLargeScreenService.correction(dto, source);
        return success(result);
    }

    /**
     * 问题整改-整改状态分布-科级对比
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/correctionDistribution")
    public AjaxResult correctionDistribution(CheckLargeScreenCorrectionQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        List<CheckLargeScreenCorrectionDto> result = checkLargeScreenService.correctionDistribution(dto, source);
        return success(result);
    }

    /**
     * 巡检执行
     */
    @PreAuthorize("@ss.hasPermi('check:checkTask:list')")
    @GetMapping("/inspectionExecute")
    public AjaxResult inspectionExecute(BaseLargeScreenQueryParamDto dto) {
        List<CheckLargeScreenInspectionExecuteDto> result = checkLargeScreenService.inspectionExecute(dto);
        return success(result);
    }

    /**
     * 巡检画像
     */
    @Cacheable(
            value = "statistics_data",
            keyGenerator = "statisticsKeyGenerator",
            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
    )
    @GetMapping("/portrait")
    public AjaxResult portrait(CheckLargeScreenCorrectionQueryParamDto dto) {
        CheckLargeScreenCorrectionPortraitDto result = checkLargeScreenService.portrait(dto);
        return success(result);
    }

    /**
     * 工作画像-管理推动-检查单
     */
    @Cacheable(
            value = "statistics_list",
            keyGenerator = "statisticsKeyGenerator",
            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
    )
    @GetMapping("/managementPromotionRecord")
    public AjaxResult managementPromotionRecord(CheckLargeScreenCorrectionQueryParamDto dto) {
        List<CheckLargeScreenPlanOverviewDto> result = checkLargeScreenService.managementPromotionRecord(dto);
        return success(result);
    }

    /**
     * 工作画像-管理推动-整改单
     */
    @Cacheable(
            value = "statistics_data",
            keyGenerator = "statisticsKeyGenerator",
            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
    )
    @GetMapping("/managementPromotionCorrection")
    public AjaxResult managementPromotionCorrection(CheckLargeScreenCorrectionQueryParamDto dto) {
        CheckLargeScreenCorrectionDto result = checkLargeScreenService.managementPromotionCorrection(dto);
        return success(result);
    }

    /**
     * 工作画像-工作产出-巡检问题统计图
     */
    @Cacheable(
            value = "statistics_list",
            keyGenerator = "statisticsKeyGenerator",
            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
    )
    @GetMapping("/workOutputCheck")
    public AjaxResult workOutputCheck(CheckLargeScreenCorrectionQueryParamDto dto) {
        List<CheckLargeScreenCommonDto> result = checkLargeScreenService.workOutputCheck(dto);
        return success(result);
    }

    /**
     * 首页
     */
//    @Cacheable(
//            value = "statistics_check_homePage",
//            keyGenerator = "statisticsKeyGenerator",
//            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
//    )
    @GetMapping("/homePage")
    public AjaxResult homePage(BaseLargeScreenQueryParamDto dto, @RequestHeader(value = "X-Request-Source", defaultValue = "mobile") String source) {
        CheckLargeScreenHomePageDto result = checkLargeScreenService.homePage(dto, source);
        return success(result);
    }

    /**
     * 首页-巡检-巡检合格率
     */
//    @Cacheable(
//            value = "statistics_check_passRate",
//            keyGenerator = "statisticsKeyGenerator",
//            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
//    )
    @GetMapping("/checkPassRate")
    public AjaxResult checkPassRate(BaseLargeScreenQueryParamDto dto) {
        BigDecimal result = checkLargeScreenService.checkPassRate(dto);
        return success(result);
    }

    /**
     * 首页-巡检-巡检合格率排名
     */
//    @Cacheable(
//            value = "statistics_check_ranking",
//            keyGenerator = "statisticsKeyGenerator",
//            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
//    )
    @GetMapping("/checkRanking")
    public AjaxResult checkRanking(BaseLargeScreenQueryParamDto dto) {
        CheckLargeScreenHomePageRankingDto result = checkLargeScreenService.checkRanking(dto);
        return success(result);
    }

    /**
     * 首页-巡检-今日巡检问题数
     */
//    @Cacheable(
//            value = "statistics_check_correction_count",
//            keyGenerator = "statisticsKeyGenerator",
//            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
//    )
    @GetMapping("/checkCorrectionCount")
    public AjaxResult checkCorrectionCount(BaseLargeScreenQueryParamDto dto) {
        Integer result = checkLargeScreenService.checkCorrectionCount(dto);
        return success(result);
    }

}
