package com.aucma.report.controller;

import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.report.domain.DeviceFaultAnalysisReport;
import com.aucma.report.domain.DeviceOeeReport;
import com.aucma.report.domain.RepairHoursReport;
import com.aucma.report.service.IDmsReportService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * DMS 设备报表 Controller
 */
@RestController
@RequestMapping("/report/dmsReport")
public class DmsReportController extends BaseController {

    @Autowired
    private IDmsReportService dmsReportService;

    /**
     * 设备故障分析
     */
    @GetMapping("/deviceFaultAnalysis")
    public AjaxResult deviceFaultAnalysis(@RequestParam(required = false) Map<String, Object> params) {
        List<DeviceFaultAnalysisReport> list = dmsReportService.deviceFaultAnalysisList(params);
        return success(list);
    }

    /**
     * 设备故障分析导出
     */
    @PostMapping("/deviceFaultAnalysis/export")
    public void deviceFaultAnalysisExport(HttpServletResponse response,
                                          @RequestParam(required = false) Map<String, Object> params) {
        if (params != null) {
            params.put("pageNum", null);
            params.put("pageSize", null);
        }
        List<DeviceFaultAnalysisReport> list = dmsReportService.deviceFaultAnalysisList(params);
        ExcelUtil<DeviceFaultAnalysisReport> util = new ExcelUtil<>(DeviceFaultAnalysisReport.class);
        util.exportExcel(response, list, "设备故障分析");
    }

    /**
     * 维修工时统计
     */
    @GetMapping("/repairHoursStat")
    public AjaxResult repairHoursStat(@RequestParam(required = false) Map<String, Object> params) {
        List<RepairHoursReport> list = dmsReportService.repairHoursReportList(params);
        return success(list);
    }

    /**
     * 维修工时统计导出
     */
    @PostMapping("/repairHoursStat/export")
    public void repairHoursStatExport(HttpServletResponse response,
                                      @RequestParam(required = false) Map<String, Object> params) {
        if (params != null) {
            params.put("pageNum", null);
            params.put("pageSize", null);
        }
        List<RepairHoursReport> list = dmsReportService.repairHoursReportList(params);
        ExcelUtil<RepairHoursReport> util = new ExcelUtil<>(RepairHoursReport.class);
        util.exportExcel(response, list, "维修工时统计");
    }

    /**
     * 设备 OEE 分析
     */
    @GetMapping("/deviceOeeAnalysis")
    public AjaxResult deviceOeeAnalysis(@RequestParam(required = false) Map<String, Object> params) {
        List<DeviceOeeReport> list = dmsReportService.deviceOeeReportList(params);
        return success(list);
    }

    /**
     * 设备 OEE 分析导出
     */
    @PostMapping("/deviceOeeAnalysis/export")
    public void deviceOeeAnalysisExport(HttpServletResponse response,
                                        @RequestParam(required = false) Map<String, Object> params) {
        if (params != null) {
            params.put("pageNum", null);
            params.put("pageSize", null);
        }
        List<DeviceOeeReport> list = dmsReportService.deviceOeeReportList(params);
        ExcelUtil<DeviceOeeReport> util = new ExcelUtil<>(DeviceOeeReport.class);
        util.exportExcel(response, list, "设备OEE分析");
    }
}
