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.qu.ElQu;
import com.ruoyi.system.domain.qu.dto.ext.QuDetailDTO;
import com.ruoyi.system.domain.qu.dto.request.QuQueryReqDTO;
import com.ruoyi.web.controller.manager.QuManager;
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 QuController
 * @date 2024/6/27
 * @description 试题
 */
@Api("试题")
@Controller
@RequestMapping("/system/qu")
public class QuController extends BaseController {

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

    @Resource
    private QuManager quManager;

    @Resource
    private RepoManager elRepoManager;


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


    @ApiOperation("试题")
    //@RequiresPermissions("system:qu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuQueryReqDTO qu) {
        startPage();
        List<ElQu> list = quManager.selectQuList(qu);
        return getDataTable(list);
    }

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


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


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

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


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


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



}
