Ver Fonte

增加答案分数空字符过滤、修复图片导入的bug

宋悦 há 8 anos atrás
pai
commit
08fc0fe1ac

+ 1 - 1
cqb-comm-utils/src/main/java/com/qmth/cqb/utils/word/DocxProcessUtil.java

@@ -492,7 +492,7 @@ public final class DocxProcessUtil {
         imgByte = IOUtils.toByteArray(is);
         base64Byte = Base64.encodeBase64(imgByte);
         IOUtils.closeQuietly(is);
-        FileUtils.deleteQuietly(imgFile);
+//        FileUtils.deleteQuietly(imgFile);
         return base64Byte;
     }
 

+ 16 - 17
cqb-paper/src/main/java/com/qmth/cqb/paper/service/ImportPaperService.java

@@ -606,8 +606,16 @@ public class ImportPaperService {
                 // 检测到答案开始段落
                 pAnswer = DocxProcessUtil.formatP(pAnswer, QuesUnit.QUES_ANSWER);
                 String tmpWordMl = DocxProcessUtil.getPWordMl(pAnswer);
-                answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
-                answerHTML.append(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
+
+                if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
+                        || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION
+                        || question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
+                    answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
+                    answerHTML.append(tmpText.replaceAll("\\[答案\\]", "").replaceAll("[:|:]", "").trim());
+                }else{
+                    answerWordML.append(DocxProcessUtil.formatPWordMl(tmpWordMl));
+                    answerHTML.append(DocxProcessUtil.docx2Html(tmpWordMl, wordMLPackage));
+                }
                 answerStart = true;
             } else if (tmpText.startsWith("[小题分数]")) {
                 // 检测到分数开始段落
@@ -624,29 +632,20 @@ public class ImportPaperService {
         }
         importPaperCheck.setIndex(i);
         // 校验答案
-        if (answerHTML.length() > 0) {
-            // 选择题过滤html标签--chenken 2017.4.25
-            if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
-                    || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION
-                    || question.getQuestionType() == QuesStructType.BOOL_ANSWER_QUESTION) {
-                String regEx_html = "<[^>]+>";
-                Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
-                Matcher m_html = p_html.matcher(answerHTML.toString()); // 过滤html标签
-                question.setQuesAnswer(m_html.replaceAll(""));
-            } else {
-                question.setQuesAnswer(answerHTML.toString());
-            }
+        if (StringUtils.isNotEmpty(answerHTML)) {
+            question.setQuesAnswer(answerHTML.toString());
             question.setQuesAnswerWord(answerWordML.toString());
         } else {
-            importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum) + "答案为空或格式不正确\n");
+            importPaperCheck.setErrorInfo(getQuesNumInfo(importPaperCheck.quesName, subQuesNum)
+                    + "答案为空或格式不正确\n");
         }
 
         // 设置预设分数
-        if (StringUtils.isNumeric(quesScore)) {
+        if (quesScore.matches("^\\d+(\\.\\d+)?$")) {
             question.setScore(Double.parseDouble(quesScore));
         }
         // 一般大题明细需要设置分数
-        if (!isNested && StringUtils.isNumeric(quesScore)) {
+        if (!isNested && quesScore.matches("^\\d+(\\.\\d+)?$")) {
             paperDetailUnit.setScore(Double.parseDouble(quesScore));
         }
     }