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.userbook.ElUserBook;
import com.ruoyi.system.domain.userbook.dto.UserBookDTO;
import com.ruoyi.web.controller.manager.UserBookManager;
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 UserBookController
 * @date 2024/7/9
 * @description 错题
 */
@Api("错题")
@Controller
@RequestMapping("/system/userBook")
public class UserBookController extends BaseController {


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

    @Resource
    private UserBookManager userBookManager;

    @ApiOperation("错题列表")
    @GetMapping("/toBook/{id}")
    public String toBook(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("examId", id);
        return prefix + "/book";
    }


    @ApiOperation("错题")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserBookDTO reqDTO) {
        startPage();
        List<ElUserBook> list = userBookManager.paging(reqDTO);
        return getDataTable(list);
    }


    @ApiOperation("删除")
    @Log(title = "错题", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(userBookManager.deleteRepoByIds(ids));
    }

    @ApiOperation("详情")
    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("quId", id);
        return prefix + "/view";
    }


    @ApiOperation("错题训练")
    @GetMapping("/toTrain/{examId}")
    public String toTrain(@PathVariable("examId") String examId, ModelMap mmap) {
        mmap.put("examId", examId);
        return prefix + "/toTrain";
    }


    @ApiOperation("查找列表")
    @PostMapping("/next")
    @ResponseBody
    public AjaxResult next(@RequestBody  UserBookDTO reqDTO) {
        return AjaxResult.success(userBookManager.findNext(reqDTO.getExamId(),reqDTO.getQuId()));
    }



}
