Jelajahi Sumber

模拟考抽题优化

小么熊🐻 2 tahun lalu
induk
melakukan
c42f37268a

+ 2 - 0
jpcj-service/src/main/java/com/miaxis/question/mapper/QuestionInfoMapper.java

@@ -56,6 +56,8 @@ public interface QuestionInfoMapper extends BaseMapper<QuestionInfo> {
 
     List<QuestionInfo> selectTestQuestionInfoList(QuestionInfoTestDTO questionInfoTestDTO);
 
+    int selectQuestionInfoCount(QuestionInfoTestDTO questionInfoTestDTO);
+
     List<QuestionInfo> selectFreeQuestionInfoList(QuestionInfoFreeDTO freeDTO);
 
     List<QuestionInfo> selectQuestionInfoListByYdtIds(Long[] ids);

+ 148 - 145
jpcj-service/src/main/java/com/miaxis/question/service/impl/QuestionInfoServiceImpl.java

@@ -31,6 +31,7 @@ public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, Que
 
     @Autowired
     private ITAppExamRuleService appExamRuleService;
+
     /**
      * 查询题库列表
      *
@@ -38,12 +39,12 @@ public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, Que
      * @return 题库
      */
     @Override
-    public List<QuestionInfo> selectQuestionInfoList(QuestionInfoDTO questionInfoDTO){
+    public List<QuestionInfo> selectQuestionInfoList(QuestionInfoDTO questionInfoDTO) {
 
         //1:分类练习:class_sort;2:精选考题:excell_sort;3:地方专题:place_sort;4:顺序练习:seque_sort;
         Integer sort = questionInfoDTO.getSort();
-        if(sort!=null) {
-            switch (sort){
+        if (sort != null) {
+            switch (sort) {
                 case 1:
                     questionInfoDTO.setSortName("class_sort");
                     break;
@@ -110,29 +111,27 @@ public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, Que
 
     @Override
     public List<QuestionInfoExcelTypeVo> getIssueTypes(int issueTypeValue, Integer subject) {
-        if (issueTypeValue == 1){
+        if (issueTypeValue == 1) {
             return questionInfoMapper.selectIssueType1(subject);
         }
-        if (issueTypeValue == 2){
+        if (issueTypeValue == 2) {
             return questionInfoMapper.selectIssueType2(subject);
         }
-        if (issueTypeValue == 3){
+        if (issueTypeValue == 3) {
             return questionInfoMapper.selectIssueType3(subject);
         }
-        if (issueTypeValue == 4){
+        if (issueTypeValue == 4) {
             return questionInfoMapper.selectIssueType4(subject);
         }
         return null;
 
 
-
     }
 
 
-
     @Override
     public List<QuestionInfo> selectFreeQuestionInfo() {
-        QuestionInfoFreeDTO freeDTO =  new QuestionInfoFreeDTO();
+        QuestionInfoFreeDTO freeDTO = new QuestionInfoFreeDTO();
         freeDTO.setNum(10);
         freeDTO.setQuestionType(1);
         freeDTO.setSubject(1);
@@ -158,92 +157,100 @@ public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, Que
         int total = 100;
         if ("mtc".equals(qt.getGs())) { //如果是摩托车取题50
             total = 50;
-        } else if (qt.getSubject()==1) {
+        } else if (qt.getSubject() == 1) {
             total = 100;
-        } else if (qt.getSubject()==4) {
+        } else if (qt.getSubject() == 4) {
             total = 50;
         }
 
-        if("mtc".equals(qt.getGs())) {
+        if ("mtc".equals(qt.getGs())) {
             qt.setLiceMoto("1");
-        } else if("xc".equals(qt.getGs())){
+        } else if ("xc".equals(qt.getGs())) {
             qt.setLiceCar("1");
-        } else if("hc".equals(qt.getGs())){
+        } else if ("hc".equals(qt.getGs())) {
             qt.setLiceTruck("1");
-        } else if("kc".equals(qt.getGs())){
+        } else if ("kc".equals(qt.getGs())) {
             qt.setLiceBus("1");
         }
 
         //全题库
         List<QuestionInfo> allList = new ArrayList<QuestionInfo>();
-        int error = 0;
-        while (allList.size() != total) {
-            allList = new ArrayList<QuestionInfo>();
-            if(error >= 10) {
-                return allList;
-            }
-            //判断题
-            List<QuestionInfo> judgeList = new ArrayList<QuestionInfo>();
-            //选择题
-            List<QuestionInfo> choiceList = new ArrayList<QuestionInfo>();
-            //多选题
-            List<QuestionInfo> multipleList = new ArrayList<QuestionInfo>();
-
-            //简单题
-            List<Integer> easyDegree = new ArrayList<Integer>();
-            easyDegree.add(1);
-            easyDegree.add(2);
-            easyDegree.add(3);
-            //难题
-            List<Integer> diffDegree = new ArrayList<Integer>();
-            diffDegree.add(4);
-            diffDegree.add(5);
-            //科目一通用
-            TAppExamRule tAppExamRule = new TAppExamRule();
-            tAppExamRule.setKemu(qt.getSubject());
-            tAppExamRule.setGs(qt.getGs());
-            tAppExamRule.setAreacode(0);
-
-            List<TAppExamRule> list = appExamRuleService.selectTAppExamRuleList(tAppExamRule);
-            if(list.size()==0){
-                return allList;
-            }
-            for (int i = 0; i < list.size(); i++) {
-                TAppExamRule er = list.get(i);
-                int easyJudge = er.getJudgeCount();
-                int easyChoice = er.getChoiceCount();
-                int easyMultiple = er.getMultipleChoiceCount();
-                int x = i + 1;
-                System.out.println("第" + x + "轮easyJudge:" + easyJudge);
-
-                Random random = new Random();
-                int p = 0; //判断题
-                int d = 0; //单选题
-                int m = 0; //多选题
-                for (int j = 0; j < er.getDifficultCount(); j++) {
-                    if (random.nextInt(9) <= 2) {   //判断题
-                        if (easyJudge - 1 < 0) {
-                            j--;
-                        } else {
-                            p++;
-                            easyJudge--;
-                        }
-                    } else if (random.nextInt(9) <= 5) {  //单选题
-                        if (easyChoice - 1 < 0) {
-                            j--;
-                        } else {
-                            d++;
-                            easyChoice--;
-                        }
-                    } else if (random.nextInt(9) <= 8) {    //多选题
-                        if (easyMultiple - 1 < 0) {
-                            j--;
-                        } else {
-                            m++;
-                            easyMultiple--;
-                        }
+
+        //判断题
+        List<QuestionInfo> judgeList = new ArrayList<QuestionInfo>();
+        //选择题
+        List<QuestionInfo> choiceList = new ArrayList<QuestionInfo>();
+        //多选题
+        List<QuestionInfo> multipleList = new ArrayList<QuestionInfo>();
+
+        //简单题
+        List<Integer> easyDegree = new ArrayList<Integer>();
+        easyDegree.add(1);
+        easyDegree.add(2);
+        easyDegree.add(3);
+        //难题
+        List<Integer> diffDegree = new ArrayList<Integer>();
+        diffDegree.add(4);
+        diffDegree.add(5);
+        //科目一通用
+        TAppExamRule tAppExamRule = new TAppExamRule();
+        tAppExamRule.setKemu(qt.getSubject());
+        tAppExamRule.setGs(qt.getGs());
+        tAppExamRule.setAreacode(0);
+
+        List<TAppExamRule> list = appExamRuleService.selectTAppExamRuleList(tAppExamRule);
+        if (list.size() == 0) {
+            return allList;
+        }
+        for (int i = 0; i < list.size(); i++) {
+            TAppExamRule er = list.get(i);
+            int easyJudge = er.getJudgeCount();
+            int easyChoice = er.getChoiceCount();
+            int easyMultiple = er.getMultipleChoiceCount();
+            int chapterId = er.getChapterId();
+
+            QuestionInfoTestDTO questionInfoTestDTO = new QuestionInfoTestDTO();
+            questionInfoTestDTO.setChapterId(chapterId);
+            questionInfoTestDTO.setDiffDegree(diffDegree);
+            questionInfoTestDTO.setQuestionType(1);
+            int judgeTotal = questionInfoMapper.selectQuestionInfoCount(questionInfoTestDTO); //章节判断难题总数
+            questionInfoTestDTO.setQuestionType(2);
+            int choiceTotal = questionInfoMapper.selectQuestionInfoCount(questionInfoTestDTO); //章节选择难题总数
+            questionInfoTestDTO.setQuestionType(3);
+            int multipleTotal = questionInfoMapper.selectQuestionInfoCount(questionInfoTestDTO); //章节多选难题总数
+
+
+            int x = i + 1;
+            System.out.println("第" + x + "轮easyJudge:" + easyJudge);
+
+            Random random = new Random();
+            int p = 0; //判断题
+            int d = 0; //单选题
+            int m = 0; //多选题
+            for (int j = 0; j < er.getDifficultCount(); j++) {
+                if (random.nextInt(9) <= 2) {   //判断题
+                    if (easyJudge - 1 < 0 || judgeTotal - p <= 0) {
+                        j--;
+                    } else {
+                        p++;
+                        easyJudge--;
+                    }
+                } else if (random.nextInt(9) <= 5) {  //单选题
+                    if (easyChoice - 1 < 0 || choiceTotal - d <= 0) {
+                        j--;
+                    } else {
+                        d++;
+                        easyChoice--;
+                    }
+                } else if (random.nextInt(9) <= 8) {    //多选题
+                    if (easyMultiple - 1 < 0 || multipleTotal - m <= 0) {
+                        j--;
+                    } else {
+                        m++;
+                        easyMultiple--;
                     }
                 }
+            }
 
 //                System.out.println("简单判断:" + easyJudge);
 //                System.out.println("简单选择:" + easyChoice);
@@ -253,73 +260,69 @@ public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, Que
 //                System.out.println("难题多择:" + m);
 //                System.out.println("---------------------------------------------");
 
-                //判断简单
-                qt.setChapterId(er.getChapterId()); //章节ID
-                qt.setDiffDegree(easyDegree);       //简单难度
-                qt.setQuestionType(1);              //判断题
-                qt.setNum(easyJudge);               //题数
-                List<QuestionInfo> easyJudgeList = this.selectTestQuestionInfoList(qt);
-                //单选简单
-                qt.setChapterId(er.getChapterId()); //章节ID
-                qt.setDiffDegree(easyDegree);       //简单难度
-                qt.setQuestionType(2);              //判断题
-                qt.setNum(easyChoice);              //题数
-                List<QuestionInfo> easyChoiceList = this.selectTestQuestionInfoList(qt);
-                //多选简单
-                qt.setChapterId(er.getChapterId()); //章节ID
-                qt.setDiffDegree(easyDegree);       //简单难度
-                qt.setQuestionType(3);              //判断题
-                qt.setNum(easyMultiple);              //题数
-                List<QuestionInfo> easyMultipleList = this.selectTestQuestionInfoList(qt);
-
-                //判断难题
-                qt.setChapterId(er.getChapterId()); //章节ID
-                qt.setDiffDegree(diffDegree);       //高难度
-                qt.setQuestionType(1);              //判断题
-                qt.setNum(p);                       //题数
-                List<QuestionInfo> diffJudgeList = this.selectTestQuestionInfoList(qt);
-                if (p != diffJudgeList.size()) {
-                    System.out.println("p!=diffJudgeList.size()");
-                    error++;
-                    break;
-                }
-
-                //单选难题
-                qt.setChapterId(er.getChapterId()); //章节ID
-                qt.setDiffDegree(diffDegree);       //高难度
-                qt.setQuestionType(2);              //判断题
-                qt.setNum(d);                       //题数
-                List<QuestionInfo> diffChoiceList = this.selectTestQuestionInfoList(qt);
-                if (d != diffChoiceList.size()) {
-                    System.out.println("d!=diffChoiceList.size()");
-                    error++;
-                    break;
-                }
-                //多选简单
-                qt.setChapterId(er.getChapterId()); //章节ID
-                qt.setDiffDegree(diffDegree);       //高难度
-                qt.setQuestionType(3);              //判断题
-                qt.setNum(m);                       //题数
-                List<QuestionInfo> diffMultipleList = this.selectTestQuestionInfoList(qt);
-                if (m != diffMultipleList.size()) {
-                    System.out.println("m!=diffMultipleList.size()");
-                    error++;
-                    break;
-                }
+            //判断简单
+            qt.setChapterId(er.getChapterId()); //章节ID
+            qt.setDiffDegree(easyDegree);       //简单难度
+            qt.setQuestionType(1);              //判断题
+            qt.setNum(easyJudge);               //题数
+            List<QuestionInfo> easyJudgeList = this.selectTestQuestionInfoList(qt);
+            //单选简单
+            qt.setChapterId(er.getChapterId()); //章节ID
+            qt.setDiffDegree(easyDegree);       //简单难度
+            qt.setQuestionType(2);              //判断题
+            qt.setNum(easyChoice);              //题数
+            List<QuestionInfo> easyChoiceList = this.selectTestQuestionInfoList(qt);
+            //多选简单
+            qt.setChapterId(er.getChapterId()); //章节ID
+            qt.setDiffDegree(easyDegree);       //简单难度
+            qt.setQuestionType(3);              //判断题
+            qt.setNum(easyMultiple);              //题数
+            List<QuestionInfo> easyMultipleList = this.selectTestQuestionInfoList(qt);
+
+            //判断难题
+            qt.setChapterId(er.getChapterId()); //章节ID
+            qt.setDiffDegree(diffDegree);       //高难度
+            qt.setQuestionType(1);              //判断题
+            qt.setNum(p);                       //题数
+            List<QuestionInfo> diffJudgeList = this.selectTestQuestionInfoList(qt);
+            if (p != diffJudgeList.size()) {
+                System.out.println("p!=diffJudgeList.size()");
+                break;
+            }
 
-                judgeList.addAll(easyJudgeList);
-                judgeList.addAll(diffJudgeList);
-                choiceList.addAll(easyChoiceList);
-                choiceList.addAll(diffChoiceList);
-                multipleList.addAll(easyMultipleList);
-                multipleList.addAll(diffMultipleList);
+            //单选难题
+            qt.setChapterId(er.getChapterId()); //章节ID
+            qt.setDiffDegree(diffDegree);       //高难度
+            qt.setQuestionType(2);              //判断题
+            qt.setNum(d);                       //题数
+            List<QuestionInfo> diffChoiceList = this.selectTestQuestionInfoList(qt);
+            if (d != diffChoiceList.size()) {
+                System.out.println("d!=diffChoiceList.size()");
+                break;
+            }
+            //多选简单
+            qt.setChapterId(er.getChapterId()); //章节ID
+            qt.setDiffDegree(diffDegree);       //高难度
+            qt.setQuestionType(3);              //判断题
+            qt.setNum(m);                       //题数
+            List<QuestionInfo> diffMultipleList = this.selectTestQuestionInfoList(qt);
+            if (m != diffMultipleList.size()) {
+                System.out.println("m!=diffMultipleList.size()");
+                break;
             }
-            allList.addAll(judgeList);
-            allList.addAll(choiceList);
-            allList.addAll(multipleList);
+
+            judgeList.addAll(easyJudgeList);
+            judgeList.addAll(diffJudgeList);
+            choiceList.addAll(easyChoiceList);
+            choiceList.addAll(diffChoiceList);
+            multipleList.addAll(easyMultipleList);
+            multipleList.addAll(diffMultipleList);
+        }
+        allList.addAll(judgeList);
+        allList.addAll(choiceList);
+        allList.addAll(multipleList);
 //            System.out.println("error:" + error);
 //            System.out.println("allList:" + allList.size());
-        }
         return allList;
     }