package com.goldenwater.slaj.hazard.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.common.utils.poi.ExcelUtil;
import com.goldenwater.slaj.hazard.domain.TBusiInspectRecord;
import com.goldenwater.slaj.hazard.service.ITBusiInspectRecordService;

/**
 * 巡查记录
 */
@RestController
@RequestMapping("/hazard/tbusiinspectrecord")
public class TBusiInspectRecordController extends BaseController {
    @Autowired
    private ITBusiInspectRecordService tBusiInspectRecordService;

    @GetMapping("/list")
    public TableDataInfo list(TBusiInspectRecord tBusiInspectRecord) {
        startPage();
        List<TBusiInspectRecord> list = tBusiInspectRecordService.selectTBusiInspectRecordList(tBusiInspectRecord);
        return getDataTable(list);
    }

    @GetMapping("/{guid}")
    public AjaxResult getInfo(@PathVariable String guid) {
        return AjaxResult.success(tBusiInspectRecordService.selectTBusiInspectRecordByGuid(guid));
    }

    @PostMapping
    public AjaxResult add(@RequestBody TBusiInspectRecord tBusiInspectRecord) {
        return toAjax(tBusiInspectRecordService.insertTBusiInspectRecord(tBusiInspectRecord));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TBusiInspectRecord tBusiInspectRecord) {
        return toAjax(tBusiInspectRecordService.updateTBusiInspectRecord(tBusiInspectRecord));
    }

    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) {
        return toAjax(tBusiInspectRecordService.deleteTBusiInspectRecordByGuids(guids));
    }

    @Log(title = "巡查记录管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('hazard:tbusiinspectrecord:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusiInspectRecord tBusiInspectRecord) {
        List<TBusiInspectRecord> list = tBusiInspectRecordService.selectTBusiInspectRecordList(tBusiInspectRecord);
        ExcelUtil<TBusiInspectRecord> util = new ExcelUtil<TBusiInspectRecord>(TBusiInspectRecord.class);
        util.exportExcel(response, list, "巡查记录数据");
    }
}
