package com.mwt.oes.controller;

import com.mwt.oes.domain.Paper;
import com.mwt.oes.service.StudentHomeService;
import com.mwt.oes.service.StudentPaperService;
import com.mwt.oes.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/exam/")
public class StudentPaperController {

    @Autowired
    StudentPaperService studentPaperService;

    @Autowired
    StudentHomeService studentHomeService;

    /**
     * 获取当前可考试卷
     * @param paperStatus
     * @return
     */
    @RequestMapping("/getCurrentPaperList")
    public ServerResponse getCurrentPaperList(@RequestParam("paperStatus")Integer paperStatus){
        List<Map<String, Object>> list = studentPaperService.getCurrentPapersList(paperStatus);
        return ServerResponse.createBySuccess("获取当前考卷成功",list);
    }

    @RequestMapping("/getPaperInfoByPaperId")
    public ServerResponse getPaperInfoByPaperId(@RequestParam("paperId") Integer paperId){
        Paper paper = studentPaperService.getPaperInfoByPaperId(paperId);
        Map<String, Integer> numObj = studentPaperService.getPaperQueNumByPaperId(paperId);
        List<Map<String, Object>> singleQueList = studentHomeService.getSingleQueListByPaperId(paperId);
        List<Map<String, Object>> multipleQueList = studentHomeService.getMultipleQueListByPaperId(paperId);
        List<Map<String, Object>> judgeQueList = studentHomeService.getJudgeQueListByPaperId(paperId);
        List<Map<String, Object>> fillQueList = studentHomeService.getFillQueListByPaperId(paperId);
        if(paper != null && numObj != null){
            Map<String, Object> map = new HashMap<>();
            map.put("paperInfo",paper);
            map.put("queNumInfo",numObj);
            map.put("singleQueList",singleQueList);
            map.put("multipleQueList",multipleQueList);
            map.put("judgeQueList",judgeQueList);
            map.put("fillQueList",fillQueList);
            return ServerResponse.createBySuccess("试卷id为" + paperId + "的试卷信息获取成功",map);
        }
        else {
            return ServerResponse.createByError("试卷id为" + paperId + "的试卷信息获取失败");
        }
    }
}
