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

import java.util.List;
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.TElUserExam;
import com.ruoyi.project.training.elearn.service.ITElUserExamService;
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-31
 */
@RestController
@RequestMapping("/elearn/userExam")
public class TElUserExamController extends BaseController
{
    @Autowired
    private ITElUserExamService tElUserExamService;

    /**
     * 查询我的成绩列表
     */
    @GetMapping("/myList")
    public TableDataInfo mylist(TElUserExam tElUserExam)
    {
        tElUserExam.setUserId(getUserId());
        startPage();
        List<TElUserExam> list = tElUserExamService.selectTElUserExamList(tElUserExam);
        return getDataTable(list);
    }

    /**
     * 查询我的成绩列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TElUserExam tElUserExam)
    {
        startPage();
        List<TElUserExam> list = tElUserExamService.selectTElUserExamList(tElUserExam);
        return getDataTable(list);
    }

    /**
     * 导出我的成绩列表
     */
    @Log(title = "我的成绩", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TElUserExam tElUserExam)
    {
        List<TElUserExam> list = tElUserExamService.selectTElUserExamList(tElUserExam);
        ExcelUtil<TElUserExam> util = new ExcelUtil<TElUserExam>(TElUserExam.class);
        return util.exportExcel(list, "userExam");
    }

    /**
     * 获取我的成绩详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tElUserExamService.selectTElUserExamById(id));
    }

    /**
     * 新增我的成绩
     */
    @Log(title = "我的成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TElUserExam tElUserExam)
    {
        return toAjax(tElUserExamService.insertTElUserExam(tElUserExam));
    }

    /**
     * 修改我的成绩
     */
    @Log(title = "我的成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TElUserExam tElUserExam)
    {
        return toAjax(tElUserExamService.updateTElUserExam(tElUserExam));
    }

    /**
     * 删除我的成绩
     */
    @Log(title = "我的成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tElUserExamService.deleteTElUserExamByIds(ids));
    }
}
