package com.pwt.web.controller;

import com.pwt.common.annotation.Log;
import com.pwt.common.core.controller.BaseController;
import com.pwt.common.core.domain.AjaxResult;
import com.pwt.common.core.page.TableDataInfo;
import com.pwt.common.enums.BusinessType;
import com.pwt.common.utils.poi.ExcelUtil;
import com.pwt.web.domain.PwtAlarmRecord;
import com.pwt.web.domain.PwtAlarmRecordQueryParam;
import com.pwt.web.domain.PwtAlarmRecordVo;
import com.pwt.web.service.IPwtAlarmRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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.Date;
import java.util.List;

/**
 * 告警记录Controller
 * 
 * @author linyun
 * @date 2022-11-17
 */
@Api("告警记录")
@RestController
@RequestMapping("/web/alarmRecord")
public class PwtAlarmRecordController extends BaseController
{
    @Autowired
    private IPwtAlarmRecordService pwtAlarmRecordService;

    /**
     * 获取来源设备字典
     * @return
     */
    @GetMapping("/getSourceDeviceDict")
    public AjaxResult getSourceDeviceDict()
    {
        return AjaxResult.success(pwtAlarmRecordService.getSourceDeviceDict());
    }

    /**
     * 查询告警记录列表
     */
    @ApiOperation("查询告警记录列表")
    @PreAuthorize("@ss.hasPermi('web:alarmRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(PwtAlarmRecordQueryParam param)
    {
        startPage();
        List<PwtAlarmRecordVo> list = pwtAlarmRecordService.selectPwtAlarmRecordList(param);
        return getDataTable(list);
    }

    /**
     * 导出告警记录列表
     */
    @ApiOperation("告警记录列表导出")
    @PreAuthorize("@ss.hasPermi('web:alarmRecord:export')")
    @Log(title = "告警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PwtAlarmRecordQueryParam param)
    {
        List<PwtAlarmRecordVo> list = pwtAlarmRecordService.selectPwtAlarmRecordList(param);
        ExcelUtil<PwtAlarmRecordVo> util = new ExcelUtil<PwtAlarmRecordVo>(PwtAlarmRecordVo.class);
        util.exportExcel(response, list, "告警记录");
    }

    /**
     * 获取告警记录详细信息
     */
    @ApiOperation("获取告警记录详细信息")
    @ApiImplicitParam(name = "recordId", value = "告警记录id", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('web:alarmRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(pwtAlarmRecordService.selectPwtAlarmRecordById(recordId));
    }
//
//    /**
//     * 新增告警记录
//     */
//    @ApiOperation("新增告警记录")
//    @ApiImplicitParams({
//        @ApiImplicitParam(name = "recordId", value = "记录id", dataType = "Long", dataTypeClass = Long.class),
//        @ApiImplicitParam(name = "alarmTime", value = "发生时间", dataType = "Date", dataTypeClass = Date.class),
//        @ApiImplicitParam(name = "sourceDevice", value = "来源设备", dataType = "String", dataTypeClass = String.class),
//        @ApiImplicitParam(name = "faultName", value = "故障名称", dataType = "String", dataTypeClass = String.class),
//        @ApiImplicitParam(name = "faultLevel", value = "故障等级", dataType = "String", dataTypeClass = String.class)
//    })
//    @PreAuthorize("@ss.hasPermi('web:alarmRecord:add')")
//    @Log(title = "告警记录", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody PwtAlarmRecord pwtAlarmRecord)
//    {
//        return toAjax(pwtAlarmRecordService.insertPwtAlarmRecord(pwtAlarmRecord));
//    }
//
//    /**
//     * 修改告警记录
//     */
//    @ApiOperation("修改告警记录")
//    @PreAuthorize("@ss.hasPermi('web:alarmRecord:edit')")
//    @Log(title = "告警记录", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody PwtAlarmRecord pwtAlarmRecord)
//    {
//        return toAjax(pwtAlarmRecordService.updatePwtAlarmRecord(pwtAlarmRecord));
//    }
//
//    /**
//     * 删除告警记录
//     */
//    @ApiOperation("删除告警记录")
//    @PreAuthorize("@ss.hasPermi('web:alarmRecord:remove')")
//    @Log(title = "告警记录", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{recordIds}")
//    public AjaxResult remove(@PathVariable Long[] recordIds)
//    {
//        return toAjax(pwtAlarmRecordService.deletePwtAlarmRecordByIds(recordIds));
//    }
}
