package com.goldenwater.slaj.hazard.controller;

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

/**
 * 管控措施
 */
@RestController
@RequestMapping("/hazard/tbusicontrolmeasure")
public class TBusiControlMeasureController extends BaseController {
    @Autowired
    private ITBusiControlMeasureService tBusiControlMeasureService;

    @GetMapping("/list")
    public TableDataInfo list(TBusiControlMeasure tBusiControlMeasure) {
        startPage();
        List<TBusiControlMeasure> list = tBusiControlMeasureService.selectTBusiControlMeasureList(tBusiControlMeasure);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody TBusiControlMeasure tBusiControlMeasure) {
        return toAjax(tBusiControlMeasureService.insertTBusiControlMeasure(tBusiControlMeasure));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TBusiControlMeasure tBusiControlMeasure) {
        return toAjax(tBusiControlMeasureService.updateTBusiControlMeasure(tBusiControlMeasure));
    }

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

    @Log(title = "管控措施管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('hazard:tbusicontrolmeasure:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBusiControlMeasure tBusiControlMeasure) {
        List<TBusiControlMeasure> list = tBusiControlMeasureService.selectTBusiControlMeasureList(tBusiControlMeasure);
        ExcelUtil<TBusiControlMeasure> util = new ExcelUtil<>(TBusiControlMeasure.class);
        util.exportExcel(response, list, "管控措施数据");
    }
}
