package com.ruoyi.ems.report.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ems.report.domain.EnergyStatisticalReport;
import com.ruoyi.ems.report.domain.PeaksValleysConsumptionReport;
import com.ruoyi.ems.report.service.IEmsReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * 能源报表Controller
 *
 * @author Yinq
 * @date 2024-05-22
 */
@RestController
@RequestMapping("/ems/report")
public class EmsReportController extends BaseController {

    @Autowired
    private IEmsReportService emsReportService;

    /**
     * 统计能耗报表
     * @param hashMap
     * @return
     */
    @GetMapping("/energyStatisticalReportList")
    public TableDataInfo energyStatisticalReportList(@RequestParam(required = false) Map hashMap) {
        startPage();
        List<EnergyStatisticalReport> list = emsReportService.energyStatisticalReportList(hashMap);
        return getDataTable(list);
    }

    /**
     * 导出统计能耗报表
     */
    @PostMapping("/energyStatisticalReportList/export" )
    public void energyStatisticalReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        List<EnergyStatisticalReport> list = emsReportService.energyStatisticalReportList(hashMap);
        ExcelUtil<EnergyStatisticalReport> util = new ExcelUtil<>(EnergyStatisticalReport. class);
        util.exportExcel(response, list, "统计能耗报表" );
    }

    /**
     * 峰平谷耗量报表
     * @param hashMap
     * @return
     */
    @GetMapping("/peaksValleysConsumptionReportList")
    public TableDataInfo peaksValleysConsumptionReportList(@RequestParam(required = false) Map hashMap) {
        startPage();
        List<PeaksValleysConsumptionReport> list = emsReportService.peaksValleysConsumptionReportList(hashMap);
        return getDataTable(list);
    }

    /**
     * 导出峰平谷耗量报表
     */
    @PostMapping("/peaksValleysConsumptionReportList/export" )
    public void peaksValleysConsumptionReportListExport(HttpServletResponse response, @RequestParam(required = false) Map hashMap) {
        List<PeaksValleysConsumptionReport> list = emsReportService.peaksValleysConsumptionReportList(hashMap);
        ExcelUtil<PeaksValleysConsumptionReport> util = new ExcelUtil<>(PeaksValleysConsumptionReport. class);
        util.exportExcel(response, list, "峰平谷耗量报表" );
    }

    /**
     * 能源预览接口
     * @param hashMap
     * @return
     */
    @GetMapping("/energyPreviewReportList")
    @ResponseBody
    public AjaxResult energyPreviewReportList(@RequestParam(required = false) Map hashMap) {
        List<Map<String, Object>> list = emsReportService.energyPreviewReportList(hashMap);
        return success(list);
    }


}
