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.DmsRecordAlarmInfo;
import com.aucma.dms.service.IDmsRecordAlarmInfoService;
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/dmsRecordAlarmInfo")
public class DmsRecordAlarmInfoController extends BaseController {

    @Autowired
    private IDmsRecordAlarmInfoService dmsRecordAlarmInfoService;

    /**
     * 查询设备报警记录列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRecordAlarmInfo:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsRecordAlarmInfo dmsRecordAlarmInfo) {
        startPage();
        List<DmsRecordAlarmInfo> list = dmsRecordAlarmInfoService.selectDmsRecordAlarmInfoList(dmsRecordAlarmInfo);
        return getDataTable(list);
    }

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

    /**
     * 获取设备报警记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRecordAlarmInfo:query')" )
    @GetMapping(value = "/{alarmId}")
    public AjaxResult getInfo(@PathVariable("alarmId") Long alarmId) {
        return success(dmsRecordAlarmInfoService.selectDmsRecordAlarmInfoByAlarmId(alarmId));
    }

    /**
     * 新增设备报警记录
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRecordAlarmInfo:add')" )
    ////@Log(title = "设备报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsRecordAlarmInfo dmsRecordAlarmInfo) {
        return toAjax(dmsRecordAlarmInfoService.insertDmsRecordAlarmInfo(dmsRecordAlarmInfo));
    }

    /**
     * 修改设备报警记录
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRecordAlarmInfo:edit')" )
    ////@Log(title = "设备报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsRecordAlarmInfo dmsRecordAlarmInfo) {
        return toAjax(dmsRecordAlarmInfoService.updateDmsRecordAlarmInfo(dmsRecordAlarmInfo));
    }

    /**
     * 删除设备报警记录
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRecordAlarmInfo:remove')" )
    ////@Log(title = "设备报警记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{alarmIds}")
    public AjaxResult remove(@PathVariable Long[] alarmIds) {
        return toAjax(dmsRecordAlarmInfoService.deleteDmsRecordAlarmInfoByAlarmIds(alarmIds));
    }

    /**
     * 设备报警人工处理
     */
    //@PreAuthorize("@ss.hasPermi('dms:dmsRecordAlarmInfo:edit')" )
    ////@Log(title = "设备报警记录", businessType = BusinessType.UPDATE)
    @PostMapping("/handleDmsRecordAlarmInfo")
    public AjaxResult handleDmsRecordAlarmInfo(@RequestBody DmsRecordAlarmInfo dmsRecordAlarmInfo) {
        return toAjax(dmsRecordAlarmInfoService.handleDmsRecordAlarmInfo(dmsRecordAlarmInfo));
    }

    /**
     * 设备报警消息通知
     * @return
     */
    @PostMapping("/alarmNotification")
    //@InnerAuth
    public AjaxResult alarmNotification() {
        return AjaxResult.success(dmsRecordAlarmInfoService.alarmNotification());
    }
}
