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.TDictMajorEd;
import com.goldenwater.slaj.hazard.service.ITDictMajorEdService;
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/tdictmajored")
public class TDictMajorEdController extends BaseController {
    @Autowired
    private ITDictMajorEdService tDictMajorEdService;

    @GetMapping("/list")
    public TableDataInfo list(TDictMajorEd tDictMajorEd) {
        startPage();
        List<TDictMajorEd> list = tDictMajorEdService.selectTDictMajorEdList(tDictMajorEd);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody TDictMajorEd tDictMajorEd) {
        return toAjax(tDictMajorEdService.insertTDictMajorEd(tDictMajorEd));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TDictMajorEd tDictMajorEd) {
        return toAjax(tDictMajorEdService.updateTDictMajorEd(tDictMajorEd));
    }

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

    @Log(title = "重大工程字典管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('hazard:tdictmajored:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDictMajorEd tDictMajorEd) {
        List<TDictMajorEd> list = tDictMajorEdService.selectTDictMajorEdList(tDictMajorEd);
        ExcelUtil<TDictMajorEd> util = new ExcelUtil<>(TDictMajorEd.class);
        util.exportExcel(response, list, "重大工程字典数据");
    }
}
