Pārlūkot izejas kodu

题库取题修改

小么熊🐻 1 gadu atpakaļ
vecāks
revīzija
906afa7616

+ 1 - 0
jpcj-service/src/main/java/com/miaxis/question/service/IQuestionInfoKtNewService.java

@@ -30,6 +30,7 @@ public interface IQuestionInfoKtNewService extends IService<QuestionInfoKtNew>{
 
 
     List<QuestionInfoKtNew> selectTestK14QuestionInfoList(QuestionInfoNewTestDTO questionInfoNewTestDTO);
+    List<QuestionInfoKtNew> selectTestK14QuestionInfoList2(QuestionInfoNewTestDTO questionInfoNewTestDTO);
 
     List<QuestionInfoKtNew> selectFreeQuestionInfo(QuestionInfoFreeDTO freeDTO);
 

+ 98 - 19
jpcj-service/src/main/java/com/miaxis/question/service/impl/QuestionInfoKtNewServiceImpl.java

@@ -38,7 +38,7 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
      * @return 获取快通题库
      */
     @Override
-    public List<QuestionInfoKtNew> selectQuestionInfoKtNewList(QuestionInfoKtNew questionInfoKtNew){
+    public List<QuestionInfoKtNew> selectQuestionInfoKtNewList(QuestionInfoKtNew questionInfoKtNew) {
         return questionInfoKtNewMapper.selectQuestionInfoKtNewList(questionInfoKtNew);
     }
 
@@ -57,12 +57,11 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
             cx = "xc";
         } else if ("truck".equals(qt.getModel())) {
             cx = "hc";
-        } else if ("kc".equals(qt.getModel())) {
-            cx = "bus";
+        } else if ("bus".equals(qt.getModel())) {
+            cx = "kc";
         }
 
 
-
         //全题库
         List<QuestionInfoKtNew> allList = new ArrayList<QuestionInfoKtNew>();
         TAppExamRule tAppExamRule = new TAppExamRule();
@@ -87,11 +86,11 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
                 int easyChoice = er.getChoiceCount(); //选择
                 int easyMultiple = er.getMultipleChoiceCount(); //多选
 
-                System.out.println("i="+i);
-                System.out.println(qt.getModel()+"+"+qt.getSubject());
-                System.out.println("判断题:"+easyJudge);
-                System.out.println("选择题:"+easyChoice);
-                System.out.println("多选题:"+easyMultiple);
+                System.out.println("i=" + i);
+                System.out.println(qt.getModel() + "+" + qt.getSubject());
+                System.out.println("判断题:" + easyJudge);
+                System.out.println("选择题:" + easyChoice);
+                System.out.println("多选题:" + easyMultiple);
 
                 total = total + easyJudge + easyChoice + easyMultiple;
 
@@ -107,7 +106,7 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
                 for (int j = 0; j < difficult; j++) {
 
 
-                    if(qt.getSubject()==1 || (qt.getSubject()==4 && easyMultiple==0)) {
+                    if (qt.getSubject() == 1 || (qt.getSubject() == 4 && easyMultiple == 0)) {
                         randomNum = random.nextInt(2); //随机出现 0和1  0表示判断 1表示单选
                         if (randomNum == 0) {   //判断题
                             diffJudeg++;
@@ -116,7 +115,7 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
                             diffChoice++;
                             easyChoice--;
                         }
-                    } else if(qt.getSubject()==4){
+                    } else if (qt.getSubject() == 4) {
                         randomNum = random.nextInt(3); //随机出现 0、1、2  0表示判断 1表示单选 2多选
                         if (randomNum == 0) {   //判断题
                             diffJudeg++;
@@ -134,7 +133,7 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
 
                 }
 
-                if(qt.getSubject()==1) {
+                if (qt.getSubject() == 1) {
                     if (diffJudeg < 0 || easyJudge < 0 || diffChoice < 0 || easyChoice < 0) {
                         shouldRetry = true;
                         sql.setLength(0);  //清空还原
@@ -143,7 +142,7 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
                     }
                 }
                 // 检查变量值是否小于0
-                if(qt.getSubject()==4) {
+                if (qt.getSubject() == 4) {
                     if (diffJudeg < 0 || easyJudge < 0 || diffChoice < 0 || easyChoice < 0 || diffMultiple < 0 || easyMultiple < 0) {
                         shouldRetry = true;
                         sql.setLength(0);  //清空还原
@@ -157,20 +156,96 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
                     sql.append(" union ");
                 }
                 //判断题
-                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND question_type = '1' AND diff_degree in (1,2,3) ORDER BY RAND() LIMIT " + easyJudge + ") ");
+                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('" + qt.getModel() + "', model)  AND question_type = '1' AND diff_degree in (1,2,3) ORDER BY RAND() LIMIT " + easyJudge + ") ");
                 sql.append(" union ");
-                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND question_type = '1' AND diff_degree in (4,5) ORDER BY RAND() LIMIT " + diffJudeg + ") ");
+                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('" + qt.getModel() + "', model)  AND question_type = '1' AND diff_degree in (4,5) ORDER BY RAND() LIMIT " + diffJudeg + ") ");
                 sql.append(" union ");
                 //选择题
-                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND question_type = '2' AND diff_degree in (1,2,3) ORDER BY RAND() LIMIT " + easyChoice + ") ");
+                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('" + qt.getModel() + "', model)  AND question_type = '2' AND diff_degree in (1,2,3) ORDER BY RAND() LIMIT " + easyChoice + ") ");
                 sql.append(" union ");
-                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND question_type = '2' AND diff_degree in (4,5) ORDER BY RAND() LIMIT " + diffChoice + ") ");
+                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('" + qt.getModel() + "', model)  AND question_type = '2' AND diff_degree in (4,5) ORDER BY RAND() LIMIT " + diffChoice + ") ");
                 //多选题
                 if (qt.getSubject() == 4) {
                     sql.append(" union ");
-                    sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND question_type = '3' AND diff_degree in (1,2,3) ORDER BY RAND() LIMIT " + easyMultiple + ") ");
+                    sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('" + qt.getModel() + "', model) AND question_type = '3' AND diff_degree in (1,2,3) ORDER BY RAND() LIMIT " + easyMultiple + ") ");
+                    sql.append(" union ");
+                    sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('" + qt.getModel() + "', model) AND question_type = '3' AND diff_degree in (4,5) ORDER BY RAND() LIMIT " + diffMultiple + ") ");
+                }
+            }
+
+        } while (shouldRetry);
+
+        sql.append(" ) as db");
+        System.out.println(sql.toString());
+        allList = questionInfoKtNewMapper.selectTestK14QuestionInfoList(sql.toString());
+
+        if (allList.size() == total) {
+            return allList;
+        } else {
+            return this.selectTestK14QuestionInfoList2(qt);
+        }
+    }
+
+
+    /**
+     * 不考虑题库难度,直接出题
+     * @param qt
+     * @return
+     */
+    @Override
+    public List<QuestionInfoKtNew> selectTestK14QuestionInfoList2(QuestionInfoNewTestDTO qt) {
+        String cx = null;
+
+        if ("mtc".equals(qt.getModel())) {
+            cx = "mtc";
+        } else if ("cart".equals(qt.getModel())) {
+            cx = "xc";
+        } else if ("truck".equals(qt.getModel())) {
+            cx = "hc";
+        } else if ("bus".equals(qt.getModel())) {
+            cx = "kc";
+        }
+
+
+        //全题库
+        List<QuestionInfoKtNew> allList = new ArrayList<QuestionInfoKtNew>();
+        TAppExamRule tAppExamRule = new TAppExamRule();
+        tAppExamRule.setKemu(qt.getSubject());
+        tAppExamRule.setGs(cx);
+        tAppExamRule.setAreacode(0);
+
+        List<TAppExamRule> list = appExamRuleService.selectTAppExamRuleList(tAppExamRule);
+        if (list.size() == 0) {
+            return allList;
+        }
+        int total = 0;
+        StringBuffer sql = new StringBuffer();
+        sql.append("SELECT * FROM (");
+
+        boolean shouldRetry = false;
+        do {
+            shouldRetry = false;
+            for (int i = 0; i < list.size(); i++) {
+                TAppExamRule er = list.get(i);
+                int judge = er.getJudgeCount(); //判断
+                int choice = er.getChoiceCount(); //选择
+                int multiple = er.getMultipleChoiceCount(); //多选
+                int chapterId = er.getChapterId();
+
+                total = total + judge + choice + multiple;
+
+                if (i != 0) {
+                    sql.append(" union ");
+                }
+                //判断题
+                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('"+ qt.getModel() +"', model)  AND question_type = '1'  ORDER BY RAND() LIMIT " + judge + ") ");
+                sql.append(" union ");
+                //选择题
+                sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('"+ qt.getModel() +"', model) AND question_type = '2'  ORDER BY RAND() LIMIT " + choice + ") ");
+                //多选题
+                if (qt.getSubject() == 4) {
                     sql.append(" union ");
-                    sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND question_type = '3' AND diff_degree in (4,5) ORDER BY RAND() LIMIT " + diffMultiple + ") ");
+                    sql.append(" (SELECT * FROM question_info_kt_new WHERE chapter_id = " + chapterId + " AND subject = " + qt.getSubject() + " AND FIND_IN_SET('"+ qt.getModel() +"', model) AND question_type = '3'  ORDER BY RAND() LIMIT " + multiple + ") ");
                 }
             }
 
@@ -179,6 +254,7 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
         sql.append(" ) as db");
         System.out.println(sql.toString());
         allList = questionInfoKtNewMapper.selectTestK14QuestionInfoList(sql.toString());
+
         if (allList.size() == total) {
             return allList;
         } else {
@@ -187,6 +263,9 @@ public class QuestionInfoKtNewServiceImpl extends ServiceImpl<QuestionInfoKtNewM
         }
     }
 
+
+
+
     @Override
     public List<QuestionInfoKtNew> selectFreeQuestionInfo(QuestionInfoFreeDTO freeDTO) {
         List<QuestionInfoKtNew> list = questionInfoKtNewMapper.selectFreeQuestionInfoList(freeDTO);