package com.ruoyi.business.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.business.domain.HwAlarmRule;
import com.ruoyi.business.service.IHwAlarmRuleService;
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 xins
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/alarmRule")
public class HwAlarmRuleController extends BaseController
{
    @Autowired
    private IHwAlarmRuleService hwAlarmRuleService;

    /**
     * 查询报警规则列表
     */
    @RequiresPermissions("business:alarmRule:list")
    @GetMapping("/list")
    public TableDataInfo list(HwAlarmRule hwAlarmRule)
    {
        startPage();
        List<HwAlarmRule> list = hwAlarmRuleService.selectHwAlarmRuleList(hwAlarmRule);
        return getDataTable(list);
    }

    /**
     * 导出报警规则列表
     */
    @RequiresPermissions("business:alarmRule:export")
    @Log(title = "报警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HwAlarmRule hwAlarmRule)
    {
        List<HwAlarmRule> list = hwAlarmRuleService.selectHwAlarmRuleList(hwAlarmRule);
        ExcelUtil<HwAlarmRule> util = new ExcelUtil<HwAlarmRule>(HwAlarmRule.class);
        util.exportExcel(response, list, "报警规则数据");
    }

    /**
     * 获取报警规则详细信息
     */
    @RequiresPermissions("business:alarmRule:query")
    @GetMapping(value = "/{alarmRuleId}")
    public AjaxResult getInfo(@PathVariable("alarmRuleId") Long alarmRuleId)
    {
        return success(hwAlarmRuleService.selectHwAlarmRuleByAlarmRuleId(alarmRuleId));
    }

    /**
     * 新增报警规则
     */
    @RequiresPermissions("business:alarmRule:add")
    @Log(title = "报警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HwAlarmRule hwAlarmRule)
    {
        return toAjax(hwAlarmRuleService.insertHwAlarmRule(hwAlarmRule));
    }

    /**
     * 修改报警规则
     */
    @RequiresPermissions("business:alarmRule:edit")
    @Log(title = "报警规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HwAlarmRule hwAlarmRule)
    {
        return toAjax(hwAlarmRuleService.updateHwAlarmRule(hwAlarmRule));
    }

    /**
     * 删除报警规则
     */
    @RequiresPermissions("business:alarmRule:remove")
    @Log(title = "报警规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmRuleIds}")
    public AjaxResult remove(@PathVariable Long[] alarmRuleIds)
    {
        return toAjax(hwAlarmRuleService.deleteHwAlarmRuleByAlarmRuleIds(alarmRuleIds));
    }
}
