package com.xhkjedu.sexam.controller.paper;

import com.xhkjedu.sexam.model.paper.EPaper;
import com.xhkjedu.sexam.model.paper.EPaperQtype;
import com.xhkjedu.sexam.model.paper.EPaperQtypeQuestion;
import com.xhkjedu.sexam.service.paper.EPaperQtypeService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description 题库试卷
 * @Author WN
 * Date 2022/7/19 9:05
 **/
@RestController
@RequestMapping("/epqt")
public class EPaperQtypeController {

    @Resource
    private EPaperQtypeService ePaperQtypeService;

    /**
     * @Description  保存试卷
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/7/19 9:09
     **/
    @PostMapping("/save")
    public ResultVo savePaperQtype(@RequestBody EPaper paper){
        N_Utils.validation(new Object[]{paper.getEpid(),"考试试卷id",1});
        List<EPaperQtype> qtypes = paper.getQtypelist();
        if(qtypes == null || qtypes.size() == 0){
            return new ResultVo(1,"未设置试题");
        }
        return ePaperQtypeService.saveQtPaper(paper);
    }

    /**
     * @Description 附件试卷详情
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/7/19 8:36
     **/
    @PostMapping("/detail")
    public ResultVo getPaperQtDetail(@RequestBody EPaper paper){
        N_Utils.validation(new Object[]{paper.getEsid(),"考试科目id",1});
        Map map = ePaperQtypeService.getPaperQtDetail(paper.getEsid());
        return new ResultVo(0,"成功获取试卷详情",map);
    }

    /**
     * @Description  设置正确答案
     * @Param [paper]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/7/25 15:09
     **/
    @PostMapping("/answer")
    public ResultVo setPaperQuestionAnswer(@RequestBody EPaper paper){
        N_Utils.validation(new Object[]{paper.getEpid(),"试卷id",1});
        ePaperQtypeService.saveQuesitonAnswer(paper);
        return new ResultVo(0,"设置成功");
    }

    /**
     * @Description 获取试卷答题卡
     * @Param [ePaper]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/7/25 11:21
     **/
    @PostMapping("/pqs")
    public ResultVo getPaperAndQuesitons(@RequestBody EPaper ePaper) {
        N_Utils.validation(new Object[]{ePaper.getEpid(),"试卷id",1});
        Map rtn = ePaperQtypeService.getPaperAndQuesitons(ePaper.getEpid());
        return new ResultVo(0,"获取成功",rtn);
    }

    /**
     * @Description 保存试卷答题卡
     * @Param [ePaper]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/7/25 17:43
     **/
    @PostMapping("/scan")
    public ResultVo savePaperScan(@RequestBody EPaper ePaper) {
        N_Utils.validation(new Object[]{ePaper.getEpid(),"试卷id",1});
        List<EPaperQtypeQuestion> ques = ePaper.getQuestions();
        if(ques == null || ques.size() == 0){
            return new ResultVo(1,"未设置试题");
        }
        ePaperQtypeService.savePaperScan(ePaper);
        return new ResultVo(0,"保存成功");
    }


}
