package com.srs.web.controller.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.teacher.domain.SysTeacherTraining;
import com.srs.teacher.service.ISysTeacherTrainingService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * trainingController
 *
 * @author srs
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/teacher/training")
@Api(value = "辅导员学习培训管理", tags = "辅导员学习培训管理")
public class SysTeacherTrainingController extends BaseController {
    @Autowired
    private ISysTeacherTrainingService sysTeacherTrainingService;

    /**
     * 查询training列表
     */
@PreAuthorize("@ss.hasPermi('teacher:training:list')")
@GetMapping("/list")
@ApiOperation("查询training列表")
    public TableDataInfo list(SysTeacherTraining sysTeacherTraining)
    {
        startPage();
        List<SysTeacherTraining> list = sysTeacherTrainingService.selectSysTeacherTrainingList(sysTeacherTraining);
        return getDataTable(list);
    }

    /**
     * 导出training列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:training:export')")
    @Log(title = "training", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出training列表")
    public void export(HttpServletResponse response, SysTeacherTraining sysTeacherTraining)
    {
        List<SysTeacherTraining> list = sysTeacherTrainingService.selectSysTeacherTrainingList(sysTeacherTraining);
        ExcelUtil<SysTeacherTraining> util = new ExcelUtil<SysTeacherTraining>(SysTeacherTraining.class);
        util.exportExcel(response, list, "training数据");
    }

    /**
     * 获取training详细信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:training:query')")
    @GetMapping(value = "/{trainingId}")
    @ApiOperation("获取training详细信息")
    public AjaxResult getInfo(@PathVariable("trainingId") Long trainingId)
    {
        return success(sysTeacherTrainingService.selectSysTeacherTrainingByTrainingId(trainingId));
    }

    /**
     * 新增training
     */
    @PreAuthorize("@ss.hasPermi('teacher:training:add')")
    @Log(title = "training", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增training")
    public AjaxResult add(@RequestBody SysTeacherTraining sysTeacherTraining)
    {
        return toAjax(sysTeacherTrainingService.insertSysTeacherTraining(sysTeacherTraining));
    }

    /**
     * 修改training
     */
    @PreAuthorize("@ss.hasPermi('teacher:training:edit')")
    @Log(title = "training", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改training")
    public AjaxResult edit(@RequestBody SysTeacherTraining sysTeacherTraining)
    {
        return toAjax(sysTeacherTrainingService.updateSysTeacherTraining(sysTeacherTraining));
    }

    /**
     * 删除training
     */
    @PreAuthorize("@ss.hasPermi('teacher:training:remove')")
    @Log(title = "training", businessType = BusinessType.DELETE)
    @PostMapping("/{trainingIds}")
    @ApiOperation("删除training")
    public AjaxResult remove(@PathVariable Long[] trainingIds)
    {
        return toAjax(sysTeacherTrainingService.deleteSysTeacherTrainingByTrainingIds(trainingIds));
    }
}
