package com.sundot.airport.web.controller.equipment;

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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.equipment.domain.EquipmentInspectionRecord;
import com.sundot.airport.equipment.service.IEquipmentInspectionRecordService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 设备定检记录Controller
 *
 * @author ruoyi
 * @date 2026-05-12
 */
@RestController
@RequestMapping("/equipment/record")
public class EquipmentInspectionRecordController extends BaseController {
    @Autowired
    private IEquipmentInspectionRecordService equipmentInspectionRecordService;

    /**
     * 查询设备定检记录列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentInspectionRecord equipmentInspectionRecord) {
        startPage();
        List<EquipmentInspectionRecord> list = equipmentInspectionRecordService.selectEquipmentInspectionRecordList(equipmentInspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出设备定检记录列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:record:export')")
    @Log(title = "设备定检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentInspectionRecord equipmentInspectionRecord) {
        List<EquipmentInspectionRecord> list = equipmentInspectionRecordService.selectEquipmentInspectionRecordList(equipmentInspectionRecord);
        ExcelUtil<EquipmentInspectionRecord> util = new ExcelUtil<EquipmentInspectionRecord>(EquipmentInspectionRecord.class);
        util.exportExcel(response, list, "设备定检记录数据");
    }

    /**
     * 获取设备定检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(equipmentInspectionRecordService.selectEquipmentInspectionRecordById(id));
    }

    /**
     * 新增设备定检记录
     */
    @PreAuthorize("@ss.hasPermi('equipment:record:add')")
    @Log(title = "设备定检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentInspectionRecord equipmentInspectionRecord) {
        equipmentInspectionRecord.setCreateBy(getUsername());
        return toAjax(equipmentInspectionRecordService.insertEquipmentInspectionRecord(equipmentInspectionRecord));
    }

    /**
     * 修改设备定检记录
     */
    @PreAuthorize("@ss.hasPermi('equipment:record:edit')")
    @Log(title = "设备定检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentInspectionRecord equipmentInspectionRecord) {
        equipmentInspectionRecord.setUpdateBy(getUsername());
        return toAjax(equipmentInspectionRecordService.updateEquipmentInspectionRecord(equipmentInspectionRecord));
    }

    /**
     * 删除设备定检记录
     */
    @PreAuthorize("@ss.hasPermi('equipment:record:remove')")
    @Log(title = "设备定检记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(equipmentInspectionRecordService.deleteEquipmentInspectionRecordByIds(ids));
    }
}
