package com.goldenwater.slaj.ttsa.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.ttsa.domain.BisTtsaTrain;
import com.goldenwater.slaj.ttsa.service.IBisTtsaTrainService;

@RestController
@RequestMapping("/ttsa/ttsatrain")
public class BisTtsaTrainController extends BaseController {
    @Autowired
    private IBisTtsaTrainService bisTtsaTrainService;

    @GetMapping("/list")
    public TableDataInfo list(BisTtsaTrain bisTtsaTrain) {
        startPage();
        List<BisTtsaTrain> list = bisTtsaTrainService.selectBisTtsaTrainList(bisTtsaTrain);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisTtsaTrain bisTtsaTrain) {
        return toAjax(bisTtsaTrainService.insertBisTtsaTrain(bisTtsaTrain));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisTtsaTrain bisTtsaTrain) {
        return toAjax(bisTtsaTrainService.updateBisTtsaTrain(bisTtsaTrain));
    }

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

    @Log(title = "考核培训管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:ttsatrain:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisTtsaTrain bisTtsaTrain) {
        List<BisTtsaTrain> list = bisTtsaTrainService.selectBisTtsaTrainList(bisTtsaTrain);
        ExcelUtil<BisTtsaTrain> util = new ExcelUtil<BisTtsaTrain>(BisTtsaTrain.class);
        util.exportExcel(response, list, "考核培训管理数据");
    }
}
