package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
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.ElecPriceStrategy;
import com.ruoyi.ems.service.IElecPriceStrategyService;
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.RestController;

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

/**
 * 电价策略Controller
 *
 * @author ruoyi
 * @date 2024-08-23
 */
@RestController
@RequestMapping("/basecfg/elecPrice/strategy")
@Api(value = "ElecPriceStrategyController", description = "峰谷电价策略管理")
public class ElecPriceStrategyController extends BaseController {
    @Autowired
    private IElecPriceStrategyService elecPriceStrategyService;

    /**
     * 查询电价策略列表
     */
    @RequiresPermissions("basecfg:price:list")
    @GetMapping("/list")
    public TableDataInfo list(ElecPriceStrategy elecPriceStrategy) {
        startPage();
        List<ElecPriceStrategy> list = elecPriceStrategyService.selectList(elecPriceStrategy);
        return getDataTable(list);
    }

    /**
     * 导出电价策略列表
     */
    @RequiresPermissions("basecfg:price:export")
    @Log(title = "电价策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElecPriceStrategy elecPriceStrategy) {
        List<ElecPriceStrategy> list = elecPriceStrategyService.selectList(elecPriceStrategy);
        ExcelUtil<ElecPriceStrategy> util = new ExcelUtil<ElecPriceStrategy>(ElecPriceStrategy.class);
        util.exportExcel(response, list, "电价策略数据");
    }

    /**
     * 获取电价策略详细信息
     */
    @RequiresPermissions("basecfg:price:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(elecPriceStrategyService.selectById(id));
    }

    /**
     * 新增电价策略
     */
    @RequiresPermissions("basecfg:price:add")
    @Log(title = "电价策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecPriceStrategy elecPriceStrategy) {
        return toAjax(elecPriceStrategyService.insert(elecPriceStrategy));
    }

    /**
     * 修改电价策略
     */
    @RequiresPermissions("basecfg:price:edit")
    @Log(title = "电价策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecPriceStrategy elecPriceStrategy) {
        return toAjax(elecPriceStrategyService.update(elecPriceStrategy));
    }

    /**
     * 删除电价策略
     */
    @RequiresPermissions("basecfg:price:remove")
    @Log(title = "电价策略", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(elecPriceStrategyService.deleteByIds(ids));
    }
}
