package com.xhkjedu.sexam.service.report;

import com.alibaba.fastjson.JSON;
import com.xhkjedu.sexam.mapper.exam.EBaseMapper;
import com.xhkjedu.sexam.mapper.exam.EClassMapper;
import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
import com.xhkjedu.sexam.mapper.paper.EPaperAnalyzeMapper;
import com.xhkjedu.sexam.mapper.paper.EPaperFileMapper;
import com.xhkjedu.sexam.mapper.paper.EPaperMapper;
import com.xhkjedu.sexam.mapper.reportclass.ERclassRankMapper;
import com.xhkjedu.sexam.mapper.reportstu.ERstudentMapper;
import com.xhkjedu.sexam.mapper.system.UserMapper;
import com.xhkjedu.sexam.model.exam.EBase;
import com.xhkjedu.sexam.utils.ExamUtil;
import com.xhkjedu.sexam.vo.report.ERankParamVo;
import com.xhkjedu.utils.N_Utils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author ywx
 * @classname EReportStudentService
 * @description 学生报告
 * @date 2022/8/8 9:47
 **/
@Service
public class EReportStudentService {
    @Resource
    private EBaseMapper eBaseMapper;
    @Resource
    private ESubjectMapper eSubjectMapper;
    @Resource
    private EClassMapper eClassMapper;
    @Resource
    private ERstudentMapper eRstudentMapper;
    @Resource
    private EPaperMapper ePaperMapper;
    @Resource
    private EPaperFileMapper ePaperFileMapper;
    @Resource
    private EPaperAnalyzeMapper ePaperAnalyzeMapper;
    @Resource
    private ERclassRankMapper eRclassRankMapper;
    @Resource
    private UserMapper userMapper;

    /**
     * @Description 获取考试基本信息（科目、班级、班级下学生）
     * @Param [examid]
     * @Return java.util.Map
     * @Author wn
     * @Date 2022/8/25 10:25
     **/
    public Map getExamSubjectClass(Integer examid) {
        Map map = eBaseMapper.findById(examid);
        List<Map> subjects = eSubjectMapper.listSubjectAndPnum(examid);
        map.put("subjects", subjects);
        List<Map> classes = eClassMapper.listExamClassAndStu(examid);
        map.put("classes", classes);
        return map;
    }

    public Map getExamSubjectClassForTeacher(Integer examid,Integer userid) {
        Map map = eBaseMapper.findById(examid);
        List<Map> subjects = eSubjectMapper.listSubjectAndPnum(examid);
        map.put("subjects", subjects);

        //获取当前用户所属学校id
        Integer schoolid = userMapper.getSchoolidByUserid(userid);

        List<Map> classes = eClassMapper.listExamClassAndStuForTeacher(examid,userid,schoolid);
        map.put("classes", classes);
        return map;
    }

    /**
     * @Description 获取考试基础--学生报告
     * @Param [examid, userid]
     * @Author ywx
     * @Date 2023/2/28 11:32
     * @return java.util.Map
     **/
    public Map getExamSubjectClassForStudent(Integer examid,Integer userid) {
        Map map = eRstudentMapper.findByExamIdAndStudentId(examid, userid);
        List<Map> subjects = eSubjectMapper.listSubjectAndPnum(examid);
        map.put("subjects", subjects);
        return map;
    }

    /**
     * @Description 报告概况--获取学生各科成绩单
     * @Param [examid]
     * @Return java.util.Map
     * @Author wn
     * @Date 2022/8/25 14:23
     **/
    public Map listStudentSubjectScoreByExamid(Integer examid, Integer studentid, Integer showrank) {
        List<Map> list = eRstudentMapper.getStudentScoreByExamid(examid, studentid, showrank);
        Map rtnmap = new LinkedHashMap();

        if (list != null && list.size() > 0) {
            String classnum = "0";
            String gradenum = "0";
            if (showrank != 0) {
                Map map1 = list.get(0);
                Integer classid = Integer.parseInt(map1.get("classid").toString());
                Map gcnum = eRstudentMapper.getStudentNumByExamid(examid, classid);
                classnum = gcnum.get("classnum").toString();
                gradenum = gcnum.get("gradenum").toString();
            }
            rtnmap.put("classnum", classnum);
            rtnmap.put("gradenum", gradenum);
        }
        rtnmap.put("subjects", list);
        return rtnmap;
    }

    /**
     * @Description 报告概况--历史排名变化
     * @Param [studentid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/25 14:35
     **/
    public List<Map> listStudentRankHistory(Integer studentid, Integer showrank) {
        if (showrank == 0) return new ArrayList<>();
        return eRstudentMapper.listStudentExamHistory(studentid, "zf");
    }

    /**
     * @Description 学科分析--名次和历史排名
     * @Param [examid, studentid, subjectid]
     * @Return java.util.Map
     * @Author wn
     * @Date 2022/8/25 15:31
     **/
    public Map getSubjectScoreByStudentid(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        Map rtnmap = eRstudentMapper.getSubjectScoreByStudentid(examid, studentid, subjectid, showrank);
        if (rtnmap != null && rtnmap.size() > 0) {
            String classnum = "0";
            String gradenum = "0";

            //历史名次
            List<Map> shlist;
            if (showrank == 0) {
                shlist = new ArrayList<>();
            } else {
                Integer classid = Integer.parseInt(rtnmap.get("classid").toString());
                Map gcnum = eRstudentMapper.getStudentNumByExamid(examid, classid);
                classnum = gcnum.get("classnum").toString();
                gradenum = gcnum.get("gradenum").toString();
                shlist = eRstudentMapper.listStudentExamHistory(studentid, subjectid);
            }
            rtnmap.put("classnum", classnum);
            rtnmap.put("gradenum", gradenum);
            rtnmap.put("historys", shlist);
        }
        return rtnmap;
    }

    /**
     * @Description 学科分析--知识点分析
     * @Param [examid, studentid, subjectid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/25 15:41
     **/
    public List<Map> listSubjectPoints(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        return eRstudentMapper.listSubjectPoints(examid, studentid, subjectid, showrank);
    }

    /**
     * @Description 学科分析--难易度分析
     * @Param [examid, studentid, subjectid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/25 15:52
     **/
    public List<Map> listSubjectComplexitys(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        return eRstudentMapper.listSubjectComplexitys(examid, studentid, subjectid, showrank);
    }

    /**
     * @Description 学科分析--题型分析
     * @Param [examid, studentid, subjectid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/25 16:21
     **/
    public List<Map> listSubjectQtypes(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        return eRstudentMapper.listSubjectQtypes(examid, studentid, subjectid, showrank);
    }

    /**
     * @Description科分析--试题分析(单题、母题)
     * @Param [examid, studentid, subjectid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/25 16:54
     **/
    public List<Map> listSubjectQuestions(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        Map map = ePaperMapper.getPaperByExamidAndSubjectid(examid, subjectid);
        Integer ptype = Integer.parseInt(map.get("ptype").toString());
        Integer epid = Integer.parseInt(map.get("epid").toString());
        Double pscore = Double.parseDouble(map.get("pscore").toString());
        List<Map> list;
        if (ptype == 1) {
            list = eRstudentMapper.listSubjectQuestionsForTk(epid, studentid, showrank);
            for (Map m : list) {
                List<Map> ques = (List<Map>) m.get("ques");
                double stuscore = ques.stream().mapToDouble(s -> Double.parseDouble(s.get("stuscore").toString())).sum();
                double qscore = ques.stream().mapToDouble(s -> Double.parseDouble(s.get("qscore").toString())).sum();
                double stusrate = N_Utils.getDoubleDivideAndMulitiply(stuscore, qscore);
                double srate = N_Utils.getDoubleDivideAndMulitiply(qscore, pscore);
                if (showrank == 0) {
                    stuscore = 0;
                    stusrate = 0;
                }
                m.put("stuscore", stuscore);
                m.put("stusrate", stusrate);
                m.put("srate", srate);
                m.remove("ques");
            }
        }else{
            list = eRstudentMapper.listSubjectQuestionsForFj(examid, studentid, subjectid, showrank);
            for (Map m : list) {
                double stuscore;
                double stusrate;
                double srate;
                double qscore = Double.parseDouble(m.get("qscore").toString());
                if (showrank == 0) {
                    stusrate = 0;
                    srate = 0;
                } else {
                    stuscore = Double.parseDouble(m.get("stuscore").toString());
                    stusrate = N_Utils.getDoubleDivideAndMulitiply(stuscore, qscore);
                    srate = N_Utils.getDoubleDivideAndMulitiply(qscore, pscore);
                }
                m.put("stusrate", stusrate);
                m.put("srate", srate);
            }
        }
        return list;
    }

    /**
     * @Description 试卷分析
     * @Param [examid, studentid, subjectid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/25 17:50
     **/
    public Map getStudentPaperQuestions(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        Integer pstate = eSubjectMapper.getPstateByExamIdSid(examid, subjectid);
        Map map = ePaperMapper.getPaperByExamidAndSubjectid(examid, subjectid);
        Integer ptype = Integer.parseInt(map.get("ptype").toString());
        Integer epid = Integer.parseInt(map.get("epid").toString());
        List<Map> list = null;
        if (ptype == 1) {
            list = eRstudentMapper.listStudentQuestionsTk(epid, studentid, showrank);
            list = setPaperQuestionForTK(list, pstate);
        } else {
            list = eRstudentMapper.listStudentQuestionsFj(epid, studentid, showrank);
            for (Map qmap : list) {
                if (pstate != 2) qmap.remove("answer");
                Double stuscore = Double.parseDouble(qmap.get("stuscore").toString());
                Double pscore = Double.parseDouble(qmap.get("qscore").toString());
                Double srate = N_Utils.getDoubleDivideAndMulitiply(stuscore, pscore);
                qmap.put("srate", srate);
                qmap.put("sratetype", ExamUtil.getScoreRateType(srate));
            }
            List<Map> files = ePaperFileMapper.listPaperFiles(epid);
            map.put("files", files);
        }
        if (N_Utils.isListNotEmpty(list)) {
            map.put("classid", list.get(0).get("classid"));
        }
        map.put("questions", list);
        return map;
    }

    //处理母子题
    private List<Map> setPaperQuestionForTK(List<Map> list, Integer pstate) {
        List<Map> rtnlist = new ArrayList<>();
        List<String> questiopids = new ArrayList<>();
        for (Map q : list) {
            Integer qlevel = Integer.parseInt(q.get("qlevel").toString());
            if (qlevel == 1) {
                //代表单题
                Double stuscore = Double.parseDouble(q.get("stuscore").toString());
                Double pscore = Double.parseDouble(q.get("qscore").toString());
                Double srate = N_Utils.getDoubleDivideAndMulitiply(stuscore, pscore);
                q.put("srate", srate);//得分率
                q.put("sratetype",ExamUtil.getScoreRateType(srate));


                q.remove("mqstem");
                q.remove("mqoption");
                q.remove("msum");
                q.remove("mqtypeid");
                q.remove("mqtypename");
                q.remove("mhashear");
                q.remove("mhearfile");
                q.remove("mquestionid");
                q.remove("mcomplexity");
                q.remove("mctype");
                q.remove("questionpid");
                q.remove("mqanalyze");
                q.remove("mqanswer");
                q.remove("mqlevel");
                if(pstate !=2) q.remove("answer");
                rtnlist.add(q);
            } else {
                //母题
                String questionpid = q.get("questionpid").toString();
                if (!questiopids.contains(questionpid)) {
                    questiopids.add(questionpid);
                    //获取所有试题
                    List<Map> sonqueslist =
                            list.stream().filter(s -> Integer.parseInt(s.get("qlevel").toString()) == 3 && questionpid.equals(s.get("questionpid").toString())).collect(Collectors.toList());
                    Map mq = new LinkedHashMap();
                    mq.put("questionid", questionpid);
                    mq.put("qlevel", 2);
                    mq.put("qorder", Integer.parseInt(q.get("qorder").toString()));
                    mq.put("ctype", Integer.parseInt(q.get("mctype").toString()));
                    if(N_Utils.isNotEmpty(q.get("mqtypename"))){
                        mq.put("qtypename", q.get("mqtypename").toString());
                    }
                    mq.put("qstem", q.get("mqstem").toString());
                    if (N_Utils.isNotEmpty(q.get("mqoption"))) {
                        mq.put("qoption", q.get("mqoption").toString());
                    } else {
                        mq.put("qoption", "");
                    }
                    if (N_Utils.isNotEmpty(q.get("mqanalyze"))) {
                        mq.put("qanalyze", q.get("mqanalyze").toString());
                    } else {
                        mq.put("qanalyze", "");
                    }
                    if (N_Utils.isNotEmpty(q.get("mqanswer"))) {
                        mq.put("qanswer", q.get("mqanswer").toString());
                    } else {
                        mq.put("qanswer", "");
                    }

                    Integer hashear = Integer.parseInt(q.get("mhashear").toString());
                    mq.put("hashear", hashear);
                    if (hashear == 1) {
                        mq.put("hearfile", q.get("mhearfile").toString());
                    }
                    if (q.get("points") != null) {
                        List<Map> points = (List<Map>) q.get("points");
                        mq.put("points", points);
                    }
                    mq.put("complexity",q.get("mcomplexity").toString());
                    mq.put("classavgscore",ExamUtil.removeStrEnd0(q.get("classavgscore")));
                    mq.put("gradeavgscore",ExamUtil.removeStrEnd0(q.get("gradeavgscore")));

                    Double stuscore = sonqueslist.stream().mapToDouble(s -> Double.parseDouble(s.get("stuscore").toString())).sum();
                    Double pscore = sonqueslist.stream().mapToDouble(s -> Double.parseDouble(s.get("qscore").toString())).sum();
                    mq.put("qscore",pscore);
                    mq.put("stuscore",stuscore);
                    Double srate = N_Utils.getDoubleDivideAndMulitiply(stuscore, pscore);
                    mq.put("srate", srate);
                    mq.put("sratetype",ExamUtil.getScoreRateType(srate));

                    for(Map sonmap : sonqueslist){
                        sonmap.remove("mqstem");
                        sonmap.remove("msnum");
                        sonmap.remove("mqoption");
                        sonmap.remove("mqtypeid");
                        sonmap.remove("mqtypename");
                        sonmap.remove("mqanalyze");
                        sonmap.remove("mqanswer");
                        sonmap.remove("mqlevel");
                        sonmap.remove("mhashear");
                        sonmap.remove("mhearfile");
                        sonmap.remove("mquestionid");
                        sonmap.remove("mctype");
                        sonmap.remove("mcomplexity");
                        sonmap.remove("points");
                        sonmap.remove("hashear");
                        sonmap.remove("hearfile");
                        if(pstate !=2) sonmap.remove("answer");
                    }
                    mq.put("sonques", sonqueslist);
                    rtnlist.add(mq);
                }
            }
        }
        return rtnlist;
    }

    /**
     * @Description 学生报告--错题集--科目错题数量
     * @Param [examid, studentid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/8/29 11:39
     **/
    public List<Map> listStudentSubjectErrorQues(Integer examid, Integer studentid, Integer teacherid) {
        List<Map> list = eRstudentMapper.listStudentSubjectErrorQues(examid, studentid);
        for (Map map : list) {
            List<Map> queslist = (List<Map>) map.get("questions");
            Integer ptype = Integer.parseInt(map.get("ptype").toString());
            if (ptype == 1) {
                //单题的数量
                List<Map> dtlist = queslist.stream().filter(s -> Integer.parseInt(s.get("qlevel").toString()) == 1).collect(Collectors.toList());
                //子题
                List<Map> sonlist = queslist.stream().filter(s -> Integer.parseInt(s.get("qlevel").toString()) == 3).collect(Collectors.toList());
                Map<String, List<Map>> mtmap = sonlist.stream().collect(Collectors.groupingBy(s -> s.get("questionpid").toString()));
                int num = 0;
                if (N_Utils.isListNotEmpty(dtlist)) {
                    num = dtlist.size();
                }
                if (mtmap != null && mtmap.size() > 0) {
                    num = num + mtmap.size();
                }
                map.put("num", num);
            } else {
                map.put("num", queslist.size());
            }
            map.remove("questions");
        }
        return list;
    }

    /**
     * @Description 学生报告--错题集--题库
     * @Param [examid, studentid, subjectid]
     * @Return java.util.Map
     * @Author wn
     * @Date 2022/8/29 16:15
     **/
    public Map listStudentErrorQuestionsTk(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        Integer pstate = eSubjectMapper.getPstateByExamIdSid(examid, subjectid);
        List<Map> list = eRstudentMapper.listStudentErrorQuestionsForTk(examid, studentid, subjectid, showrank);
        Map panalyze = ePaperAnalyzeMapper.getPaperAnalzyeBySubjectid(examid, subjectid);
        String pointjson = panalyze.get("pointjson").toString();
        List<Map> pointlist = JSON.parseArray(pointjson, Map.class);
        List<Map> pointqueslist = new ArrayList<>();
        for (Map pointmap : pointlist) {
            //知识点包含的试题
            List<Map> ques = (List<Map>) pointmap.get("ques");
            List<Integer> eptqidlist = new ArrayList<>();//知识点关联的所有试题
            for (Map qovo : ques) {
                List<Integer> eptqids = (List<Integer>) qovo.get("eptqids");
                eptqidlist.addAll(eptqids);
            }
            //获取知识点下试题
            List<Map> poinques = list.stream().filter(s -> eptqidlist.contains(Integer.parseInt(s.get("eptqid").toString()))).collect(Collectors.toList());
            if (N_Utils.isListNotEmpty(poinques)) {
                Map pmap = new HashMap();
                pmap.put("pointid", pointmap.get("pointid").toString());
                pmap.put("pointname", pointmap.get("pointname").toString());
                List<Map> plist = new ArrayList<>();
                String jsonlist = JSON.toJSONString(poinques);
                plist = JSON.parseArray(jsonlist,Map.class);
                /*pmap.put("questions", setPaperQuestionForTK(plist));*/
                List<Map> questionlist = setPaperQuestionForTK(plist, pstate);
                pmap.put("quesnum",questionlist.size());
                pointqueslist.add(pmap);
            }
        }
        Map map = new HashMap();
        map.put("questions", setPaperQuestionForTK(list, pstate));
        map.put("points", pointqueslist);
        return map;
    }

    /**
     * @Description 学生报告-错题集-学生科目下错题（附件）
     * @Param [examid, studentid, subjectid]
     * @Return java.util.Map
     * @Author wn
     * @Date 2022/8/29 16:15
     **/
    public List<Map> listStudentErrorQuestionsFj(Integer examid, Integer studentid, String subjectid, Integer showrank) {
        List<Map> list = eRstudentMapper.listStudentErrorQuestionsForFj(examid, studentid, subjectid, showrank);
        if (showrank == 0) return list;
        for (Map map : list) {
            Double stuscore = Double.parseDouble(map.get("stuscore").toString());
            Double pscore = Double.parseDouble(map.get("qscore").toString());
            Double srate = N_Utils.getDoubleDivideAndMulitiply(stuscore, pscore);
            map.put("srate", srate);
            map.put("sratetype",ExamUtil.getScoreRateType(srate));
        }
        return list;
    }

    /**
     * @Description 学生报告-监控照片-考试科目下违规图片数量
     * @Param [examid, studentid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/10/28 14:31
     **/
    public List<Map> listExamSubjectBadNums(Integer examid, Integer studentid){
        return eRstudentMapper.listExamSubjectBadNums(examid,studentid);
    }

    /**
     * @Description 学生报告-监控照片-学生单科图片
     * @Param [esid, studentid]
     * @Return java.util.List<java.util.Map>
     * @Author wn
     * @Date 2022/10/28 15:03
     **/
    public List<Map> listExamSubjectBadimgs(Integer esid, Integer studentid) {
        return eRstudentMapper.listExamSubjectBadimgs(esid, studentid);
    }

    //获取学生显示排名得分
    public Integer getShowRank(Integer examid, Integer teacherid) {
        EBase base = eBaseMapper.getShowRankById(examid);
        Integer showrank;
        if (!N_Utils.isEmptyInteger(teacherid)) {
            showrank = base.getTeashowrank();
        } else {
            showrank = base.getStushowrank();
        }
        return showrank;
    }

    //pdf报告-考试概况
    public Map getPdfKsGk(Integer examid, Integer studentid) {
        Map map = eRstudentMapper.getPdfKsGk(examid, studentid);
        return map;
    }

    //分数等级统计
    public List<Map> listFsDjTj(Integer examid) {
        ERankParamVo rank = new ERankParamVo();
        rank.setExamid(examid);
        rank.setClassid(0);
        rank.setRanktype(1);
        rank.setSubjectid("zf");
        return eRclassRankMapper.listByExamAndClassId(rank);
    }

    //pdf报告-科目概况
    public List<Map> listKmGg(Integer examid, Integer studentid, Integer showrank) {
        List<Map> subjects = eRstudentMapper.listSubjectScoreByStudentid(examid, studentid, showrank);//学科名次
        for (Map subject : subjects) {
            getDkgk(examid, studentid, showrank, subject);
        }
        return subjects;
    }

    //pdf报告-单科概况
    @Async("asyncPoolTaskExecutor")
    public void getDkgk(Integer examid, Integer studentid, Integer showRank, Map subject) {
        String subjectid = subject.get("subjectid").toString();
        Map map = ePaperMapper.getPaperByExamidAndSubjectid(examid, subjectid);
        Integer ptype = Integer.parseInt(map.get("ptype").toString());
        subject.put("ptype", ptype);
        subject.put("historys", eRstudentMapper.listStudentExamHistory(studentid, subjectid));//历史排名
        subject.put("types", listSubjectQtypes(examid, studentid, subjectid, showRank));//大题分析
        subject.put("questions", listSubjectQuestions(examid, studentid, subjectid, showRank));//小题分析
        if (ptype == 1) {
            getErrorQuestionsTk(examid, studentid, subjectid, showRank, subject);//错题集
        } else {
            Map errorq = new HashMap();
            List<Map> questions = listStudentErrorQuestionsFj(examid, studentid, subjectid, showRank);
            errorq.put("questions", questions);//错题
            errorq.put("num", questions.size());//错题数量
            subject.put("errorq", errorq);//错题集
        }
        if (ptype == 2) return;
        subject.put("points", listSubjectPoints(examid, studentid, subjectid, showRank));//知识点分析
        subject.put("complexes", listSubjectComplexitys(examid, studentid, subjectid, showRank));//难易度分析
    }

    //pdf报告-题库错题集
    public void getErrorQuestionsTk(Integer examid, Integer studentid, String subjectid, Integer showrank, Map subject) {
        Integer pstate = 2;
        //int sstate = Integer.parseInt(subject.get("sstate").toString());
        //if (sstate >= 2) {
        //    pstate = 2;
        //}
        List<Map> list = eRstudentMapper.listStudentErrorQuestionsForTk(examid, studentid, subjectid, showrank);
        Map panalyze = ePaperAnalyzeMapper.getPaperAnalzyeBySubjectid(examid, subjectid);
        String pointjson = panalyze.get("pointjson").toString();
        List<Map> pointlist = JSON.parseArray(pointjson, Map.class);
        List<Map> pointqueslist = new ArrayList<>();
        for (Map pointmap : pointlist) {
            //知识点包含的试题
            List<Map> ques = (List<Map>) pointmap.get("ques");
            List<Integer> eptqidlist = new ArrayList<>();//知识点关联的所有试题
            for (Map qovo : ques) {
                List<Integer> eptqids = (List<Integer>) qovo.get("eptqids");
                eptqidlist.addAll(eptqids);
            }
            //获取知识点下试题
            List<Map> poinques =
                    list.stream().filter(s -> eptqidlist.contains(Integer.parseInt(s.get("eptqid").toString()))).collect(Collectors.toList());
            if (N_Utils.isListNotEmpty(poinques)) {
                Map pmap = new HashMap();
                pmap.put("pointid", pointmap.get("pointid").toString());
                pmap.put("pointname", pointmap.get("pointname").toString());
                List<Map> questionlist = setPaperQuestionForTK(JSON.parseArray(JSON.toJSONString(poinques), Map.class), pstate);
                pmap.put("quesnum", questionlist.size());
                pointqueslist.add(pmap);
            }
        }
        List<Map> questions = setPaperQuestionForTK(list, pstate);
        Map errorq = new HashMap();
        errorq.put("questions", questions);//错题
        errorq.put("points", pointqueslist);
        errorq.put("num", questions.size());//错题数量
        subject.put("errorq", errorq);//错题集
    }

    //学生报告-pdf报告状态和学生报告地址
    public Map getReportStuState(Integer examid,Integer studentid){
        return eRstudentMapper.getReportStuState(examid,studentid);
    }

    //获取考试PDF报告基础信息
    public Map getPdfInfo(Integer examid, Integer studentid) {
        return eRstudentMapper.getPdfInfo(examid, studentid);
    }
}
