Ver código fonte

Merge branch 'master' of http://git.qmth.com.cn/ExamCloud-2/examcloud-core-questions

deason 7 anos atrás
pai
commit
41d5f0e6a4

+ 35 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/CommonUtils.java

@@ -501,6 +501,22 @@ public final class CommonUtils {
 	    return list;
 	}
     
+    /**
+     * 截取a标签中的id的值
+     * @param htmlString
+     * @return
+     */
+    public static List<String> getTagANames2(String htmlString){
+		List<String> list = new ArrayList<String>();
+		Pattern p = Pattern.compile("<a[^<>]*\\s+name=\"([0-9A-Za-z-_]+)\"\\s*"); 
+	    Matcher m = p.matcher(htmlString);
+	    while(m.find()) {
+		  String str = m.group(1);
+		  list.add(str);
+	    }
+	    return list;
+	}
+    
     public static void main(String[] args){
     	String htmlString = "<a id=\"111\" name=\"111\"><\\a><a id=\"222\" name=\"222\"><\\a>";
     	System.out.println(getTagANames(htmlString));
@@ -747,4 +763,23 @@ public final class CommonUtils {
     	}
 		return false;
     }
+    
+    public static String relaceQuestionIdx(String str, int baseIdx) {
+        StringBuffer sb = new StringBuffer("");
+        Pattern pattern = Pattern.compile("##(\\d+)##");
+
+        Matcher matcher = pattern.matcher(str);
+
+        while (matcher.find()) {
+            String idx = matcher.group(1);
+            matcher.appendReplacement(sb, "___" + String.valueOf(Integer.parseInt(idx) + baseIdx) + "___");
+        }
+
+        if (StringUtils.isEmpty(sb.toString())) {
+            return str;
+        } else {
+            matcher.appendTail(sb);
+            return sb.toString();
+        }
+    }
 }

+ 4 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/ExtractConfigServiceImpl.java

@@ -1040,7 +1040,10 @@ public class ExtractConfigServiceImpl implements ExtractConfigService {
 					}
 				}else{
 					//添加题干
-					body = startWithP(paperDetailUnitDto.getQuesBody(), paperDetailUnitDto.getNumber(),false);
+					if(paperDetailUnitDto.getQuestionType() == QuesStructType.FILL_BLANK_QUESTION){
+						body = paperDetailUnitDto.getQuesBody().replaceAll("<span>", "").replaceAll("</span>", "").replaceAll("###","___");
+					}
+					body = startWithP(body, paperDetailUnitDto.getNumber(),false);
 					answerHtml.append(body);
 					//添加答案
 					answer = startWithP(paperDetailUnitDto.getAnswer(), -1,false);

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/GenPaperService.java

@@ -337,7 +337,7 @@ public class GenPaperService {
     			}
     			//生成随机抽取的题号
     			List<Integer> questionsIndex = new ArrayList<Integer>();
-    			questionsIndex = CommonUtils.getTandom(questionsIndex, needNumber, questionSum);
+    			questionsIndex = CommonUtils.getTandom(questionsIndex, unitList.size(), unitList.size());
     			//定义随机抽题的数量
     			int lastNumber = 0;
     			List<PaperDetailUnit> newDetailUnits = new ArrayList<PaperDetailUnit>();

+ 1 - 22
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PaperServiceImpl.java

@@ -618,7 +618,7 @@ public class PaperServiceImpl implements PaperService{
                                 subQues.setQuesParams(params);
                                 quesService.formatQuesUnit(subQues);
                             }
-                            String quesBodyHtml = relaceQuestionIdx(question.getQuesBody(),0);
+                            String quesBodyHtml = CommonUtils.relaceQuestionIdx(question.getQuesBody(),0);
                             question.setQuesBody(quesBodyHtml);
                         }
                     }
@@ -627,8 +627,6 @@ public class PaperServiceImpl implements PaperService{
         }
     }
 
-
-
     /**
      * 格式化查询条件
      *
@@ -939,25 +937,6 @@ public class PaperServiceImpl implements PaperService{
         }
     }
 
-    private String relaceQuestionIdx(String str, int baseIdx) {
-        StringBuffer sb = new StringBuffer("");
-        Pattern pattern = Pattern.compile("##(\\d+)##");
-
-        Matcher matcher = pattern.matcher(str);
-
-        while (matcher.find()) {
-            String idx = matcher.group(1);
-            matcher.appendReplacement(sb, "___" + String.valueOf(Integer.parseInt(idx) + baseIdx) + "___");
-        }
-
-        if (StringUtils.isEmpty(sb.toString())) {
-            return str;
-        } else {
-            matcher.appendTail(sb);
-            return sb.toString();
-        }
-    }
-
     public Page<Paper> getPapersNotInIds(PaperSearchInfo paperSearchInfo, String[] ids, int curPage,int pageSize,PaperType paperType) {
     	Set<String> selectedIds = new HashSet<>();
     	for (String id : ids) {