package com.jjt.elec.controller;

import com.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.core.page.TableDataInfo;
import com.jjt.common.enums.BusinessType;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.elec.domain.ElecPeriod;
import com.jjt.elec.service.IElecPeriodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 电费分时配置Controller
 *
 * @author wukai
 * @date 2025-03-14
 */
@Api(tags = "电费分时配置")
@RestController
@RequestMapping("/elec/period")
public class ElecPeriodController extends BaseController {
    @Resource
    private IElecPeriodService elecPeriodService;

    /**
     * 查询电费分时配置列表
     */
    @ApiOperation("查询电费分时配置列表")
    //@PreAuthorize("@ss.hasPermi('elec:period:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElecPeriod elecPeriod) {
        startPage();
        List<ElecPeriod> list = elecPeriodService.selectElecPeriodList(elecPeriod);
        return getDataTable(list);
    }

    /**
     * 导出电费分时配置列表
     */
    @ApiOperation("导出电费分时配置列表")
    //@PreAuthorize("@ss.hasPermi('elec:period:export')")
    @Log(title = "电费分时配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElecPeriod elecPeriod) {
        List<ElecPeriod> list = elecPeriodService.selectElecPeriodList(elecPeriod);
        ExcelUtil<ElecPeriod> util = new ExcelUtil<ElecPeriod>(ElecPeriod.class);
        util.exportExcel(response, list, "电费分时配置数据");
    }

    /**
     * 获取电费分时配置详细信息
     */
    @ApiOperation("获取电费分时配置详细信息")
    //@PreAuthorize("@ss.hasPermi('elec:period:query')")
    @GetMapping(value = "/{periodId}")
    public AjaxResult getInfo(@PathVariable("periodId") Long periodId) {
        return success(elecPeriodService.selectElecPeriodByPeriodId(periodId));
    }

    /**
     * 新增电费分时配置
     */
    @ApiOperation("新增电费分时配置")
    //@PreAuthorize("@ss.hasPermi('elec:period:add')")
    @Log(title = "电费分时配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecPeriod elecPeriod) {
        return toAjax(elecPeriodService.insertElecPeriod(elecPeriod));
    }

    /**
     * 修改电费分时配置
     */
    @ApiOperation("修改电费分时配置")
    //@PreAuthorize("@ss.hasPermi('elec:period:edit')")
    @Log(title = "电费分时配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecPeriod elecPeriod) {
        return toAjax(elecPeriodService.updateElecPeriod(elecPeriod));
    }

    /**
     * 删除电费分时配置
     */
    @ApiOperation("删除电费分时配置")
    //@PreAuthorize("@ss.hasPermi('elec:period:remove')")
    @Log(title = "电费分时配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{periodIds}")
    public AjaxResult remove(@PathVariable Long[] periodIds) {
        return toAjax(elecPeriodService.deleteElecPeriodByPeriodIds(periodIds));
    }
}
