package com.ruoyi.model.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.Training;
import com.ruoyi.model.service.ITrainingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核培训Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/model/Training")
public class TrainingController extends BaseController
{
    @Autowired
    private ITrainingService trainingService;

    /**
     * 查询考核培训列表
     */
    @PreAuthorize("@ss.hasPermi('model:Training:list')")
    @GetMapping("/list")
    public TableDataInfo list(Training training)
    {
        startPage();
        List<Training> list = trainingService.selectTrainingList(training);
        return getDataTable(list);
    }

    /**
     * 导出考核培训列表
     */
    @PreAuthorize("@ss.hasPermi('model:Training:export')")
    @Log(title = "考核培训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Training training) throws IOException {
        List<Training> list = trainingService.selectTrainingList(training);
        ExcelUtil<Training> util = new ExcelUtil<Training>(Training.class);
        util.exportExcel(response, list, "考核培训数据");
    }

    /**
     * 获取考核培训详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:Training:query')")
    @GetMapping(value = "/{trainingId}")
    public AjaxResult getInfo(@PathVariable("trainingId") Long trainingId)
    {
        return success(trainingService.selectTrainingByTrainingId(trainingId));
    }

    /**
     * 新增考核培训
     */
    @PreAuthorize("@ss.hasPermi('model:Training:add')")
    @Log(title = "考核培训", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Training training)
    {
        return toAjax(trainingService.insertTraining(training));
    }

    /**
     * 修改考核培训
     */
    @PreAuthorize("@ss.hasPermi('model:Training:edit')")
    @Log(title = "考核培训", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Training training)
    {
        return toAjax(trainingService.updateTraining(training));
    }

    /**
     * 删除考核培训
     */
    @PreAuthorize("@ss.hasPermi('model:Training:remove')")
    @Log(title = "考核培训", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trainingIds}")
    public AjaxResult remove(@PathVariable Long[] trainingIds)
    {
        return toAjax(trainingService.deleteTrainingByTrainingIds(trainingIds));
    }
}
