瀏覽代碼

BUG修改已经导入测试

gaoxing 8 年之前
父節點
當前提交
fc65776d84

+ 6 - 1
cqb-comm-utils/pom.xml

@@ -22,7 +22,6 @@
             <artifactId>gson</artifactId>
             <version>2.7</version>
         </dependency>
-
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
@@ -56,5 +55,11 @@
             <artifactId>spring-boot-test</artifactId>
             <scope>test</scope>
         </dependency>
+
+         <dependency>
+             <groupId>org.docx4j</groupId>
+ 	         <artifactId>docx4j</artifactId>
+	          <version>3.3.3</version>
+         </dependency>
     </dependencies>
 </project>

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

@@ -1,8 +1,54 @@
 package com.qmth.cqb.utils;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
 /**
  * Created by songyue on 16/12/27.
  */
 public final class CommonUtils {
+	
+	/**
+	 * 提取Html里面的文本信息,并把一般的转义字符串转换回来
+	 * @param htmlStr
+	 * @return
+	 * @throws ParserException
+	 */
+	public static String extractText(String htmlStr){
+		if(htmlStr.toLowerCase().contains("<!doctype")){
+			int index1 = htmlStr.toLowerCase().indexOf("<!doctype");
+			int index2 = htmlStr.indexOf('>',index1 + 1);
+			htmlStr = htmlStr.substring(0, index1) + htmlStr.substring(index2 + 1);
+		}
+		String regEx_head = "<[\\s]*?head[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?head[\\s]*?>"; //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script> }
+		String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script> }
+        String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style> }
+        String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
+
+        Pattern p_head = Pattern.compile(regEx_head,Pattern.CASE_INSENSITIVE);
+        Matcher m_head = p_head.matcher(htmlStr);
+        htmlStr = m_head.replaceAll(""); //过滤script标签
+
+        Pattern p_script = Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
+        Matcher m_script = p_script.matcher(htmlStr);
+        htmlStr = m_script.replaceAll(""); //过滤script标签
+
+        Pattern p_style = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
+        Matcher m_style = p_style.matcher(htmlStr);
+        htmlStr = m_style.replaceAll(""); //过滤style标签
+
+        htmlStr = htmlStr.replace("<div", " <div").replace("<DIV", " <DIV")
+        		.replace("<p", " <p").replace("<P", " <P")
+        		.replace("<h", " <h").replace("<H", " <H")
+        		.replace("<br", " <br").replace("<BR", " <BR")
+        		.replace("<td", " <td").replace("<TD", " <TD")
+        		.replace("<th", " <th").replace("<TH", " <TH");
+        Pattern p_html = Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
+        Matcher m_html = p_html.matcher(htmlStr);
+        htmlStr = m_html.replaceAll(""); //过滤html标签
+        
+        return htmlStr.trim();
+	}
 
 }

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

@@ -75,5 +75,6 @@ public class ImportPaperService {
     public void deleteImportPaper(String paperId){
     	paperRepo.delete(paperId);
     }
+    
 
 }

+ 2 - 10
cqb-paper/src/main/java/com/qmth/cqb/paper/service/PaperService.java

@@ -1,18 +1,12 @@
 package com.qmth.cqb.paper.service;
 
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
-
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 
 import com.qmth.cqb.paper.dao.ExamPaperRepo;
@@ -51,10 +45,8 @@ public class PaperService {
     	examPaper.setExamId(id);
     	examPaper.setCourseCode(courseCode);
     	examPaper.setGroupCode(groupCode);
-//		List<ExamPaper> examPapers = new ArrayList<ExamPaper>();
-//		examPapers.add(examPaperRepo.findOne(Example.of(examPaper)));
-
-    	List<ExamPaper> examPapers = examPaperRepo.findAll(Example.of(examPaper));
+    	Example<ExamPaper> example = Example.of(examPaper); 
+    	List<ExamPaper> examPapers = examPaperRepo.findAll(example);
     	for(ExamPaper ePaper:examPapers){
     		Paper paper = paperRepo.findOne(ePaper.getPaperId());
     		papers.add(paper);