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.repo.ElRepo;
import com.ruoyi.system.domain.repo.vo.RepoVO;
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 RepoController
 * @date 2024/6/27
 * @description 题库
 */
@Api("题库")
@Controller
@RequestMapping("/system/repo")
public class RepoController extends BaseController {


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

    @Resource
    private RepoManager elRepoManager;

    @ApiOperation("题库列表")
    @RequiresPermissions("system:repo:view")
    @GetMapping()
    public String repo() {
        return prefix + "/repo";
    }


    @ApiOperation("列表")
    @RequiresPermissions("system:repo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ElRepo repo) {
        startPage();
        List<RepoVO> list = elRepoManager.selectRepoList(repo);
        return getDataTable(list);
    }


    /**
     * 新增公告
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }


    @ApiOperation("新增")
    @RequiresPermissions("system:repo:add")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated ElRepo repo) {
        return toAjax(elRepoManager.saveOrUpdate(repo));
    }


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


    @ApiOperation("题库修改")
    @RequiresPermissions("system:repo:edit")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated ElRepo repo) {
        return toAjax(elRepoManager.saveOrUpdate(repo));
    }


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


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

    @ApiOperation("查询所有的题库")
    @Log(title = "题库", businessType = BusinessType.OTHER)
    @GetMapping("/repoList")
    @ResponseBody
    public AjaxResult repoList() {
        return success(elRepoManager.getList());
    }


}
