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.common.security.annotation.RequiresPermissions;
import com.ruoyi.ems.domain.ElecPriceStrategyHour;
import com.ruoyi.ems.service.IElecPriceStrategyHourService;
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/hour")
@Api(value = "ElecPriceStrategyHourController", description = "峰谷电价小时策略参数")
public class ElecPriceStrategyHourController extends BaseController {
    @Autowired
    private IElecPriceStrategyHourService elecPriceStrategyHourService;

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

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

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

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

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

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