package com.ruoyi.ems.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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 com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ems.domain.ElecUseH;
import com.ruoyi.ems.service.IElecUseHService;

import io.swagger.annotations.Api;

/**
 * 用能计量-小时Controller
 *
 * @author ruoyi
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/elec/use/hour")
@Api(value = "ElecUseHController", description = "用电计量数据接口")
public class ElecUseHController extends BaseController {
    @Autowired
    private IElecUseHService elecUseHService;

    /**
     * 查询用能计量-小时列表
     */
    @RequiresPermissions("ems:h:list")
    @GetMapping("/list")
    public TableDataInfo list(ElecUseH admEmsFacsUseH) {
        startPage();
        List<ElecUseH> list = elecUseHService.selectElecUseHList(admEmsFacsUseH);
        return getDataTable(list);
    }

    /**
     * 导出用能计量-小时列表
     */
    @RequiresPermissions("ems:h:export")
    @Log(title = "用能计量-小时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElecUseH admEmsFacsUseH) {
        List<ElecUseH> list = elecUseHService.selectElecUseHList(admEmsFacsUseH);
        ExcelUtil<ElecUseH> util = new ExcelUtil<ElecUseH>(ElecUseH.class);
        util.exportExcel(response, list, "用能计量-小时数据");
    }

    /**
     * 获取用能计量-小时详细信息
     */
    @RequiresPermissions("ems:h:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(elecUseHService.selectElecUseHById(id));
    }

    /**
     * 新增用能计量-小时
     */
    @RequiresPermissions("ems:h:add")
    @Log(title = "用能计量-小时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecUseH admEmsFacsUseH) {
        return toAjax(elecUseHService.insertElecUseH(admEmsFacsUseH));
    }

    /**
     * 修改用能计量-小时
     */
    @RequiresPermissions("ems:h:edit")
    @Log(title = "用能计量-小时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecUseH admEmsFacsUseH) {
        return toAjax(elecUseHService.updateElecUseH(admEmsFacsUseH));
    }

    /**
     * 删除用能计量-小时
     */
    @RequiresPermissions("ems:h:remove")
    @Log(title = "用能计量-小时", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(elecUseHService.deleteElecUseHByIds(ids));
    }

    /**
     * 网-用电量月度统计
     *
     * @param area the area
     * @return the area month use supply
     * @author chen.cheng
     */
    @GetMapping("/area/month/use/supply")
    public AjaxResult getAreaMonthUseSupply(@RequestParam("area") String area) {
        return success(elecUseHService.selectElecAndPower(area));
    }

    /**
     * 荷-近一年用能
     *
     * @param area
     * @return
     */
    @GetMapping("/area/month/elec/use")
    public AjaxResult getAreaMonthElecUse(@RequestParam(value = "area", required = false) String area) {
        return success(elecUseHService.selectMonthElecUse(area));
    }

    /**
     * 荷-当日用能-设备类型占比
     *
     * @param area
     * @return
     */
    @GetMapping("/area/thisday/fac/type/elec/use")
    public AjaxResult getAreaThisDayFacTypeElecUse(@RequestParam(value = "area", required = false) String area) {
        return success(elecUseHService.selectThisDayFacsTypeElecUse(area));
    }

    /**
     * 荷-当日用能
     *
     * @param area
     * @return
     */
    @GetMapping("/area/thisday/elec/use")
    public AjaxResult getAreaThisDayElecUse(@RequestParam(value = "area", required = false) String area) {
        return success(elecUseHService.selectThisDayAreaElecUse(area));
    }
}
