package com.aucma.dms.controller;


import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.dms.domain.DmsBaseAlarmRule;
import com.aucma.dms.service.IDmsBaseAlarmRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 设备报警规则Controller
 *
 * @author Yinq
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/dms/dmsBaseAlarmRule")
public class DmsBaseAlarmRuleController extends BaseController {
    @Autowired
    private IDmsBaseAlarmRuleService dmsBaseAlarmRuleService;

    /**
     * 查询设备报警规则列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBaseAlarmRule:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsBaseAlarmRule dmsBaseAlarmRule) {
        startPage();
        List<DmsBaseAlarmRule> list = dmsBaseAlarmRuleService.selectDmsBaseAlarmRuleList(dmsBaseAlarmRule);
        return getDataTable(list);
    }

    /**
     * 查询设备报警规则下拉框列表
     */
    @GetMapping("/getAlarmRuleList")
    public AjaxResult getAlarmRuleList(DmsBaseAlarmRule dmsBaseAlarmRule) {
        List<DmsBaseAlarmRule> list = dmsBaseAlarmRuleService.selectDmsBaseAlarmRuleList(dmsBaseAlarmRule);
        return success(list);
    }

    /**
     * 导出设备报警规则列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBaseAlarmRule:export')" )
    //@Log(title = "设备报警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBaseAlarmRule dmsBaseAlarmRule) {
        List<DmsBaseAlarmRule> list = dmsBaseAlarmRuleService.selectDmsBaseAlarmRuleList(dmsBaseAlarmRule);
        ExcelUtil<DmsBaseAlarmRule> util = new ExcelUtil<DmsBaseAlarmRule>(DmsBaseAlarmRule.class);
        util.exportExcel(response, list, "设备报警规则数据");
    }

    /**
     * 获取设备报警规则详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBaseAlarmRule:query')" )
    @GetMapping(value = "/{alarmRuleId}")
    public AjaxResult getInfo(@PathVariable("alarmRuleId") Long alarmRuleId) {
        return success(dmsBaseAlarmRuleService.selectDmsBaseAlarmRuleByAlarmRuleId(alarmRuleId));
    }

    /**
     * 新增设备报警规则
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBaseAlarmRule:add')" )
    //@Log(title = "设备报警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsBaseAlarmRule dmsBaseAlarmRule) {
        return toAjax(dmsBaseAlarmRuleService.insertDmsBaseAlarmRule(dmsBaseAlarmRule));
    }

    /**
     * 修改设备报警规则
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBaseAlarmRule:edit')" )
    //@Log(title = "设备报警规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBaseAlarmRule dmsBaseAlarmRule) {
        return toAjax(dmsBaseAlarmRuleService.updateDmsBaseAlarmRule(dmsBaseAlarmRule));
    }

    /**
     * 删除设备报警规则
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsBaseAlarmRule:remove')" )
    //@Log(title = "设备报警规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{alarmRuleIds}")
    public AjaxResult remove(@PathVariable Long[] alarmRuleIds) {
        return toAjax(dmsBaseAlarmRuleService.deleteDmsBaseAlarmRuleByAlarmRuleIds(alarmRuleIds));
    }
}
