瀏覽代碼

后端题目数量格式不正确bug

weiwenhai 7 年之前
父節點
當前提交
ae16883986

+ 10 - 0
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/CommonUtils.java

@@ -730,4 +730,14 @@ public final class CommonUtils {
 		getTandom(list,size,original);
     	return list;
     }
+    
+    /**
+     * 判断字符串是否为整数
+     * @param str
+     * @return
+     */
+    public static boolean isInteger(String str) {  
+        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");  
+        return pattern.matcher(str).matches();  
+    }
 }

+ 4 - 0
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -555,6 +555,10 @@ public class ImportPaperService {
                 }
                 importPaperCheck.setQuesName(getContent(tmpText,ImportPaperMsg.questionName_word));
             } else if (tmpText.startsWith(ImportPaperMsg.questionNum_word)) {
+            	if(!CommonUtils.isInteger(getContent(tmpText,ImportPaperMsg.questionNum_word))){
+            		importPaperCheck.setErrorInfo("[题目数量]的格式不正确");
+                	throw new PaperException(importPaperCheck.errorInfo);
+            	}
             	if(!nextTmpText.startsWith(ImportPaperMsg.score_word)){
                 	importPaperCheck.setErrorInfo("[题目数量]的下一题头应该是[分数],当前读到的信息为:“"+nextTmpText+"”,请检查word中格式问题");
                 	throw new PaperException(importPaperCheck.errorInfo);