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.ElecGwPriceConfig;
import com.ruoyi.ems.domain.ElecPvPriceConfig;
import com.ruoyi.ems.service.IElecPriceConfigService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.RestController;

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

/**
 * 电价配置Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/ems/basecfg/elecPrice")
@Api(value = "ElecPriceController", description = "国网电价管理")
public class ElecPriceController extends BaseController {
    @Autowired
    private IElecPriceConfigService configService;

    /**
     * 查询电价配置列表
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:list')")
    @GetMapping("/gw/list")
    public TableDataInfo listGw(ElecGwPriceConfig elecValencyConfig) {
        startPage();
        List<ElecGwPriceConfig> list = configService.selectGwElecPriceCfgList(elecValencyConfig);
        return getDataTable(list);
    }

    /**
     * 导出电价配置列表
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:export')")
    @Log(title = "国网电价配置", businessType = BusinessType.EXPORT)
    @PostMapping("/gw/export")
    public void exportGw(HttpServletResponse response, ElecGwPriceConfig elecValencyConfig) {
        List<ElecGwPriceConfig> list = configService.selectGwElecPriceCfgList(elecValencyConfig);
        ExcelUtil<ElecGwPriceConfig> util = new ExcelUtil<>(ElecGwPriceConfig.class);
        util.exportExcel(response, list, "国网电价配置数据");
    }

    /**
     * 获取电价配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:query')")
    @GetMapping(value = "/gw/{id}")
    public AjaxResult getGwInfo(@PathVariable("id") Long id) {
        return success(configService.selectGwElecPriceCfgById(id));
    }

    /**
     * 新增电价配置
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:add')")
    @Log(title = "电价配置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/gw")
    public AjaxResult addGw(@RequestBody ElecGwPriceConfig elecValencyConfig) {
        return toAjax(configService.insertGwElecPriceCfg(elecValencyConfig));
    }

    /**
     * 修改电价配置
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:edit')")
    @Log(title = "电价配置", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/gw")
    public AjaxResult editGw(@RequestBody ElecGwPriceConfig elecValencyConfig) {
        return toAjax(configService.updateGwElecPriceCfg(elecValencyConfig));
    }

    /**
     * 删除电价配置
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:remove')")
    @Log(title = "电价配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/gw/{ids}")
    public AjaxResult removeGw(@PathVariable Long[] ids) {
        return toAjax(configService.deleteGwElecPriceCfgByIds(ids));
    }

    /**
     * 列出价格列表
     * @return 价格列表
     */
    @GetMapping("/gw/listall")
    public AjaxResult listAllGw() {
        List<ElecGwPriceConfig> list = configService.selectGwElecPriceCfgList(new ElecGwPriceConfig());
        return success(list);
    }

    /**
     * 查询光伏电价配置列表
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:list')")
    @GetMapping("/pv/list")
    public TableDataInfo listPv(ElecPvPriceConfig pvPriceConfig)
    {
        startPage();
        List<ElecPvPriceConfig> list = configService.selectPvPriceCfgList(pvPriceConfig);
        return getDataTable(list);
    }

    /**
     * 导出光伏电价配置列表
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:export')")
    @Log(title = "光伏电价配置", businessType = BusinessType.EXPORT)
    @PostMapping("/pv/export")
    public void exportPv(HttpServletResponse response, ElecPvPriceConfig pvPriceConfig)
    {
        List<ElecPvPriceConfig> list = configService.selectPvPriceCfgList(pvPriceConfig);
        ExcelUtil<ElecPvPriceConfig> util = new ExcelUtil<>(ElecPvPriceConfig.class);
        util.exportExcel(response, list, "光伏电价配置数据");
    }

    /**
     * 获取光伏电价配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:query')")
    @GetMapping(value = "/pv/{id}")
    public AjaxResult getPvInfo(@PathVariable("id") Long id)
    {
        return success(configService.selectPvPriceCfgById(id));
    }

    /**
     * 新增光伏电价配置
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:add')")
    @Log(title = "光伏电价配置", businessType = BusinessType.INSERT)
    @PostMapping(value = "/pv")
    public AjaxResult addPv(@RequestBody ElecPvPriceConfig pvPriceConfig)
    {
        return toAjax(configService.insertPvPriceCfg(pvPriceConfig));
    }

    /**
     * 修改光伏电价配置
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:edit')")
    @Log(title = "光伏电价配置", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/pv")
    public AjaxResult editPv(@RequestBody ElecPvPriceConfig pvPriceConfig)
    {
        return toAjax(configService.updatePvPriceCfg(pvPriceConfig));
    }

    /**
     * 删除光伏电价配置
     */
    @PreAuthorize("@ss.hasPermi('basecfg:price:remove')")
    @Log(title = "光伏电价配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/pv/{ids}")
    public AjaxResult removePv(@PathVariable Long[] ids)
    {
        return toAjax(configService.deletePvPriceCfgByIds(ids));
    }
}
