package com.aucma.report.controller;

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

import com.aucma.common.utils.DateUtils;
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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.report.domain.DeviceAlarmRecord;
import com.aucma.report.service.IDeviceAlarmRecordService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 设备报警记录Controller
 *
 * @author Yinq
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/report/deviceAlarmRecord")
public class DeviceAlarmRecordController extends BaseController {
    @Autowired
    private IDeviceAlarmRecordService deviceAlarmRecordService;

    /**
     * 查询设备报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('report:deviceAlarmRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceAlarmRecord deviceAlarmRecord) {
        startPage();
        List<DeviceAlarmRecord> list = deviceAlarmRecordService.selectDeviceAlarmRecordList(deviceAlarmRecord);
        return getDataTable(list);
    }

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

    /**
     * 获取设备报警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:deviceAlarmRecord:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId) {
        return success(deviceAlarmRecordService.selectDeviceAlarmRecordByObjId(objId));
    }

    /**
     * 新增设备报警记录
     */
    @PreAuthorize("@ss.hasPermi('report:deviceAlarmRecord:add')")
    @Log(title = "设备报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceAlarmRecord deviceAlarmRecord) {
        deviceAlarmRecord.setCreatedBy(getUsername());
        deviceAlarmRecord.setCreatedTime(DateUtils.getNowDate());
        return toAjax(deviceAlarmRecordService.insertDeviceAlarmRecord(deviceAlarmRecord));
    }

    /**
     * 修改设备报警记录
     */
    @PreAuthorize("@ss.hasPermi('report:deviceAlarmRecord:edit')")
    @Log(title = "设备报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceAlarmRecord deviceAlarmRecord) {
        return toAjax(deviceAlarmRecordService.updateDeviceAlarmRecord(deviceAlarmRecord));
    }

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