package com.cmvr.web.controller.inspection;

import java.util.List;
import javax.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.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.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.inspection.domain.InspectionAlarm;
import com.cmvr.inspection.domain.vo.InspectionAlarmVo;
import com.cmvr.inspection.service.IInspectionAlarmService;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.common.core.page.TableDataInfo;

/**
 * 巡检告警Controller
 * 
 * @author cmvr-iot
 * @since 2026-05-29
 */
@RestController
@RequestMapping("/inspection/alarm")
@Api(tags = "智能巡检--告警管理")
public class InspectionAlarmController extends BaseController
{
    @Autowired
    private IInspectionAlarmService inspectionAlarmService;

    /**
     * 查询巡检告警列表
     */
    @ApiOperation("查询巡检告警列表")
    @PreAuthorize("@ss.hasPermi('inspection:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionAlarm inspectionAlarm)
    {
        startPage();
        List<InspectionAlarmVo> list = inspectionAlarmService.selectInspectionAlarmList(inspectionAlarm);
        return getDataTable(list);
    }

    /**
     * 导出巡检告警列表
     */
    @ApiOperation("导出巡检告警列表")
    @PreAuthorize("@ss.hasPermi('inspection:alarm:export')")
    @Log(title = "巡检告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionAlarm inspectionAlarm)
    {
        List<InspectionAlarmVo> list = inspectionAlarmService.selectInspectionAlarmList(inspectionAlarm);
        ExcelUtil<InspectionAlarmVo> util = new ExcelUtil<>(InspectionAlarmVo.class);
        util.exportExcel(response, list, "巡检告警数据");
    }

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

    /**
     * 新增巡检告警
     */
    @ApiOperation("新增巡检告警")
    @PreAuthorize("@ss.hasPermi('inspection:alarm:add')")
    @Log(title = "巡检告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionAlarm inspectionAlarm)
    {
        return toAjax(inspectionAlarmService.insertInspectionAlarm(inspectionAlarm));
    }

    /**
     * 修改巡检告警
     */
    @ApiOperation("修改巡检告警")
    @PreAuthorize("@ss.hasPermi('inspection:alarm:edit')")
    @Log(title = "巡检告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionAlarm inspectionAlarm)
    {
        return toAjax(inspectionAlarmService.updateInspectionAlarm(inspectionAlarm));
    }

    /**
     * 删除巡检告警
     */
    @ApiOperation("删除巡检告警")
    @PreAuthorize("@ss.hasPermi('inspection:alarm:remove')")
    @Log(title = "巡检告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(inspectionAlarmService.deleteInspectionAlarmByIds(ids));
    }
}
