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.BisTtsaTrainPers;
import com.goldenwater.slaj.ttsa.service.IBisTtsaTrainPersService;

@RestController
@RequestMapping("/ttsa/ttsatrainpers")
public class BisTtsaTrainPersController extends BaseController {
    @Autowired
    private IBisTtsaTrainPersService bisTtsaTrainPersService;

    @GetMapping("/list")
    public TableDataInfo list(BisTtsaTrainPers bisTtsaTrainPers) {
        startPage();
        List<BisTtsaTrainPers> list = bisTtsaTrainPersService.selectBisTtsaTrainPersList(bisTtsaTrainPers);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisTtsaTrainPers bisTtsaTrainPers) {
        return toAjax(bisTtsaTrainPersService.insertBisTtsaTrainPers(bisTtsaTrainPers));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisTtsaTrainPers bisTtsaTrainPers) {
        return toAjax(bisTtsaTrainPersService.updateBisTtsaTrainPers(bisTtsaTrainPers));
    }

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

    @Log(title = "培训人员管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:ttsatrainpers:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisTtsaTrainPers bisTtsaTrainPers) {
        List<BisTtsaTrainPers> list = bisTtsaTrainPersService.selectBisTtsaTrainPersList(bisTtsaTrainPers);
        ExcelUtil<BisTtsaTrainPers> util = new ExcelUtil<BisTtsaTrainPers>(BisTtsaTrainPers.class);
        util.exportExcel(response, list, "培训人员管理数据");
    }
}
