xiatian hace 1 año
padre
commit
41b67a6e60

+ 0 - 0
file/临时.txt → file/新建文本文档.txt


+ 1 - 1
src/main/java/cn/com/qmth/export/ChuanNongExportPaperByCourseCode.java

@@ -24,7 +24,7 @@ public class ChuanNongExportPaperByCourseCode {
 			Map<String, Object> param=new HashMap<>();
 			param.put("paperSuff", paperSuff);
 			param.put("dbName", dbName);
-			pro.startDispose(MyConsumer.class, 8, param);
+			pro.startDispose(MyConsumer.class, 4, param);
 		} catch (Exception e) {
 			logger.error(e.getCause(), e);
 		}

+ 4 - 8
src/main/java/cn/com/qmth/export/DetailDto.java

@@ -1,13 +1,15 @@
 package cn.com.qmth.export;
 
+import java.util.UUID;
+
 public class DetailDto {
 	private String typeId;
 	private String typeName;
 	
 	
-	public DetailDto(String typeId, String typeName) {
+	public DetailDto(String typeName) {
 		super();
-		this.typeId = typeId;
+		this.typeId = UUID.randomUUID().toString();
 		this.typeName = typeName;
 	}
 	public String getTypeId() {
@@ -26,7 +28,6 @@ public class DetailDto {
 	public int hashCode() {
 		final int prime = 31;
 		int result = 1;
-		result = prime * result + ((typeId == null) ? 0 : typeId.hashCode());
 		result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
 		return result;
 	}
@@ -39,11 +40,6 @@ public class DetailDto {
 		if (getClass() != obj.getClass())
 			return false;
 		DetailDto other = (DetailDto) obj;
-		if (typeId == null) {
-			if (other.typeId != null)
-				return false;
-		} else if (!typeId.equals(other.typeId))
-			return false;
 		if (typeName == null) {
 			if (other.typeName != null)
 				return false;

+ 5 - 4
src/main/java/cn/com/qmth/export/FileUtil.java

@@ -139,12 +139,12 @@ public class FileUtil {
         HttpURLConnection connection;
         try {
             connection = (HttpURLConnection) url.openConnection();
-            connection.setConnectTimeout(30000); 
-            connection.setReadTimeout(30000); 
+            connection.setConnectTimeout(60000); 
+            connection.setReadTimeout(60000); 
         } catch (IOException e) {
         	throw new RuntimeException("连接出错:"+e.getMessage(),e);
         }
-
+        long start=System.currentTimeMillis();
         try (DataInputStream dataInputStream = new DataInputStream(connection.getInputStream());
                 FileOutputStream fileOutputStream = new FileOutputStream(localFilePath);
                 DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);) {
@@ -158,7 +158,8 @@ public class FileUtil {
             dataOutputStream.flush();
             return true;
         } catch (Exception e) {
-        	throw new RuntimeException("下载出错:"+fileUrl,e);
+        	long end=System.currentTimeMillis();
+        	throw new RuntimeException("下载出错:"+((end-start)/1000)+"s | "+fileUrl,e);
         } finally {
             if (connection != null) {
                 connection.disconnect();

+ 9 - 17
src/main/java/cn/com/qmth/export/KdQuestion.java

@@ -8,10 +8,9 @@ public class KdQuestion {
 	private String cname;
 	private Integer id;
 	private Integer pid;
-	private String typeId;
 	private String detailName;
 	private QuesStructType quesStructType;
-	private YunkaiDifficulty difficulty;
+	private Double difficultyDegree;
 	private String body;
 	private String answer;
 	private Boolean haveAudio;
@@ -37,13 +36,6 @@ public class KdQuestion {
 		this.quesStructType = quesStructType;
 	}
 
-	public YunkaiDifficulty getDifficulty() {
-		return difficulty;
-	}
-
-	public void setDifficulty(YunkaiDifficulty difficulty) {
-		this.difficulty = difficulty;
-	}
 
 	public String getBody() {
 		return body;
@@ -117,14 +109,6 @@ public class KdQuestion {
 		this.detailName = detailName;
 	}
 
-	public String getTypeId() {
-		return typeId;
-	}
-
-	public void setTypeId(String typeId) {
-		this.typeId = typeId;
-	}
-
 	public String getPname() {
 		return pname;
 	}
@@ -157,4 +141,12 @@ public class KdQuestion {
 		this.pid = pid;
 	}
 
+	public Double getDifficultyDegree() {
+		return difficultyDegree;
+	}
+
+	public void setDifficultyDegree(Double difficultyDegree) {
+		this.difficultyDegree = difficultyDegree;
+	}
+
 }

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

@@ -30,7 +30,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 	private static String imgDir = "d:/chuannong/img";
 	private static String imgDomain = "http://any.cnzx.info:81";
 
-	private Pattern imgPat = Pattern.compile("<img[^<]+src=['\"]([^<\"]+)['\"][^<]*>");
+	private Pattern imgPat = Pattern.compile("(<img[^<]+src=['\"])([^<\"]+)(['\"][^<]*>)");
 
 	@Override
 	public void consume(PaperExportDto dto) {
@@ -92,7 +92,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 //						num++;
 						subScores.add(1.0);
 						KdQuestion subq = of(subvo);
-						subq.setId(null);
+//						subq.setId(null);
 //						if (CusQuesStructType.cloze.equals(q.getCusType()) && StringUtils.isBlank(subq.getBody())) {
 //							subq.setBody("___" + num + "___");
 //						}
@@ -112,7 +112,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		q.setQuesStructType(vo.getqType());
 		q.setDetailName(vo.getTypeName());
 		q.setBody(vo.getBody());
-		q.setDifficulty(vo.getDifficulty());
+		q.setDifficultyDegree(vo.getDifficulty().getType());
 		q.setHaveAudio(false);
 		q.setId(vo.getQid());
 		q.setScore(1.0);
@@ -143,7 +143,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 				q.setTypeName(typeName);
 				q.setDifficulty(getDiff(resultSet.getInt("DiffCoef")));
 				q.setAtype(resultSet.getInt("atype"));
-				q.setqType(getQuesType(q.getQid(), typeName, dto.getNestedQids()));
+				q.setqType(getQuesType(q.getQid(), q.getAtype(),typeName, dto.getNestedQids()));
 				q.setBody(resultSet.getString("body"));
 				qs.add(q);
 			}
@@ -173,7 +173,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		throw new StatusException("难度值错误");
 	}
 
-	private QuesStructType getQuesType(Integer qid, String typeName, Set<Integer> nestedQids) {
+	private QuesStructType getQuesType(Integer qid,Integer aType, String typeName, Set<Integer> nestedQids) {
 		if (nestedQids.contains(qid)) {
 			return QuesStructType.NESTED_ANSWER_QUESTION;
 		}
@@ -186,6 +186,12 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		if (typeName.startsWith("判断")) {
 			return QuesStructType.BOOL_ANSWER_QUESTION;
 		}
+		if (aType==1) {
+			return QuesStructType.SINGLE_ANSWER_QUESTION;
+		}
+		if (aType==2) {
+			return QuesStructType.MULTIPLE_ANSWER_QUESTION;
+		}
 		return QuesStructType.TEXT_ANSWER_QUESTION;
 	}
 
@@ -236,44 +242,45 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 	}
 
 	private String disposeImg(String str, Integer qid) {
+		if (StringUtils.isBlank(str)) {
+			return str;
+		}
+		StringBuffer buffer = new StringBuffer();
+		Matcher matcher = imgPat.matcher(str);
 		try {
-			if (StringUtils.isBlank(str)) {
-				return str;
-			}
-			Matcher matcher = imgPat.matcher(str);
-			Map<String, String> srcMap = new HashMap<>();
 			while (matcher.find()) {
-				String imgSrc = matcher.group(1).trim();
-				if (imgSrc.startsWith("data:image/")) {
-
-				} else if (imgSrc.startsWith("/")) {
-					if (srcMap.get(imgSrc) == null) {
-						String[] ss = imgSrc.split("\\?");
-						String suff = ss[0].substring(ss[0].lastIndexOf("."));
-						File img = new File(imgDir + "/" + UUID.randomUUID() + suff);
-						FileUtil.saveUrlAs(imgDomain + imgSrc, img.getAbsolutePath());
-						String base64 = FileUtil.fileToBase64Src(img);
-						img.delete();
-						srcMap.put(imgSrc, base64);
-					}
-				} else if (imgSrc.toLowerCase().trim().startsWith("http")) {
-					if (srcMap.get(imgSrc) == null) {
-						String[] ss = imgSrc.split("\\?");
-						String suff = ss[0].substring(ss[0].lastIndexOf("."));
-						File img = new File(imgDir + "/" + UUID.randomUUID() + suff);
-						FileUtil.saveUrlAs(imgSrc, img.getAbsolutePath());
-						String base64 = FileUtil.fileToBase64Src(img);
-						img.delete();
-						srcMap.put(imgSrc, base64);
-					}
+				String g1 = matcher.group(1);
+				g1=Matcher.quoteReplacement(g1);
+				String g2 = matcher.group(2);
+				String g3 = matcher.group(3);
+				g3=Matcher.quoteReplacement(g3);
+				if (g2.startsWith("data:image/")) {
+
+				} else if (g2.startsWith("/")) {
+					String[] ss = g2.split("\\?");
+					String suff = ss[0].substring(ss[0].lastIndexOf("."));
+					File img = new File(imgDir + "/" + UUID.randomUUID() + suff);
+					FileUtil.saveUrlAs(imgDomain + g2, img.getAbsolutePath());
+					g2 = FileUtil.fileToBase64Src(img);
+					img.delete();
+				} else if (g2.toLowerCase().trim().startsWith("http")) {
+					String[] ss = g2.split("\\?");
+					String suff = ss[0].substring(ss[0].lastIndexOf("."));
+					File img = new File(imgDir + "/" + UUID.randomUUID() + suff);
+					FileUtil.saveUrlAs(g2, img.getAbsolutePath());
+					g2 = FileUtil.fileToBase64Src(img);
+					img.delete();
 				} else {
 					throw new StatusException("图片有误:" + qid);
 				}
+				try {
+					matcher.appendReplacement(buffer, g1 + g2 + g3);
+				} catch (Exception e) {
+					throw new RuntimeException("图片有误:" + qid, e);
+				}
 			}
-			for (String imgSrc : srcMap.keySet()) {
-				str = str.replaceAll(imgSrc, srcMap.get(imgSrc));
-			}
-			return str;
+			matcher.appendTail(buffer);
+			return buffer.toString();
 		} catch (Exception e) {
 			throw new RuntimeException("图片有误:" + qid, e);
 		}
@@ -293,7 +300,7 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 
 		Map<DetailDto, List<KdQuestion>> qmap = new HashMap<>();
 		for (KdQuestion q : qs) {
-			DetailDto tem = new DetailDto(q.getTypeId(), q.getDetailName());
+			DetailDto tem = new DetailDto(q.getDetailName());
 			List<KdQuestion> list = qmap.get(tem);
 			if (list == null) {
 				list = new ArrayList<>();
@@ -389,70 +396,79 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 		}
 
 		for (KdQuestion q : qs) {
-			if (QuesStructType.SINGLE_ANSWER_QUESTION.equals(q.getQuesStructType())) {
-				List<KdQuesOption> ops = new ArrayList<>();
-				q.setOptions(ops);
-				int num = 0;
-				int answerCount = 0;
-				for (Answer a : map.get(q.getId())) {
-					num++;
-					KdQuesOption op = new KdQuesOption();
-					ops.add(op);
-					op.setNumber(num);
-					op.setBody(a.getBody());
-					op.setSelect(a.getRight() == 1);
-					if (op.getSelect()) {
-						q.setAnswer(getOptionNum(num));
-						answerCount++;
-					}
-				}
-				if (answerCount == 0) {
-					throw new StatusException("没有答案:" + q.getId());
+			setAnswer(map, q);
+			if(QuesStructType.NESTED_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+				for(KdQuestion subq:q.getSubQuestions()) {
+					setAnswer(map, subq);
 				}
-				if (answerCount > 1) {
-					throw new StatusException("答案过多:" + q.getId());
-				}
-			} else if (QuesStructType.MULTIPLE_ANSWER_QUESTION.equals(q.getQuesStructType())) {
-				List<String> as = new ArrayList<>();
-				List<KdQuesOption> ops = new ArrayList<>();
-				q.setOptions(ops);
-				int num = 0;
-				int answerCount = 0;
-				for (Answer a : map.get(q.getId())) {
-					num++;
-					KdQuesOption op = new KdQuesOption();
-					ops.add(op);
-					op.setNumber(num);
-					op.setBody(a.getBody());
-					op.setSelect(a.getRight() == 1);
-					if (op.getSelect()) {
-						as.add(getOptionNum(num));
-						answerCount++;
-					}
-				}
-				if (answerCount == 0) {
-					throw new StatusException("没有答案" + q.getId());
+			}
+		}
+	}
+	
+	private void setAnswer(Map<Integer, List<Answer>> map,KdQuestion q) {
+		if (QuesStructType.SINGLE_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+			List<KdQuesOption> ops = new ArrayList<>();
+			q.setOptions(ops);
+			int num = 0;
+			int answerCount = 0;
+			for (Answer a : map.get(q.getId())) {
+				num++;
+				KdQuesOption op = new KdQuesOption();
+				ops.add(op);
+				op.setNumber(num);
+				op.setBody(a.getBody());
+				op.setSelect(a.getRight() == 1);
+				if (op.getSelect()) {
+					q.setAnswer(getOptionNum(num));
+					answerCount++;
 				}
-				if (answerCount == 1) {
-					throw new StatusException("答案只有一个:" + q.getId());
+			}
+			if (answerCount == 0) {
+				throw new StatusException("没有答案:" + q.getId());
+			}
+			if (answerCount > 1) {
+				throw new StatusException("答案过多:" + q.getId());
+			}
+		} else if (QuesStructType.MULTIPLE_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+			List<String> as = new ArrayList<>();
+			List<KdQuesOption> ops = new ArrayList<>();
+			q.setOptions(ops);
+			int num = 0;
+			int answerCount = 0;
+			for (Answer a : map.get(q.getId())) {
+				num++;
+				KdQuesOption op = new KdQuesOption();
+				ops.add(op);
+				op.setNumber(num);
+				op.setBody(a.getBody());
+				op.setSelect(a.getRight() == 1);
+				if (op.getSelect()) {
+					as.add(getOptionNum(num));
+					answerCount++;
 				}
-				q.setAnswer(StringUtils.join(as, ","));
-			} else if (QuesStructType.BOOL_ANSWER_QUESTION.equals(q.getQuesStructType())) {
-				for (Answer a : map.get(q.getId())) {
-					if (a.getRight() == 1) {
-						q.setAnswer(getBool(a.getBody()));
-					}
+			}
+			if (answerCount == 0) {
+				throw new StatusException("没有答案" + q.getId());
+			}
+			if (answerCount == 1) {
+				throw new StatusException("答案只有一个:" + q.getId());
+			}
+			q.setAnswer(StringUtils.join(as, ","));
+		} else if (QuesStructType.BOOL_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+			for (Answer a : map.get(q.getId())) {
+				if (a.getRight() == 1) {
+					q.setAnswer(getBool(a.getBody()));
 				}
+			}
 
-			} else {
-				StringBuilder sb = new StringBuilder();
-				if (CollectionUtils.isNotEmpty(map.get(q.getId()))) {
-					for (Answer a : map.get(q.getId())) {
-						sb.append(a.getBody());
-					}
+		} else {
+			StringBuilder sb = new StringBuilder();
+			if (CollectionUtils.isNotEmpty(map.get(q.getId()))) {
+				for (Answer a : map.get(q.getId())) {
+					sb.append(a.getBody());
 				}
-				q.setAnswer(sb.toString());
 			}
+			q.setAnswer(sb.toString());
 		}
 	}
 
@@ -472,7 +488,21 @@ public class MyConsumer extends Consumer<PaperExportDto> {
 
 	private List<Answer> getAnswerBatch(Connection connect, List<KdQuestion> qs) {
 		List<Answer> as = new ArrayList<>();
-		List<Integer> ids = qs.stream().map(e -> e.getId()).collect(Collectors.toList());
+		List<Integer> ids = new ArrayList<>();
+		for(KdQuestion q:qs) {
+			if(q.getId()==null) {
+				throw new StatusException("s" + q.getId());
+			}
+			ids.add(q.getId());
+			if(QuesStructType.NESTED_ANSWER_QUESTION.equals(q.getQuesStructType())) {
+				for(KdQuestion subq:q.getSubQuestions()) {
+					if(subq.getId()==null) {
+						throw new StatusException("s" + subq.getId());
+					}
+					ids.add(subq.getId());
+				}
+			}
+		}
 		String idsstr = StringUtils.join(ids, ",");
 		PreparedStatement preState = null;
 		ResultSet resultSet = null;