package com.ruoyi.ems.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.huashe.common.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.CoChargingConfig;
import com.ruoyi.ems.service.ICoChargingConfigService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商户能源计费配置Controller
 *
 * @author ruoyi
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/basecfg/elecPrice/coCharging")
@Api(value = "CoChargingConfigController", description = "商户能源计费配置")
public class CoChargingConfigController extends BaseController {
    @Autowired
    private ICoChargingConfigService coChargingConfigService;

    /**
     * 查询商户能源计费配置列表
     */
    @RequiresPermissions("basecfg:price:list")
    @GetMapping("/list")
    public TableDataInfo list(CoChargingConfig coChargingConfig) {
        startPage();
        List<CoChargingConfig> list = coChargingConfigService.selectCoChargingConfigList(coChargingConfig);
        return getDataTable(list);
    }

    /**
     * 根据区域查询商户能源计费配置
     * @param areaCode areaCode
     * @return
     */
    @GetMapping("/getByArea")
    public AjaxResult getByArea(@RequestParam(name = "areaCode") String areaCode) {
        CoChargingConfig config = coChargingConfigService.selectByArea(areaCode);
        return success(config);
    }

    /**
     * 获取商户能源计费配置详细信息
     */
    @RequiresPermissions("basecfg:price:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(coChargingConfigService.selectCoChargingConfigById(id));
    }

    /**
     * 新增商户能源计费配置
     */
    @RequiresPermissions("basecfg:price:add")
    @Log(title = "商户能源计费配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoChargingConfig coChargingConfig) {
        return toAjax(coChargingConfigService.insertCoChargingConfig(coChargingConfig));
    }

    /**
     * 修改商户能源计费配置
     */
    @RequiresPermissions("ems:config:edit")
    @Log(title = "商户能源计费配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoChargingConfig coChargingConfig) {
        return toAjax(coChargingConfigService.updateCoChargingConfig(coChargingConfig));
    }

    /**
     * 删除商户能源计费配置
     */
    @RequiresPermissions("ems:config:remove")
    @Log(title = "商户能源计费配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(coChargingConfigService.deleteCoChargingConfigByIds(ids));
    }
}
