package com.ruoyi.ems.record.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ems.record.domain.EmsRecordAlarmRule;
import com.ruoyi.ems.record.service.IEmsRecordAlarmRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异常告警规则Controller
 * 
 * @author Yinq
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/ems/record/recordAlarmRule")
public class EmsRecordAlarmRuleController extends BaseController
{
    @Autowired
    private IEmsRecordAlarmRuleService emsRecordAlarmRuleService;

    /**
     * 查询异常告警规则列表
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsRecordAlarmRule emsRecordAlarmRule)
    {
        startPage();
        List<EmsRecordAlarmRule> list = emsRecordAlarmRuleService.selectEmsRecordAlarmRuleList(emsRecordAlarmRule);
        return getDataTable(list);
    }

    /**
     * 导出异常告警规则列表
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmRule:export')")
    @Log(title = "异常告警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsRecordAlarmRule emsRecordAlarmRule)
    {
        List<EmsRecordAlarmRule> list = emsRecordAlarmRuleService.selectEmsRecordAlarmRuleList(emsRecordAlarmRule);
        ExcelUtil<EmsRecordAlarmRule> util = new ExcelUtil<EmsRecordAlarmRule>(EmsRecordAlarmRule.class);
        util.exportExcel(response, list, "异常告警规则数据");
    }

    /**
     * 获取异常告警规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmRule:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsRecordAlarmRuleService.selectEmsRecordAlarmRuleByObjId(objId));
    }

    /**
     * 新增异常告警规则
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmRule:add')")
    @Log(title = "异常告警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsRecordAlarmRule emsRecordAlarmRule)
    {
        emsRecordAlarmRule.setCreateBy(getUsername());
        return toAjax(emsRecordAlarmRuleService.insertEmsRecordAlarmRule(emsRecordAlarmRule));
    }

    /**
     * 修改异常告警规则
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmRule:edit')")
    @Log(title = "异常告警规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsRecordAlarmRule emsRecordAlarmRule)
    {
        emsRecordAlarmRule.setUpdateBy(getUsername());
        return toAjax(emsRecordAlarmRuleService.updateEmsRecordAlarmRule(emsRecordAlarmRule));
    }

    /**
     * 删除异常告警规则
     */
    @PreAuthorize("@ss.hasPermi('ems/record:recordAlarmRule:remove')")
    @Log(title = "异常告警规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsRecordAlarmRuleService.deleteEmsRecordAlarmRuleByObjIds(objIds));
    }
}
