package com.xhkjedu.sstudy.service.paperreport;

import com.alibaba.fastjson.JSON;
import com.xhkjedu.sstudy.mapper.paper.PaperAnalyzeMapper;
import com.xhkjedu.sstudy.mapper.paper.PaperMapper;
import com.xhkjedu.sstudy.mapper.paper.PaperQtypeQuestionMapper;
import com.xhkjedu.sstudy.mapper.paperreport.*;
import com.xhkjedu.sstudy.mapper.paperstudent.PaperClassMapper;
import com.xhkjedu.sstudy.mapper.paperstudent.PaperStudentMapper;
import com.xhkjedu.sstudy.mapper.paperstudent.PaperStudentQuestionMapper;
import com.xhkjedu.sstudy.mapper.paperstudent.PaperStudentScantronMapper;
import com.xhkjedu.sstudy.mapper.question.QuestionClassMapper;
import com.xhkjedu.sstudy.mapper.question.QuestionStudentMapper;
import com.xhkjedu.sstudy.model.paper.TPaper;
import com.xhkjedu.sstudy.model.paper.TPaperAnalyze;
import com.xhkjedu.sstudy.model.paperreport.*;
import com.xhkjedu.sstudy.model.question.TQuestionClass;
import com.xhkjedu.sstudy.model.question.TQuestionStudent;
import com.xhkjedu.sstudy.utils.ArithUtil;
import com.xhkjedu.sstudy.utils.StudyUtil;
import com.xhkjedu.sstudy.vo.paper.QuestionPointVo;
import com.xhkjedu.sstudy.vo.paperreport.PaperPointStuScoreVo;
import com.xhkjedu.sstudy.vo.paperreport.PaperRQuestionVo;
import com.xhkjedu.sstudy.vo.paperreport.PaperRStuQuestionVo;
import com.xhkjedu.sstudy.vo.paperreport.PaperRStuVo;
import com.xhkjedu.sstudy.vo.paperstudent.PaperStudentVo;
import com.xhkjedu.sstudy.vo.paperstudent.StudentPaperVo;
import com.xhkjedu.utils.N_Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @Description 作业报告
 * @Author WN
 * @Date 2023/4/17 9:51
 **/
@Service
public class PaperReportService {
    @Resource
    private PaperMapper paperMapper;
    @Resource
    private PaperAnalyzeMapper paperAnalyzeMapper;
    @Resource
    private PaperStudentQuestionMapper paperStudentQuestionMapper;
    @Resource
    private PaperStudentScantronMapper paperStudentScantronMapper;
    @Resource
    private PaperStudentMapper paperStudentMapper;
    @Resource
    private PaperQtypeQuestionMapper paperQtypeQuestionMapper;
    @Resource
    private PaperRclassMapper paperRclassMapper;
    @Resource
    private PaperRclassPointMapper paperRclassPointMapper;
    @Resource
    private PaperRclassQuestionMapper paperRclassQuestionMapper;
    @Resource
    private PaperRstudentMapper paperRstudentMapper;
    @Resource
    private PaperRclassRankMapper paperRclassRankMapper;
    @Resource
    private QuestionStudentMapper questionStudentMapper;
    @Resource
    private PaperRstudentQuestionMapper paperRstudentQuestionMapper;
    @Resource
    private PaperRstudentPointMapper paperRstudentPointMapper;
    @Resource
    private QuestionClassMapper questionClassMapper;
    @Resource
    private PaperClassMapper paperClassMapper;
    @Resource
    private PaperReportMapper paperReportMapper;


    /*
     * @Description 生成作业报告
     * @Author WN
     * @Date 2023/4/17 10:26
     */
    @Transactional(rollbackFor = Exception.class)
    public void generatePaperReport(Integer paperid) {
        TPaper paper = paperMapper.selectByPrimaryKey(paperid);
        List<PaperRStuQuestionVo> stuQlist = new ArrayList<>();
        if (paper.getPapertype() == 2) {
            // 答题卡作业
            stuQlist = paperStudentScantronMapper.listAllStuAnswers(paper.getPaperid());

        } else {
            // 题库和靶向作业
            stuQlist = paperStudentQuestionMapper.listAllStuAnswers(paper.getPaperid());
        }
        if (N_Utils.isListNotEmpty(stuQlist)) {
            paperReportMapper.deletePaperReport(paperid);// 删除作业报告
            // 学生作业
            List<PaperRStuVo> stuList = paperStudentMapper.listPaperAllStu(paper.getPaperid());
            Map<Integer, String> stuMap = stuList.stream().collect(Collectors.toMap(PaperRStuVo::getStudentid, PaperRStuVo::getStuname, (v1, v2) -> v2));
            stuQlist.stream().forEach(s -> {
                s.setStuname(stuMap.get(s.getStudentid()));
            });

            setQuestionClass(paper, stuQlist, stuList);
            // 作业报告班级等级统计
            if(paper.getPapertype() == 3){
                //靶向作业按照得分率
                setClassRankForBx(stuList,paper);
            }else{
                setClassRank(stuList, paper);
            }

            List<Integer> classids = stuList.stream().map(PaperRStuVo::getClassid).distinct().collect(Collectors.toList());
            setQuestionError(paper, classids);// 结束批阅错题进入错题集
            paperReportMapper.updateHasreport(paperid, 1);// 更改作业是否生成报告
        }

    }

    /**
     * @return void
     * @Description 结束批阅错题进入错题集
     *  选定的班级，超过 30%(含 30%)的学生作答，且作答学生内 30%(含30%)以上的学生均未答对的试题进入错题集
     * @Param [paper, classids]
     * @Author ywx
     * @Date 2023/4/18 11:07
     **/
    public void setQuestionError(TPaper paper, List<Integer> classids) {
        Integer pid = paper.getPaperid();
        Long paperid = Long.valueOf(pid);
        Integer qctype = paper.getPapertype();
        String subjectid = paper.getSubjectid();
        Integer hashear;
        if (N_Utils.isEmpty(paper.getHearfile())) {
            hashear = 0;
        } else {
            hashear = 1;
        }
        //学校错误率%
        Integer serrorrate = 30;
        for (Integer classid : classids) {
            // 已批阅未得满分的试题
            List<TQuestionStudent> questions = questionStudentMapper.listQuestions(paperid, classid, qctype);
            for (TQuestionStudent q : questions) {
                q.setQctype(qctype);
                q.setSubjectid(subjectid);
                q.setPaperid(paperid);
                if (qctype == 2) q.setHashear(hashear);
                q.setScorerate(N_Utils.getDoubleDivideAndMulitiply(q.getStuscore(), q.getQscore()));
                q.setHandletime(N_Utils.getSecondTimestamp());
                questionStudentMapper.saveQuestionStudent(q);
            }

            List<TQuestionClass> questionClasses;
            if (qctype == 1 || qctype == 3) {// 题库/靶向作业
                questionClasses = questionClassMapper.getQuestionAnalyze(paperid, classid, qctype);
            } else {// 附件作业
                questionClasses = questionClassMapper.getSQuestionAnalyze(paperid, classid);
            }
            List<TQuestionClass> list = new ArrayList<>();// 班级错题集合
            for (TQuestionClass q : questionClasses) {
                Integer stunum = q.getStunum();
                Integer tjnum = q.getTjnum();
                double tjrate = N_Utils.getIntegerDivideAndMulitiply(tjnum, stunum);//提交率
                Double stuscore = q.getStuscore();
                Integer pynum = q.getPynum();
                Double totalscore = q.getQscore() * pynum;
                Double errorrate = N_Utils.getDoubleDivideAndMulitiply((totalscore - stuscore), totalscore);//错误率
                if (errorrate < serrorrate || tjrate < serrorrate) {
                    continue;
                }
                q.setPaperid(paperid);
                q.setClassid(classid);
                q.setQctype(qctype);
                Double qscore = N_Utils.formatDouble(stuscore / pynum, 2);
                q.setAvgscore(qscore);
                q.setErrorrate(errorrate);
                q.setCreatetime(N_Utils.getSecondTimestamp());
                if (qctype == 2) q.setHashear(hashear);
                list.add(q);
            }

            if (N_Utils.isListNotEmpty(list)) {
                questionClassMapper.insertList(list);
            }
            paperClassMapper.updateChecked(pid, classid);
        }
    }

    /**
     * @return void
     * @Description 作业报告班级等级统计
     * @Param [stuList]
     * @Author ywx
     * @Date 2023/4/17 16:52
     **/
    public void setClassRank(List<PaperRStuVo> list, TPaper paper) {
        Integer paperid = paper.getPaperid();
        Double paperscore = paper.getPaperscore();// 满分
        double yxscore = ArithUtil.mul(paperscore, 0.85);// 优秀分
        double lhscore = ArithUtil.mul(paperscore, 0.7);// 良好分
        double jgscore = ArithUtil.mul(paperscore, 0.6);// 及格分

        List<PaperRclassRank> classRanks = new ArrayList<>();
        List<PaperRStuVo> pStus;
        List<PaperRStuVo> students;
        int classnum;
        String rankname;
        Map<Integer, List<PaperRStuVo>> classMap = list.stream().collect(Collectors.groupingBy(PaperRStuVo::getClassid));
        for (Map.Entry<Integer, List<PaperRStuVo>> entry : classMap.entrySet()) {
            pStus = entry.getValue();
            Integer classid = entry.getKey();
            classnum = pStus.size();// 班级人数

            // 满分
            students = pStus.stream().filter(l -> isTj(l) && l.getUserscore().equals(paperscore)).collect(Collectors.toList());
            rankname = ArithUtil.doubleToStr(paperscore);
            djTj(paperid, rankname, 1, classRanks, students, classnum, classid);

            // 优秀
            students = pStus.stream().filter(s -> isTj(s) && s.getUserscore().compareTo(yxscore) != -1
                    && s.getUserscore().compareTo(paperscore) == -1).collect(Collectors.toList());
            rankname = getRankRange(yxscore, paperscore) + ")";
            djTj(paperid, rankname, 2, classRanks, students, classnum, classid);

            // 良好
            students = pStus.stream().filter(s -> isTj(s) && s.getUserscore().compareTo(lhscore) != -1
                    && s.getUserscore().compareTo(yxscore) == -1).collect(Collectors.toList());
            rankname = getRankRange(lhscore, yxscore) + ")";
            djTj(paperid, rankname, 3, classRanks, students, classnum, classid);

            // 及格
            students = pStus.stream().filter(s -> isTj(s) && s.getUserscore().compareTo(jgscore) != -1
                    && s.getUserscore().compareTo(lhscore) == -1).collect(Collectors.toList());
            rankname = getRankRange(jgscore, lhscore) + ")";
            djTj(paperid, rankname, 4, classRanks, students, classnum, classid);

            // 其他
            students = pStus.stream().filter(s -> isTj(s) && s.getUserscore().compareTo(jgscore) == -1).collect(Collectors.toList());
            rankname = getRankRange(0, jgscore) + ")";
            djTj(paperid, rankname, 5, classRanks, students, classnum, classid);

            // 未提交
            students = pStus.stream().filter(s -> isWtj(s)).collect(Collectors.toList());
            rankname = "";
            djTj(paperid, rankname, 6, classRanks, students, classnum, classid);
        }

        paperRclassRankMapper.insertList(classRanks);
    }

    /**
     * @Description 作业提交
     * @Date 2023/12/4 17:15
     * @Author YWX
     * @Param [s]
     * @Return boolean
     **/
    private boolean isTj(PaperRStuVo s) {
        return StudyUtil.tjlist.contains(s.getPsstate());
    }

    /**
     * @Description 作业未提交
     * @Date 2023/12/4 17:16
     * @Author YWX
     * @Param [s]
     * @Return boolean
     **/
    private boolean isWtj(PaperRStuVo s) {
        return StudyUtil.wtjlist.contains(s.getPsstate());
    }

    /*
    * @Description 靶向作业成绩概况
    * @Author WN
    * @Date 2023/4/26 11:32:12
    */
    public void setClassRankForBx(List<PaperRStuVo> list, TPaper paper) {
        Integer paperid = paper.getPaperid();
        double paperscore = 100;// 满分
        double yxscore = 85;// 优秀分
        double lhscore = 70;// 良好分
        double jgscore = 60;// 及格分

        List<PaperRclassRank> classRanks = new ArrayList<>();
        List<PaperRStuVo> pStus;
        int classnum;
        String rankname;
        Map<Integer, List<PaperRStuVo>> classMap = list.stream().collect(Collectors.groupingBy(PaperRStuVo::getClassid));
        for (Map.Entry<Integer, List<PaperRStuVo>> entry : classMap.entrySet()) {
            pStus = entry.getValue();
            Integer classid = entry.getKey();
            classnum = pStus.size();// 班级人数
            List<PaperRStuVo> mfList = new ArrayList<>();
            List<PaperRStuVo> yxList = new ArrayList<>();
            List<PaperRStuVo> lhList = new ArrayList<>();
            List<PaperRStuVo> jgList = new ArrayList<>();
            List<PaperRStuVo> qtList = new ArrayList<>();
            List<PaperRStuVo> wtjList = new ArrayList<>();

            for (PaperRStuVo paperRStuVo : pStus) {
                PaperRStuVo stu = new PaperRStuVo();
                stu.setStudentid(paperRStuVo.getStudentid());
                stu.setStuname(paperRStuVo.getStuname());
                Double userscore = paperRStuVo.getUserscore();
                stu.setUserscore(userscore);
                double stupaperscore = paperRStuVo.getPaperscore();

                if (isWtj(paperRStuVo)) {
                    //未提交学生
                    wtjList.add(stu);
                }else{
                    if(userscore.equals(stupaperscore)){
                        //满分
                        stu.setUserscore(paperscore);
                        mfList.add(stu);
                    }else{
                        Double sturate = N_Utils.getDoubleDivideAndMulitiply(userscore,stupaperscore);
                        stu.setUserscore(sturate);
                        if(sturate.compareTo(yxscore)!=-1 && sturate.compareTo(paperscore)==-1){
                            yxList.add(stu);
                        }else if(sturate.compareTo(lhscore)!=-1 && sturate.compareTo(yxscore)==-1){
                            lhList.add(stu);
                        }else if(sturate.compareTo(jgscore)!=-1 && sturate.compareTo(lhscore)==-1){
                            jgList.add(stu);
                        }else if(sturate.compareTo(jgscore)==-1){
                            qtList.add(stu);
                        }
                    }
                }
            }

            // 满分
            rankname = ArithUtil.doubleToStr(paperscore) + "%";
            djTj(paperid, rankname, 1, classRanks, mfList, classnum, classid);

            // 优秀
            rankname = getRankRange2(yxscore, paperscore) + ")";
            djTj(paperid, rankname, 2, classRanks, yxList, classnum, classid);

            // 良好
            rankname = getRankRange2(lhscore, yxscore) + ")";
            djTj(paperid, rankname, 3, classRanks, lhList, classnum, classid);

            // 及格
            rankname = getRankRange2(jgscore, lhscore) + ")";
            djTj(paperid, rankname, 4, classRanks, jgList, classnum, classid);

            // 其他
            rankname = getRankRange2(0, jgscore) + ")";
            djTj(paperid, rankname, 5, classRanks, qtList, classnum, classid);

            // 未提交
            rankname = "";
            djTj(paperid, rankname, 6, classRanks, wtjList, classnum, classid);
        }

        paperRclassRankMapper.insertList(classRanks);
    }

    // 等级统计
    private void djTj(Integer paperid, String rankname, Integer ranktype
            , List<PaperRclassRank> classRanks, List<PaperRStuVo> students
            , int classnum, Integer classid) {
        PaperRclassRank rr = new PaperRclassRank();
        rr.setPaperid(paperid);
        rr.setClassid(classid);
        rr.setRanktype(ranktype);
        rr.setRankname(rankname);
        int stunum = students.size();
        rr.setStunum(stunum);
        rr.setSturate(N_Utils.getIntegerDivideAndMulitiply(stunum, classnum));
        rr.setStujson(stuJson(students));
        classRanks.add(rr);
    }

    // 等级分类范围
    private String getRankRange(double minscore, double maxscore) {
        return "[" + ArithUtil.doubleToStr(minscore) + "," + ArithUtil.doubleToStr(maxscore);
    }

    // 等级分类范围
    private String getRankRange2(double minscore, double maxscore) {
        return "[" + ArithUtil.doubleToStr(minscore) + "%," + ArithUtil.doubleToStr(maxscore) + "%";
    }

    // 学生名单
    private String stuJson(List<PaperRStuVo> list) {
        List<Map> students = new ArrayList<>();
        for (PaperRStuVo rstudent : list) {
            Map s = new HashMap();
            s.put("studentid", rstudent.getStudentid());
            s.put("studentname", rstudent.getStuname());
            s.put("userscore", rstudent.getUserscore());
            students.add(s);
        }
        return JSON.toJSONString(students);
    }

    /*
     * @Description 保存班级试题相关报告信息
     * @Author WN
     * @Date 2023/4/17 14:50
     */
    private void setQuestionClass(TPaper paper, List<PaperRStuQuestionVo> stuQlist, List<PaperRStuVo> stuList) {
        List<PaperRclass> rclassList = new ArrayList<>();// 班级报告
        List<PaperRclassPoint> rclassPointList = new ArrayList<>();// 知识点分析
        List<PaperRclassQuestion> rclassQuesList = new ArrayList<>();// 试题分析
        List<PaperRstudent> rstuList = new ArrayList<>();// 学生作业分析
        List<PaperRstudentQuestion> rstuQuesList = new ArrayList<>();//学生单题分析
        List<PaperRstudentPoint> rstuPointList = new ArrayList<>();//学生知识点分析


        // 学生试题按照学校id分组计算班级情况
        Map<Integer, List<PaperRStuQuestionVo>> stuQschoolMap = stuQlist.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getSchoolid));

        // 学生作业
        Map<Integer, List<PaperRStuVo>> stuSchoolMap = stuList.stream().collect(Collectors.groupingBy(PaperRStuVo::getSchoolid));

        // 设置作业班级信息
        setPaperRClass(stuSchoolMap,stuQlist,paper, rclassList);
        // 班级作业试题情况
        if (paper.getPapertype() == 2) {
            setPaperQuestionForScan(stuQschoolMap, stuSchoolMap, rclassQuesList, paper, rstuQuesList);//试题分析
            setPaperQuestionStuForScan(stuQlist, rstuList, paper);// 学生得分
        } else {
            // 获取原来作业本身试题分析
            TPaperAnalyze paperAnalyze = paperAnalyzeMapper.getAnalyzeByPaperid(paper.getPaperid());
            setPaperQuestionForQues(stuQschoolMap, stuSchoolMap, rclassQuesList, paper, rstuQuesList);//试题分析
            setPaperQuestionPoint(stuQlist,stuList, rclassPointList, paperAnalyze,rstuPointList);// 知识点分析
            setPaperQuestionStuForQues(stuQlist, rstuList, paper);// 学生得分
        }
        if (N_Utils.isListNotEmpty(rclassList)) paperRclassMapper.insertList(rclassList);
        if (N_Utils.isListNotEmpty(rclassQuesList)) paperRclassQuestionMapper.insertList(rclassQuesList);
        if (N_Utils.isListNotEmpty(rstuQuesList)) paperRstudentQuestionMapper.insertList(rstuQuesList);
        if (N_Utils.isListNotEmpty(rclassPointList)) paperRclassPointMapper.insertList(rclassPointList);
        if (N_Utils.isListNotEmpty(rstuPointList)) paperRstudentPointMapper.insertList(rstuPointList);
        if (N_Utils.isListNotEmpty(rstuList)) paperRstudentMapper.insertList(rstuList);
    }

    // 班级作业总体情况
    private void setPaperRClass(Map<Integer, List<PaperRStuVo>> stuSchoolMap,List<PaperRStuQuestionVo> stuQlist,TPaper paper, List<PaperRclass> rclassList) {
        // 分学校处理班级报告
        for (Map.Entry<Integer, List<PaperRStuVo>> entry : stuSchoolMap.entrySet()) {
            List<PaperRStuVo> qgradeList = entry.getValue();
            // 本校最高分学生
            PaperRStuVo schoolMaxScoreStu = qgradeList.stream().max(Comparator.comparingDouble(PaperRStuVo::getUserscore)).get();
            // 本校总分
            double schoolscore = qgradeList.stream().mapToDouble(PaperRStuVo::getUserscore).sum();// 全校总分
            double schoolavgscore = N_Utils.getDoubleDivideForAvg(schoolscore, qgradeList.size());// 校平均分

            // 处理班级
            Map<Integer, List<PaperRStuVo>> classMap = qgradeList.stream().collect(Collectors.groupingBy(PaperRStuVo::getClassid));
            for (Map.Entry<Integer, List<PaperRStuVo>> entryclass : classMap.entrySet()) {
                List<PaperRStuVo> qclassList = entryclass.getValue();
                int classid = entryclass.getKey();
                PaperRStuVo classMaxScoreStu = qclassList.stream().max(Comparator.comparingDouble(PaperRStuVo::getUserscore)).get();
                PaperRStuVo classMinScoreStu = qclassList.stream().min(Comparator.comparingDouble(PaperRStuVo::getUserscore)).get();
                double classscore = qclassList.stream().mapToDouble(PaperRStuVo::getUserscore).sum();// 班级总分
                double classavgscore = N_Utils.getDoubleDivideForAvg(classscore, qclassList.size());// 班级平均分

                // 提交学生
                List<PaperRStuVo> commitStuList = getCommitStuList(qclassList);
                // 批改学生
                List<PaperRStuVo> checkStuList = getCheckStuList(qclassList);

                // 总用时
                Integer classCosttime = commitStuList.stream().mapToInt(PaperRStuVo::getCosttime).sum();
                // 班级平均用时
                double classavgCosttime = N_Utils.getDoubleDivideForAvg(classCosttime, commitStuList.size());

                //计算班级得分率：当前班级所有学生的得分率之和 / 学生数量
                for(PaperRStuVo stu : qclassList){
                    double sturate = N_Utils.getDoubleDivideAndMulitiply(stu.getUserscore(),stu.getPaperscore());
                    stu.setSturate(sturate);
                }

                double classAllSturate = qclassList.stream().mapToDouble(PaperRStuVo::getSturate).sum();

                //计算班级批改率：当前班级已批阅题量（含自动批阅）/所有学生收到体量之和
                //获取班级下学生所有试题
                List<PaperRStuQuestionVo> classStuQList = stuQlist.stream().filter(s -> s.getClassid().equals(classid) && s.getChecked()==1).collect(Collectors.toList());
                int classChecknum = 0;//已批阅题量
                if(paper.getPapertype() == 2){
                    //附件作业
                    classChecknum = classStuQList.size();
                }else{
                    //题库作业和附件作业，算单题和母题数量
                    //先按学生分组，然后questionpid分组
                    Map<Integer,List<PaperRStuQuestionVo>> stuQmap = classStuQList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getStudentid));
                    for(Map.Entry<Integer,List<PaperRStuQuestionVo>> stuqentry : stuQmap.entrySet()){
                        Map<String,List<PaperRStuQuestionVo>> quemap = stuqentry.getValue().stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getQuestionpid));
                        classChecknum = classChecknum + quemap.size();
                    }
                }
                int queAllnum = qclassList.stream().mapToInt(PaperRStuVo :: getPapernum).sum();//所有学生收到题量之和
                double checkrate = N_Utils.getIntegerDivideAndMulitiply(classChecknum, queAllnum);

                PaperRclass paperRclass = new PaperRclass();
                paperRclass.setPaperid(qclassList.get(0).getPaperid());
                paperRclass.setClassid(entryclass.getKey());
                paperRclass.setClassnum(qclassList.size());
                paperRclass.setCommitnum(commitStuList.size());
                paperRclass.setChecknum(checkStuList.size());
                paperRclass.setCheckrate(checkrate);
                paperRclass.setPaperscore(qclassList.get(0).getPaperscore());
                paperRclass.setClassscorerate(N_Utils.getDoubleDivideForAvg(classAllSturate, qclassList.size()));
                paperRclass.setClassavgscore(classavgscore);
                paperRclass.setClassmaxscore(classMaxScoreStu.getUserscore());
                paperRclass.setClassminscore(classMinScoreStu.getUserscore());
                paperRclass.setSchoolavgscore(schoolavgscore);
                paperRclass.setSchoolmaxscore(schoolMaxScoreStu.getUserscore());
                paperRclass.setClassavgtime(classavgCosttime);
                rclassList.add(paperRclass);
            }
        }
    }

    //批阅学生列表
    private List<PaperRStuVo> getCheckStuList(List<PaperRStuVo> qclassList) {
        return qclassList.stream().filter(s -> StudyUtil.tjlist.contains(s.getPsstate()) && s.getPschecked() == 1).collect(Collectors.toList());
    }

    //提交学生列表
    private List<PaperRStuVo> getCommitStuList(List<PaperRStuVo> qclassList) {
        return qclassList.stream().filter(s -> StudyUtil.tjlist.contains(s.getPsstate())).collect(Collectors.toList());
    }

    // 班级作业试题情况-附件作业试题分析
    //试题得分率：已批改学生得分(含自动批改)/(已批改学生数*当前试题满分)
    private void setPaperQuestionForScan(Map<Integer, List<PaperRStuQuestionVo>> stuQschoolMap, Map<Integer, List<PaperRStuVo>> stuSchoolMap, List<PaperRclassQuestion> rclassQuesList,
                                          TPaper paper,List<PaperRstudentQuestion> rstuQuesList) {
        List<PaperRQuestionVo> quesList = paperStudentScantronMapper.listAllQuesByPaperid(paper.getPaperid());// 作业中所有试题
        //遍历学校
        for (Map.Entry<Integer, List<PaperRStuVo>> psEntry : stuSchoolMap.entrySet()) {
            int schoolid = psEntry.getKey();

            //获取学校提交作业学生数量，无学生提交时不生成试题得分率
            List<PaperRStuVo> commitList = getCommitStuList(psEntry.getValue());
            if(N_Utils.isListNotEmpty(commitList)){
                //获取学校下学生
                List<PaperRStuQuestionVo> stuQSchoolList = stuQschoolMap.get(schoolid);
                //把学生按照班级进行分组
                Map<Integer,List<PaperRStuQuestionVo>> stuQClassList = stuQSchoolList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getClassid));

                //作业中试题进行计算
                for(PaperRQuestionVo q : quesList){
                    //获取已批改试题学生
                    List<PaperRStuQuestionVo> checkStuQSchool = stuQSchoolList.stream().filter(s -> s.getPtqid().equals(q.getPtqid()) && s.getChecked()==1).collect(Collectors.toList());
                    int schoolStunum = checkStuQSchool.size();
                    double gradeStuscore = checkStuQSchool.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                    double gradeavgscore = N_Utils.getDoubleDivideForAvg(gradeStuscore, schoolStunum);
                    double gradeScorerate = N_Utils.getDoubleDivideAndMulitiply(gradeStuscore, q.getQscore() * schoolStunum);
                    double gradeLostrate = N_Utils.getDoubleReduce(100.0, gradeScorerate);

                    //计算试题班级得分情况
                    for(Map.Entry<Integer,List<PaperRStuQuestionVo>> stuQClassEntry : stuQClassList.entrySet()){
                        int classid = stuQClassEntry.getKey();
                        //试题 班级学生作答情况
                        List<PaperRStuQuestionVo> stuQClass = stuQClassEntry.getValue().stream().filter(s -> s.getPtqid().equals(q.getPtqid())).collect(Collectors.toList());;
                        List<PaperRStuQuestionVo> checkStuQClass = stuQClass.stream().filter(s -> s.getChecked()==1).collect(Collectors.toList());
                        //已批改试题学生
                        int classStunum = checkStuQClass.size();
                        //说明该学校有学生提交作业，则进行计算试题得分率
                        double classStuscore = checkStuQClass.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();// 班级单题学生总分
                        double classAvgScore = N_Utils.getDoubleDivideForAvg(classStuscore, classStunum);// 班级平均分
                        double classScorerate = N_Utils.getDoubleDivideAndMulitiply(classStuscore, q.getQscore() * classStunum);// 班级学生得分率
                        double classLostrate = N_Utils.getDoubleReduce(100.0, classScorerate);// 学生失分率

                        PaperRStuQuestionVo firstPs = stuQClass.get(0);
                        PaperRclassQuestion rq = new PaperRclassQuestion();
                        rq.setPaperid(firstPs.getPaperid());
                        rq.setClassid(firstPs.getClassid());
                        rq.setPtqid(q.getPtqid());
                        rq.setCtype(q.getCtype());
                        rq.setQn(q.getQn());
                        rq.setQorder(q.getQorder());
                        rq.setQtypename(q.getQtypename());
                        rq.setQscore(q.getQscore());
                        rq.setClassavgscore(classAvgScore);
                        rq.setClassscorerate(classScorerate);
                        rq.setClasslostrate(classLostrate);
                        rq.setSchoolavgscore(gradeavgscore);
                        rq.setSchoolscorerate(gradeScorerate);
                        rq.setSchoollostrate(gradeLostrate);

                        // 处理单题的学生作答情况
                        Map stuanswer = setPaperQuestionForStuAnswer(stuQClass,q.getCtype());
                        rq.setAnswerjson(JSON.toJSONString(stuanswer));
                        rq.setScorejson(JSON.toJSONString(setPaperQuestionForStuScore(stuQClass)));
                        rclassQuesList.add(rq);

                        //处理作业学生试题分析
                        for(PaperRStuQuestionVo s : stuQClass){
                            PaperRstudentQuestion  prq = new PaperRstudentQuestion();
                            prq.setPaperid(firstPs.getPaperid());
                            prq.setClassid(firstPs.getClassid());
                            prq.setStudentid(s.getStudentid());
                            prq.setCtype(q.getCtype());
                            prq.setPtqid(q.getPtqid());
                            prq.setQn(q.getQn());
                            prq.setQorder(q.getQorder());
                            prq.setQtypename(q.getQtypename());
                            prq.setQscore(q.getQscore());
                            prq.setClassscorerate(classScorerate);
                            prq.setClasslostrate(classLostrate);
                            double stuScorerate = N_Utils.getDoubleDivideAndMulitiply(s.getStuscore(), q.getQscore());// 学生得分率
                            double stuLostrate = N_Utils.getDoubleReduce(100.0, stuScorerate);// 学生失分率
                            prq.setScorerate(stuScorerate);
                            prq.setLostrate(stuLostrate);
                            rstuQuesList.add(prq);
                        }
                    }
                }
            }
        }
    }

    /**
     * @Description 得分详情
     * @Date 2024/3/12 14:55
     * @Author YWX
     * @Param [stuQClass]
     * @Return java.util.Map
     **/
    private Map setPaperQuestionForStuScore(List<PaperRStuQuestionVo> stuQClass) {
        Map<String, Map> map = new LinkedHashMap<>();
        PaperRStuQuestionVo q = stuQClass.get(0);// 取第一条数据获取基本得分
        Double qscore = q.getQscore();
        List<Map> mfStudents = new ArrayList<>();//满分学生
        List<Map> fmfStudents = new ArrayList<>();//0%-100%学生
        List<Map> zfStudents = new ArrayList<>();//0分学生
        List<Map> wtjStudents = new ArrayList<>();//未提交学生
        stuQClass = stuQClass.stream().sorted(Comparator.comparing(PaperRStuQuestionVo::getStuscore)).collect(Collectors.toList());
        for (PaperRStuQuestionVo sq : stuQClass) {
            Double stuscore = sq.getStuscore();
            Map stu = new LinkedHashMap();
            stu.put("studentid", sq.getStudentid());
            stu.put("stuname", sq.getStuname());
            stu.put("stuscore", sq.getStuscore());
            if (sq.getAnswered().equals(0)) {
                wtjStudents.add(stu);
            } else if (stuscore.compareTo(qscore) == 0) {
                mfStudents.add(stu);
            } else if (stuscore.compareTo(0.0) == 0) {
                zfStudents.add(stu);
            } else {
                fmfStudents.add(stu);
            }
        }
        Map mf = new LinkedHashMap();
        mf.put("students", mfStudents);
        mf.put("num", mfStudents.size());
        map.put("满分", mf);

        Map fmf = new LinkedHashMap();
        fmf.put("students", fmfStudents);
        fmf.put("num", fmfStudents.size());
        map.put("0%-100%", fmf);

        Map zf = new LinkedHashMap();
        zf.put("students", zfStudents);
        zf.put("num", zfStudents.size());
        map.put("0分", zf);

        Map wtj = new LinkedHashMap();
        wtj.put("students", wtjStudents);
        wtj.put("num", wtjStudents.size());
        map.put("未提交", wtj);
        return map;
    }

    // 班级报告-附件学生得分
    private void setPaperQuestionStuForScan(List<PaperRStuQuestionVo> stuQschoolList, List<PaperRstudent> rstuList, TPaper paper) {
        // 根据班级进行分组，避免一个学生在多个班级收到多份作业
        List<Integer> zgtList = new ArrayList<>();// 主观题试题id
        List<Integer> kgtList = new ArrayList<>();// 客观题试题id
        boolean isForValue = false;// 是否获取到主观题和客观题（遍历第一个学生即可获取到主观题和客观题）
        Map<Integer, List<PaperRStuQuestionVo>> classMap = stuQschoolList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getClassid));
        for (Map.Entry<Integer, List<PaperRStuQuestionVo>> classEntry : classMap.entrySet()) {
            List<PaperRStuQuestionVo> classStuList = classEntry.getValue();

            // 根据学生id进行分组，获取用户的试题
            Map<Integer, List<PaperRStuQuestionVo>> stuMap = classStuList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getStudentid));

            for (Map.Entry<Integer, List<PaperRStuQuestionVo>> entry : stuMap.entrySet()) {
                List<PaperRStuQuestionVo> stuList = entry.getValue();
                if (!isForValue) {
                    for (PaperRStuQuestionVo q : stuList) {
                        if (N_Utils.isObjectiveQuestion(q.getCtype())) {
                            kgtList.add(q.getPtqid());
                        } else {
                            zgtList.add(q.getPtqid());
                        }
                    }
                    isForValue = true;
                }
                PaperRStuQuestionVo stuFirst = stuList.get(0);
                List<PaperRStuQuestionVo> stuZgtList = stuList.stream().filter(s -> zgtList.contains(s.getPtqid())).collect(Collectors.toList());
                List<PaperRStuQuestionVo> stuKgtList = stuList.stream().filter(s -> kgtList.contains(s.getPtqid())).collect(Collectors.toList());
                double zgtScore = stuZgtList.stream().mapToDouble(PaperRStuQuestionVo::getQscore).sum();
                double zgtStuScore = stuZgtList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                double kgtScore = stuKgtList.stream().mapToDouble(PaperRStuQuestionVo::getQscore).sum();
                double kgtStuScore = stuKgtList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();

                double stuscore = stuList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                double stuscorerate = N_Utils.getDoubleDivideAndMulitiply(stuscore, paper.getPaperscore());

                PaperRstudent ps = new PaperRstudent();
                ps.setPaperid(stuFirst.getPaperid());
                ps.setClassid(stuFirst.getClassid());
                ps.setStudentid(stuFirst.getStudentid());
                ps.setZgtscore(zgtScore);
                ps.setStuzgtscore(zgtStuScore);
                ps.setKgtscore(kgtScore);
                ps.setStukgtscore(kgtStuScore);
                ps.setStuscore(stuscore);
                ps.setStuscorerate(stuscorerate);

                rstuList.add(ps);
            }
        }
    }

    // 班级作业试题情况-题库作业试题分析
    private void setPaperQuestionForQues(Map<Integer, List<PaperRStuQuestionVo>> stuQschoolMap, Map<Integer, List<PaperRStuVo>> stuSchoolMap, List<PaperRclassQuestion> rclassQuesList,
                                          TPaper paper, List<PaperRstudentQuestion> rstuQuesList) {
        List<PaperRQuestionVo> quesList = paperStudentQuestionMapper.listAllQuesByPaperid(paper.getPaperid());// 获取试卷中所有试题
        // 把试题按照单题和母题进行分组，方便计算得分
        Map<String, List<PaperRQuestionVo>> quesMap = quesList.stream().collect(Collectors.groupingBy(PaperRQuestionVo::getQuestionpid));

        //先处理学生作业中试题为单题
        List<PaperRStuQuestionVo> newStuQSchoolList = new ArrayList<>();
        //先判断学校下是否有学生提交作业，如果无学生提交则不生成试题得分率
        for(Map.Entry<Integer, List<PaperRStuVo>> stuSchoolEntry : stuSchoolMap.entrySet()){
            int schoolid = stuSchoolEntry.getKey();
            List<PaperRStuVo> commitStuList = getCommitStuList(stuSchoolEntry.getValue());
            if(N_Utils.isListNotEmpty(commitStuList)){
                //获取学校下学生作答情况
                List<PaperRStuQuestionVo> stuQSchoolList = stuQschoolMap.get(schoolid);
                //按班级进行分组
                Map<Integer,List<PaperRStuQuestionVo>> stuQClassMap = stuQSchoolList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getClassid));
                for(Map.Entry<Integer,List<PaperRStuQuestionVo>> stuQClassEntry : stuQClassMap.entrySet()){
                    //班级下所有学生试题作答情况
                    List<PaperRStuQuestionVo> stuQClass = stuQClassEntry.getValue();
                    //按学生进行分组
                    Map<Integer,List<PaperRStuQuestionVo>> stuQMap = stuQClass.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getStudentid));
                    for(Map.Entry<Integer,List<PaperRStuQuestionVo>> stuQEntry : stuQMap.entrySet()){
                        List<PaperRStuQuestionVo> stuQList = stuQEntry.getValue();
                        //按照questionpid进行分组
                        Map<String,List<PaperRStuQuestionVo>> squesMap = stuQList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getQuestionpid));
                        for(Map.Entry<String,List<PaperRStuQuestionVo>> squesEntry : squesMap.entrySet()){
                            List<PaperRStuQuestionVo> qlist = squesEntry.getValue();
                            PaperRStuQuestionVo q = qlist.get(0);
                            if(qlist.size() == 1){
                                //单题，不需要处理
                                newStuQSchoolList.add(q);
                            }else{
                                //获取子题已批改数量
                                List<PaperRStuQuestionVo> checkQList = qlist.stream().filter(s -> s.getChecked() == 1).collect(Collectors.toList());
                                double qscore = qlist.stream().mapToDouble(PaperRStuQuestionVo::getQscore).sum();
                                PaperRStuQuestionVo sq = new PaperRStuQuestionVo();
                                sq.setPaperid(q.getPaperid());
                                sq.setClassid(q.getClassid());
                                sq.setStudentid(q.getStudentid());
                                sq.setStuname(q.getStuname());
                                sq.setQuestionpid(q.getQuestionpid());
                                sq.setSchoolid(q.getSchoolid());
                                sq.setQn(q.getQn());
                                sq.setQorder(q.getQorder());
                                sq.setQscore(qscore);
                                sq.setPsid(q.getPsid());
                                sq.setPsqid(q.getPsqid());
                                sq.setPtid(q.getPtid());
                                sq.setQuestionid(q.getQuestionpid());
                                if(N_Utils.isListNotEmpty(checkQList)){
                                    //说明有子题批改，默认试题为已批改
                                    sq.setChecked(1);
                                    double stuscore = qlist.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                                    sq.setStuscore(stuscore);
                                }else{
                                    sq.setChecked(0);
                                    sq.setStuscore(0.0);
                                }
                                List<Integer> list = qlist.stream().map(PaperRStuQuestionVo::getAnswered).sorted().collect(Collectors.toList());
                                sq.setAnswered(list.get(list.size() - 1));
                                newStuQSchoolList.add(sq);
                            }
                        }
                    }
                }
            }
        }

        //获取试卷中试题题型
        List<PaperRStuQuestionVo> types = paperReportMapper.listPaperType(paper.getPaperid(), paper.getPapertype());
        Map<String, PaperRStuQuestionVo> typeMap = types.stream().collect(Collectors.toMap(t -> t.getQuestionid(), t -> t));

        //根据学校对新数据进行分组,进行计算单题得分
        Map<Integer,List<PaperRStuQuestionVo>> newStuQSchoolMap = newStuQSchoolList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getSchoolid));
        for(Map.Entry<Integer,List<PaperRStuQuestionVo>> nschoolEntry : newStuQSchoolMap.entrySet()){
            List<PaperRStuQuestionVo> nschoolList = nschoolEntry.getValue();

            //遍历试题进行计算
            for (Map.Entry<String, List<PaperRQuestionVo>> quesEntry : quesMap.entrySet()) {
                // 遍历试题
                List<PaperRQuestionVo> sonQList = quesEntry.getValue();
                String qnstr = "";
                double qscore = 0;
                PaperRQuestionVo q = sonQList.get(0);
                String questionpid = quesEntry.getKey();
                int ctype = 0;

                String questionidStr = quesEntry.getKey();
                if (N_Utils.isEmpty(questionidStr)) questionidStr = q.getPtqid().toString();
                PaperRStuQuestionVo type = typeMap.get(questionidStr);

                if(sonQList.size() == 1){
                    PaperRQuestionVo sonQ = sonQList.get(0);
                    qnstr = sonQ.getQn();
                    qscore = sonQ.getQscore();
                    ctype = q.getCtype();
                }else{
                    List<String> qnList = sonQList.stream().map(PaperRQuestionVo::getQn).collect(Collectors.toList());
                    qnstr = String.join(",", qnList);
                    qscore = sonQList.stream().mapToDouble(PaperRQuestionVo::getQscore).sum();
                    ctype = q.getPctype();
                }

                //学校下指定试题的学生
                List<PaperRStuQuestionVo> nschoolqList = nschoolList.stream().filter(s -> s.getQuestionpid().equals(questionpid)).collect(Collectors.toList());
                //获取学生试题批改数量
                List<PaperRStuQuestionVo> checkStuSchoolList = nschoolqList.stream().filter(s -> s.getChecked() ==1).collect(Collectors.toList());
                int schoolStunum = checkStuSchoolList.size();
                double schoolStuscore = checkStuSchoolList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                double shcoolAvgscore = N_Utils.getDoubleDivideForAvg(schoolStuscore, schoolStunum);
                double schoolScorerate = N_Utils.getDoubleDivideAndMulitiply(schoolStuscore, qscore * schoolStunum);
                double schoolLostrate = N_Utils.getDoubleReduce(100.0, schoolScorerate);

                //从试题中获取，避免班级因为没有批阅学生试题而没有数据
                Map<Integer,List<PaperRStuQuestionVo>> newStuQClassMap = nschoolqList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getClassid));
                for(Map.Entry<Integer,List<PaperRStuQuestionVo>> newStuQClassEntry : newStuQClassMap.entrySet()){
                    List<PaperRStuQuestionVo> nclassList = newStuQClassEntry.getValue();
                    List<PaperRStuQuestionVo> checkClassList = nclassList.stream().filter(s -> s.getChecked() ==1).collect(Collectors.toList());

                    int classStunum = checkClassList.size();
                    double classStuscore = checkClassList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                    double classAvgscore = N_Utils.getDoubleDivideForAvg(classStuscore, classStunum);
                    double classScorerate = N_Utils.getDoubleDivideAndMulitiply(classStuscore, qscore * classStunum);
                    double classLostrate = N_Utils.getDoubleReduce(100.0, classScorerate);
                    PaperRStuQuestionVo pfirst = nclassList.get(0);
                    PaperRclassQuestion rq = new PaperRclassQuestion();
                    rq.setPaperid(pfirst.getPaperid());
                    rq.setClassid(pfirst.getClassid());
                    rq.setQuestionid(quesEntry.getKey());
                    rq.setCtype(q.getPctype());
                    rq.setQn(qnstr);
                    rq.setQorder(q.getQorder());
                    rq.setQtypename(q.getQtypename());
                    rq.setQscore(qscore);
                    rq.setClassavgscore(classAvgscore);
                    rq.setClassscorerate(classScorerate);
                    rq.setClasslostrate(classLostrate);
                    rq.setSchoolavgscore(shcoolAvgscore);
                    rq.setSchoolscorerate(schoolScorerate);
                    rq.setSchoollostrate(schoolLostrate);
                    rq.setPtid(type.getPtid());
                    rq.setPtorder(type.getPtorder());
                    rq.setQtypename(type.getQtypename());
                    rq.setCtype(type.getCtype());

                    Map stuanswer = setPaperQuestionForStuAnswer(nclassList,ctype);
                    rq.setAnswerjson(JSON.toJSONString(stuanswer));

                    rq.setScorejson(JSON.toJSONString(setPaperQuestionForStuScore(nclassList)));
                    rclassQuesList.add(rq);

                    //处理作业学生试题分析
                    for(PaperRStuQuestionVo s : nclassList){
                        PaperRstudentQuestion  prq = new PaperRstudentQuestion();
                        prq.setPaperid(pfirst.getPaperid());
                        prq.setClassid(pfirst.getClassid());
                        prq.setStudentid(s.getStudentid());
                        prq.setQuestionid(quesEntry.getKey());
                        prq.setCtype(q.getCtype());
                        prq.setQn(qnstr);
                        prq.setQorder(q.getQorder());
                        prq.setQtypename(q.getQtypename());
                        prq.setQscore(qscore);
                        prq.setClassscorerate(classScorerate);
                        prq.setClasslostrate(classLostrate);
                        prq.setPtid(type.getPtid());
                        prq.setPtorder(type.getPtorder());
                        prq.setQtypename(type.getQtypename());
                        prq.setCtype(type.getCtype());
                        double stuScorerate = N_Utils.getDoubleDivideAndMulitiply(s.getStuscore(), qscore);// 学生得分率
                        double stuLostrate = N_Utils.getDoubleReduce(100.0, stuScorerate);// 学生失分率
                        prq.setScorerate(stuScorerate);
                        prq.setLostrate(stuLostrate);
                        rstuQuesList.add(prq);
                    }
                }
            }
        }
    }

    // 作业试题分析--学生答案
    private Map setPaperQuestionForStuAnswer(List<PaperRStuQuestionVo> classQnList,int ctype) {
        Map<String, List<Map>> answermap = null;
        Double score8 = 0.0;
        Double score5 = 0.0;
        String key1 = "";
        String key2 = "";
        String key3 = "";
        PaperRStuQuestionVo q = classQnList.get(0);// 取第一条数据获取基本得分
        Double qscore = q.getQscore();
        //int stunum = classQnList.size();
        for (int i = 0; i < classQnList.size(); i++) {
            PaperRStuQuestionVo sq = classQnList.get(i);
            String stuanswer = sq.getUseranswer();
            if (N_Utils.isSimpleCheckQuestion(ctype)) {
                // 如果是选择题和判断题，进行选项区分
                String answeroption = "未作答";
                if (N_Utils.isNotEmpty(stuanswer)) {
                    List<String> stuanswers = JSON.parseArray(stuanswer, String.class);
                    if (N_Utils.isListNotEmpty(stuanswers)) {
                        String stuansopt = stuanswers.get(0);
                        if (N_Utils.isNotEmpty(stuansopt)) {
                            answeroption = stuansopt;
                        }
                    }
                }

                if (i == 0) {
                    answermap = new TreeMap<>();
                }

                Map stumap = new HashMap();
                stumap.put("studentid", sq.getStudentid());
                stumap.put("stuname", sq.getStuname());
                stumap.put("stuscore", sq.getStuscore());
                if (answermap.containsKey(answeroption)) {
                    List<Map> stulist = answermap.get(answeroption);
                    stulist.add(stumap);
                } else {
                    List<Map> stulist = new ArrayList<>();
                    stulist.add(stumap);
                    answermap.put(answeroption, stulist);
                }
            } else {
                // 复合题和主观题，根据分值范围
                // 主观题
                if (i == 0) {
                    answermap = new LinkedHashMap<>();
                    // 处理分数分段对应,用于分数段[0，50%）   [50%，80%）,  [80%，100%]
                    score8 = N_Utils.getScoreRateScore(qscore, 0.8);
                    score5 = N_Utils.getScoreRateScore(qscore, 0.5);
                    String str10 = N_Utils.formatDouble(qscore);
                    String str8 = N_Utils.formatDouble(score8);
                    String str5 = N_Utils.formatDouble(score5);
                    key1 = str8 + "-" + str10;
                    key2 = str5 + "-" + str8;
                    key3 = 0 + "-" + str5;
                    answermap.put(key1, new ArrayList<>());
                    answermap.put(key2, new ArrayList<>());
                    answermap.put(key3, new ArrayList<>());
                }

                List<Map> stulist = null;
                if (sq.getStuscore() >= score8) {
                    stulist = answermap.get(key1);
                } else if (sq.getStuscore() >= score5 && sq.getStuscore() < score8) {
                    stulist = answermap.get(key2);
                } else {
                    stulist = answermap.get(key3);
                }

                Map stumap = new HashMap();
                stumap.put("studentid", sq.getStudentid());
                stumap.put("stuname", sq.getStuname());
                stumap.put("stuscore", sq.getStuscore());
                stulist.add(stumap);
            }
        }

        Map<String,List<Map>> answermapNew = new LinkedHashMap<>();
        if(ctype == 4 || ctype == 5 || ctype ==6){
            for (Map.Entry<String, List<Map>> entry : answermap.entrySet()) {
                if(!entry.getKey().equals("未作答")){
                    answermapNew.put(entry.getKey(),entry.getValue());
                }
            }
            //判断题把“未作答”放最后
            answermapNew.put("未作答",answermap.get("未作答"));
        }else{
            answermapNew.putAll(answermap);
        }

        //格式化每个选项百分比（总和为100）
        List<Integer> nums = new ArrayList<>();
        for (Map.Entry<String, List<Map>> entry : answermap.entrySet()) {
            nums.add(entry.getValue().size());
        }
        Map<Integer, Double> percent = N_Utils.parsePercent(nums);

        Map<String, Map> dafbmap = new LinkedHashMap<>();// 答案分布
        for (Map.Entry<String, List<Map>> entry : answermapNew.entrySet()) {
            String key = entry.getKey();
            List<Map> students = entry.getValue();
            Map dafb = new HashMap();
            int num = 0;
            if(N_Utils.isListNotEmpty(students)){
                num = students.size();
            }
            dafb.put("students", students);
            dafb.put("num", num);
            //dafb.put("numrate", N_Utils.getIntegerDivideAndMulitiply(num, stunum));
            dafb.put("numrate", percent.get(num));
            dafbmap.put(key, dafb);
        }

        return dafbmap;
    }

    // 班级作业试题情况-题库作业知识点分析
    private void setPaperQuestionPoint(List<PaperRStuQuestionVo> stuQschoolList,List<PaperRStuVo> stuList, List<PaperRclassPoint> rclassPointList,
                                       TPaperAnalyze paperAnalyze,  List<PaperRstudentPoint> rstuPointList) {

        //获取学校提交作业学生数量，无学生提交时不生成试题得分率
        List<PaperRStuVo> commitStuList = getCommitStuList(stuList);

        if(N_Utils.isListNotEmpty(commitStuList)){
            // 原试卷知识点分析
            String pointjson = paperAnalyze.getPointjson();
            List<Map> pointlist = JSON.parseArray(pointjson, Map.class);

            // 试题对应知识点关系
            String quespointjson = paperAnalyze.getQuespointjson();
            List<QuestionPointVo> quepointlist = JSON.parseArray(quespointjson, QuestionPointVo.class);

            List<PaperPointStuScoreVo> gradestulist = new ArrayList<>();// 每个知识点每个学生的得分
            for (int i = 0; i < quepointlist.size(); i++) {
                QuestionPointVo qpoint = quepointlist.get(i);
                List<Map> points = qpoint.getPointids();
                if (N_Utils.isListNotEmpty(points)) {
                    if (qpoint.getQlevel() == 1 || !N_Utils.isEmptyInteger(qpoint.getPtqid())) {
                        // 说明本题为单题,获取该题下所有学生的得分情况
                        List<PaperRStuQuestionVo> stuqueslist = stuQschoolList.stream().filter(s -> s.getPtqid().equals(qpoint.getPtqid())).collect(Collectors.toList());
                        for (PaperRStuQuestionVo sq : stuqueslist) {
                            setEPaperQuestionPointsForStuQues(gradestulist, sq, points, qpoint.getPtqid().toString());
                        }
                    } else {
                        // 说明该题为复合题，获取所有子题
                        List<Integer> eptqids = qpoint.getPtqids();
                        String eptqidsStr = eptqids.stream().map(String::valueOf).collect(Collectors.joining(","));
                        List<PaperRStuQuestionVo> stuqueslist = stuQschoolList.stream().filter(s -> eptqids.contains(s.getPtqid())).collect(Collectors.toList());
                        // 根据每个学生分组获取每个学生该题分值:因一份作业可能发给多个班级的同一个学生，所有需要按学校班级分组后再按学生算
                        Map<Integer,List<PaperRStuQuestionVo>> schoolQueMap = stuqueslist.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getSchoolid));
                        for(Map.Entry<Integer,List<PaperRStuQuestionVo>> schoolQueEntry : schoolQueMap.entrySet()){
                            List<PaperRStuQuestionVo> classQueList = schoolQueEntry.getValue();
                            Map<Integer,List<PaperRStuQuestionVo>> classQueMap = classQueList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getClassid));
                            for(Map.Entry<Integer,List<PaperRStuQuestionVo>> sclassQueEntry : classQueMap.entrySet()){
                                List<PaperRStuQuestionVo> stuQueList = sclassQueEntry.getValue();

                                Map<Integer, List<PaperRStuQuestionVo>> stuquesmap = stuQueList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getStudentid));
                                for (Map.Entry<Integer, List<PaperRStuQuestionVo>> entry : stuquesmap.entrySet()) {
                                    List<PaperRStuQuestionVo> stuques = entry.getValue();
                                    Double stuscore = stuques.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                                    stuscore = N_Utils.formatDouble(stuscore, 1);
                                    PaperRStuQuestionVo sqfirst = stuques.get(0);
                                    PaperRStuQuestionVo sq = new PaperRStuQuestionVo();
                                    sq.setStudentid(entry.getKey());
                                    sq.setClassid(sqfirst.getClassid());
                                    sq.setStuscore(stuscore);
                                    sq.setPaperid(sqfirst.getPaperid());
                                    sq.setSchoolid(sqfirst.getSchoolid());
                                    setEPaperQuestionPointsForStuQues(gradestulist, sq, points, eptqidsStr);
                                }
                            }
                        }
                    }
                }
            }

            //把提交学生按学校进行分组
            Map<Integer,List<PaperRStuVo>> schoolCommitStuList = commitStuList.stream().collect(Collectors.groupingBy(PaperRStuVo :: getSchoolid));

            // 根据试卷知识点分析进行生成班级、学校知识点分析
            for (Map map : pointlist) {
                String pointid = map.get("pointid").toString();
                String pointname = map.get("pointname").toString();
                Double pointscore = Double.parseDouble(map.get("score").toString());
                // Double pointrate = Double.parseDouble(map.get("srate").toString());
                List<Map> qorders = (List<Map>) map.get("ques");
                List<Integer> orders = qorders.stream().map(s -> Integer.parseInt(s.get("order").toString())).collect(Collectors.toList());
                String orderstr = orders.stream().map(String::valueOf).collect(Collectors.joining(","));//试题
                // 单个知识点学生得分情况:一个知识对应一个或多个试题，
                List<PaperPointStuScoreVo> gradepointstulist = gradestulist.stream().filter(s -> s.getPointid().equals(pointid)).collect(Collectors.toList());

                List<PaperPointStuScoreVo> pointstuscorelist = new ArrayList<>(); // 知识点下多个试题，处理成单个学生总分值情况
                //先按照班级进行分组，防止一个学生在多个班级收到多份作业
                Map<Integer,List<PaperPointStuScoreVo>> pointclassscoremap = gradepointstulist.stream().collect(Collectors.groupingBy(PaperPointStuScoreVo::getClassid));
                for(Map.Entry<Integer, List<PaperPointStuScoreVo>> classEntry : pointclassscoremap.entrySet()){
                    List<PaperPointStuScoreVo> pointstuscoreList = classEntry.getValue();
                    Map<Integer, List<PaperPointStuScoreVo>> pointstuscoremap = pointstuscoreList.stream().collect(Collectors.groupingBy(PaperPointStuScoreVo::getStudentid));
                    for (Map.Entry<Integer, List<PaperPointStuScoreVo>> entry : pointstuscoremap.entrySet()) {
                        List<PaperPointStuScoreVo> stuscorelist = entry.getValue();
                        Double stuscore = stuscorelist.stream().mapToDouble(PaperPointStuScoreVo::getStuscore).sum();
                        stuscore = N_Utils.formatDouble(stuscore, 1);

                        PaperPointStuScoreVo sscorevofirst = stuscorelist.get(0);
                        PaperPointStuScoreVo sscorevo = new PaperPointStuScoreVo();
                        sscorevo.setStudentid(sscorevofirst.getStudentid());
                        sscorevo.setClassid(sscorevofirst.getClassid());
                        sscorevo.setStuscore(stuscore);
                        sscorevo.setSchoolid(sscorevofirst.getSchoolid());
                        pointstuscorelist.add(sscorevo);
                    }
                }

                Map<Integer, List<PaperPointStuScoreVo>> schoolStuMap = pointstuscorelist.stream().collect(Collectors.groupingBy(PaperPointStuScoreVo::getSchoolid));
                for (Map.Entry<Integer, List<PaperPointStuScoreVo>> schoolentry : schoolStuMap.entrySet()) {
                    Integer schoolid = schoolentry.getKey();
                    //当学校有学生提交作业时进行计算知识点
                    if(schoolCommitStuList.containsKey(schoolid)){
                        List<PaperPointStuScoreVo> schoolStuList = schoolentry.getValue();
                        double schoolScore = pointscore * schoolStuList.size();
                        double schoolStuScore = schoolStuList.stream().mapToDouble(PaperPointStuScoreVo::getStuscore).sum();
                        double schoolScorerate = N_Utils.getDoubleDivideAndMulitiply(schoolStuScore, schoolScore);
                        double schoolLostrate = N_Utils.getDoubleReduce(100.0, schoolScorerate);

                        // 学校下班级内学生试题
                        Map<Integer, List<PaperPointStuScoreVo>> classStuMap = schoolStuList.stream().collect(Collectors.groupingBy(PaperPointStuScoreVo::getClassid));
                        for (Map.Entry<Integer, List<PaperPointStuScoreVo>> classMap : classStuMap.entrySet()) {
                            List<PaperPointStuScoreVo> classStuList = classMap.getValue();
                            PaperPointStuScoreVo pstuqVo = classStuList.get(0);
                            double classScore = pointscore * classStuList.size();
                            double classStuScore = classStuList.stream().mapToDouble(PaperPointStuScoreVo::getStuscore).sum();
                            double classScorerate = N_Utils.getDoubleDivideAndMulitiply(classStuScore, classScore);
                            double classLostrate = N_Utils.getDoubleReduce(100.0, classScorerate);

                            PaperRclassPoint ppoint = new PaperRclassPoint();
                            ppoint.setPaperid(paperAnalyze.getPaperid());
                            ppoint.setClassid(pstuqVo.getClassid());
                            ppoint.setPointid(pointid);
                            ppoint.setPointname(pointname);
                            ppoint.setClassscorerate(classScorerate);
                            ppoint.setClasslostrate(classLostrate);
                            ppoint.setSchoolscorerate(schoolScorerate);
                            ppoint.setSchoollostrate(schoolLostrate);
                            ppoint.setQns(orderstr);
                            rclassPointList.add(ppoint);

                            for(PaperPointStuScoreVo ps : classStuList){
                                PaperRstudentPoint psp = new PaperRstudentPoint();
                                psp.setPaperid(paperAnalyze.getPaperid());
                                psp.setClassid(pstuqVo.getClassid());
                                psp.setStudentid(ps.getStudentid());
                                psp.setPointid(pointid);
                                psp.setPointname(pointname);
                                double stuScorerate = N_Utils.getDoubleDivideAndMulitiply(ps.getStuscore(), pointscore);
                                double stuLostrate = N_Utils.getDoubleReduce(100.0, stuScorerate);
                                psp.setScorerate(stuScorerate);
                                psp.setLostrate(stuLostrate);
                                psp.setQns(orderstr);
                                rstuPointList.add(psp);
                            }
                        }
                    }
                }

            }
        }
    }

    // 班级作业试题情况-题库作业知识点分析-设置分值
    private void setEPaperQuestionPointsForStuQues(List<PaperPointStuScoreVo> gradestulist, PaperRStuQuestionVo sq, List<Map> points, String eptqids) {
        if (points.size() == 1) {
            Map pointmap = points.get(0);
            // 说明该试题仅有一个知识点得分直接为改知识点分值
            PaperPointStuScoreVo pscvo = new PaperPointStuScoreVo();
            pscvo.setClassid(sq.getClassid());
            pscvo.setStudentid(sq.getStudentid());
            pscvo.setStuscore(sq.getStuscore());
            String pointid = pointmap.get("pointid").toString();
            pscvo.setPointid(pointid);
            pscvo.setEptqids(eptqids);
            pscvo.setSchoolid(sq.getSchoolid());
            pscvo.setPaperid(sq.getPaperid());
            gradestulist.add(pscvo);
        } else {
            // 计算每个知识点所占分值（平均分配）
            Double[] avgps = N_Utils.getPointAvgScore(points.size(), sq.getStuscore());
            for (int j = 0; j < points.size(); j++) {
                Map pointmap = points.get(j);
                PaperPointStuScoreVo pscvo = new PaperPointStuScoreVo();
                pscvo.setClassid(sq.getClassid());
                pscvo.setStudentid(sq.getStudentid());
                String pointid = pointmap.get("pointid").toString();
                pscvo.setPointid(pointid);
                pscvo.setEptqids(eptqids);
                pscvo.setSchoolid(sq.getSchoolid());
                pscvo.setPaperid(sq.getPaperid());
                if (avgps.length == 2 && (j + 1) == points.size()) {
                    pscvo.setStuscore(avgps[1]);
                } else {
                    pscvo.setStuscore(avgps[0]);
                }

                gradestulist.add(pscvo);
            }
        }
    }

    // 班级报告-题库学生得分
    private void setPaperQuestionStuForQues(List<PaperRStuQuestionVo> stuQschoolList, List<PaperRstudent> rstuList, TPaper paper) {
        // 获取作业中试题
        List<PaperRQuestionVo> queList = paperQtypeQuestionMapper.listPaperQuesitonsByPaperid(paper.getPaperid());
        // 根据单题和父题的ctype区分主观题和客观题
        List<Integer> zgtList = new ArrayList<>();
        List<Integer> kgtList = new ArrayList<>();
        for (PaperRQuestionVo q : queList) {
            if (N_Utils.isObjectiveQuestion(q.getPctype())) {
                // 客观题
                kgtList.add(q.getPtqid());
            } else {
                zgtList.add(q.getPtqid());
            }
        }

        // 先按照班级进行分组在计算
        Map<Integer, List<PaperRStuQuestionVo>> classMap = stuQschoolList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getClassid));
        for (Map.Entry<Integer, List<PaperRStuQuestionVo>> classEntry : classMap.entrySet()) {
            List<PaperRStuQuestionVo> classStuList = classEntry.getValue();
            // 根据学生id进行分组，获取用户的试题
            Map<Integer, List<PaperRStuQuestionVo>> stuMap = classStuList.stream().collect(Collectors.groupingBy(PaperRStuQuestionVo::getStudentid));
            for (Map.Entry<Integer, List<PaperRStuQuestionVo>> entry : stuMap.entrySet()) {
                List<PaperRStuQuestionVo> stuList = entry.getValue();
                PaperRStuQuestionVo stuFirst = stuList.get(0);
                List<PaperRStuQuestionVo> stuZgtList = stuList.stream().filter(s -> zgtList.contains(s.getPtqid())).collect(Collectors.toList());
                List<PaperRStuQuestionVo> stuKgtList = stuList.stream().filter(s -> kgtList.contains(s.getPtqid())).collect(Collectors.toList());
                double zgtScore = stuZgtList.stream().mapToDouble(PaperRStuQuestionVo::getQscore).sum();
                double zgtStuScore = stuZgtList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                double kgtScore = stuKgtList.stream().mapToDouble(PaperRStuQuestionVo::getQscore).sum();
                double kgtStuScore = stuKgtList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();

                double stuscore = stuList.stream().mapToDouble(PaperRStuQuestionVo::getStuscore).sum();
                double paperscore = 0.0;
                if (paper.getPapertype() == 3) {
                    paperscore = stuList.stream().mapToDouble(PaperRStuQuestionVo::getQscore).sum();
                } else {
                    paperscore = paper.getPaperscore();
                }
                double stuscorerate = N_Utils.getDoubleDivideAndMulitiply(stuscore, paperscore);

                PaperRstudent ps = new PaperRstudent();
                ps.setPaperid(stuFirst.getPaperid());
                ps.setClassid(stuFirst.getClassid());
                ps.setStudentid(stuFirst.getStudentid());
                ps.setZgtscore(zgtScore);
                ps.setStuzgtscore(zgtStuScore);
                ps.setKgtscore(kgtScore);
                ps.setStukgtscore(kgtStuScore);
                ps.setStuscore(stuscore);
                ps.setStuscorerate(stuscorerate);

                rstuList.add(ps);
            }
        }
    }

    /**
     * @return java.util.Map
     * @Description 作业概况
     * @Param [paperid, classid]
     * @Author ywx
     * @Date 2023/4/18 16:20
     **/
    public Map getPaperOverview(Integer paperid, Integer classid) {
        Map map = paperReportMapper.getPaperClass(paperid, classid);// 作业概况-班级概况
        List<Map> ranks = paperReportMapper.listPaperClassRank(paperid, classid);
        map.put("ranks", ranks);// 作业概况-成绩概况
        List<Map> qscores = paperReportMapper.listPaperClassQuestionScore(paperid, classid);
        map.put("qscores", qscores);// 作业概况-试题得分率
        List<Map> questions = paperReportMapper.listPaperClassQuestionRate(paperid, classid);
        map.put("questions", questions);// 作业概况-试题错误率
        List<Map> points = paperReportMapper.listPaperClassPointRate(paperid, classid);
        map.put("points", points);// 作业概况-知识点错误率
        return map;
    }

    /**
     * @return java.util.Map
     * @Description 作业详情
     * @Param [paperid, classid]
     * @Author ywx
     * @Date 2023/4/19 10:41
     **/
    public Map getPaperDetail(Integer paperid, Integer classid) {
        Map paper = paperReportMapper.getPaperAnalyze(paperid);
        Integer papertype = (Integer) paper.get("papertype");
        List<Map> list;
        if (papertype == 1 || papertype == 3) {// 题库、靶向作业
            list = paperReportMapper.listTkSt(paperid, classid, papertype);
            List<Map> questions = new ArrayList<>();// 题库作业子题
            List<String> questionids = new ArrayList<>();
            list.forEach(t -> {
                List<Map> questionList = (List<Map>) t.get("questions");
                questionids.addAll(questionList.stream().filter(q -> q.get("qlevel").equals(2))
                                               .map(q -> q.get("questionid").toString()).collect(Collectors.toList()));
            });

            // List<String> questionids = list.stream().filter(q -> q.get("qlevel").equals(2)).map(q -> q.get("questionid").toString()).collect(Collectors.toList());
            if (N_Utils.isListNotEmpty(questionids)) questions = paperReportMapper.listZtQuestion(questionids,paperid);
            Object pointjson = paper.get("pointjson");
            List<Map> points = JSON.parseArray(pointjson.toString(), Map.class);
            for (Map t : list) {
                for (Map q : (List<Map>) t.get("questions")) {
                    String questionid = q.get("questionid").toString();
                    q.put("pointnames", getQuestionPoint(points, questionid));// 试题知识点
                    if (q.get("qlevel").equals(2)) {
                        List<Map> sonques = questions.stream().filter(tq -> questionid.equals(tq.get("questionpid"))).collect(Collectors.toList());
                        q.put("sonques", sonques);
                    }
                    q.put("classratetype", StudyUtil.getScoreRateType(StudyUtil.objToDouble(q.get("classscorerate"))));
                    if(N_Utils.isEmpty(q.get("classavgscore"))){
                        q.put("classavgscore",0);
                    }
                    if(N_Utils.isEmpty(q.get("classscorerate"))){
                        q.put("classscorerate",0);
                    }
                    if(N_Utils.isEmpty(q.get("schoolavgscore"))){
                        q.put("schoolavgscore",0);
                    }
                    if(N_Utils.isEmpty(q.get("schoolscorerate"))){
                        q.put("schoolscorerate",0);
                    }
                }
            }
        } else {// 附件作业
            String papername = paper.get("papername").toString();
            list = paperReportMapper.listFjSt(paperid, classid);
            for (Map t : list) {
                for (Map q : (List<Map>) t.get("questions")) {
                    q.put("qstem", papername + "-第" + q.get("qn") + "题");
                    q.put("classratetype", StudyUtil.getScoreRateType(StudyUtil.objToDouble(q.get("classscorerate"))));
                    if(N_Utils.isEmpty(q.get("classavgscore"))){
                        q.put("classavgscore",0);
                    }
                    if(N_Utils.isEmpty(q.get("classscorerate"))){
                        q.put("classscorerate",0);
                    }
                    if(N_Utils.isEmpty(q.get("schoolavgscore"))){
                        q.put("schoolavgscore",0);
                    }
                    if(N_Utils.isEmpty(q.get("schoolscorerate"))){
                        q.put("schoolscorerate",0);
                    }
                }
            }
        }
        paper.remove("papername");
        paper.remove("pointjson");
        paper.put("types", list);
        return paper;
    }

    // 试题知识点
    private List<String> getQuestionPoint(List<Map> points, String questionid) {
        List<String> pointnames = new ArrayList<>();
        for (Map p : points) {
            String ques = p.get("ques").toString();
            String pointname = p.get("pointname").toString();
            if (ques.contains("\"" + questionid + "\"")) pointnames.add(pointname);
        }
        return pointnames;
    }

    /**
     * @return java.util.List<java.util.Map>
     * @Description 未提交学生列表
     * @Param [paperid, classid]
     * @Author ywx
     * @Date 2023/4/19 11:31
     **/
    public List<Map> listWtjStu(Integer paperid, Integer classid) {
        return paperReportMapper.listWtjStu(paperid, classid);
    }

    /**
     * @return java.util.List<java.util.Map>
     * @Description 已提交学生列表
     * @Param [paper]
     * @Author ywx
     * @Date 2023/4/19 14:10
     **/
    public List<Map> listTjStu(TPaper paper) {
        return paperReportMapper.listTjStu(paper);
    }

    /**
     * @return java.util.Map
     * @Description 作业基本信息
     * @Param [paperid]
     * @Author ywx
     * @Date 2023/4/19 17:16
     **/
    public Map getPaper(Integer paperid) {
        return paperReportMapper.getPaper(paperid);
    }

    /**
     * @Description 优秀作答班级
     * @Param [paperid, schoolid, papertype]
     * @Author ywx
     * @Date 2023/6/26 9:59
     * @return java.util.List<java.util.Map>
     **/
    public List<Map> listGoodAnswerClass(Integer paperid, Integer schoolid, Integer papertype) {
        return paperReportMapper.listGoodAnswerClass(paperid,schoolid,papertype);
    }

    /**
     * @Description 作业提交详情
     * @Date 2024/6/19 10:35
     * @Author YWX
     * @Param [paper]
     * @Return java.util.List<java.util.Map>
     **/
    public List<Map> listStu(TPaper paper) {
        List<StudentPaperVo> students = paperReportMapper.listStu(paper);
        List<Map> list = new ArrayList<>();
        int totalnum = students.size();//总人数
        int wtjnum = 0;//未提交人数
        int ytjnum = 0;//已提交人数
        int ypynum = 0;//已批阅人数
        List<String> wtjStu = new ArrayList<>();//未提交学生名单
        List<String> ytjStu = new ArrayList<>();//已提交学生名单
        List<String> ypyStu = new ArrayList<>();//已批阅学生名单
        for (StudentPaperVo student : students) {
            Integer psstate = student.getPsstate();
            String studentname = student.getStudentname();
            if (StudyUtil.wtjlist.contains(psstate)) {
                wtjnum++;
                wtjStu.add(studentname);
            } else if (student.getPschecked().equals(1)) {
                ypynum++;
                ypyStu.add(studentname);
            } else {
                ytjnum++;
                ytjStu.add(studentname);
            }
        }
        //添加提交类型数据
        addCommitType("未提交", wtjnum, totalnum, list, wtjStu);
        addCommitType("已提交", ytjnum, totalnum, list, ytjStu);
        addCommitType("已批阅", ypynum, totalnum, list, ypyStu);
        return list;
    }

    //添加提交类型数据
    private void addCommitType(String type, int num, int totalnum, List<Map> list, List<String> students) {
        Map wtj = new HashMap();
        wtj.put("type", type);
        wtj.put("num", num);
        wtj.put("numrate", N_Utils.formatProportion(num, totalnum));
        wtj.put("students", students);
        list.add(wtj);
    }
}
