package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
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.FdEnergyPriceConfig;
import com.ruoyi.ems.service.IFdEnergyPriceConfigService;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;

/**
 * 非电能源价格配置Controller
 *
 * @author ruoyi
 * @date 2025-08-16
 */
@RestController
@RequestMapping("/basecfg/fdPrice")
public class FdEnergyPriceConfigController extends BaseController {
    @Autowired
    private IFdEnergyPriceConfigService fdEnergyPriceConfigService;

    /**
     * 查询非电能源价格配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FdEnergyPriceConfig config) {
        startPage();
        List<FdEnergyPriceConfig> list = fdEnergyPriceConfigService.selectList(config);
        return getDataTable(list);
    }

    /**
     * 获取非电能源价格配置详细信息
     */
    @RequiresPermissions("ems:FdEnergyPriceConfig:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fdEnergyPriceConfigService.selectConfigById(id));
    }

    /**
     * 新增非电能源价格配置
     */
    @Log(title = "非电能源价格配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FdEnergyPriceConfig config) {
        return toAjax(fdEnergyPriceConfigService.insertConfig(config));
    }

    /**
     * 修改非电能源价格配置
     */
    @Log(title = "非电能源价格配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FdEnergyPriceConfig config) {
        return toAjax(fdEnergyPriceConfigService.updateConfig(config));
    }
}
