package com.aucma.report.controller;

import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.report.domain.*;
import com.aucma.report.service.IQualityReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 质量报表Controller
 *
 * @author Yinq
 * @date 2023-11-21
 */
@RestController
@RequestMapping("/report/qualityReport")
public class QualityReportController extends BaseController {
    @Autowired
    private IQualityReportService qualityReportService;


    /**
     * 质量缺陷统计分析
     * @param hashMap
     * @return
     */
    @GetMapping("/qualityDefectsStatisticalAnalysisList")
    public AjaxResult qualityDefectsStatisticalAnalysisList(@RequestParam(required = false) Map hashMap) {
        List<QualityDefectsStatisticalAnalysis> list = qualityReportService.qualityDefectsStatisticalAnalysisList(hashMap);
        return success(list);
    }

    /**
     * 质量缺陷统计分析导出
     * @param hashMap
     * @return
     */
    @PostMapping("/qualityDefectsStatisticalAnalysisList/export" )
    public void qualityDefectsStatisticalAnalysisListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<QualityDefectsStatisticalAnalysis> list = qualityReportService.qualityDefectsStatisticalAnalysisList(hashMap);
        ExcelUtil<QualityDefectsStatisticalAnalysis> util = new ExcelUtil<>(QualityDefectsStatisticalAnalysis. class);
        util.exportExcel(response, list, "质量缺陷统计分析" );
    }

    /**
     * 质量缺陷统计分析明细
     * @param hashMap
     * @return
     */
    @GetMapping("/qualityDefectsDetailList")
    public AjaxResult qualityDefectsDetailList(@RequestParam(required = false) Map hashMap) {
        List<HashMap<String, Object>> list = qualityReportService.qualityDefectsDetailList(hashMap);
        return success(list);
    }

    /**
     * 质量缺陷统计分析明细导出
     * @param hashMap
     * @return
     */
    @PostMapping("/qualityDefectsDetailList/export" )
    public void qualityDefectsDetailListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<QualityDefectsDetail> list = qualityReportService.qualityDefectsDetailListExport(hashMap);
        ExcelUtil<QualityDefectsDetail> util = new ExcelUtil<>(QualityDefectsDetail. class);
        util.exportExcel(response, list, "质量缺陷统计分析明细" );
    }

    /**
     * 少错件报表
     * @param hashMap
     * @return
     */
    @GetMapping("/fewerMistakesReportList")
    public AjaxResult fewerMistakesReportList(@RequestParam(required = false) Map hashMap) {
        List<FewerMistakesReport> list = qualityReportService.fewerMistakesReportList(hashMap);
        return success(list);
    }

    /**
     * 少错件报表导出
     * @param hashMap
     * @return
     */
    @PostMapping("/fewerMistakesReportList/export" )
    public void fewerMistakesReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<FewerMistakesReport> list = qualityReportService.fewerMistakesReportList(hashMap);
        ExcelUtil<FewerMistakesReport> util = new ExcelUtil<>(FewerMistakesReport. class);
        util.exportExcel(response, list, "少错件报表" );
    }


    /**
     * 质量问题前80报表
     * @param hashMap
     * @return
     */
    @GetMapping("/qualityIssuesReportList")
    public AjaxResult qualityIssuesReportList(@RequestParam(required = false) Map hashMap) {
        List<QualityIssuesReport> list = qualityReportService.qualityIssuesReportList(hashMap);
        return success(list);
    }

    /**
     * 质量问题前80报表导出
     * @param hashMap
     * @return
     */
    @PostMapping("/qualityIssuesReportList/export" )
    public void qualityIssuesReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<QualityIssuesReport> list = qualityReportService.qualityIssuesReportList(hashMap);
        ExcelUtil<QualityIssuesReport> util = new ExcelUtil<>(QualityIssuesReport. class);
        util.exportExcel(response, list, "质量问题前80报表" );
    }

    /**
     * 产品追溯报表
     * @param hashMap
     * @return
     */
    @GetMapping("/productTraceabilityReportList")
    public TableDataInfo productTraceabilityReportList(@RequestParam(required = false) Map hashMap) {
        startPage();
        List<ProductTraceabilityReport> list = qualityReportService.productTraceabilityReportList(hashMap);
        return getDataTable(list);
    }

    /**
     * 产品追溯报表导出
     * @param hashMap
     * @return
     */
    @PostMapping("/productTraceabilityReportList/export" )
    public void productTraceabilityReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<ProductTraceabilityReport> list = qualityReportService.productTraceabilityReportList(hashMap);
        ExcelUtil<ProductTraceabilityReport> util = new ExcelUtil<>(ProductTraceabilityReport. class);
        util.exportExcel(response, list, "产品追溯报表" );
    }

    /**
     * 产品追溯明细
     * @param hashMap
     * @return
     */
    @GetMapping("/productTraceabilityDetailList")
    public AjaxResult productTraceabilityDetailList(@RequestParam(required = false) Map hashMap) {
        List<HashMap<String, Object>> list = qualityReportService.productTraceabilityDetailList(hashMap);
        return success(list);
    }

    /**
     * 测温记录报表
     * @param hashMap
     * @return
     */
    @GetMapping("/temperatureRecordReportList")
    public AjaxResult temperatureRecordReportList(@RequestParam(required = false) Map hashMap) {
        List<HashMap<String, Object>> list = qualityReportService.temperatureRecordReportList(hashMap);
        return success(list);
    }

    /**
     * 灌注记录报表
     * @param hashMap
     * @return
     */
    @GetMapping("/pourRecordReportList")
    public AjaxResult pourRecordReportList(@RequestParam(required = false) Map hashMap) {
        List<HashMap<String, Object>> list = qualityReportService.pourRecordReportList(hashMap);
        return success(list);
    }

    /**
     * 质量返修率报表
     * @param hashMap
     * @return
     */
    @GetMapping("/repairRateReportList")
    public AjaxResult repairRateReportList(@RequestParam(required = false) Map hashMap) {
        List<RepairRateReport> list = qualityReportService.repairRateReportList(hashMap);
        return success(list);
    }

    /**
     * 质量返修率报表导出
     * @param hashMap
     * @return
     */
    @PostMapping("/repairRateReportList/export" )
    public void repairRateReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<RepairRateReport> list = qualityReportService.repairRateReportList(hashMap);
        ExcelUtil<RepairRateReport> util = new ExcelUtil<>(RepairRateReport. class);
        util.exportExcel(response, list, "质量返修率报表" );
    }

    /**
     * 降级率报表
     * @param hashMap
     * @return
     */
    @GetMapping("/downgradeProportionReportList")
    public AjaxResult downgradeProportionReportList(@RequestParam(required = false) Map hashMap) {
        List<DowngradeProportionReport> list = qualityReportService.downgradeProportionReportList(hashMap);
        return success(list);
    }

    /**
     * 降级率报表导出
     * @param hashMap
     * @return
     */
    @PostMapping("/downgradeProportionReportList/export" )
    public void downgradeProportionReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        hashMap.put("pageNum",null);
        hashMap.put("pageSize",null);
        List<DowngradeProportionReport> list = qualityReportService.downgradeProportionReportList(hashMap);
        ExcelUtil<DowngradeProportionReport> util = new ExcelUtil<>(DowngradeProportionReport. class);
        util.exportExcel(response, list, "降级率报表" );
    }

    /**
     * 年度不良率同比报表
     * @param hashMap
     * @return
     */
    @GetMapping("/adverseRecordYearOnYearList")
    public AjaxResult adverseRecordYearOnYearList(@RequestParam(required = false) Map hashMap) {
        List<AdverseRecordYearOnYearReport> list = qualityReportService.adverseRecordYearOnYearList(hashMap);
        return success(list);
    }

    /**
     * 高故障率TOP20报表
     * @param hashMap
     * @return
     */
    @GetMapping("/highFaultList")
    public AjaxResult highFaultList(@RequestParam(required = false) Map hashMap) {
        List<HighFaultReport> list = qualityReportService.highFaultList(hashMap);
        return success(list);
    }

    /**
     * 焊漏率报表
     * @param hashMap
     * @return
     */
    @GetMapping("/weldLeakRateList")
    public AjaxResult weldLeakRateList(@RequestParam(required = false) Map hashMap) {
        List<WeldLeakRateReport> list = qualityReportService.weldLeakRateList(hashMap);
        return success(list);
    }

}
