|
@@ -53,9 +53,10 @@ public class PaperService {
|
|
|
this.wishUniversitiesService = wishUniversitiesService;
|
|
this.wishUniversitiesService = wishUniversitiesService;
|
|
|
this.bBusiWishUniversitiesMapper = bBusiWishUniversitiesMapper;
|
|
this.bBusiWishUniversitiesMapper = bBusiWishUniversitiesMapper;
|
|
|
this.learnKnowledgeTreeMapper = learnKnowledgeTreeMapper;
|
|
this.learnKnowledgeTreeMapper = learnKnowledgeTreeMapper;
|
|
|
- // buildAllPapers(0);
|
|
|
|
|
|
|
+ // buildAllPapers(2);
|
|
|
// buildSimulatedPaper(20154L, 1001L);
|
|
// buildSimulatedPaper(20154L, 1001L);
|
|
|
// buildSimulatedPaper(20950L, 1001L);
|
|
// buildSimulatedPaper(20950L, 1001L);
|
|
|
|
|
+ // buildSimulatedPaperForUniversity(20972L, 11L, 215L, 2);
|
|
|
// test2();
|
|
// test2();
|
|
|
// testCulture();
|
|
// testCulture();
|
|
|
}
|
|
}
|
|
@@ -73,7 +74,10 @@ public class PaperService {
|
|
|
if(null == universities) {
|
|
if(null == universities) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- buildSimulatedPaper(1001L, seq, universities, universityDirectedMap.get(universityId));
|
|
|
|
|
|
|
+ for(LearnDirectedKnowledge dk : universityDirectedMap.get(universityId)) {
|
|
|
|
|
+ buildSimulatedPaperForKnowledge(11L, seq, universities, dk);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -235,12 +239,16 @@ public class PaperService {
|
|
|
return paperQuestionList;
|
|
return paperQuestionList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int buildSimulatedPaper(Long universityId, Long subjectId, Integer seq) {
|
|
|
|
|
|
|
+ public int buildSimulatedPaperForUniversity(Long universityId, Long subjectId, Long directedId, Integer seq) {
|
|
|
LearnDirectedKnowledge dkCond = new LearnDirectedKnowledge();
|
|
LearnDirectedKnowledge dkCond = new LearnDirectedKnowledge();
|
|
|
dkCond.setUniversityId(universityId);
|
|
dkCond.setUniversityId(universityId);
|
|
|
List<LearnDirectedKnowledge> directedKnowledgeList = learnDirectedKnowledgeMapper.selectLearnDirectedKnowledgeList(dkCond);
|
|
List<LearnDirectedKnowledge> directedKnowledgeList = learnDirectedKnowledgeMapper.selectLearnDirectedKnowledgeList(dkCond);
|
|
|
BBusiWishUniversities universities = wishUniversitiesService.selectBBusiWishUniversitiesById(universityId);
|
|
BBusiWishUniversities universities = wishUniversitiesService.selectBBusiWishUniversitiesById(universityId);
|
|
|
- buildSimulatedPaper(subjectId, seq, universities, directedKnowledgeList);
|
|
|
|
|
|
|
+ for(LearnDirectedKnowledge dk : directedKnowledgeList) {
|
|
|
|
|
+ if(null == directedId || directedId.equals(dk.getId())) {
|
|
|
|
|
+ buildSimulatedPaperForKnowledge(subjectId, seq, universities, dk);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -248,44 +256,49 @@ public class PaperService {
|
|
|
* 根据院校专业要求生成模拟试卷
|
|
* 根据院校专业要求生成模拟试卷
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
|
|
+ public int buildSimulatedPaperForKnowledge(Long subjectId, Integer seq, BBusiWishUniversities universities, LearnDirectedKnowledge dk) {
|
|
|
|
|
+ if(StringUtils.isBlank(dk.getConditions())) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ TestPaperVO.PaperDef2 paperDef = new TestPaperVO.PaperDef2(dk.getKnowledges(), dk.getConditions());
|
|
|
|
|
+ paperDef.setFillExclude(false);
|
|
|
|
|
|
|
|
- public int buildSimulatedPaper(Long subjectId, Integer seq, BBusiWishUniversities universities, List<LearnDirectedKnowledge> directedKnowledgeList) {
|
|
|
|
|
- for(LearnDirectedKnowledge dk : directedKnowledgeList) {
|
|
|
|
|
- if(StringUtils.isBlank(dk.getConditions())) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- TestPaperVO.PaperDef2 paperDef = new TestPaperVO.PaperDef2(dk.getKnowledges(), dk.getConditions());
|
|
|
|
|
- paperDef.setFillExclude(false);
|
|
|
|
|
-
|
|
|
|
|
- LearnPaper paper = new LearnPaper();
|
|
|
|
|
- paper.setSubjectId(subjectId);
|
|
|
|
|
- paper.setPaperType(PaperType.Simulated.name());
|
|
|
|
|
- paper.setRelateId(dk.getId()); // 定向ID
|
|
|
|
|
- paper.setYear(dk.getYear());
|
|
|
|
|
- paper.setPaperSource(seq);
|
|
|
|
|
- if(CollectionUtils.isNotEmpty(paperMapper.selectLearnPaperList(paper))) {
|
|
|
|
|
- log.warn("已经生成: {}:{}", dk.getId(), seq);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- paper.setPaperName(StringUtils.isNotBlank(dk.getDirectKey()) ? universities.getName() + "(" + dk.getDirectKey() + ")" : universities.getName());
|
|
|
|
|
- paper.setDirectKey(universities.getId() + "_" + dk.getExamineeTypes() + "_" + dk.getDirectKey());
|
|
|
|
|
- paper.setStatus(PaperStatus.Valid.getVal());
|
|
|
|
|
- paper.setNumber(paperDef.getTotal());
|
|
|
|
|
- paper.setFenshu(paperDef.getScore().intValue());
|
|
|
|
|
- AnswerSheet.PaperCond info = new AnswerSheet.PaperCond();
|
|
|
|
|
- info.setScore(paper.getFenshu());
|
|
|
|
|
- info.setTime(dk.getTime() * 60);
|
|
|
|
|
- info.setTypes(paperDef.getTypes().stream().map(t -> new AnswerSheet.PaperCondType(t.getType().getTitle(), t.getCount(), t.getScore())).collect(Collectors.toList()));
|
|
|
|
|
- paper.setPaperInfo(JSONObject.toJSONString(info));
|
|
|
|
|
- try {
|
|
|
|
|
- Pair<LearnPaper, List<LearnPaperQuestion>> paperResult = buildPaper2(null, paper, paperDef);
|
|
|
|
|
- savePaper(paperResult.getKey(), paperResult.getValue());
|
|
|
|
|
- } catch(Exception e) {
|
|
|
|
|
- log.error(e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ LearnPaper paper = new LearnPaper();
|
|
|
|
|
+ paper.setSubjectId(subjectId);
|
|
|
|
|
+ paper.setPaperType(PaperType.Simulated.name());
|
|
|
|
|
+ paper.setRelateId(dk.getId()); // 定向ID
|
|
|
|
|
+ paper.setYear(dk.getYear());
|
|
|
|
|
+ paper.setPaperSource(seq);
|
|
|
|
|
+ paper.setStatus(1);
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(paperMapper.selectLearnPaperList(paper))) {
|
|
|
|
|
+ log.warn("已经生成: {}:{}", dk.getId(), seq);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ paper.setPaperName(StringUtils.isNotBlank(dk.getDirectKey()) ? universities.getName() + "(" + dk.getDirectKey() + ")" : universities.getName());
|
|
|
|
|
+ paper.setDirectKey(universities.getId() + "_" + dk.getExamineeTypes() + "_" + dk.getDirectKey());
|
|
|
|
|
+ paper.setStatus(PaperStatus.Valid.getVal());
|
|
|
|
|
+ paper.setNumber(paperDef.getTotal());
|
|
|
|
|
+ paper.setFenshu(paperDef.getScore().intValue());
|
|
|
|
|
+ AnswerSheet.PaperCond info = new AnswerSheet.PaperCond();
|
|
|
|
|
+ info.setScore(paper.getFenshu());
|
|
|
|
|
+ info.setTime(dk.getTime() * 60);
|
|
|
|
|
+ info.setTypes(paperDef.getTypes().stream().map(t -> new AnswerSheet.PaperCondType(t.getType().getTitle(), t.getCount(), t.getScore())).collect(Collectors.toList()));
|
|
|
|
|
+ paper.setPaperInfo(JSONObject.toJSONString(info));
|
|
|
|
|
+ try {
|
|
|
|
|
+ Pair<LearnPaper, List<LearnPaperQuestion>> paperResult = buildPaper2(null, paper, paperDef);
|
|
|
|
|
+ savePaper(paperResult.getKey(), paperResult.getValue());
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ } catch(Exception e) {
|
|
|
|
|
+ log.error(e.getMessage());
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 原版本,新的是2
|
|
|
|
|
+ * @param directedKnowledge
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
public Pair<LearnPaper, List<LearnPaperQuestion>> buildSimulatedPaper(LearnDirectedKnowledge directedKnowledge) {
|
|
public Pair<LearnPaper, List<LearnPaperQuestion>> buildSimulatedPaper(LearnDirectedKnowledge directedKnowledge) {
|
|
|
LearnPaper paper = new LearnPaper();
|
|
LearnPaper paper = new LearnPaper();
|
|
|
paper.setPaperType(PaperType.Simulated.name());
|
|
paper.setPaperType(PaperType.Simulated.name());
|
|
@@ -353,14 +366,32 @@ public class PaperService {
|
|
|
List<LearnPaperQuestion> pqList = Lists.newArrayList();
|
|
List<LearnPaperQuestion> pqList = Lists.newArrayList();
|
|
|
Set<Long> existQuestionIdSet = Sets.newHashSet();
|
|
Set<Long> existQuestionIdSet = Sets.newHashSet();
|
|
|
for(TestPaperVO.KnowledgeTypeDef2 ktd : paperDef.getKnowTypes()) {
|
|
for(TestPaperVO.KnowledgeTypeDef2 ktd : paperDef.getKnowTypes()) {
|
|
|
- Set<Long> knownIdSet = Sets.newHashSet(ktd.getKnowledges());
|
|
|
|
|
- for(LearnKnowledgeTree kt : learnKnowledgeTreeMapper.selectLearnKnowledgeTreeByParentIds(ktd.getKnowledges())) {
|
|
|
|
|
- knownIdSet.remove(kt.getPid());
|
|
|
|
|
- knownIdSet.add(kt.getId());
|
|
|
|
|
|
|
+ Map<Long, List<Long>> ktSubMap = Maps.newHashMap();
|
|
|
|
|
+ Integer maxSubCount = 6;
|
|
|
|
|
+ List<Long> newKnownList = Lists.newArrayList();
|
|
|
|
|
+ List<Long> tailKnownList = Lists.newArrayList();
|
|
|
|
|
+ List<LearnKnowledgeTree> ktList = learnKnowledgeTreeMapper.selectLearnKnowledgeTreeByParentIds(ktd.getKnowledges());
|
|
|
|
|
+ for(LearnKnowledgeTree kt : ktList) {
|
|
|
|
|
+ List<Long> subIdList = ktSubMap.computeIfAbsent(kt.getPid(), k -> Lists.newArrayList());
|
|
|
|
|
+ subIdList.add(kt.getId());
|
|
|
}
|
|
}
|
|
|
- Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), knownIdSet, paperDef.getFillExclude());
|
|
|
|
|
|
|
+ for(Long knownId : ktd.getKnowledges()) {
|
|
|
|
|
+ List<Long> subList = ktSubMap.get(knownId);
|
|
|
|
|
+ if(null == subList) {
|
|
|
|
|
+ newKnownList.add(knownId);
|
|
|
|
|
+ } else if(subList.size() > maxSubCount) {
|
|
|
|
|
+ newKnownList.addAll(subList.subList(0, maxSubCount));
|
|
|
|
|
+ tailKnownList.addAll(subList.subList(maxSubCount, subList.size()));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ newKnownList.addAll(subList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ newKnownList.addAll(tailKnownList);
|
|
|
|
|
+ ktd.setKnowledges(newKnownList);
|
|
|
|
|
+ Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude());
|
|
|
assignTypeFirst(paperDef.getFillExclude(), ktd, knowTypeAssignMap);
|
|
assignTypeFirst(paperDef.getFillExclude(), ktd, knowTypeAssignMap);
|
|
|
- pqList.addAll(getQuestions2(studentId, ktd.getCount(), knownIdSet, ktd.getTypes(), knowTypeAssignMap, existQuestionIdSet));
|
|
|
|
|
|
|
+ pqList.addAll(getQuestions2(studentId, ktd.getCount(), pqList.size(), newKnownList, ktd.getTypes(), knowTypeAssignMap, existQuestionIdSet));
|
|
|
}
|
|
}
|
|
|
return pqList;
|
|
return pqList;
|
|
|
}
|
|
}
|
|
@@ -664,7 +695,7 @@ public class PaperService {
|
|
|
qCond.setId(studentId);
|
|
qCond.setId(studentId);
|
|
|
qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) : 0L);
|
|
qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) : 0L);
|
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
|
- ktc.exclAssign = addRandomList(knowId, ktc.getType(), questions, random, paperDef.getTotal(), ktc.exclAssign, typeDef.getScore().doubleValue(), existQuestionIdSet, pqList);
|
|
|
|
|
|
|
+ ktc.exclAssign = addRandomList(knowId, ktc.getType(), questions, random, paperDef.getTotal(), ktc.exclAssign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
|
|
|
if(pqList.size() == total) {
|
|
if(pqList.size() == total) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -673,7 +704,7 @@ public class PaperService {
|
|
|
qCond.setId(null);
|
|
qCond.setId(null);
|
|
|
qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) : 0L);
|
|
qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) : 0L);
|
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
|
- ktc.assign = addRandomList(knowId, ktc.getType(), questions, random, paperDef.getTotal(), ktc.assign, typeDef.getScore().doubleValue(), existQuestionIdSet, pqList);
|
|
|
|
|
|
|
+ ktc.assign = addRandomList(knowId, ktc.getType(), questions, random, paperDef.getTotal(), ktc.assign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
|
|
|
if(pqList.size() == total) {
|
|
if(pqList.size() == total) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -689,7 +720,7 @@ public class PaperService {
|
|
|
return pqList;
|
|
return pqList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<LearnPaperQuestion> getQuestions2(Long studentId, Integer total, Collection<Long> knownIds, List<TestPaperVO.TypeDef2> types, Map<String, KnowTypeAssign> knowTypeAssignMap, Set<Long> existQuestionIdSet) {
|
|
|
|
|
|
|
+ public List<LearnPaperQuestion> getQuestions2(Long studentId, Integer total, Integer seqId, Collection<Long> knownIds, List<TestPaperVO.TypeDef2> types, Map<String, KnowTypeAssign> knowTypeAssignMap, Set<Long> existQuestionIdSet) {
|
|
|
// 知识点已经分配,准备题型分配
|
|
// 知识点已经分配,准备题型分配
|
|
|
LearnQuestions qCond = new LearnQuestions();
|
|
LearnQuestions qCond = new LearnQuestions();
|
|
|
Random random = new Random();
|
|
Random random = new Random();
|
|
@@ -708,7 +739,7 @@ public class PaperService {
|
|
|
qCond.setId(studentId);
|
|
qCond.setId(studentId);
|
|
|
qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) : 0L);
|
|
qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) : 0L);
|
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
|
- ktc.exclAssign = addRandomList(knowId, typeTitle, questions, random, typeDef.getCount().longValue(), ktc.exclAssign, typeDef.getScore(), existQuestionIdSet, pqList);
|
|
|
|
|
|
|
+ ktc.exclAssign = addRandomList(knowId, typeTitle, questions, random, typeDef.getCount().longValue(), ktc.exclAssign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
|
|
|
if(pqList.size() == total) {
|
|
if(pqList.size() == total) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -717,7 +748,7 @@ public class PaperService {
|
|
|
qCond.setId(null);
|
|
qCond.setId(null);
|
|
|
qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) : 0L);
|
|
qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) : 0L);
|
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
|
|
|
- ktc.assign = addRandomList(knowId, typeTitle, questions, random, typeDef.getCount().longValue(), ktc.assign, typeDef.getScore(), existQuestionIdSet, pqList);
|
|
|
|
|
|
|
+ ktc.assign = addRandomList(knowId, typeTitle, questions, random, typeDef.getCount().longValue(), ktc.assign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
|
|
|
if(pqList.size() == total) {
|
|
if(pqList.size() == total) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -728,7 +759,7 @@ public class PaperService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(CollectionUtils.isEmpty(pqList)) {
|
|
if(CollectionUtils.isEmpty(pqList)) {
|
|
|
- throw new RuntimeException("题数不足");
|
|
|
|
|
|
|
+ throw new RuntimeException("题数不足 " + types.stream().map( t -> t.getType().getTitle()).collect(Collectors.joining(",")) + ":" + StringUtils.join(knownIds, ","));
|
|
|
}
|
|
}
|
|
|
return pqList;
|
|
return pqList;
|
|
|
}
|
|
}
|
|
@@ -778,12 +809,12 @@ public class PaperService {
|
|
|
* @param existQuestionIdSet 不能使用的题
|
|
* @param existQuestionIdSet 不能使用的题
|
|
|
* @param pqList 卷题关系
|
|
* @param pqList 卷题关系
|
|
|
*/
|
|
*/
|
|
|
- private Long addRandomList(Long knowId, String type, List<LearnQuestions> questions, Random random, Long totalCount, Long count, Double score, Set<Long> existQuestionIdSet, List<LearnPaperQuestion> pqList) {
|
|
|
|
|
|
|
+ private Long addRandomList(Long knowId, String type, List<LearnQuestions> questions, Random random, Long totalCount, Long count, Double score, Set<Long> existQuestionIdSet, Integer baseSeq, List<LearnPaperQuestion> pqList) {
|
|
|
while(count > 0L && !questions.isEmpty()) {
|
|
while(count > 0L && !questions.isEmpty()) {
|
|
|
LearnQuestions q = questions.size() > 1 ? questions.remove(random.nextInt(questions.size() - 1)) : questions.remove(0);
|
|
LearnQuestions q = questions.size() > 1 ? questions.remove(random.nextInt(questions.size() - 1)) : questions.remove(0);
|
|
|
if(existQuestionIdSet.add(q.getId())) {
|
|
if(existQuestionIdSet.add(q.getId())) {
|
|
|
LearnPaperQuestion pq = new LearnPaperQuestion();
|
|
LearnPaperQuestion pq = new LearnPaperQuestion();
|
|
|
- pq.setSeq(pqList.size() + 1);
|
|
|
|
|
|
|
+ pq.setSeq(baseSeq + pqList.size());
|
|
|
pq.setKnowledgeId(knowId);
|
|
pq.setKnowledgeId(knowId);
|
|
|
pq.setScore(score);
|
|
pq.setScore(score);
|
|
|
pq.setQuestionId(q.getId());
|
|
pq.setQuestionId(q.getId());
|