package com.ruoyi.web.controller.ems;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ems.domain.ElecLoadIndex;
import com.ruoyi.ems.model.QueryMeter;
import com.ruoyi.ems.service.IElecLoadIndexService;
import io.swagger.annotations.Api;
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.RequestBody;
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;

/**
 * 电力负荷设施指标Controller
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/ems/object/loadIndex")
@Api(value = "ElecLoadIndexController", description = "电力负荷指标数据接口")
public class ElecLoadIndexController extends BaseController {
    @Autowired
    private IElecLoadIndexService indexService;

    /**
     * 查询电力负荷设施指标列表
     */
    @GetMapping("/min/15/list")
    public TableDataInfo min15List(QueryMeter param) {
        startPage();
        List<ElecLoadIndex> list = indexService.selectMin15IndexList(param);
        return getDataTable(list);
    }

    @GetMapping("/min/15/getMaxLoad")
    public AjaxResult getMin15MaxLoad(QueryMeter param) {
        ElecLoadIndex maxLoad = indexService.selectMin15IndexMaxLoad(param);
        return success(maxLoad);
    }

    @GetMapping("/day/getMaxLoad")
    public TableDataInfo getMaxLoad(QueryMeter param) {
        startPage();
        List<ElecLoadIndex> list = indexService.selectDayIndexMaxLoad(param);
        return getDataTable(list);
    }

    /**
     * 查询最新电力负荷设施指标
     *
     * @param areaCode 区域代码
     * @param objType  对象类型
     * @param objCode  对象代码
     * @return 电力负荷设施指标
     */
    @GetMapping("/getNewIndex")
    public AjaxResult getNewIndex(@RequestParam(name = "areaCode") String areaCode,
        @RequestParam(name = "objType") String objType, @RequestParam(name = "objCode") String objCode) {
        return success(indexService.selectNewIndex(areaCode, objType, objCode));
    }

    /**
     * 导出电力负荷设施指标列表
     */
    @Log(title = "电力负荷设施指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QueryMeter param) {
        List<ElecLoadIndex> list = indexService.selectMin15IndexList(param);
        ExcelUtil<ElecLoadIndex> util = new ExcelUtil<ElecLoadIndex>(ElecLoadIndex.class);
        util.exportExcel(response, list, "电力负荷设施指标数据");
    }

    /**
     * 新增电力负荷设施指标
     */
    @Log(title = "电力负荷设施指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecLoadIndex index) {
        return toAjax(indexService.insertMin15Index(index));
    }
}
