package com.ruoyi.inspection.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.inspection.domain.InspectionManageTable;
import com.ruoyi.inspection.domain.VoAttendanceReport;
import com.ruoyi.inspection.service.IAttendanceReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 可视化巡检记录Controller
 *
 * @author ruoyi
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/inspection/report")
public class AttendanceReportController extends BaseController {
    @Autowired
    private IAttendanceReportService attendanceReportService;

    // 柱形图可视化统计
    @GetMapping("/ColumnList")
    public AjaxResult getEchartsData(VoAttendanceReport voAttendanceReport) {
        try {
            Map<String, Object> echartsData = attendanceReportService.getEchartsData(voAttendanceReport);
            return AjaxResult.success("data",echartsData);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }

    // 圆形图可视化统计
    @GetMapping("/RoundList")
    public AjaxResult getEchartsPieChartData(VoAttendanceReport voAttendanceReport) {
        try {
            Map<String, Object> echartsData = attendanceReportService.getEchartsPieChartData(voAttendanceReport);
            return AjaxResult.success("data",echartsData);
        } catch (Exception e) {
            return AjaxResult.error();
        }
    }

    // 总条数
    @GetMapping("/total")
    public AjaxResult getTotal(){
        int total = attendanceReportService.tatol();
        return AjaxResult.success("总条数",total);
    }

    // 本月总条数
    @GetMapping("monthTotal")
    public AjaxResult getmonthTotal(VoAttendanceReport voAttendanceReport){
        int monthTotal = attendanceReportService.monthTota(voAttendanceReport);
        return AjaxResult.success(monthTotal);
    }

    // 按天趋势统计
    @GetMapping("/trendDaily")
    public AjaxResult trendDaily(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.trendDaily(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 按天双序列
    @GetMapping("/trendDailyDual")
    public AjaxResult trendDailyDual(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.trendDailyDual(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 巡检类型占比
    @GetMapping("/typeProportion")
    public AjaxResult typeProportion(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.typeProportion(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 覆盖率统计
    @GetMapping("/coverage")
    public AjaxResult coverage(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.coverage(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 未巡检点清单
    @GetMapping("/uninspectedPoints")
    public AjaxResult uninspectedPoints(VoAttendanceReport voAttendanceReport) {
        List<InspectionManageTable> list = attendanceReportService.listUninspectedPoints(voAttendanceReport);
        return AjaxResult.success(list);
    }

    // 点位类型对应的已巡检点数量（distinct）
    @GetMapping("/pointTypeCounts")
    public AjaxResult pointTypeCounts(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.pointTypeCounts(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 管理表点位状态分布
    @GetMapping("/statusDistribution")
    public AjaxResult statusDistribution() {
        Map<String, Object> data = attendanceReportService.statusDistribution();
        return AjaxResult.success("data", data);
    }

    // 按月双序列
    @GetMapping("/trendMonthlyDual")
    public AjaxResult trendMonthlyDual(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.trendMonthlyDual(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 巡检人统计（三合一：总/月/日）
    @GetMapping("/inspectorStats3")
    public AjaxResult inspectorStats3(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.inspectorStats3(voAttendanceReport);
        return AjaxResult.success("data", data);
    }

    // 巡检点统计（三合一：总/月/日）
    @GetMapping("/pointStats3")
    public AjaxResult pointStats3(VoAttendanceReport voAttendanceReport) {
        Map<String, Object> data = attendanceReportService.pointStats3(voAttendanceReport);
        return AjaxResult.success("data", data);
    }
}
