package com.ruoyi.web.controller.test;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.gson.Gson;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.test.domain.DO.ExamCreateDO;
import com.ruoyi.test.domain.DO.ExamDO;
import com.ruoyi.test.domain.DO.OptionDO;
import com.ruoyi.test.domain.DO.SingleChoiceDO;
import com.ruoyi.test.domain.ExamCreate;
import com.ruoyi.test.domain.Questionbank;
import com.ruoyi.test.domain.Vo.ExamCreateVo;
import com.ruoyi.test.domain.Vo.QuestionbankVo;
import com.ruoyi.test.domain.Vo.QuestionbankVo1;
import com.ruoyi.test.seriver.IExamCreateService;
import com.ruoyi.test.seriver.IExamDOService;
import com.ruoyi.test.seriver.IExamPaperService;
import com.ruoyi.test.seriver.ISubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "题库管理")
@RestController
@RequestMapping("/examcreate")
public class ExamDOController {

    @Autowired
    private IExamDOService iExamDOService;

    @Autowired
    private IExamCreateService iExamCreateService;

    @Autowired
    private IExamPaperService iExamPaperService;

    @ApiOperation("题库列表")
    @GetMapping("selectList")
    public R<IPage<QuestionbankVo>> selectList(int pagenum,int pagesize){
        return R.ok(iExamDOService.selectExamDoList(pagenum,pagesize));
    }

    @ApiOperation("预览")
    @GetMapping("preview")
    public R<QuestionbankVo1> preview(Long id){
        return R.ok(iExamDOService.preview(id));
    }

    @ApiOperation("题目创编")
    @PostMapping("add")
    public R<String> add(@RequestBody SingleChoiceDO singleChoiceDO){
        String subject = singleChoiceDO.getSubject();
        String grade = singleChoiceDO.getGrade();

        Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade);
        String chance = "";
        if(singleChoiceDO.getType()==1||singleChoiceDO.getType()==2){
            List<OptionDO> optionDOS = singleChoiceDO.getList();
            Gson gson = new Gson();
            chance = gson.toJson(optionDOS);
        }
        Questionbank questionbank = new Questionbank();
        questionbank.setQuestiontype(singleChoiceDO.getType());
        questionbank.setContent(singleChoiceDO.getContent());
        questionbank.setAnswer(singleChoiceDO.getAnswer());
        questionbank.setChance(chance);
        questionbank.setDifficulty(singleChoiceDO.getDifficulty());
        questionbank.setAnalysis(singleChoiceDO.getAnalysis());
        questionbank.setScore(singleChoiceDO.getScore());
        questionbank.setSubject(singleChoiceDO.getSubject());
        if(iExamDOService.addSingleChoice(questionbank)!=0){
            return R.ok("添加成功");
        }
        return R.ok("添加失败");
    }


//
//    @ApiOperation("单选创编")
//    @PostMapping("addSingleChoice")
//    public R<String> addSingleChoice(@RequestBody SingleChoiceDO singleChoiceDO){
//
//        String subject = singleChoiceDO.getSubject();
//        String grade = singleChoiceDO.getGrade();
//
//        Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade);
//
//        List<OptionDO> optionDOS = singleChoiceDO.getList();
//        Gson gson = new Gson();
//        String chance = gson.toJson(optionDOS);
//
//        Questionbank questionbank = new Questionbank();
//        questionbank.setQuestiontype(1);
//        questionbank.setContent(singleChoiceDO.getContent());
//        questionbank.setAnswer(singleChoiceDO.getAnswer());
//        questionbank.setChance(chance);
//        questionbank.setDifficulty(singleChoiceDO.getDifficulty());
//        questionbank.setAnalysis(singleChoiceDO.getAnalysis());
//        questionbank.setScore(singleChoiceDO.getScore());
//        questionbank.setSubject(singleChoiceDO.getSubject());
//        if(iExamDOService.addSingleChoice(questionbank)!=0){
//            return R.ok("添加成功");
//        }
//        return R.ok("添加失败");
//    }
//
//    @ApiOperation("判断创编")
//    @PostMapping("addtfQuestions")
//    public R<String> addtfQuestions(@RequestBody ExamCreateDO examCreateDO){
//
//        String subject = examCreateDO.getSubject();
//        String grade = examCreateDO.getGrade();
//
//        Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade);
//
//        Questionbank questionbank = new Questionbank();
//        questionbank.setQuestiontype(5);
//        questionbank.setContent(examCreateDO.getContent());
//        questionbank.setAnswer(examCreateDO.getAnswer());
//        questionbank.setChance(examCreateDO.getChance());
//        questionbank.setDifficulty(examCreateDO.getDifficulty());
//        questionbank.setAnalysis(examCreateDO.getAnalysis());
//        questionbank.setScore(examCreateDO.getScore());
//        questionbank.setSubject(examCreateDO.getSubject());
//        if(iExamDOService.addtfQuestions(questionbank)!=0){
//            return R.ok("添加成功");
//        }
//        return R.ok("添加失败");
//    }
//
//    @ApiOperation("多选创编")
//    @PostMapping("addMSingleChoice")
//    public R<String> addMSingleChoice(@RequestBody SingleChoiceDO singleChoiceDO){
//
//        String subject = singleChoiceDO.getSubject();
//        String grade = singleChoiceDO.getGrade();
//
//        Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade);
//
//        List<OptionDO> optionDOS = singleChoiceDO.getList();
//        Gson gson = new Gson();
//        String chance = gson.toJson(optionDOS);
//
//        Questionbank questionbank = new Questionbank();
//        questionbank.setQuestiontype(2);
//        questionbank.setContent(singleChoiceDO.getContent());
//        questionbank.setAnswer(singleChoiceDO.getAnswer());
//        questionbank.setChance(chance);
//        questionbank.setDifficulty(singleChoiceDO.getDifficulty());
//        questionbank.setAnalysis(singleChoiceDO.getAnalysis());
//        questionbank.setScore(singleChoiceDO.getScore());
//        questionbank.setSubject(singleChoiceDO.getSubject());
//        if(iExamDOService.addMSingleChoice(questionbank)!=0){
//            return R.ok("添加成功");
//        }
//        return R.ok("添加失败");
//    }
//
//    @ApiOperation("填空创编")
//    @PostMapping("addGapFilling")
//    public R<String> addGapFilling(@RequestBody ExamCreateDO examCreateDO){
//
//        String subject = examCreateDO.getSubject();
//        String grade = examCreateDO.getGrade();
//
//        Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade);
//
//        Questionbank questionbank = new Questionbank();
//        questionbank.setQuestiontype(3);
//        questionbank.setContent(examCreateDO.getContent());
//        questionbank.setAnswer(examCreateDO.getAnswer());
//        questionbank.setChance(examCreateDO.getChance());
//        questionbank.setDifficulty(examCreateDO.getDifficulty());
//        questionbank.setAnalysis(examCreateDO.getAnalysis());
//        questionbank.setScore(examCreateDO.getScore());
//        questionbank.setSubject(examCreateDO.getSubject());
//        if(iExamDOService.addGapFilling(questionbank)!=0){
//            return R.ok("添加成功");
//        }
//        return R.ok("添加失败");
//    }
//
//    @ApiOperation("解答创编")
//    @PostMapping("addfrQuestions")
//    public R<String> addfrQuestions(@RequestBody ExamCreateDO examCreateDO){
//
//        String subject = examCreateDO.getSubject();
//        String grade = examCreateDO.getGrade();
//
//        Long id = iExamPaperService.selectIdBySubjectAndGrade(subject,grade);
//
//        Questionbank questionbank = new Questionbank();
//        questionbank.setQuestiontype(4);
//        questionbank.setContent(examCreateDO.getContent());
//        questionbank.setAnswer(examCreateDO.getAnswer());
//        questionbank.setChance(examCreateDO.getChance());
//        questionbank.setDifficulty(examCreateDO.getDifficulty());
//        questionbank.setAnalysis(examCreateDO.getAnalysis());
//        questionbank.setScore(examCreateDO.getScore());
//        questionbank.setSubject(examCreateDO.getSubject());
//        if(iExamDOService.addfrQuestions(questionbank)!=0){
//            return R.ok("添加成功");
//        }
//        return R.ok("添加失败");
//    }
}
