package org.dromara.ems.report.controller;

import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.report.domain.EnergyStatisticalReport;
import org.dromara.ems.report.domain.PeaksValleysConsumptionReport;
import org.dromara.ems.report.service.IEmsReportService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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


/**
 * 能源报表Controller
 *
 * @author Yinq
 * @date 2024-05-22
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/report")
public class EmsReportController extends EmsBaseController {

    
    private final 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.exportExcel(list, "统计能耗报表", EnergyStatisticalReport.class, response);
    }

    /**
     * 峰平谷耗量报表
     * @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.exportExcel(list, "峰平谷耗量报表", PeaksValleysConsumptionReport.class, response);
    }

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


}
