Преглед изворни кода

文化组卷及做题优先查院校卷再查全量卷

mingfu пре 1 месец
родитељ
комит
44100972df

+ 11 - 2
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -441,7 +441,6 @@ public class ExamService {
             }
             existPaperIdSet.add(e.getPaperId());
         }
-        existPaperIdSet.clear(); // TODO 忽略已做的卷
         LearnPaper paper = getBestPaper(sysUser.getExamType(), plan, subjectId, existPaperIdSet); // getAvailPaper(sysUser.getExamType(), ls, subjectId, existPaperIdSet)
         examinee.setPaperId(paper.getId());
         examinee.setState(ExamineeStatus.Sign.getVal());
@@ -604,8 +603,19 @@ public class ExamService {
         paperCond.setPaperType(PaperType.Simulated.name());
         paperCond.setStatus(1);
         String baseKey = plan.getUniversityId() + "_" + examType.name() + "_";
+        paperCond.setDirectKey(baseKey);
         if(!subjectId.equals(11L)) {
             List<LearnPaper> paperList = learnPaperService.selectLearnPaperList(paperCond);
+            if(paperList.isEmpty()) {
+                paperCond.setDirectKey(null);
+                paperList = learnPaperService.selectLearnPaperList(paperCond);
+            }
+            for(LearnPaper paper : paperList) {
+                if(existPaperIdSet.add(paper.getId())) {
+                    return paper;
+                }
+            }
+            existPaperIdSet.clear(); // TODO 忽略已做的卷
             for(LearnPaper paper : paperList) {
                 if(existPaperIdSet.add(paper.getId())) {
                     return paper;
@@ -613,7 +623,6 @@ public class ExamService {
             }
             throw new ValidationException("未初始化院校模拟题库: " + subjectId + ":" + plan.getId());
         }
-        paperCond.setDirectKey(baseKey);
         List<LearnPaper> paperList = learnPaperService.selectLearnPaperList(paperCond);
         for(int i = 3; i>0; i--) {
             if(i == 3) {

+ 31 - 12
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -65,7 +65,7 @@ public class PaperService {
         // buildSimulatedPaperForUniversity(20950L, 11L, 78L, 2);
         // buildSimulatedPaperForUniversity(20962L, 11L, 156L, 2);
         // test2();
-        // testCulture();
+        // testCulture(900);
         // corrQuestions();
     }
 
@@ -192,15 +192,21 @@ public class PaperService {
         }
     }
 
-    public void testCulture() {
+    public void testCulture(Integer seq) {
         LearnCultureKnowledge ckCond = new LearnCultureKnowledge();
+        ckCond.setUniversityId(20154L);
         List<LearnCultureKnowledge> cultureKnowledgeList = learnCultureKnowledgeMapper.selectLearnCultureKnowledgeList(ckCond);
 
+        List<Long> errorIdList = Lists.newArrayList();
         Map uCond = new HashMap();
+        Set<Long> validIdSet = Sets.newHashSet();
         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) {
+            if(!validIdSet.isEmpty() && !validIdSet.contains(ck.getId())) {
+                continue;
+            }
             TestPaperVO.PaperDef2 paperDef = new TestPaperVO.PaperDef2(ck.getConditions());
             if(ck.getScore() != (int) Math.round(paperDef.getScore())) {
                 throw new RuntimeException("分值不对称");
@@ -213,12 +219,15 @@ public class PaperService {
             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.setPaperSource(seq);
+            paper.setDirectKey(universities.getId() + "_" + ck.getExamineeTypes() + "_");
             paper.setStatus(PaperStatus.Valid.getVal());
+            if(CollectionUtils.isNotEmpty(paperMapper.selectLearnPaperList(paper))) {
+                log.warn("已经生成: {}:{}", ck.getId(), seq);
+                continue;
+            }
             paper.setNumber(paperDef.getTotal());
             paper.setFenshu(paperDef.getScore().intValue());
             AnswerSheet.PaperCond info = new AnswerSheet.PaperCond();
@@ -228,12 +237,16 @@ public class PaperService {
             paper.setPaperInfo(JSONObject.toJSONString(info));
             try {
                 Pair<LearnPaper, List<LearnPaperQuestion>> paperResult = buildPaper2(null, paper, paperDef);
-                // savePaper(paperResult.getKey(), paperResult.getValue());
-                return;
+                savePaper(paperResult.getKey(), paperResult.getValue());
+                continue;
             } catch(Exception e) {
-                log.error(e.getMessage());
+                errorIdList.add(ck.getId());
+                log.error(ck.getId() + ":" + e.getMessage());
             }
         }
+        if(!errorIdList.isEmpty()) {
+            System.out.println(StringUtils.join(errorIdList, ","));
+        }
     }
     public void testCultureOld() {
         LearnPaper paper = new LearnPaper();
@@ -527,7 +540,7 @@ public class PaperService {
             }
             newKnownList.addAll(tailKnownList);
             ktd.setKnowledges(newKnownList);
-            Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, ktd.getSubType().toString(), 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().get(0).getCount(), 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.getSubType().toString(), ktd.getTypes(), knowTypeAssignMap, existQuestionSet));
         }
@@ -536,7 +549,7 @@ public class PaperService {
     }
 
     public List<LearnPaperQuestion> getQuestionsByRandom(Long studentId, Integer total, Collection<Long> knowledgeIds, List<String> types) {
-        Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "1", types, knowledgeIds, false);
+        Map<String, KnowTypeAssign> knowTypeAssignMap = buildKnowTypeAssignMap(studentId, "2", null, types, knowledgeIds, false);
         List<KnowTypeAssign> knowTypeAssignList = Lists.newArrayList(knowTypeAssignMap.values());
         List<LearnPaperQuestion> pqList = Lists.newArrayList();
         Set<String> existQuestionSet = Sets.newHashSet();
@@ -950,6 +963,9 @@ public class PaperService {
                 qCond.setKnowledgeId(ktc.getKnowId());
                 qCond.setQtpye(typeTitle);
                 qCond.setIsSubType(isSubType);
+                if ("1".equals(isSubType)) {
+                    qCond.setSubCnt(typeDef.getCount());
+                }
                 if(ktc.exclAssign > 0){
                     qCond.setId(studentId);
                     qCond.setNumber(ktc.exclAssign > 500 ? (long) random.nextInt(ktc.exclAssign.intValue() - 500) :  0L);
@@ -987,7 +1003,7 @@ public class PaperService {
      * @return
      */
     private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, TestPaperVO.PaperDef paperDef) {
-        return buildKnowTypeAssignMap(studentId, "0", paperDef.getTypes().stream().map(TestPaperVO.TypeDef::getType).collect(Collectors.toList()), paperDef.getKnowIds(), paperDef.getFillExclude());
+        return buildKnowTypeAssignMap(studentId, "0", null, paperDef.getTypes().stream().map(TestPaperVO.TypeDef::getType).collect(Collectors.toList()), paperDef.getKnowIds(), paperDef.getFillExclude());
     }
 
     /**
@@ -998,13 +1014,16 @@ public class PaperService {
      * @param fillExclude
      * @return
      */
-    private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, String isSubType, List<String> types, Collection<Long> knownIds, Boolean fillExclude) {
+    private Map<String, KnowTypeAssign> buildKnowTypeAssignMap(Long studentId, String isSubType, Integer subCnt, List<String> types, Collection<Long> knownIds, Boolean fillExclude) {
         Map<String, KnowTypeAssign> knowTypeAssignMap = Maps.newHashMap();
         Map cond = Maps.newHashMap();
         cond.put("studentId", studentId);
         cond.put("knowIds", knownIds);
         cond.put("types", types);
         cond.put("isSubType", isSubType);
+        if("1".equals(isSubType)) {
+            cond.put("subCnt", subCnt);
+        }
         setValue(knowTypeAssignMap, cond, 1); // 填充排除后总量
         if (null != studentId && fillExclude) {
             cond.remove("studentId");

+ 10 - 0
ie-system/src/main/java/com/ruoyi/learn/domain/LearnQuestions.java

@@ -196,6 +196,16 @@ public class LearnQuestions extends BaseEntity
     private Long userId;
     boolean collect;
 
+    private Integer subCnt;
+
+
+    public Integer getSubCnt() {
+        return subCnt;
+    }
+
+    public void setSubCnt(Integer subCnt) {
+        this.subCnt = subCnt;
+    }
 
     public Integer getTypeId() {
         return typeId;

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

@@ -308,7 +308,8 @@ 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 (q.knowId = q.id)</if>
+            <if test="isSubType != null  and isSubType == 1"> and (q.knowId = q.id <if test="subCnt != null"> and kq.sub = #{subCnt}</if>)</if>
+            <if test="isSubType != null  and isSubType == 2"> and (kq.sub = 0 or q.knowId = q.id <if test="subCnt != null"> and kq.sub = #{subCnt}</if>)</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>
@@ -318,14 +319,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="selectQuestionsForPaper" parameterType="LearnQuestions" resultMap="LearnQuestionsResult">
-        SELECT q.`id`, kq.knowledge_id `knowledgeId`, q.isSubType
+        SELECT q.`id`, kq.knowledge_id `knowledgeId`, q.title, q.isSubType
         FROM `learn_knowledge_question` kq
         <if test="id != null">
             LEFT JOIN `learn_answer` a ON kq.`question_id` = a.`question_id` AND a.`student_id` = #{id}
         </if>
         JOIN `learn_questions` q ON q.`id` = kq.`question_id`
         <where>
-            <if test="isSubType != null  and isSubType == 1"> and (q.knowId = q.id)</if>
+            <if test="isSubType != null  and isSubType == 1"> and (q.knowId = q.id <if test="subCnt != null"> and kq.sub = #{subCnt}</if>)</if>
+            <if test="isSubType != null  and isSubType == 2"> and (kq.sub = 0 or q.knowId = q.id <if test="subCnt != null"> and kq.sub = #{subCnt}</if>)</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>