xiatian 1 year ago
parent
commit
effd84ff7a

+ 1 - 1
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/findreduplicatequestion/ExportQuesReduplicateConsumer.java

@@ -172,7 +172,7 @@ public class ExportQuesReduplicateConsumer extends Consumer<Course> {
 		Set<String> checkIds = new HashSet<>();
 		for (QuestionDto dto : dtos) {
 			dto.setExtractText(PaperUtil.getExtractText(dto));
-			if (StringUtils.isEmpty(dto.getExtractText())) {
+			if (StringUtils.isEmpty(dto.getExtractText())||PaperUtil.hasImg(dto)) {
 				checkIds.add(dto.getId());
 			}
 		}

+ 1 - 1
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/findreduplicatequestion/ExportReduplicateQuestionService.java

@@ -17,7 +17,7 @@ import cn.com.qmth.examcloud.web.support.SpringContextHolder;
 
 @Service
 public class ExportReduplicateQuestionService {
-	private String rootOrgId = "17068";
+	private String rootOrgId = "22163";
 //	private String paperName = "230517";
 	private int threadCount=4;
 

+ 84 - 47
src/main/java/cn/com/qmth/dp/examcloud/oe/util/PaperUtil.java

@@ -1,6 +1,8 @@
 package cn.com.qmth.dp.examcloud.oe.util;
 
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.commons.lang3.StringUtils;
 import org.jsoup.Jsoup;
@@ -11,51 +13,86 @@ import cn.com.qmth.dp.examcloud.oe.modules.findreduplicatequestion.QuesOptionDto
 import cn.com.qmth.dp.examcloud.oe.modules.findreduplicatequestion.QuestionDto;
 
 public class PaperUtil {
-    public static String getExtractText(String html) {
-        if (StringUtils.isBlank(html)) {
-            return "";
-        }
-        return getTextInHtml(html);
-    }
-    public static String getExtractText(QuestionDto question) {
-        StringBuilder quesText = new StringBuilder();
-        if (question == null) {
-            return quesText.toString();
-        }
-
-        if (!StringUtils.isEmpty(question.getQuesBody())) {
-            quesText.append(getTextInHtml(question.getQuesBody()));
-        }
-
-        List<QuesOptionDto> quesOptionList = question.getQuesOptions();
-        if (quesOptionList != null && quesOptionList.size() > 0) {
-            for (QuesOptionDto quesOption : quesOptionList) {
-                if (!StringUtils.isEmpty(quesOption.getOptionBody())) {
-                    quesText.append(getTextInHtml(quesOption.getOptionBody()));
-                }
-            }
-        }
-
-        return quesText.toString();
-    }
-    public static String getTextInHtml(String htmlStr) {
-        htmlStr = htmlStr.replaceAll("\\&[a-zA-Z]{1,10};", "").trim();
-        if (!htmlStr.startsWith("<p>")) {
-            return htmlStr;
-        }
-
-        try {
-            org.jsoup.nodes.Document doc = Jsoup.parse(htmlStr);
-            StringBuilder textStr = new StringBuilder();
-            Elements links = doc.select("p").removeAttr("img");
-
-            for (Element link : links) {
-                textStr.append(link.text().trim());
-            }
-
-            return textStr.toString();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
+	private static Pattern imgPat = Pattern.compile("(<img[^<]+src=['\"])([^<\"]+)(['\"][^<]*>)");
+
+	public static boolean hasImg(QuestionDto question) {
+		if (question == null) {
+			return false;
+		}
+
+		if (hasImg(question.getQuesBody())) {
+			return true;
+		}
+
+		List<QuesOptionDto> quesOptionList = question.getQuesOptions();
+		if (quesOptionList != null && quesOptionList.size() > 0) {
+			for (QuesOptionDto quesOption : quesOptionList) {
+				if (hasImg(quesOption.getOptionBody())) {
+					return true;
+				}
+			}
+		}
+
+		return false;
+	}
+
+	public static boolean hasImg(String htmlStr) {
+		Matcher matcher = imgPat.matcher(htmlStr);
+		if (matcher.find()) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	public static String getExtractText(String html) {
+		if (StringUtils.isBlank(html)) {
+			return "";
+		}
+		return getTextInHtml(html);
+	}
+
+	public static String getExtractText(QuestionDto question) {
+		StringBuilder quesText = new StringBuilder();
+		if (question == null) {
+			return quesText.toString();
+		}
+
+		if (!StringUtils.isEmpty(question.getQuesBody())) {
+			quesText.append(getTextInHtml(question.getQuesBody()));
+		}
+
+		List<QuesOptionDto> quesOptionList = question.getQuesOptions();
+		if (quesOptionList != null && quesOptionList.size() > 0) {
+			for (QuesOptionDto quesOption : quesOptionList) {
+				if (!StringUtils.isEmpty(quesOption.getOptionBody())) {
+					quesText.append(getTextInHtml(quesOption.getOptionBody()));
+				}
+			}
+		}
+
+		return quesText.toString();
+	}
+
+	public static String getTextInHtml(String htmlStr) {
+		htmlStr = htmlStr.replaceAll("\\&[a-zA-Z]{1,10};", "").trim();
+		if (!htmlStr.startsWith("<p>")) {
+			return htmlStr;
+		}
+
+		try {
+			org.jsoup.nodes.Document doc = Jsoup.parse(htmlStr);
+			StringBuilder textStr = new StringBuilder();
+			Elements links = doc.select("p").removeAttr("img");
+
+			for (Element link : links) {
+				textStr.append(link.text().trim());
+			}
+
+			return textStr.toString();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+	
 }