package com.ruoyi.project.training.elearn.controller;

import java.util.List;

import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
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.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.training.elearn.domain.TElExam;
import com.ruoyi.project.training.elearn.service.ITElExamService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 考试Controller
 *
 * @author ssy
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/elearn/exam")
public class TElExamController extends BaseController
{
    @Autowired
    private ITElExamService tElExamService;

    /**
     * 查询考试列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TElExam tElExam)
    {
        startPage();
        List<TElExam> list = tElExamService.selectTElExamList(tElExam);
        return getDataTable(list);
    }

    /**
     * 导出考试列表
     */
    @Log(title = "考试", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TElExam tElExam)
    {
        List<TElExam> list = tElExamService.selectTElExamList(tElExam);
        ExcelUtil<TElExam> util = new ExcelUtil<TElExam>(TElExam.class);
        return util.exportExcel(list, "exam");
    }

    /**
     * 获取考试详细信息
     */
    @GetMapping(value = "/{examId}")
    public AjaxResult getInfo(@PathVariable("examId") Long examId)
    {
        return AjaxResult.success(tElExamService.selectTElExamById(examId));
    }

    /**
     * 新增考试
     */
    @Log(title = "考试", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TElExam tElExam)
    {
        return toAjax(tElExamService.insertTElExam(tElExam));
    }

    /**
     * 修改考试
     */
    @Log(title = "考试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TElExam tElExam)
    {
        return toAjax(tElExamService.updateTElExam(tElExam));
    }

    /**
     * 删除考试
     */
    @Log(title = "考试", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examIds}")
    public AjaxResult remove(@PathVariable Long[] examIds)
    {
        return toAjax(tElExamService.deleteTElExamByIds(examIds));
    }
}
