package com.ruoyi.web.controller.system.exam;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TdExamnum;
import com.ruoyi.system.domain.TdQuestion;
import com.ruoyi.system.service.ITdExamnumService;
import com.ruoyi.system.service.ITdQuestionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.core.controller.BaseController;

import java.util.List;

/**
 * 保密考试
 *
 */
@Controller
@RequestMapping("/system/exam")
public class TdExamController extends BaseController{
    private String prefix = "system/exam";

    @Autowired
    private ITdQuestionService tdQuestionService;
    @Autowired
    private ITdExamnumService tdExamnumService;

    @RequiresPermissions("system:exam:view")
    @GetMapping()
    public String index(ModelMap mmap){
        SysUser user = getSysUser();
        mmap.put("user", user);
        return prefix + "/index";
    }

    /**
     * 保存人员考试结果
     */
    @Log(title = "保密考试", businessType = BusinessType.EXAM)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TdExamnum tdExamnum)
    {
        return toAjax(tdExamnumService.insertTdExamnum(tdExamnum));
    }

    /**
     * 查询题库列表返回
     */
    @RequiresPermissions("system:exam:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TdQuestion tdQuestion)
    {
        startPage();
        List<TdQuestion> list = tdQuestionService.selectTdQuestionList(tdQuestion);
        return getDataTable(list);
    }

    /**
     * 访问考试界面，点击开始答题，重定向到exam页面
     */
    @GetMapping("/edit")
    public String index(){
        return prefix + "/exam";
    }
}
