package com.ruoyi.web.controller.exam;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.paper.dto.response.PaperListRespDTO;
import com.ruoyi.system.domain.userexam.dto.request.UserExamReqDTO;
import com.ruoyi.system.domain.userexam.dto.response.UserExamRespDTO;
import com.ruoyi.web.controller.manager.UserExamManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * packageName com.ruoyi.web.controller.exam
 *
 * @author wangxy
 * @version JDK 8
 * @className UserExamController
 * @date 2024/7/3
 * @description 考试详情
 */
@Api("考试详情")
@Controller
@RequestMapping("/system/userExam")
public class UserExamController extends BaseController {

    @Resource
    private UserExamManager userExamManager;


    private String prefix = "system/elExam/userExam";


    @ApiOperation("考试详情")
    @GetMapping("/toExam/{id}")
    public String toExam(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("examId", id);
        return prefix + "/userExam";
    }


    @ApiOperation("考试详情")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserExamReqDTO reqDTO) {
        startPage();
        List<UserExamRespDTO> list = userExamManager.selectExamList(reqDTO);
        return getDataTable(list);
    }

    @ApiOperation("详情")
    @GetMapping("/detail/{examId}/{userId}")
    public String detail(@PathVariable("examId") String examId, @PathVariable("userId") Long userId, ModelMap mmap) {
        List<PaperListRespDTO> list = userExamManager.detail(examId, userId);
        mmap.put("list", list);
        return prefix + "/view";
    }

    @ApiOperation("我的成绩")
    @RequiresPermissions("system:userExam:list")
    @PostMapping("/myGrades")
    @ResponseBody
    public TableDataInfo myGrades(UserExamReqDTO reqDTO) {
        startPage();
        reqDTO.setUserId(getUserId());
        List<UserExamRespDTO> list = userExamManager.selectExamList(reqDTO);
        return getDataTable(list);
    }

    @ApiOperation("我的成绩")
    @RequiresPermissions("system:userExam:view")
    @GetMapping()
    public String userExam() {
        return prefix + "/myGrades";
    }





}
