package com.ruoyi.ems.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.AdmOpAlarmPolicy;
import com.ruoyi.ems.service.IAdmOpAlarmPolicyService;
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-26
 */
@RestController
@RequestMapping("/alarm")
public class AdmOpAlarmPolicyController extends BaseController
{
    @Autowired
    private IAdmOpAlarmPolicyService admOpAlarmPolicyService;

    /**
     * 查询能源设施告警策略列表
     */
    @RequiresPermissions("ems:alarm-strategy:list")
    @GetMapping("/list")
    public TableDataInfo list(AdmOpAlarmPolicy admOpAlarmPolicy)
    {
        startPage();
        List<AdmOpAlarmPolicy> list = admOpAlarmPolicyService.selectAdmOpAlarmPolicyList(admOpAlarmPolicy);
        return getDataTable(list);
    }

    /**
     * 导出能源设施告警策略列表
     */
    @RequiresPermissions("ems:alarm-strategy:export")
    @Log(title = "能源设施告警策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdmOpAlarmPolicy admOpAlarmPolicy)
    {
        List<AdmOpAlarmPolicy> list = admOpAlarmPolicyService.selectAdmOpAlarmPolicyList(admOpAlarmPolicy);
        ExcelUtil<AdmOpAlarmPolicy> util = new ExcelUtil<AdmOpAlarmPolicy>(AdmOpAlarmPolicy.class);
        util.exportExcel(response, list, "能源设施告警策略数据");
    }

    /**
     * 获取能源设施告警策略详细信息
     */
    @RequiresPermissions("ems:alarm-strategy:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(admOpAlarmPolicyService.selectAdmOpAlarmPolicyById(id));
    }

    /**
     * 新增能源设施告警策略
     */
    @RequiresPermissions("ems:alarm-strategy:add")
    @Log(title = "能源设施告警策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdmOpAlarmPolicy admOpAlarmPolicy)
    {
        return toAjax(admOpAlarmPolicyService.insertAdmOpAlarmPolicy(admOpAlarmPolicy));
    }

    /**
     * 修改能源设施告警策略
     */
    @RequiresPermissions("ems:alarm-strategy:edit")
    @Log(title = "能源设施告警策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdmOpAlarmPolicy admOpAlarmPolicy)
    {
        return toAjax(admOpAlarmPolicyService.updateAdmOpAlarmPolicy(admOpAlarmPolicy));
    }

    /**
     * 删除能源设施告警策略
     */
    @RequiresPermissions("ems:alarm-strategy:remove")
    @Log(title = "能源设施告警策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(admOpAlarmPolicyService.deleteAdmOpAlarmPolicyByIds(ids));
    }
}
