package com.goldenwater.slaj.eme.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.eme.domain.BusiTrainRecord;
import com.goldenwater.slaj.eme.service.IBusiTrainRecordService;

/**
 * 应急预案培训记录
 */
@RestController
@RequestMapping("/eme/trainrecord")
public class BusiTrainRecordController extends BaseController {
    @Autowired
    private IBusiTrainRecordService busiTrainRecordService;

    @GetMapping("/list")
    public TableDataInfo list(BusiTrainRecord busiTrainRecord) {
        startPage();
        List<BusiTrainRecord> list = busiTrainRecordService.selectBusiTrainRecordList(busiTrainRecord);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BusiTrainRecord busiTrainRecord) {
        return toAjax(busiTrainRecordService.insertBusiTrainRecord(busiTrainRecord));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BusiTrainRecord busiTrainRecord) {
        return toAjax(busiTrainRecordService.updateBusiTrainRecord(busiTrainRecord));
    }

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

    @Log(title = "应急预案培训记录管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eme:trainrecord:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiTrainRecord busiTrainRecord) {
        List<BusiTrainRecord> list = busiTrainRecordService.selectBusiTrainRecordList(busiTrainRecord);
        ExcelUtil<BusiTrainRecord> util = new ExcelUtil<BusiTrainRecord>(BusiTrainRecord.class);
        util.exportExcel(response, list, "应急预案培训记录数据");
    }
}
