package com.xzzn.web.controller.ems;

import java.util.List;

import com.xzzn.ems.domain.vo.EnergyPriceVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xzzn.common.annotation.Log;
import com.xzzn.common.core.controller.BaseController;
import com.xzzn.common.core.domain.AjaxResult;
import com.xzzn.common.enums.BusinessType;
import com.xzzn.ems.service.IEmsEnergyPriceConfigService;
import com.xzzn.common.core.page.TableDataInfo;

/**
 * 电价配置Controller
 *
 * @author xzzn
 * @date 2025-09-28
 */
@RestController
@RequestMapping("/ems/energyPriceConfig")
public class EmsEnergyPriceConfigController extends BaseController
{
    @Autowired
    private IEmsEnergyPriceConfigService emsEnergyPriceConfigService;

    /**
     * 查询电价配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(String siteId, String startTime,String endTime)
    {
        List<EnergyPriceVo> list = emsEnergyPriceConfigService.selectEmsEnergyPriceConfigList(siteId,startTime,endTime);
        return getDataTable2(list);
    }

    /**
     * 获取电价配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emsEnergyPriceConfigService.selectEmsEnergyPriceConfigById(id));
    }

    /**
     * 新增电价配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "电价配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnergyPriceVo priceVo)
    {
        return toAjax(emsEnergyPriceConfigService.insertEmsEnergyPriceConfig(priceVo));
    }

    /**
     * 修改电价配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "电价配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnergyPriceVo priceVo)
    {
        return toAjax(emsEnergyPriceConfigService.updateEmsEnergyPriceConfig(priceVo));
    }

    /**
     * 删除电价配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "电价配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emsEnergyPriceConfigService.deleteEmsEnergyPriceConfigByIds(ids));
    }
}
