package com.ruoyi.inspection.controller;

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

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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.inspection.domain.InspectionAbnormal;
import com.ruoyi.inspection.service.IInspectionAbnormalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检异常Controller
 *
 * @author LSD
 * @date 2025-10-24
 */
@RestController
@RequestMapping("/inspection/abnormal")
public class InspectionAbnormalController extends BaseController {
    @Autowired
    private IInspectionAbnormalService inspectionAbnormalService;

    /**
     * 查询巡检异常列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:abnormal:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionAbnormal inspectionAbnormal) {
        startPage();
        List<InspectionAbnormal> list = inspectionAbnormalService.selectInspectionAbnormalList(inspectionAbnormal);
        return getDataTable(list);
    }

    /**
     * 导出巡检异常列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:abnormal:export')")
    @Log(title = "巡检异常", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionAbnormal inspectionAbnormal) {
        List<InspectionAbnormal> list = inspectionAbnormalService.selectInspectionAbnormalList(inspectionAbnormal);
        ExcelUtil<InspectionAbnormal> util = new ExcelUtil<InspectionAbnormal>(InspectionAbnormal.class);
        util.exportExcel(response, list, "巡检异常数据");
    }

    /**
     * 获取巡检异常详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:abnormal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(inspectionAbnormalService.selectInspectionAbnormalById(id));
    }

    /**
     * 新增巡检异常
     */
    @PreAuthorize("@ss.hasPermi('inspection:abnormal:add')")
    @Log(title = "巡检异常", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionAbnormal inspectionAbnormal) {
        return toAjax(inspectionAbnormalService.insertInspectionAbnormal(inspectionAbnormal));
    }

    /**
     * 修改巡检异常
     */
    @PreAuthorize("@ss.hasPermi('inspection:abnormal:edit')")
    @Log(title = "巡检异常", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionAbnormal inspectionAbnormal) {
        return toAjax(inspectionAbnormalService.updateInspectionAbnormal(inspectionAbnormal));
    }

    /**
     * 删除巡检异常
     */
    @PreAuthorize("@ss.hasPermi('inspection:abnormal:remove')")
    @Log(title = "巡检异常", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inspectionAbnormalService.deleteInspectionAbnormalByIds(ids));
    }
}
