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.TBusiHazardArchive;
import com.goldenwater.slaj.hazard.service.ITBusiHazardArchiveService;

/**
 * 危险源档案
 */
@RestController
@RequestMapping("/hazard/tbusihazardarchive")
public class TBusiHazardArchiveController extends BaseController {
    @Autowired
    private ITBusiHazardArchiveService tBusiHazardArchiveService;

    @GetMapping("/list")
    public TableDataInfo list(TBusiHazardArchive tBusiHazardArchive) {
        startPage();
        List<TBusiHazardArchive> list = tBusiHazardArchiveService.selectTBusiHazardArchiveList(tBusiHazardArchive);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody TBusiHazardArchive tBusiHazardArchive) {
        return toAjax(tBusiHazardArchiveService.insertTBusiHazardArchive(tBusiHazardArchive));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TBusiHazardArchive tBusiHazardArchive) {
        return toAjax(tBusiHazardArchiveService.updateTBusiHazardArchive(tBusiHazardArchive));
    }

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

    @Log(title = "危险源档案管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('hazard:tbusihazardarchive:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusiHazardArchive tBusiHazardArchive) {
        List<TBusiHazardArchive> list = tBusiHazardArchiveService.selectTBusiHazardArchiveList(tBusiHazardArchive);
        ExcelUtil<TBusiHazardArchive> util = new ExcelUtil<TBusiHazardArchive>(TBusiHazardArchive.class);
        util.exportExcel(response, list, "危险源档案数据");
    }
}
