package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.web.controller.BaseController;
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.ElecAttr;
import com.ruoyi.ems.service.IElecAttrService;
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-07-23
 */
@RestController
@RequestMapping("/basecfg/elec/attr")
@Api(value = "ElecAttrController", description = "用电属性管理")
public class ElecAttrController extends BaseController {
    /**
     * 用电属性服务
     */
    @Autowired
    private IElecAttrService attrService;

    /**
     * 查询服务区用电属性列表
     */
    @RequiresPermissions("basecfg:price:list")
    @GetMapping("/list")
    public AjaxResult list(ElecAttr elecAttr) {
        List<ElecAttr> list = attrService.selectElecAttrList(elecAttr);
        return success(list);
    }

    /**
     * 获取服务区用电属性详细信息
     */
    @RequiresPermissions("basecfg:price:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(attrService.selectElecAttrById(id));
    }

    /**
     * 获取服务区用电属性详细信息
     */
    @RequiresPermissions("basecfg:price:query")
    @GetMapping(value = "/getEffectiveListByArea")
    public AjaxResult getEffectiveListByArea(@RequestParam(name="areaCode") String areaCode) {
        return success(attrService.getEffectiveListByArea(areaCode));
    }

    /**
     * 获取服务区用电属性详细信息
     */
    @RequiresPermissions("basecfg:price:query")
    @GetMapping(value = "/getEffectiveByArea")
    public AjaxResult getEffectiveByArea(@RequestParam(name="areaCode") String areaCode) {
        return success(attrService.getEffectiveByArea(areaCode));
    }

    /**
     * 新增服务区用电属性
     */
    @RequiresPermissions("basecfg:price:add")
    @Log(title = "服务区用电属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecAttr elecAttr) {
        return toAjax(attrService.insertElecAttr(elecAttr));
    }

    /**
     * 修改服务区用电属性
     */
    @RequiresPermissions("basecfg:price:edit")
    @Log(title = "服务区用电属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecAttr elecAttr) {
        return toAjax(attrService.updateElecAttr(elecAttr));
    }

    /**
     * 删除服务区用电属性
     */
    @RequiresPermissions("basecfg:price:remove")
    @Log(title = "服务区用电属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(attrService.deleteElecAttrByIds(ids));
    }
}
