package com.ruoyi.web.controller.exam;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.exam.dto.ExamDTO;
import com.ruoyi.system.domain.exam.dto.request.ExamSaveReqDTO;
import com.ruoyi.system.domain.repo.ElRepo;
import com.ruoyi.web.controller.manager.ExamManager;
import com.ruoyi.web.controller.manager.RepoManager;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * packageName com.ruoyi.web.controller.examination
 *
 * @author wangxy
 * @version JDK 8
 * @className ExamController
 * @date 2024/6/28
 * @description 涉密考试
 */
@Api("考试")
@Controller
@RequestMapping("/system/newExam")
public class ExamController extends BaseController {


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

    @Resource
    private ExamManager examManager;

    @Resource
    private RepoManager elRepoManager;



    @ApiOperation("考试")
    @RequiresPermissions("system:exam:view")
    @GetMapping()
    public String exam() {
        return prefix + "/exam";
    }


    @ApiOperation("考试")
    //@RequiresPermissions("system:exam:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamDTO examDTO) {
        startPage();
        List<ExamDTO> list = examManager.selectExamList(examDTO);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("repo",elRepoManager.selectRepoList(new ElRepo()));
        return prefix + "/add";
    }

    @ApiOperation("新增")
    //@RequiresPermissions("system:exam:add")
    @Log(title = "考试", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated ExamSaveReqDTO reqDTO) {
        return toAjax(examManager.saveOrUpdate(reqDTO));
    }

    @ApiOperation("修改")
    //@RequiresPermissions("system:exam:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("repo",elRepoManager.selectRepoList(new ElRepo()));
        mmap.put("detailDTO", examManager.detail(id));
        return prefix + "/edit";
    }

    @ApiOperation("试题修改")
    //@RequiresPermissions("system:exam:edit")
    @Log(title = "考试", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated ExamSaveReqDTO reqDTO) {
        return toAjax(examManager.saveOrUpdate(reqDTO));
    }

    @ApiOperation("删除")
    //@RequiresPermissions("system:exam:remove")
    @Log(title = "考试", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(examManager.deleteQuByIds(ids));
    }

    @ApiOperation("详情")
    @Log(title = "考试", businessType = BusinessType.OTHER)
    @GetMapping("/detail")
    @ResponseBody
    public AjaxResult detail(String id) {
        return success(examManager.detail(id));
    }










}
