package com.cmvr.web.controller.aima;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.aima.domain.AimaAlarm;
import com.cmvr.aima.service.IAimaAlarmService;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/aima/alarm")
@Api(tags = "爱玛电动车--告警管理")
public class AimaAlarmController extends BaseController {
    @Autowired
    private IAimaAlarmService aimaAlarmService;

    @ApiOperation("查询告警列表")
    @PreAuthorize("@ss.hasPermi('aima:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(AimaAlarm aimaAlarm) {
        startPage();
        List<AimaAlarm> list = aimaAlarmService.selectAimaAlarmList(aimaAlarm);
        return getDataTable(list);
    }

    @ApiOperation("导出告警列表")
    @PreAuthorize("@ss.hasPermi('aima:alarm:export')")
    @Log(title = "告警管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AimaAlarm aimaAlarm) {
        List<AimaAlarm> list = aimaAlarmService.selectAimaAlarmList(aimaAlarm);
        ExcelUtil<AimaAlarm> util = new ExcelUtil<>(AimaAlarm.class);
        util.exportExcel(response, list, "告警数据");
    }

    @ApiOperation("获取告警详细信息")
    @PreAuthorize("@ss.hasPermi('aima:alarm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(aimaAlarmService.selectAimaAlarmById(id));
    }

    @ApiOperation("新增告警")
    @PreAuthorize("@ss.hasPermi('aima:alarm:add')")
    @Log(title = "告警管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AimaAlarm aimaAlarm) {
        return toAjax(aimaAlarmService.insertAimaAlarm(aimaAlarm));
    }

    @ApiOperation("修改告警")
    @PreAuthorize("@ss.hasPermi('aima:alarm:edit')")
    @Log(title = "告警管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AimaAlarm aimaAlarm) {
        return toAjax(aimaAlarmService.updateAimaAlarm(aimaAlarm));
    }

    @ApiOperation("删除告警")
    @PreAuthorize("@ss.hasPermi('aima:alarm:remove')")
    @Log(title = "告警管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(aimaAlarmService.deleteAimaAlarmByIds(ids));
    }
}
