package com.ruoyi.ems.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.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.EmsFacsAttr;
import com.ruoyi.ems.service.IEmsFacsAttrService;
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.RestController;

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

/**
 * 能源设施属性Controller
 * 
 * @author ruoyi
 * @date 2024-08-22
 */
@RestController
@RequestMapping("/basecfg/emsfacs/attr")
@Api(value = "EmsFacsAttrController", description = "能源设施属性管理")
public class EmsFacsAttrController extends BaseController
{
    @Autowired
    private IEmsFacsAttrService facsAttrService;

    /**
     * 查询能源设施属性列表
     */
    @RequiresPermissions("basecfg:emsfacs:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsFacsAttr emsFacsAttr)
    {
        startPage();
        List<EmsFacsAttr> list = facsAttrService.selectEmsFacsAttrList(emsFacsAttr);
        return getDataTable(list);
    }

    /**
     * 导出能源设施属性列表
     */
    @RequiresPermissions("basecfg:emsfacs:export")
    @Log(title = "能源设施属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsFacsAttr emsFacsAttr)
    {
        List<EmsFacsAttr> list = facsAttrService.selectEmsFacsAttrList(emsFacsAttr);
        ExcelUtil<EmsFacsAttr> util = new ExcelUtil<EmsFacsAttr>(EmsFacsAttr.class);
        util.exportExcel(response, list, "能源设施属性数据");
    }

    /**
     * 获取能源设施属性详细信息
     */
    @RequiresPermissions("basecfg:emsfacs:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(facsAttrService.selectEmsFacsAttrById(id));
    }

    /**
     * 新增能源设施属性
     */
    @RequiresPermissions("basecfg:emsfacs:add")
    @Log(title = "能源设施属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsFacsAttr emsFacsAttr)
    {
        return toAjax(facsAttrService.insertEmsFacsAttr(emsFacsAttr));
    }

    /**
     * 新增能源设施属性
     */
    @RequiresPermissions("basecfg:emsfacs:add")
    @Log(title = "能源设施属性", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult addBatch(@RequestBody List<EmsFacsAttr> emsFacsAttrs)
    {
        return toAjax(facsAttrService.insertEmsFacsAttrBatch(emsFacsAttrs));
    }

    /**
     * 修改能源设施属性
     */
    @RequiresPermissions("basecfg:emsfacs:edit")
    @Log(title = "能源设施属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsFacsAttr emsFacsAttr)
    {
        return toAjax(facsAttrService.updateEmsFacsAttr(emsFacsAttr));
    }

    /**
     * 删除能源设施属性
     */
    @RequiresPermissions("basecfg:emsfacs:remove")
    @Log(title = "能源设施属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(facsAttrService.deleteEmsFacsAttrByIds(ids));
    }
}
