|
@@ -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;
|