package com.ruoyi.web.controller.test.gl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.test.domain.DO.PaperCreateDO;
import com.ruoyi.test.domain.DO.QuestionbankDO;
import com.ruoyi.test.domain.DO.QuestionbankDO1;
import com.ruoyi.test.domain.ExamPaper;
import com.ruoyi.test.domain.Questionbank;
import com.ruoyi.test.seriver.IExamCreateService;
import com.ruoyi.test.seriver.IExamPaperService;
import com.ruoyi.test.seriver.IQuestionbankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "管理端卷库管理")
@RestController
@RequestMapping("/gl/exampaper")
public class ExamPaperController {
    @Autowired
    private IExamPaperService iExamPaperService;

    @Autowired
    private IExamCreateService iExamCreateService;

    @Autowired
    private IQuestionbankService iQuestionbankService;

    @ApiOperation("试卷列表")
    @GetMapping("selectAll")
    public R<IPage<ExamPaper>> selectAll(int pagenum,int pagesize){
        return R.ok(iExamPaperService.selectAll(pagenum,pagesize));
    }

    @ApiOperation("查询试卷列表")
    @GetMapping("selectByGrateAndSubjectAndId")
    public R<IPage<ExamPaper>> selectByGrateAndSubjectAndId(int pagenum,int pagesize,String grade,String subject,Long id){
        return R.ok(iExamPaperService.selectByGrateAndSubjectAndId(pagenum,pagesize,grade,subject,id));
    }

//    @ApiOperation("根据年级查试卷列表")
//    @GetMapping("selectByGrate")
//    public R<IPage<ExamPaper>> selectByGrate(int pagenum,String grade){
//        return R.ok(iExamPaperService.selectByGrate(pagenum,grade));
//    }
//
//    @ApiOperation("根据学科查试卷列表")
//    @GetMapping("selectBySubject")
//    public R<IPage<ExamPaper>> selectBySubject(int pagenum,String subject){
//        return R.ok(iExamPaperService.selectBySubject(pagenum,subject));
//    }
//
//    @ApiOperation("根据id查试卷列表")
//    @GetMapping("selectById")
//    public R<IPage<ExamPaper>> selectById(int pagenum,Long id){
//        return R.ok(iExamPaperService.selectById(pagenum,id));
//    }

    @ApiOperation("试卷创编（添加试卷）")
    @PostMapping("addPaperExam")
    public R<String> addPaperExam(@RequestBody PaperCreateDO paperCreateDO){
        if(iExamPaperService.addPaperExam(paperCreateDO)!=0){
            return R.ok("试卷添加成功！");
        }
        return R.fail("试卷添加失败！");
    }

    //自动返回
    @GetMapping("selectId")
    public Long selectId(@RequestBody PaperCreateDO paperCreateDO){
        return iExamPaperService.selectId(paperCreateDO);
    }

    @ApiOperation("试卷创编（添加题目）")
    @GetMapping("addPaperCreate")
    public R<String> addPaperCreate(Long id,Long pid){
        if(pid!=-1){
            if(iExamCreateService.addPaperCreate(id,pid)!=0){
                return R.ok("添加成功！");
            }
            return R.fail("添加失败！");
        }
        return R.fail("找不到该试卷！");
    }

    @ApiOperation("试卷创编（删除题目）")
    @DeleteMapping("deletePaperCreate")
    public R<String> deletePaperCreate(Long id,Long pid){
        if(iExamCreateService.deletePaperCreate(id,pid)!=0){
            return R.ok("删除成功！");
        }
        return R.fail("删除失败！");
    }

    @ApiOperation("试卷创编（试卷显示）")
    @GetMapping("selectPaperCreate")
    public R<List<QuestionbankDO>> selectPaperCreate(Long pid){
        return R.ok(iExamCreateService.selectPaperCreate(pid));
    }

//    @ApiOperation("试卷创编（通过id查找题库）")
//    @GetMapping("selectQuestionBankById")
//    public R<QuestionbankDO1> selectQuestionBankById(Long id){
//        return R.ok(iQuestionbankService.selectQuestionBankById(id));
//    }
//
//    @ApiOperation("试卷创编（通过题目类型查找题库）")
//    @GetMapping("selectQuestionBankByQuestionType")
//    public R<List<QuestionbankDO1>> selectQuestionBankByQuestionType(String type){
//        return R.ok(iQuestionbankService.selectQuestionBankByQuestionType(type));
//    }

    @ApiOperation("试卷创编（查找题库）")
    @GetMapping("selectQuestionBankByIdAndQuestionType")
    public R<List<QuestionbankDO1>> selectQuestionBankByIdAndQuestionType(Long id,String type) {
        return R.ok(iQuestionbankService.selectQuestionBankByIdAndQuestionType(id,type));
    }
}
