package com.ruoyi.ems.controller;

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.ems.domain.ElecLoadIndex;
import com.ruoyi.ems.domain.vo.QueryIndex;
import com.ruoyi.ems.service.IElecLoadIndexService;
import io.swagger.annotations.Api;
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 javax.servlet.http.HttpServletResponse;
import java.util.List;

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

    /**
     * 查询电力负荷设施指标列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ElecLoadIndex index) {
        startPage();
        List<ElecLoadIndex> list = indexService.selectIndexList(index);
        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));
    }

    /**
     * 根据时间查询电力负荷设施指标
     *
     * @param queryIndex 参数
     * @return 电力负荷设施指标集合
     */
    @GetMapping("/getByTime")
    public AjaxResult getByTime(QueryIndex queryIndex) {
        return success(indexService.selectByTime(queryIndex));
    }

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

    /**
     * 获取电力负荷设施指标详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(indexService.selectIndexById(id));
    }

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

    /**
     * 修改电力负荷设施指标
     */
    @Log(title = "电力负荷设施指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecLoadIndex index) {
        return toAjax(indexService.updateIndex(index));
    }

    /**
     * 删除电力负荷设施指标
     */
    @Log(title = "电力负荷设施指标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(indexService.deleteIndexByIds(ids));
    }
}
