package com.ruoyi.ems.controller;

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

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.EmsFacsEvent;
import com.ruoyi.ems.service.IEmsFacsEventService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 能源设施事件Controller
 * 
 * @author ruoyi
 * @date 2024-08-22
 */
@RestController
@RequestMapping("/basecfg/emsfacs/event")
@Api(value = "EmsFacsEventController", description = "能源设施事件特性管理")
public class EmsFacsEventController extends BaseController
{
    @Autowired
    private IEmsFacsEventService emsFacsEventService;

    /**
     * 查询能源设施事件列表
     */
    @RequiresPermissions("ems:event:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsFacsEvent admEmsFacsEvent)
    {
        startPage();
        List<EmsFacsEvent> list = emsFacsEventService.selectEmsFacsEventList(admEmsFacsEvent);
        return getDataTable(list);
    }

    /**
     * 导出能源设施事件列表
     */
    @RequiresPermissions("ems:event:export")
    @Log(title = "能源设施事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsFacsEvent admEmsFacsEvent)
    {
        List<EmsFacsEvent> list = emsFacsEventService.selectEmsFacsEventList(admEmsFacsEvent);
        ExcelUtil<EmsFacsEvent> util = new ExcelUtil<EmsFacsEvent>(EmsFacsEvent.class);
        util.exportExcel(response, list, "能源设施事件数据");
    }

    /**
     * 获取能源设施事件详细信息
     */
    @RequiresPermissions("ems:event:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emsFacsEventService.selectEmsFacsEventById(id));
    }

    /**
     * 新增能源设施事件
     */
    @RequiresPermissions("ems:event:add")
    @Log(title = "能源设施事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsFacsEvent admEmsFacsEvent)
    {
        return toAjax(emsFacsEventService.insertEmsFacsEvent(admEmsFacsEvent));
    }

    /**
     * 新增能源设施事件
     */
    @RequiresPermissions("ems:event:add")
    @Log(title = "能源设施事件", businessType = BusinessType.INSERT)
    @PostMapping(value = "/batch")
    public AjaxResult addBatch(@RequestBody List<EmsFacsEvent> emsFacsEvents)
    {
        return toAjax(emsFacsEventService.insertEmsFacsEventBatch(emsFacsEvents));
    }

    /**
     * 修改能源设施事件
     */
    @RequiresPermissions("ems:event:edit")
    @Log(title = "能源设施事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsFacsEvent admEmsFacsEvent)
    {
        return toAjax(emsFacsEventService.updateEmsFacsEvent(admEmsFacsEvent));
    }

    /**
     * 删除能源设施事件
     */
    @RequiresPermissions("ems:event:remove")
    @Log(title = "能源设施事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emsFacsEventService.deleteEmsFacsEventByIds(ids));
    }
}
