Преглед на файлове

已做完卷的提示 "试卷次数已用完"

mingfu преди 2 дни
родител
ревизия
e7938cc693
променени са 1 файла, в които са добавени 86 реда и са изтрити 0 реда
  1. 86 0
      ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

+ 86 - 0
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -77,6 +77,89 @@ public class ExamService {
         this.dzControlService = dzControlService;
     }
 
+
+    private void initPaper() {
+        LearnWrongBook wbCond = new LearnWrongBook();
+        Long studentId = 5L;
+        wbCond.setStudentId(studentId);
+        Map<Long, Set<Long>> knownQuestionsMap = wrongBookMapper.selectLearnWrongBookList(wbCond).stream().collect(Collectors.groupingBy(LearnWrongBook::getKnownledgeId, Collectors.mapping(LearnWrongBook::getQuestionId, Collectors.toSet())));
+
+        for(Long knownId : knownQuestionsMap.keySet()) {
+            LearnKnowledgeTree kt = knowledgeTreeMapper.selectLearnKnowledgeTreeById(knownId);
+            List<Long> questionIds = Lists.newArrayList(knownQuestionsMap.get(knownId));
+            if(questionIds.size() <= 50) {
+                buildSheet(studentId, kt, questionIds);
+                continue;
+            }
+            for(int i = 0; i < questionIds.size(); i++) {
+                List<Long> subList = questionIds.subList(i, Math.min(questionIds.size(), i + 50));
+                buildSheet(studentId, kt, subList);
+                i += 50;
+            }
+        }
+
+    }
+
+    private void buildSheet(Long studentId, LearnKnowledgeTree kt, List<Long> questionIds) {
+        LearnPaper paper = new LearnPaper();
+        paper.setPaperType(PaperType.Practice.name());
+        paper.setRelateId(kt.getId());
+        paper.setYear(Calendar.getInstance().get(Calendar.YEAR));
+        paper.setStatus(PaperStatus.TmpValid.getVal());
+        paper.setDirectKey(studentId + "__0");
+        List<LearnPaperQuestion> pqList = Lists.newArrayList();
+        Set<String> existQuestionSet = Sets.newHashSet();
+        for(LearnQuestions q : learnQuestionsMapper.selectLearnQuestionsByIds(questionIds.toArray(new Long[questionIds.size()]))) {
+            if(existQuestionSet.add(q.getId().toString()) && existQuestionSet.add(q.getTitle())) {
+                QuestionType type = QuestionType.of(q.getQtpye());
+                if ("1".equals(q.getIsSubType())) {
+                    LearnQuestions subCond = new LearnQuestions();
+                    subCond.setKnowId(q.getId());
+                    for (LearnQuestions sq : learnQuestionsMapper.selectLearnQuestionsList(subCond)) {
+                        LearnPaperQuestion pq = new LearnPaperQuestion();
+                        pq.setSeq(pqList.size());
+                        pq.setKnowledgeId(kt.getId());
+                        pq.setScore(1.0);
+                        pq.setQuestionId(sq.getId());
+                        pq.setType(type.getTitle());
+                        pq.setDiff(type.getVal());
+                        pq.setPaperId(q.getId());
+                        pqList.add(pq);
+                    }
+                } else {
+                    LearnPaperQuestion pq = new LearnPaperQuestion();
+                    pq.setSeq(pqList.size());
+                    pq.setKnowledgeId(kt.getId());
+                    pq.setScore(1.0);
+                    pq.setQuestionId(q.getId());
+                    pq.setType(type.getTitle());
+                    pq.setDiff(type.getVal());
+                    pq.setPaperId(0L);
+                    pqList.add(pq);
+                }
+            }
+        }
+        if(pqList.isEmpty()) {
+            return;
+        }
+        paper.setPaperSource(909);
+        paper.setFenshu(0);
+        paper.setSubjectId(kt.getSubjectId());
+        paper.setPaperName(studentId + "-" + kt.getName() + "-" + DateUtils.format(new Date(), "yyyyMMddHHmmss"));
+        paper.setRelateId(kt.getId());
+        paperService.savePaper(paper, pqList);
+
+        LearnExaminee learnExaminee = new LearnExaminee();
+        learnExaminee.setStudentId(studentId);
+        learnExaminee.setPaperType(PaperType.Practice.getVal());
+        learnExaminee.setPaperId(paper.getId());
+        learnExaminee.setPaperKey(String.valueOf(kt.getId()));
+        learnExaminee.setState(ExamineeStatus.Exam.getVal());
+        learnExaminee.setBeginTime(new Date());
+        learnExaminee.setDuration(0L);
+        examineeMapper.insertLearnExaminee(learnExaminee);
+    }
+
     /**
      * 开卷 (卷, 实时组卷)
      * @return
@@ -691,6 +774,9 @@ public class ExamService {
                 }
             }
         }
+        if(existPaperIdSet.size() > 0) {
+            throw new ValidationException("试卷次数已用完:" + subjectId + ":" + plan.getId() + "\n  " + plan.getEnrollFormula());
+        }
         throw new ValidationException("未初始化院校定向模拟题库:" + subjectId + ":" + plan.getId() + "\n  " + plan.getEnrollFormula());
     }