xiatian 4 سال پیش
والد
کامیت
a0fa8cd144

BIN
course.xlsx


+ 5 - 0
pom.xml

@@ -10,6 +10,11 @@
 		<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
 	</properties>
 	<dependencies>
+		<dependency>
+			<groupId>net.coobird</groupId>
+			<artifactId>thumbnailator</artifactId>
+			<version>0.4.8</version>
+		</dependency>
 		<dependency>
 			<groupId>io.swagger</groupId>
 			<artifactId>swagger-annotations</artifactId>

+ 68 - 8
src/main/java/cn/com/qmth/export/Answer.java

@@ -3,6 +3,12 @@ package cn.com.qmth.export;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.lang3.StringUtils;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
+
 public class Answer {
 	private Long id;
 	private String body;
@@ -24,7 +30,6 @@ public class Answer {
 		this.score = score;
 	}
 
-
 	public Long getId() {
 		return id;
 	}
@@ -32,15 +37,70 @@ public class Answer {
 	public void setId(Long id) {
 		this.id = id;
 	}
+
 	public static void main(String[] args) {
-		String s="<p><img scr=\"sds\" /><a href=\"@@PLUGINFILE@@/boy-quiz03\" \"dfsd\">boy-quiz03.mp3</a></p><p>(如没有自动播放,请手动点击播放按钮)</p><p>你听到的单词是:</p>";
-		Pattern p = Pattern.compile("<a[^<]+href=\"[^<\"]+(?!\\.mp3)\"[^<]*>([^<]*)</a>");
-		Matcher m = p.matcher(s);
-		while(m.find()) {
-			System.out.println("+++++++++++++++++++");
-			System.out.println(m.group());
-			System.out.println(m.group(1));
+		String s="<p><span style=\"color: #4e4e4e; font-family: -apple-system, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 15px; white-space: nowrap; background-color: #e4e4e4;\">为知笔记</span></p>";
+		System.out.println(disBody(s));
+	}
+
+	private static String disBody(String html) {
+		Document doc = Jsoup.parse(html);
+		Element b = doc.body();
+		if (b.childrenSize()== 1&&"p".equals(b.child(0).nodeName())) {
+			b.child(0).tagName("span");
+			b.child(0).removeAttr("style");
+		}
+		if (b.childrenSize()> 0) {
+			for (Element n : b.children()) {
+				if("p".equals(n.nodeName())) {
+					boolean[] find=new boolean[] {false};
+					findImg(n, find);
+					if(!find[0]&&StringUtils.isBlank(n.text())) {
+						n.tagName("span");
+					}
+				}
+				disNode(n);
+			}
 		}
+		return b.html();
 	}
 	
+	private static void findImg(Element e,boolean[] find) {
+		if(find[0]) {
+			return;
+		}else {
+			if("img".equals(e.nodeName())) {
+				find[0]=true;
+				return;
+			}else {
+				if(e.childrenSize()>0) {
+					for(Element ce:e.children()) {
+						findImg(ce, find);
+					}
+				}else {
+					return;
+				}
+			}
+		}
+	}
+	private static void disNode(Node n) {
+		if (n instanceof Element) {
+			if (!"img".equals(n.nodeName())) {
+				n.removeAttr("style");
+			}
+			if ("h1".equals(n.nodeName()) || "h2".equals(n.nodeName()) || "h3".equals(n.nodeName())
+					|| "h4".equals(n.nodeName()) || "h5".equals(n.nodeName())) {
+				((Element) n).tagName("h6");
+			}
+			if ("strong".equals(n.nodeName())||"a".equals(n.nodeName())||"u".equals(n.nodeName())||"em".equals(n.nodeName())) {
+				((Element) n).tagName("span");
+			}
+			if (n.childNodeSize() > 0) {
+				for (Node cn : n.childNodes()) {
+					disNode(cn);
+				}
+			}
+		}
+	}
+
 }

+ 20 - 2
src/main/java/cn/com/qmth/export/Course.java

@@ -1,34 +1,52 @@
 package cn.com.qmth.export;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 public class Course {
 	private String name;
 	private String code;
 	private String idnumber;
 	private Long id;
+
 	public String getName() {
 		return name;
 	}
+
 	public void setName(String name) {
 		this.name = name;
 	}
+
 	public String getCode() {
 		return code;
 	}
+
 	public void setCode(String code) {
 		this.code = code;
 	}
+
 	public Long getId() {
 		return id;
 	}
+
 	public void setId(Long id) {
 		this.id = id;
 	}
+
 	public String getIdnumber() {
 		return idnumber;
 	}
+
 	public void setIdnumber(String idnumber) {
 		this.idnumber = idnumber;
 	}
-	
-	
+
+	public static void main(String[] args) {
+		String s = "<span><span>已知<span lang=\"EN-US\">A=<img src=\"@@PLUGINFILE@@/4.png?time=1594114072778\" alt=\"\" width=\"75\" height=\"54\"></span></span><span>,<span lang=\"EN-US\">B=<img src=\"@@PLUGINFILE@@/5.png?time=1594114090754\" alt=\"\" width=\"93\" height=\"48\"></span></span><span>,下列运算可行的是(&nbsp; &nbsp; &nbsp; )。&nbsp;</span></span>";
+		String k="@@PLUGINFILE@@/4.png?time=1594114072778";
+		k=k.replaceAll("\\?", "\\\\?");
+		System.out.println(k);
+		System.out.println(s.replaceAll(k, "AAAAAA"));
+	}
+
 }

+ 0 - 7
src/main/java/cn/com/qmth/export/ExportByCourseCode.java

@@ -80,13 +80,6 @@ public class ExportByCourseCode {
 				FileUtils.writeStringToFile(file, "answerid idnumber source", "utf-8", true);
 				FileUtils.writeLines(file, azip,true);
 			}
-			logger.debug("===============================================答案zip没有文件:" + azip.size());
-			if (azip.size() > 0) {
-				File file=new File(notFoundDir+"\\答案在zip中找不到文件.txt");
-				file.createNewFile();
-				FileUtils.writeStringToFile(file, "answerid idnumber source", "utf-8", true);
-				FileUtils.writeLines(file, azip,true);
-			}
 			logger.debug("===============================================http连接数:" + http.size());
 			if (http.size() > 0) {
 				File file=new File(notFoundDir+"\\http连接.txt");

+ 7 - 0
src/main/java/cn/com/qmth/export/KdQuestion.java

@@ -12,6 +12,7 @@ public class KdQuestion {
 	private String qtype;
 	private Boolean haveAudio;
 	private List<KdQuesOption> options;
+	private Boolean valid;
 	public Integer getNumber() {
 		return number;
 	}
@@ -66,6 +67,12 @@ public class KdQuestion {
 	public void setHaveAudio(Boolean haveAudio) {
 		this.haveAudio = haveAudio;
 	}
+	public Boolean getValid() {
+		return valid;
+	}
+	public void setValid(Boolean valid) {
+		this.valid = valid;
+	}
 	
 	
 }

+ 10 - 0
src/main/java/cn/com/qmth/export/MediaNotFoundException.java

@@ -0,0 +1,10 @@
+package cn.com.qmth.export;
+
+public class MediaNotFoundException extends RuntimeException{
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -1479053529732022388L;
+
+}

+ 226 - 96
src/main/java/cn/com/qmth/export/MyConsumer.java

@@ -24,15 +24,19 @@ import org.apache.commons.lang3.StringUtils;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
+import org.jsoup.nodes.Node;
 
 import com.alibaba.fastjson.JSONObject;
 
 public class MyConsumer extends Consumer<String> {
+	private String paperSuff = "(211)";
+	private int maxqc = 100;
 
 	private String excelDir = "D:\\kd_export\\";
+	private String picFiles = "D:\\files\\";
 
 	private Pattern mp3Pat = Pattern.compile("<a[^<]+href=\"([^<\"]+\\.mp3)\"[^<]*>[^<]*</a>");
-	private Pattern imgPat = Pattern.compile("<img[^<]+src=\"([^<\"]+)\"[^<]*/>");
+	private Pattern imgPat = Pattern.compile("<img[^<]+src=\"([^<\"]+)\"[^<]*>");
 
 	private Pattern notmp3Pat = Pattern.compile("<a[^<]+href=\"[^<\"]+(?!\\.mp3)\"[^<]*>([^<]*)</a>");
 
@@ -169,7 +173,7 @@ public class MyConsumer extends Consumer<String> {
 			while (resultSet.next()) {
 				KdQuestion q = new KdQuestion();
 				q.setId(resultSet.getLong("id"));
-				q.setBody(resultSet.getString("questiontext"));
+				q.setBody(disBody(resultSet.getString("questiontext")));
 				q.setQtype(resultSet.getString("qtype"));
 				q.setObjective(true);
 				qs.add(q);
@@ -237,7 +241,6 @@ public class MyConsumer extends Consumer<String> {
 		for (KdQuestion q : qs) {
 			List<Answer> as = getAnswer(connect, q);
 			disposeAnswer(q, as);
-			removeATag(q);
 		}
 
 		qs = removeInvalidQuestion(qs, code);
@@ -245,17 +248,28 @@ public class MyConsumer extends Consumer<String> {
 			noques.add(code);
 			return;
 		}
-
-		KdPaper paper = new KdPaper();
-		paper.setTotalScore((double) qs.size());
-		paper.setName(c.getName());
-		paper.setCourseCode(c.getCode());
-		File courseCode = new File(excelDir + paper.getCourseCode() + "\\");
+		File courseCode = new File(excelDir + c.getCode() + "\\");
 		courseCode.mkdirs();
-		File att = new File(excelDir + paper.getCourseCode() + "\\att\\");
+		File att = new File(excelDir + c.getCode() + "\\att\\");
 		att.mkdirs();
 		for (KdQuestion q : qs) {
-			disposeMedia(connect, c.getIdnumber(), q, att);
+			try {
+				disposeMedia(connect, c.getIdnumber(), q, att);
+				q.setValid(true);
+			} catch (MediaNotFoundException e) {
+				q.setValid(false);
+			}
+		}
+		List<KdQuestion> tem = new ArrayList<>();
+		for (KdQuestion q : qs) {
+			if (q.getValid()) {
+				tem.add(q);
+			}
+		}
+		qs = tem;
+		if (qs.size() == 0) {
+			noques.add(code);
+			return;
 		}
 
 		List<KdQuestion> single = new ArrayList<>();
@@ -270,43 +284,96 @@ public class MyConsumer extends Consumer<String> {
 				boo.add(q);
 			}
 		}
+		createPapers(single, c, 1);
+		createPapers(muti, c, 2);
+		createPapers(boo, c, 3);
+
+//		int detailIndx = 0;
+//		List<KdDetail> des = new ArrayList<>();
+//		if (single.size() > 0) {
+//			detailIndx++;
+//			KdDetail d = new KdDetail();
+//			d.setName("单选题");
+//			d.setNumber(detailIndx);
+//			d.setQuestionCount(single.size());
+//			d.setTotalScore((double) single.size());
+//			d.setQuestions(single);
+//			des.add(d);
+//		}
+//		if (muti.size() > 0) {
+//			detailIndx++;
+//			KdDetail d = new KdDetail();
+//			d.setName("多选题");
+//			d.setNumber(detailIndx);
+//			d.setQuestionCount(muti.size());
+//			d.setTotalScore((double) muti.size());
+//			d.setQuestions(muti);
+//			des.add(d);
+//		}
+//		if (boo.size() > 0) {
+//			detailIndx++;
+//			KdDetail d = new KdDetail();
+//			d.setName("判断题");
+//			d.setNumber(detailIndx);
+//			d.setQuestionCount(boo.size());
+//			d.setTotalScore((double) boo.size());
+//			d.setQuestions(boo);
+//			des.add(d);
+//		}
+//		paper.setDetails(des);
+//		paper.setDetailCount(detailIndx);
+//
+//		FileUtil.writeFile(courseCode.getAbsolutePath(), "\\paper.json", JSONObject.toJSONString(paper));
+	}
 
-		int detailIndx = 0;
-		List<KdDetail> des = new ArrayList<>();
-		if (single.size() > 0) {
-			detailIndx++;
-			KdDetail d = new KdDetail();
-			d.setName("单选题");
-			d.setNumber(detailIndx);
-			d.setQuestionCount(single.size());
-			d.setTotalScore((double) single.size());
-			d.setQuestions(single);
-			des.add(d);
-		}
-		if (muti.size() > 0) {
-			detailIndx++;
-			KdDetail d = new KdDetail();
-			d.setName("多选题");
-			d.setNumber(detailIndx);
-			d.setQuestionCount(muti.size());
-			d.setTotalScore((double) muti.size());
-			d.setQuestions(muti);
-			des.add(d);
-		}
-		if (boo.size() > 0) {
-			detailIndx++;
-			KdDetail d = new KdDetail();
-			d.setName("判断题");
-			d.setNumber(detailIndx);
-			d.setQuestionCount(boo.size());
-			d.setTotalScore((double) boo.size());
-			d.setQuestions(boo);
-			des.add(d);
+	private void createPapers(List<KdQuestion> qs, Course c, int structType) throws IOException {
+		if (qs == null || qs.size() == 0) {
+			return;
+		}
+		if (qs.size() <= maxqc) {
+			createPaper(qs, c, structType, 1);
+		} else {
+			int size = qs.size();
+			int len = maxqc;
+			int count = (size + len - 1) / len;
+
+			for (int i = 0; i < count; i++) {
+				List<KdQuestion> subList = qs.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
+				createPaper(subList, c, structType, i + 1);
+			}
 		}
-		paper.setDetails(des);
-		paper.setDetailCount(detailIndx);
 
-		FileUtil.writeFile(courseCode.getAbsolutePath(), "\\paper.json", JSONObject.toJSONString(paper));
+	}
+
+	private void createPaper(List<KdQuestion> qs, Course c, int structType, int indx) throws IOException {
+		if (qs.size() == 0) {
+			return;
+		}
+		String detailName="";
+		if (structType == 1) {
+			detailName="单选题";
+		} else if (structType == 2) {
+			detailName="多选题";
+		} else if (structType == 3) {
+			detailName="判断题";
+		}
+		KdPaper paper = new KdPaper();
+		paper.setTotalScore((double) qs.size());
+		paper.setName(c.getName()+paperSuff+detailName+"_"+indx);
+		paper.setCourseCode(c.getCode());
+		List<KdDetail> des = new ArrayList<>();
+		KdDetail d = new KdDetail();
+		d.setName(detailName);
+		d.setNumber(1);
+		d.setQuestionCount(qs.size());
+		d.setTotalScore((double) qs.size());
+		d.setQuestions(qs);
+		des.add(d);
+		paper.setDetails(des);
+		paper.setDetailCount(1);
+		File paperdir = new File(excelDir + c.getCode() + "\\paper"+structType+"_"+indx+"\\");
+		paperdir.mkdirs();
+		FileUtil.writeFile(paperdir.getAbsolutePath(), "\\paper.json", JSONObject.toJSONString(paper));
 	}
 
 	private List<KdQuestion> removeInvalidQuestion(List<KdQuestion> qs, String courseCode) {
@@ -371,7 +438,7 @@ public class MyConsumer extends Consumer<String> {
 				KdQuesOption op = new KdQuesOption();
 				op.setAnswerId(a.getId());
 				op.setNumber(index);
-				op.setBody(a.getBody());
+				op.setBody(disBody(a.getBody()));
 				if (a.getScore() > 0) {
 					op.setSelect(true);
 					sb.append(index).append(",");
@@ -393,56 +460,117 @@ public class MyConsumer extends Consumer<String> {
 		}
 	}
 
-	private String getInStr(List<Long> cids) {
-		StringBuilder sb = new StringBuilder();
-		for (Long id : cids) {
-			sb.append(id).append(",");
+	private String disBody(String html) {
+		Document doc = Jsoup.parse(html);
+		Element b = doc.body();
+		if (b.childrenSize() == 1 && "p".equals(b.child(0).nodeName())) {
+			b.child(0).tagName("span");
+		}
+		if (b.childrenSize() > 0) {
+			for (Element n : b.children()) {
+				if ("p".equals(n.nodeName())) {
+					boolean[] find = new boolean[] { false };
+					findImg(n, find);
+					if (!find[0] && StringUtils.isBlank(n.text())) {
+						n.tagName("span");
+					}
+				}
+				disNode(n);
+			}
 		}
-		sb.deleteCharAt(sb.length() - 1);
-		return sb.toString();
+		return b.html();
 	}
 
-	private Map<String, String> findAtag(String body) {
-		Map<String, String> set = new HashMap<>();
-		if (StringUtils.isBlank(body)) {
-			return set;
-		}
-		Matcher m = notmp3Pat.matcher(body);
-		while (m.find()) {
-			String f = m.group(1);
-			set.put(m.group(), f);
+	private void findImg(Element e, boolean[] find) {
+		if (find[0]) {
+			return;
+		} else {
+			if ("img".equals(e.nodeName())) {
+				find[0] = true;
+				return;
+			} else {
+				if (e.childrenSize() > 0) {
+					for (Element ce : e.children()) {
+						findImg(ce, find);
+					}
+				} else {
+					return;
+				}
+			}
 		}
-		return set;
 	}
 
-	private void removeATag(KdQuestion q) throws Exception {
-		String body = q.getBody();
-
-		Map<String, String> as = findAtag(body);
-		if (as.size() > 0) {
-			for (String k : as.keySet()) {
-				String val = as.get(k);
-				body = body.replaceAll(k, val);
+	private static void disNode(Node n) {
+		if (n instanceof Element) {
+			if (!"img".equals(n.nodeName())) {
+				n.removeAttr("style");
 			}
-			q.setBody(body);
-		}
-
-		if (CollectionUtils.isNotEmpty(q.getOptions())) {
-			for (KdQuesOption o : q.getOptions()) {
-				String obody = o.getBody();
-
-				Map<String, String> oas = findAtag(obody);
-				if (oas.size() > 0) {
-					for (String k : oas.keySet()) {
-						String val = oas.get(k);
-						obody = obody.replaceAll(k, val);
-					}
-					o.setBody(obody);
+			if ("h1".equals(n.nodeName()) || "h2".equals(n.nodeName()) || "h3".equals(n.nodeName())
+					|| "h4".equals(n.nodeName()) || "h5".equals(n.nodeName())) {
+				((Element) n).tagName("h6");
+			}
+			if ("strong".equals(n.nodeName()) || "a".equals(n.nodeName()) || "u".equals(n.nodeName())
+					|| "em".equals(n.nodeName())) {
+				((Element) n).tagName("span");
+			}
+			if (n.childNodeSize() > 0) {
+				for (Node cn : n.childNodes()) {
+					disNode(cn);
 				}
 			}
 		}
 	}
 
+	private String getInStr(List<Long> cids) {
+		StringBuilder sb = new StringBuilder();
+		for (Long id : cids) {
+			sb.append(id).append(",");
+		}
+		sb.deleteCharAt(sb.length() - 1);
+		return sb.toString();
+	}
+
+//	private Map<String, String> findAtag(String body) {
+//		Map<String, String> set = new HashMap<>();
+//		if (StringUtils.isBlank(body)) {
+//			return set;
+//		}
+//		Matcher m = notmp3Pat.matcher(body);
+//		while (m.find()) {
+//			String f = m.group(1);
+//			set.put(m.group(), f);
+//		}
+//		return set;
+//	}
+//
+//	private void removeATag(KdQuestion q) throws Exception {
+//		String body = q.getBody();
+//
+//		Map<String, String> as = findAtag(body);
+//		if (as.size() > 0) {
+//			for (String k : as.keySet()) {
+//				String val = as.get(k);
+//				body = body.replaceAll(k, val);
+//			}
+//			q.setBody(body);
+//		}
+//
+//		if (CollectionUtils.isNotEmpty(q.getOptions())) {
+//			for (KdQuesOption o : q.getOptions()) {
+//				String obody = o.getBody();
+//
+//				Map<String, String> oas = findAtag(obody);
+//				if (oas.size() > 0) {
+//					for (String k : oas.keySet()) {
+//						String val = oas.get(k);
+//						obody = obody.replaceAll(k, val);
+//					}
+//					o.setBody(obody);
+//				}
+//			}
+//		}
+//	}
+
 	private void disposeMedia(Connection connect, String courseidnumber, KdQuestion q, File att) throws Exception {
 		String body = q.getBody();
 
@@ -454,10 +582,11 @@ public class MyConsumer extends Consumer<String> {
 				File file = getQuestionFile(connect, q.getId(), courseidnumber, fileName);
 				if (file == null) {
 					ExportByCourseCode.addNotFd();
-					body = body.replaceAll(k, "[未找到图片文件]");
+//					body = body.replaceAll(k, "[未找到图片文件]");
+					throw new MediaNotFoundException();
 				} else {
 					ExportByCourseCode.addFd();
-					body = body.replaceAll(img, FileUtil.fileToBase64Src(file));
+					body = body.replaceAll(img.replaceAll("\\?", "\\\\?"), FileUtil.fileToBase64Src(file));
 				}
 			}
 			q.setBody(body);
@@ -471,13 +600,14 @@ public class MyConsumer extends Consumer<String> {
 				File file = getQuestionFile(connect, q.getId(), courseidnumber, fileName);
 				if (file == null) {
 					ExportByCourseCode.addNotFd();
-					body = body.replaceAll(k, "[未找到音频文件]");
+//					body = body.replaceAll(k, "[未找到音频文件]");
+					throw new MediaNotFoundException();
 				} else {
 					ExportByCourseCode.addFd();
 					File newAudio = new File(att.getAbsoluteFile() + "\\" + file.getName());
 					newAudio.createNewFile();
 					FileUtils.copyFile(file, newAudio);
-					body = body.replaceAll(k, "<a id=\"" + file.getName() + "\" name=\"" + file.getName() + "\"></a>");
+					body = body.replaceAll(k.replaceAll("\\?", "\\\\?"), "<a id=\"" + file.getName() + "\" name=\"" + file.getName() + "\"></a>");
 				}
 			}
 			q.setBody(body);
@@ -495,10 +625,11 @@ public class MyConsumer extends Consumer<String> {
 						File file = getAnswerFile(connect, o.getAnswerId(), courseidnumber, fileName);
 						if (file == null) {
 							ExportByCourseCode.addNotFd();
-							obody = obody.replaceAll(k, "[未找到图片文件]");
+//							obody = obody.replaceAll(k, "[未找到图片文件]");
+							throw new MediaNotFoundException();
 						} else {
 							ExportByCourseCode.addFd();
-							obody = obody.replaceAll(img, FileUtil.fileToBase64Src(file));
+							obody = obody.replaceAll(img.replaceAll("\\?", "\\\\?"), FileUtil.fileToBase64Src(file));
 						}
 					}
 					o.setBody(obody);
@@ -513,13 +644,14 @@ public class MyConsumer extends Consumer<String> {
 						File file = getAnswerFile(connect, o.getAnswerId(), courseidnumber, fileName);
 						if (file == null) {
 							ExportByCourseCode.addNotFd();
-							obody = obody.replaceAll(k, "[未找到音频文件]");
+//							obody = obody.replaceAll(k, "[未找到音频文件]");
+							throw new MediaNotFoundException();
 						} else {
 							ExportByCourseCode.addFd();
 							File newAudio = new File(att.getAbsoluteFile() + "\\" + file.getName());
 							newAudio.createNewFile();
 							FileUtils.copyFile(file, newAudio);
-							obody = obody.replaceAll(k,
+							obody = obody.replaceAll(k.replaceAll("\\?", "\\\\?"),
 									"<a id=\"" + file.getName() + "\" name=\"" + file.getName() + "\"></a>");
 						}
 					}
@@ -641,8 +773,7 @@ public class MyConsumer extends Consumer<String> {
 				return null;
 			}
 			String suff = fileName.substring(fileName.lastIndexOf("."));
-			File directory = new File("");
-			File file = new File(directory.getAbsolutePath() + "\\files\\" + courseidnumber + "\\" + hash + suff);
+			File file = new File(picFiles + courseidnumber + "\\" + hash + suff);
 			if (!file.exists()) {
 				qzip.add(quesId + " " + courseidnumber + " " + fileName);
 				return null;
@@ -679,8 +810,7 @@ public class MyConsumer extends Consumer<String> {
 				return null;
 			}
 			String suff = fileName.substring(fileName.lastIndexOf("."));
-			File directory = new File("");
-			File file = new File(directory.getAbsolutePath() + "\\files\\" + courseidnumber + "\\" + hash + suff);
+			File file = new File(picFiles + courseidnumber + "\\" + hash + suff);
 			if (!file.exists()) {
 				azip.add(answerId + " " + courseidnumber + " " + fileName);
 				return null;

+ 48 - 0
src/main/java/cn/com/qmth/export/PicCompress.java

@@ -0,0 +1,48 @@
+package cn.com.qmth.export;
+
+import java.io.File;
+import java.io.IOException;
+
+import net.coobird.thumbnailator.Thumbnails;
+
+public class PicCompress {
+	private static long size = 100 * 1024;
+
+	private static int count=0;
+	public static void main(String[] args) {
+		File root = new File("d://files/");
+		try {
+			dis(root);
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	private static void dis(File file) throws IOException {
+		if (file.isFile()) {
+			count++;
+			String suff = file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase();
+			if ((suff.equals("png") || suff.equals("jpg") || suff.equals("jpeg") || suff.equals("bmp"))
+					&& file.length() > size) {
+				compressImageFiles(file);
+			}
+			System.out.println(count);
+		} else if (file.listFiles().length > 0) {
+			for (File cf : file.listFiles()) {
+				dis(cf);
+			}
+		}
+	}
+
+	private static void compressImageFiles(File file) throws IOException {
+		Thumbnails.of(file)
+//                .size(800, 800) //按指定大小进行缩放
+//                 .scale(0.8f) //按比例缩小
+//                .scale(1.5f) //按比例放大
+				.scale(1.0f).outputQuality(0.5f) // 尺寸不变,质量压缩
+//                .scale(1.0f).rotate(90) //尺寸不变,旋转N度(0,90,180,270,45)
+//                 .outputFormat("jpg") //按格式输出
+				// .toFiles(Rename.SUFFIX_HYPHEN_THUMBNAIL);
+				.toFile(file);
+	}
+}