package com.xinda.itsm.controller;

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.xinda.common.annotation.Log;
import com.xinda.common.core.controller.BaseController;
import com.xinda.common.core.domain.AjaxResult;
import com.xinda.common.enums.BusinessType;
import com.xinda.itsm.domain.InspectionRecord;
import com.xinda.itsm.service.IInspectionRecordService;
import com.xinda.common.utils.poi.ExcelUtil;
import com.xinda.common.core.page.TableDataInfo;

/**
 * 巡检记录Controller
 *
 * @author kerwincui
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/itsm/record")
@Api(tags = "巡检记录")
public class InspectionRecordController extends BaseController
{
    @Autowired
    private IInspectionRecordService inspectionRecordService;

/**
 * 查询巡检记录列表
 */
@PreAuthorize("@ss.hasPermi('itsm:record:list')")
@GetMapping("/list")
@ApiOperation("查询巡检记录列表")
    public TableDataInfo list(InspectionRecord inspectionRecord)
    {
        startPage();
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出巡检记录列表
     */
    @ApiOperation("导出巡检记录列表")
    @PreAuthorize("@ss.hasPermi('itsm:record:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionRecord inspectionRecord)
    {
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        ExcelUtil<InspectionRecord> util = new ExcelUtil<InspectionRecord>(InspectionRecord.class);
        util.exportExcel(response, list, "巡检记录数据");
    }

    /**
     * 获取巡检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('itsm:record:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取巡检记录详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inspectionRecordService.selectInspectionRecordById(id));
    }

    /**
     * 新增巡检记录
     */
    @PreAuthorize("@ss.hasPermi('itsm:record:add')")
    @PostMapping
    @ApiOperation("新增巡检记录")
    public AjaxResult add(@RequestBody InspectionRecord inspectionRecord)
    {
        return toAjax(inspectionRecordService.insertInspectionRecord(inspectionRecord));
    }

    /**
     * 修改巡检记录
     */
    @PreAuthorize("@ss.hasPermi('itsm:record:edit')")
    @PutMapping
    @ApiOperation("修改巡检记录")
    public AjaxResult edit(@RequestBody InspectionRecord inspectionRecord)
    {
        return toAjax(inspectionRecordService.updateInspectionRecord(inspectionRecord));
    }

    /**
     * 删除巡检记录
     */
    @PreAuthorize("@ss.hasPermi('itsm:record:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除巡检记录")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inspectionRecordService.deleteInspectionRecordByIds(ids));
    }
}
