Просмотр исходного кода

组卷时,标题也不能重复

mingfu 1 месяц назад
Родитель
Сommit
d1b211e79c

+ 66 - 20
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -1,6 +1,6 @@
 package com.ruoyi.web.service;
 
-import com.alibaba.fastjson.JSONArray;
+import cn.hutool.core.lang.Dict;
 import com.alibaba.fastjson2.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.google.common.collect.Lists;
@@ -8,6 +8,8 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.dz.domain.DzSubject;
+import com.ruoyi.dz.mapper.DzSubjectMapper;
 import com.ruoyi.enums.PaperStatus;
 import com.ruoyi.enums.PaperType;
 import com.ruoyi.enums.QuestionType;
@@ -29,7 +31,6 @@ import java.util.function.Function;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  * 考卷服务
@@ -46,9 +47,10 @@ public class PaperService {
     private final IBBusiWishUniversitiesService wishUniversitiesService;
     private final BBusiWishUniversitiesMapper bBusiWishUniversitiesMapper;
     private final LearnKnowledgeTreeMapper learnKnowledgeTreeMapper;
-    private final LearnKnowledgeCourseMapper learnKnowledgeCourseMapper;
+    private final LearnCultureKnowledgeMapper learnCultureKnowledgeMapper;
+    private final DzSubjectMapper dzSubjectMapper;
 
-    PaperService(LearnPaperMapper paperMapper, LearnPaperQuestionMapper paperQuestionMapper, LearnQuestionsMapper questionsMapper, ILearnQuestionsService learnQuestionsService, LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper, IBBusiWishUniversitiesService wishUniversitiesService, BBusiWishUniversitiesMapper bBusiWishUniversitiesMapper, LearnKnowledgeTreeMapper learnKnowledgeTreeMapper, LearnKnowledgeCourseMapper learnKnowledgeCourseMapper) {
+    PaperService(LearnPaperMapper paperMapper, LearnPaperQuestionMapper paperQuestionMapper, LearnQuestionsMapper questionsMapper, ILearnQuestionsService learnQuestionsService, LearnDirectedKnowledgeMapper learnDirectedKnowledgeMapper, IBBusiWishUniversitiesService wishUniversitiesService, BBusiWishUniversitiesMapper bBusiWishUniversitiesMapper, LearnKnowledgeTreeMapper learnKnowledgeTreeMapper, LearnCultureKnowledgeMapper learnCultureKnowledgeMapper, DzSubjectMapper dzSubjectMapper) {
         this.paperMapper = paperMapper;
         this.paperQuestionMapper = paperQuestionMapper;
         this.questionsMapper = questionsMapper;
@@ -57,7 +59,8 @@ public class PaperService {
         this.wishUniversitiesService = wishUniversitiesService;
         this.bBusiWishUniversitiesMapper = bBusiWishUniversitiesMapper;
         this.learnKnowledgeTreeMapper = learnKnowledgeTreeMapper;
-        this.learnKnowledgeCourseMapper = learnKnowledgeCourseMapper;
+        this.learnCultureKnowledgeMapper = learnCultureKnowledgeMapper;
+        this.dzSubjectMapper = dzSubjectMapper;
         // buildAllPapers(2);
         // buildSimulatedPaperForUniversity(20950L, 11L, 78L, 2);
         // buildSimulatedPaperForUniversity(20962L, 11L, 156L, 2);
@@ -190,6 +193,49 @@ public class PaperService {
     }
 
     public void testCulture() {
+        LearnCultureKnowledge ckCond = new LearnCultureKnowledge();
+        List<LearnCultureKnowledge> cultureKnowledgeList = learnCultureKnowledgeMapper.selectLearnCultureKnowledgeList(ckCond);
+
+        Map uCond = new HashMap();
+        uCond.put("ids", cultureKnowledgeList.stream().map(LearnCultureKnowledge::getUniversityId).collect(Collectors.toSet()));
+        Map<Long, BBusiWishUniversities> universityMap = bBusiWishUniversitiesMapper.selectBBusiWishUniversitiesListSimpleByIds(uCond).stream().collect(Collectors.toMap(BBusiWishUniversities::getId, Function.identity()));
+        Map<Long, String> subjectMap = dzSubjectMapper.selectDzSubjectList(new DzSubject()).stream().collect(Collectors.toMap(DzSubject::getSubjectId, DzSubject::getSubjectName));
+        for(LearnCultureKnowledge ck : cultureKnowledgeList) {
+            TestPaperVO.PaperDef2 paperDef = new TestPaperVO.PaperDef2(ck.getConditions());
+            if(ck.getScore() != (int) Math.round(paperDef.getScore())) {
+                throw new RuntimeException("分值不对称");
+            }
+            paperDef.setFillExclude(false);
+
+            BBusiWishUniversities universities = universityMap.get(ck.getUniversityId());
+            LearnPaper paper = new LearnPaper();
+            paper.setSubjectId(Long.parseLong(ck.getSubjects()));
+            paper.setRelateId(ck.getId());
+            paper.setPaperName(universities.getName() + "(" + subjectMap.get(paper.getSubjectId()) + ")");
+            paper.setExamineeTypes(ck.getExamineeTypes());
+
+            paper.setPaperType(PaperType.Simulated.name());
+            paper.setYear(ck.getYear());
+            paper.setPaperSource(1);
+            paper.setDirectKey("");
+            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(ck.getTime().intValue() * 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;
+            } catch(Exception e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+    public void testCultureOld() {
         LearnPaper paper = new LearnPaper();
 
 //        TestPaperVO.PaperDef2 paperDef = new TestPaperVO.PaperDef2("", "[{\"score\":40,\"knowledges\":[2001,2002,2003,2004,2005,2006,2007,2010,2013],\"types\":{\"judgment\":\"0\",\"single\":\"10/4\",\"multiple\":\"0\",\"subjective\":\"0\",\"fill\":\"0\",\"essay\":\"0\",\"short\":\"0\"}},{\"score\":20,\"knowledges\":[2012],\"types\":{\"judgment\":\"0\",\"single\":\"5/4\",\"multiple\":\"0\",\"subjective\":\"0\",\"fill\":\"0\",\"essay\":\"0\",\"short\":\"0\"}},{\"score\":40,\"knowledges\":[2011],\"types\":{\"judgment\":\"0\",\"single\":\"8/5\",\"multiple\":\"0\",\"subjective\":\"0\",\"fill\":\"0\",\"essay\":\"0\",\"short\":\"0\"}}]");
@@ -456,7 +502,7 @@ public class PaperService {
 
     public List<LearnPaperQuestion> getQuestions2(Long studentId, TestPaperVO.PaperDef2 paperDef) {
         List<LearnPaperQuestion> pqList = Lists.newArrayList();
-        Set<Long> existQuestionIdSet = Sets.newHashSet();
+        Set<String> existQuestionSet = Sets.newHashSet();
         for(TestPaperVO.KnowledgeTypeDef2 ktd : paperDef.getKnowTypes()) {
             Map<Long, List<Long>> ktSubMap = Maps.newHashMap();
             Integer maxSubCount = 6;
@@ -481,9 +527,9 @@ public class PaperService {
             }
             newKnownList.addAll(tailKnownList);
             ktd.setKnowledges(newKnownList);
-            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "0", ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude());
+            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, ktd.getSubType().toString(), ktd.getTypes().stream().map(t -> t.getType().getTitle()).collect(Collectors.toList()), newKnownList, paperDef.getFillExclude());
             assignTypeFirst(paperDef.getFillExclude(), ktd, knowTypeAssignMap);
-            pqList.addAll(getQuestions2(studentId, ktd.getCount(), pqList.size(), newKnownList, ktd.getTypes(), knowTypeAssignMap, existQuestionIdSet));
+            pqList.addAll(getQuestions2(studentId, ktd.getCount(), pqList.size(), newKnownList, ktd.getSubType().toString(), ktd.getTypes(), knowTypeAssignMap, existQuestionSet));
         }
         reSort(pqList);
         return pqList;
@@ -493,7 +539,7 @@ public class PaperService {
         Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "1", types, knowledgeIds, false);
         List<KnowTypeAssign> knowTypeAssignList = Lists.newArrayList(knowTypeAssignMap.values());
         List<LearnPaperQuestion> pqList = Lists.newArrayList();
-        Set<Long> existQuestionIdSet = Sets.newHashSet();
+        Set<String> existQuestionSet = Sets.newHashSet();
         Random random = new Random();
         Map<String, List<LearnQuestions>> typeQuestionMap = Maps.newHashMap();
         LearnQuestions qCond = new LearnQuestions();
@@ -516,7 +562,7 @@ public class PaperService {
                 }
                 if(!questions.isEmpty()) {
                     int oldSize = pqList.size();
-                    addRandomList(knowTypeAssign.getKnowId(), QuestionType.of(knowTypeAssign.getType()), questions, random, total.longValue(), 1L, 1.0, existQuestionIdSet, 1, pqList);
+                    addRandomList(knowTypeAssign.getKnowId(), QuestionType.of(knowTypeAssign.getType()), questions, random, total.longValue(), 1L, 1.0, existQuestionSet, 1, pqList);
                     if(oldSize != pqList.size()) {
                         knowTypeAssign.exclAssign++;
                     }
@@ -845,7 +891,7 @@ public class PaperService {
         LearnQuestions qCond = new LearnQuestions();
         Random random = new Random();
         List<LearnPaperQuestion> pqList = Lists.newArrayList();
-        Set<Long> existQuestionIdSet = Sets.newHashSet();
+        Set<String> existQuestionSet = Sets.newHashSet();
         int total = paperDef.getTotal().intValue();
         for (TestPaperVO.TypeDef typeDef : paperDef.getTypes()) {
             for (Long knowId : paperDef.getKnowIds()) {
@@ -862,7 +908,7 @@ public class PaperService {
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.exclAssign = addRandomList(knowId, qt, questions, random, paperDef.getTotal(), ktc.exclAssign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
+                    ktc.exclAssign = addRandomList(knowId, qt, questions, random, paperDef.getTotal(), ktc.exclAssign, typeDef.getScore().doubleValue(), existQuestionSet, 1, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -871,7 +917,7 @@ public class PaperService {
                     qCond.setId(null);
                     qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.assign = addRandomList(knowId, qt, questions, random, paperDef.getTotal(), ktc.assign, typeDef.getScore().doubleValue(), existQuestionIdSet, 1, pqList);
+                    ktc.assign = addRandomList(knowId, qt, questions, random, paperDef.getTotal(), ktc.assign, typeDef.getScore().doubleValue(), existQuestionSet, 1, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -888,7 +934,7 @@ public class PaperService {
         return pqList;
     }
 
-    public List<LearnPaperQuestion> getQuestions2(Long studentId, Integer total, Integer seqId, 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, String isSubType, List<TestPaperVO.TypeDef2> types, Map<String, KnowTypeAssign> knowTypeAssignMap, Set<String> existQuestionSet) {
         // 知识点已经分配,准备题型分配
         LearnQuestions qCond = new LearnQuestions();
         Random random = new Random();
@@ -903,12 +949,12 @@ public class PaperService {
                 }
                 qCond.setKnowledgeId(ktc.getKnowId());
                 qCond.setQtpye(typeTitle);
-                qCond.setIsSubType("0");
+                qCond.setIsSubType(isSubType);
                 if(ktc.exclAssign > 0){
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.exclAssign = addRandomList(knowId, typeDef.getType(), questions, random, total.longValue(), ktc.exclAssign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
+                    ktc.exclAssign = addRandomList(knowId, typeDef.getType(), questions, random, total.longValue(), ktc.exclAssign, typeDef.getScore(), existQuestionSet, seqId, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -917,7 +963,7 @@ public class PaperService {
                     qCond.setId(null);
                     qCond.setNumber(ktc.assign > 500 ? (long) random.nextInt(ktc.assign.intValue() - 500) :  0L);
                     List<LearnQuestions> questions = questionsMapper.selectQuestionsForPaper(qCond);
-                    ktc.assign = addRandomList(knowId, typeDef.getType(), questions, random, total.longValue(), ktc.assign, typeDef.getScore(), existQuestionIdSet, seqId, pqList);
+                    ktc.assign = addRandomList(knowId, typeDef.getType(), questions, random, total.longValue(), ktc.assign, typeDef.getScore(), existQuestionSet, seqId, pqList);
                     if(pqList.size() == total) {
                         break;
                     }
@@ -976,13 +1022,13 @@ public class PaperService {
      * @param totalCount 总题数
      * @param count  本池分配数
      * @param score 题分
-     * @param existQuestionIdSet 不能使用的题
+     * @param existQuestionSet 不能使用的题
      * @param pqList 卷题关系  diff(type),paperId(parentId),seq,questionId(id)
      */
-    private Long addRandomList(Long knowId, QuestionType type, List<LearnQuestions> questions, Random random, Long totalCount, Long count, Double score, Set<Long> existQuestionIdSet, Integer baseSeq, List<LearnPaperQuestion> pqList) {
+    private Long addRandomList(Long knowId, QuestionType type, List<LearnQuestions> questions, Random random, Long totalCount, Long count, Double score, Set<String> existQuestionSet, Integer baseSeq, List<LearnPaperQuestion> pqList) {
         while(count > 0L && !questions.isEmpty()) {
             LearnQuestions q = questions.size() > 1 ? questions.remove(random.nextInt(questions.size() - 1)) : questions.remove(0);
-            if(existQuestionIdSet.add(q.getId())) {
+            if(existQuestionSet.add(q.getId().toString()) && existQuestionSet.add(q.getTitle())) {
                 if("1".equals(q.getIsSubType())) {
                     LearnQuestions subCond = new LearnQuestions();
                     subCond.setKnowId(q.getId());

+ 32 - 1
ie-system/src/main/java/com/ruoyi/learn/domain/TestPaperVO.java

@@ -135,6 +135,37 @@ public class TestPaperVO {
         List<TypeDef2> types;
         List<KnowledgeTypeDef2> knowTypes;
 
+        public PaperDef2(String conditions) {
+            types = Lists.newArrayList();
+            knowTypes = JSONArray.parseArray(conditions, KnowledgeTypeDef2.class);
+            this.total = 0;
+            this.score = 0.0;
+
+            Map<String, TypeDef2> typeMap = Maps.newHashMap();
+            for(KnowledgeTypeDef2 kt : knowTypes) {
+                kt.setCount(0);
+                kt.setScore(0.0);
+                for(TypeDef2 kd : kt.getTypes()) {
+                    TypeDef2 cType = typeMap.get(kd.getType().name());
+
+                    Double kdScore = kd.getScore() * kd.getCount();
+                    this.total += kd.getCount();
+                    this.score += kdScore;
+                    if(null == cType) {
+                        cType = new TypeDef2();
+                        BeanUtils.copyProperties(kd, cType);
+                        cType.setScore(kdScore);
+                        types.add(cType);
+                        typeMap.put(kd.getType().name(), cType);
+                    } else {
+                        cType.setScore(cType.getScore() + kdScore);
+                        cType.setCount(cType.getCount() + kd.getCount());
+                    }
+                    kt.setScore(kt.getScore() + kdScore);
+                    kt.setCount(kt.getCount() + kd.getCount());
+                }
+            }
+        }
         public PaperDef2(String knowledges, String json) {
             JSONArray root = JSONArray.parseArray(json);
             this.total = 0;
@@ -201,6 +232,7 @@ public class TestPaperVO {
         Integer count;
         Double score;
         List<Long> knowledges;
+        Integer subType; // 是否子题 1是 0不是
         List<TypeDef2> types = Lists.newArrayList();
     }
 
@@ -208,7 +240,6 @@ public class TestPaperVO {
     public static class TypeDef2 {
         String title;
         QuestionType type;
-        Integer subType; // 是否子题 1是 0不是
         Integer count;
         Double score;
     }

+ 2 - 2
ie-system/src/main/resources/mapper/learn/LearnQuestionsMapper.xml

@@ -308,7 +308,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </if>
          JOIN `learn_questions` q ON q.`id` = kq.`question_id`
         <where>
-            <if test="isSubType != null  and isSubType == 1"> and (kq.sub = 0 or q.knowId = q.id)</if>
+            <if test="isSubType != null  and isSubType == 1"> and (q.knowId = q.id)</if>
             <if test="isSubType != null  and isSubType == 0"> and (kq.sub = 0)</if>
             <if test="knowIds != null"> and kq.`knowledge_id` in <foreach item="id" collection="knowIds" open="(" separator="," close=")">#{id}</foreach></if>
             <if test="types != null"> and q.`qtpye` in <foreach item="id" collection="types" open="(" separator="," close=")">#{id}</foreach></if>
@@ -325,7 +325,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
         JOIN `learn_questions` q ON q.`id` = kq.`question_id`
         <where>
-            <if test="isSubType != null  and isSubType == 1"> and (kq.sub = 0 or q.knowId = q.id)</if>
+            <if test="isSubType != null  and isSubType == 1"> and (q.knowId = q.id)</if>
             <if test="isSubType != null  and isSubType == 0"> and (kq.sub = 0)</if>
             <if test="qtpye != null  and qtpye != ''"> and qtpye = #{qtpye}</if>
             <if test="id != null ">  AND a.`student_id` IS NULL</if>