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.BusiDrillRecord;
import com.goldenwater.slaj.eme.service.IBusiDrillRecordService;

/**
 * 演练实施记录
 */
@RestController
@RequestMapping("/eme/drillrecord")
public class BusiDrillRecordController extends BaseController {
    @Autowired
    private IBusiDrillRecordService busiDrillRecordService;

    @GetMapping("/list")
    public TableDataInfo list(BusiDrillRecord busiDrillRecord) {
        startPage();
        List<BusiDrillRecord> list = busiDrillRecordService.selectBusiDrillRecordList(busiDrillRecord);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BusiDrillRecord busiDrillRecord) {
        return toAjax(busiDrillRecordService.insertBusiDrillRecord(busiDrillRecord));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BusiDrillRecord busiDrillRecord) {
        return toAjax(busiDrillRecordService.updateBusiDrillRecord(busiDrillRecord));
    }

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

    @Log(title = "演练实施记录管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eme:drillrecord:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiDrillRecord busiDrillRecord) {
        List<BusiDrillRecord> list = busiDrillRecordService.selectBusiDrillRecordList(busiDrillRecord);
        ExcelUtil<BusiDrillRecord> util = new ExcelUtil<BusiDrillRecord>(BusiDrillRecord.class);
        util.exportExcel(response, list, "演练实施记录数据");
    }
}
