|
@@ -2,8 +2,6 @@ package cn.com.qmth.export;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.net.URLDecoder;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
|
@@ -11,60 +9,41 @@ import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.UUID;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
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;
|
|
|
+public class MyConsumer extends Consumer<Course> {
|
|
|
+ private static String paperSuff = "(230517)";
|
|
|
+ private int maxqc = 200;
|
|
|
|
|
|
- private String excelDir = "D:\\kd_export\\";
|
|
|
- private String picFiles = "D:\\files\\";
|
|
|
+ private static String paperDir = "d:/yunkai/paper/";
|
|
|
|
|
|
- private Pattern mp3Pat = Pattern.compile("<a[^<]+href=\"([^<\"]+\\.mp3)\"[^<]*>[^<]*</a>");
|
|
|
private Pattern imgPat = Pattern.compile("<img[^<]+src=\"([^<\"]+)\"[^<]*>");
|
|
|
|
|
|
- private Pattern notmp3Pat = Pattern.compile("<a[^<]+href=\"[^<\"]+(?!\\.mp3)\"[^<]*>([^<]*)</a>");
|
|
|
-
|
|
|
- private List<String> qdb = new ArrayList<>();
|
|
|
- private List<String> qzip = new ArrayList<>();
|
|
|
- private List<String> adb = new ArrayList<>();
|
|
|
- private List<String> azip = new ArrayList<>();
|
|
|
- private List<String> http = new ArrayList<>();
|
|
|
- private List<String> file = new ArrayList<>();
|
|
|
-
|
|
|
- private Set<String> noques = new HashSet<>();
|
|
|
-
|
|
|
- private Set<Long> invalidAnswerCode = new HashSet<>();
|
|
|
-
|
|
|
@Override
|
|
|
- public void consume(String code) {
|
|
|
+ public void consume(Course course) {
|
|
|
Connection connect = null;
|
|
|
-
|
|
|
+ File sub = new File(paperDir + course.getId() + "/");
|
|
|
+ sub.mkdir();
|
|
|
try {
|
|
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
|
|
|
|
|
- String url = "jdbc:mysql://210.38.32.28:3306/moodle_question?serverTimezone=GMT%2B8";
|
|
|
+ String url = "jdbc:mysql://localhost:3306/yunkai_question?serverTimezone=GMT%2B8";
|
|
|
|
|
|
- String user = "questionreader";
|
|
|
+ String user = "root";
|
|
|
|
|
|
- String password = "xhhG88tdsk4Rvbgd";
|
|
|
+ String password = "123456";
|
|
|
connect = DriverManager.getConnection(url, user, password);
|
|
|
- exportPaper(connect, code);
|
|
|
+ exportPaper(connect, course);
|
|
|
ExportByCourseCode.addDisposeCount();
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
@@ -78,27 +57,32 @@ public class MyConsumer extends Consumer<String> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Course getCourse(Connection connect, String code) throws SQLException, IOException {
|
|
|
- Course c = new Course();
|
|
|
+ private List<KdQuestion> getQuestion(Connection connect, Course course) throws SQLException, IOException {
|
|
|
+ List<KdQuestion> qs = new ArrayList<>();
|
|
|
PreparedStatement preState = null;
|
|
|
ResultSet resultSet = null;
|
|
|
try {
|
|
|
- String sql = "select * from mdl_course where idnumber like '" + code + "_%';";
|
|
|
+ String sql = " select q.id,q.question_type,q.topic,q.difficulty,q.answer "
|
|
|
+ + " from wq_question_bank_subject t " + " left join wq_question_bank b on t.question_bank_id=b.id "
|
|
|
+ + " left join wq_question_question_bank f on t.question_bank_id=f.question_bank_id "
|
|
|
+ + " left join wq_question q on f.question_id=q.id " + " where t.subject_id=" + course.getId()
|
|
|
+ + " and b.rent_id=811 and b.is_deleted=0 " + " and q.is_deleted=0 and q.rent_id=811 ";
|
|
|
+
|
|
|
preState = connect.prepareStatement(sql);
|
|
|
|
|
|
resultSet = preState.executeQuery();
|
|
|
- int count = 0;
|
|
|
+
|
|
|
while (resultSet.next()) {
|
|
|
- count++;
|
|
|
- if (count > 1) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- c.setId(resultSet.getLong("id"));
|
|
|
- c.setName(resultSet.getString("shortname"));
|
|
|
- c.setIdnumber(resultSet.getString("idnumber"));
|
|
|
- c.setCode(code);
|
|
|
+ KdQuestion q = new KdQuestion();
|
|
|
+ q.setId(resultSet.getLong("id"));
|
|
|
+ q.setBody(disposeImg(resultSet.getString("topic"), course.getId()));
|
|
|
+ q.setQst(YunkaiQuesStructType.getByYunKaiType(resultSet.getInt("question_type")));
|
|
|
+ q.setDifficulty(YunkaiDifficulty.getByYunKaiType(resultSet.getInt("difficulty")));
|
|
|
+ q.setAnswer(disposeImg(resultSet.getString("answer"), course.getId()));
|
|
|
+ q.setObjective(q.getQst().isObjective());
|
|
|
+ qs.add(q);
|
|
|
}
|
|
|
- return c;
|
|
|
+ return qs;
|
|
|
} finally {
|
|
|
if (resultSet != null) {
|
|
|
resultSet.close();
|
|
@@ -109,231 +93,282 @@ public class MyConsumer extends Consumer<String> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<Long> getContextIds(Connection connect, Long courseId) throws SQLException, IOException {
|
|
|
- List<Long> ids = new ArrayList<>();
|
|
|
- PreparedStatement preState = null;
|
|
|
- ResultSet resultSet = null;
|
|
|
- try {
|
|
|
- String sql = "select * from mdl_context where instanceid =" + courseId
|
|
|
- + " and contextlevel=50 order by id ";
|
|
|
- preState = connect.prepareStatement(sql);
|
|
|
+ private String disposeImg(String str, Long subid) {
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ StringBuffer sb = new StringBuffer("");
|
|
|
+ Matcher matcher = imgPat.matcher(str);
|
|
|
|
|
|
- resultSet = preState.executeQuery();
|
|
|
+ while (matcher.find()) {
|
|
|
+ String imgSrc = matcher.group(1).trim();
|
|
|
+ String suff = imgSrc.substring(imgSrc.lastIndexOf(".") + 1).toLowerCase();
|
|
|
+ File img = new File(paperDir + subid + "/" + UUID.randomUUID() + "." + suff);
|
|
|
+ FileUtil.saveUrlAs(imgSrc, img.getAbsolutePath());
|
|
|
+ String base64 = FileUtil.fileToBase64Src(img);
|
|
|
+ matcher.appendReplacement(sb, base64);
|
|
|
+ }
|
|
|
|
|
|
- while (resultSet.next()) {
|
|
|
- ids.add(resultSet.getLong("id"));
|
|
|
- }
|
|
|
- return ids;
|
|
|
- } finally {
|
|
|
- if (resultSet != null) {
|
|
|
- resultSet.close();
|
|
|
- }
|
|
|
- if (preState != null) {
|
|
|
- preState.close();
|
|
|
- }
|
|
|
+ if (StringUtils.isEmpty(sb.toString())) {
|
|
|
+ return str;
|
|
|
+ } else {
|
|
|
+ matcher.appendTail(sb);
|
|
|
+ return sb.toString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<Long> getQuestionCategorie(Connection connect, List<Long> cids) throws SQLException, IOException {
|
|
|
- List<Long> ids = new ArrayList<>();
|
|
|
+ private List<QuestionProp> getQuestionProp(Connection connect, List<KdQuestion> qs) {
|
|
|
+ List<QuestionProp> as = new ArrayList<>();
|
|
|
+ List<Long> ids = qs.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
|
+ String idsstr = StringUtils.join(ids, ",");
|
|
|
PreparedStatement preState = null;
|
|
|
ResultSet resultSet = null;
|
|
|
try {
|
|
|
- String sql = "select * from mdl_question_categories where contextid in (" + getInStr(cids)
|
|
|
- + ") order by id ";
|
|
|
+ String sql = " select t.knowledge_system_id,t.question_id " + " from wq_question_knowledge_system t "
|
|
|
+ + " where t.question_id in (" + idsstr + ") ";
|
|
|
preState = connect.prepareStatement(sql);
|
|
|
|
|
|
resultSet = preState.executeQuery();
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
- ids.add(resultSet.getLong("id"));
|
|
|
+ QuestionProp a = new QuestionProp();
|
|
|
+ a.setKnowledgeId(resultSet.getLong("knowledge_system_id"));
|
|
|
+ a.setQuestionId(resultSet.getLong("question_id"));
|
|
|
+ as.add(a);
|
|
|
}
|
|
|
- return ids;
|
|
|
+ return as;
|
|
|
+ } catch (Exception e1) {
|
|
|
+ throw new RuntimeException(e1);
|
|
|
} finally {
|
|
|
if (resultSet != null) {
|
|
|
- resultSet.close();
|
|
|
+ try {
|
|
|
+ resultSet.close();
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ }
|
|
|
}
|
|
|
if (preState != null) {
|
|
|
- preState.close();
|
|
|
+ try {
|
|
|
+ preState.close();
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<KdQuestion> getQuestion(Connection connect, List<Long> qcids) throws SQLException, IOException {
|
|
|
- List<KdQuestion> qs = new ArrayList<>();
|
|
|
- PreparedStatement preState = null;
|
|
|
- ResultSet resultSet = null;
|
|
|
- try {
|
|
|
- String sql = "SELECT f.* FROM mdl_question f WHERE category IN (" + getInStr(qcids)
|
|
|
- + ") AND f.qtype IN ('multichoice','truefalse','multichoiceset') ";
|
|
|
-// + ") AND f.qtype = 'multichoiceset' ";
|
|
|
-
|
|
|
- preState = connect.prepareStatement(sql);
|
|
|
+ private void fillProp(Connection connect, List<KdQuestion> qs) {
|
|
|
+ List<QuestionProp> qps = new BatchGetDataUtil<QuestionProp, KdQuestion>() {
|
|
|
|
|
|
- resultSet = preState.executeQuery();
|
|
|
+ @Override
|
|
|
+ protected List<QuestionProp> getData(List<KdQuestion> paramList) {
|
|
|
+ return getQuestionProp(connect, paramList);
|
|
|
+ }
|
|
|
+ }.getDataForBatch(qs, 200);
|
|
|
+ if (CollectionUtils.isEmpty(qps)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, KdQuestion> map = new HashMap<>();
|
|
|
+ for (KdQuestion q : qs) {
|
|
|
+ map.put(q.getId(), q);
|
|
|
+ }
|
|
|
+ for (QuestionProp qp : qps) {
|
|
|
+ KdQuestion q = map.get(qp.getQuestionId());
|
|
|
+ List<Long> qpids = q.getPropIds();
|
|
|
+ if (qpids == null) {
|
|
|
+ qpids = new ArrayList<>();
|
|
|
+ q.setPropIds(qpids);
|
|
|
+ }
|
|
|
+ qpids.add(qp.getKnowledgeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- while (resultSet.next()) {
|
|
|
- KdQuestion q = new KdQuestion();
|
|
|
- q.setId(resultSet.getLong("id"));
|
|
|
- q.setBody(disBody(resultSet.getString("questiontext")));
|
|
|
- q.setQtype(resultSet.getString("qtype"));
|
|
|
- q.setObjective(true);
|
|
|
- qs.add(q);
|
|
|
+ private void fillAnswer(Connection connect, List<KdQuestion> qs, Course course) {
|
|
|
+ List<Answer> qps = new BatchGetDataUtil<Answer, KdQuestion>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected List<Answer> getData(List<KdQuestion> paramList) {
|
|
|
+ return getAnswerBatch(connect, paramList, course);
|
|
|
}
|
|
|
- return qs;
|
|
|
- } finally {
|
|
|
- if (resultSet != null) {
|
|
|
- resultSet.close();
|
|
|
+ }.getDataForBatch(qs, 200);
|
|
|
+ if (CollectionUtils.isEmpty(qps)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, List<Answer>> map = new HashMap<>();
|
|
|
+ for (Answer qp : qps) {
|
|
|
+ List<Answer> list = map.get(qp.getQuestionId());
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ map.put(qp.getQuestionId(), list);
|
|
|
}
|
|
|
- if (preState != null) {
|
|
|
- preState.close();
|
|
|
+ list.add(qp);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdQuestion q : qs) {
|
|
|
+ if (YunkaiQuesStructType.DANXUAN.equals(q.getQst())) {
|
|
|
+ List<KdQuesOption> ops = new ArrayList<>();
|
|
|
+ q.setOptions(ops);
|
|
|
+ int num = 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (YunkaiQuesStructType.DUOXUAN.equals(q.getQst())
|
|
|
+ || YunkaiQuesStructType.BUDINGXIANG.equals(q.getQst())) {
|
|
|
+ List<String> as = new ArrayList<>();
|
|
|
+ List<KdQuesOption> ops = new ArrayList<>();
|
|
|
+ q.setOptions(ops);
|
|
|
+ int num = 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ q.setAnswer(StringUtils.join(as, ","));
|
|
|
+ } else if (YunkaiQuesStructType.PANDUAN.equals(q.getQst())) {
|
|
|
+ for (Answer a : map.get(q.getId())) {
|
|
|
+ if (a.getRight() == 1) {
|
|
|
+ }
|
|
|
+ q.setAnswer(getBool(a.getBody()));
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (YunkaiQuesStructType.TIANKONGTI.equals(q.getQst())) {
|
|
|
+ q.setBody(relaceQuestionIdx(q.getBody()));
|
|
|
+ if (map.get(q.getId()) != null) {
|
|
|
+ List<String> as = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ for (Answer a : map.get(q.getId())) {
|
|
|
+ if (a.getRight() == 1) {
|
|
|
+ as.add(a.getBody());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ q.setAnswer(StringUtils.join(as, "##"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // nothing
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<Answer> getAnswer(Connection connect, KdQuestion q) throws SQLException, IOException {
|
|
|
+ private String relaceQuestionIdx(String str) {
|
|
|
+ StringBuffer sb = new StringBuffer("");
|
|
|
+ Pattern pattern = Pattern.compile("__(\\d+)__");
|
|
|
+
|
|
|
+ Matcher matcher = pattern.matcher(str);
|
|
|
+
|
|
|
+ while (matcher.find()) {
|
|
|
+ matcher.appendReplacement(sb, "###");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(sb.toString())) {
|
|
|
+ return str;
|
|
|
+ } else {
|
|
|
+ matcher.appendTail(sb);
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将数字1,2,3,4转化成A,B,C,D
|
|
|
+ *
|
|
|
+ * @param number
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getOptionNum(int number) {
|
|
|
+ char optionNum = (char) (65 + number);
|
|
|
+ return String.valueOf(optionNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getBool(String bu) {
|
|
|
+ if (bu.contains("对")) {
|
|
|
+ return "正确";
|
|
|
+ } else {
|
|
|
+ return "错误";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Answer> getAnswerBatch(Connection connect, List<KdQuestion> qs, Course course) {
|
|
|
List<Answer> as = new ArrayList<>();
|
|
|
+ List<Long> ids = qs.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
|
+ String idsstr = StringUtils.join(ids, ",");
|
|
|
PreparedStatement preState = null;
|
|
|
ResultSet resultSet = null;
|
|
|
try {
|
|
|
- String sql = "select * from mdl_question_answers where question =" + q.getId();
|
|
|
+ String sql = " select t.question_id,t.answer_text,t.is_right " + " from wq_question_answer_item t "
|
|
|
+ + " where t.question_id in (" + idsstr + ") " + " order by t.question_id,t.sequence ";
|
|
|
preState = connect.prepareStatement(sql);
|
|
|
|
|
|
resultSet = preState.executeQuery();
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
Answer a = new Answer();
|
|
|
- a.setId(resultSet.getLong("id"));
|
|
|
- a.setBody(resultSet.getString("answer"));
|
|
|
- a.setScore(resultSet.getDouble("fraction"));
|
|
|
+ a.setBody(disposeImg(resultSet.getString("answer_text"), course.getId()));
|
|
|
+ a.setRight(resultSet.getInt("is_right"));
|
|
|
+ a.setQuestionId(resultSet.getLong("question_id"));
|
|
|
as.add(a);
|
|
|
}
|
|
|
return as;
|
|
|
+ } catch (Exception e1) {
|
|
|
+ throw new RuntimeException(e1);
|
|
|
} finally {
|
|
|
if (resultSet != null) {
|
|
|
- resultSet.close();
|
|
|
+ try {
|
|
|
+ resultSet.close();
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ }
|
|
|
}
|
|
|
if (preState != null) {
|
|
|
- preState.close();
|
|
|
+ try {
|
|
|
+ preState.close();
|
|
|
+ } catch (SQLException e1) {
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void exportPaper(Connection connect, String code) throws Exception {
|
|
|
- Course c = getCourse(connect, code);
|
|
|
- if (c == null) {
|
|
|
- noques.add(code);
|
|
|
- return;
|
|
|
- }
|
|
|
- List<Long> ctids = getContextIds(connect, c.getId());
|
|
|
- if (ctids.size() == 0) {
|
|
|
- noques.add(code);
|
|
|
- return;
|
|
|
- }
|
|
|
- List<Long> qcids = getQuestionCategorie(connect, ctids);
|
|
|
- if (qcids.size() == 0) {
|
|
|
- noques.add(code);
|
|
|
- return;
|
|
|
- }
|
|
|
- List<KdQuestion> qs = getQuestion(connect, qcids);
|
|
|
+ private void exportPaper(Connection connect, Course course) throws Exception {
|
|
|
+ List<KdQuestion> qs = getQuestion(connect, course);
|
|
|
if (qs.size() == 0) {
|
|
|
- noques.add(code);
|
|
|
return;
|
|
|
}
|
|
|
- for (KdQuestion q : qs) {
|
|
|
- List<Answer> as = getAnswer(connect, q);
|
|
|
- disposeAnswer(q, as);
|
|
|
- }
|
|
|
+ fillProp(connect, qs);
|
|
|
+ fillAnswer(connect, qs, course);
|
|
|
|
|
|
- qs = removeInvalidQuestion(qs, code);
|
|
|
- if (qs.size() == 0) {
|
|
|
- noques.add(code);
|
|
|
- return;
|
|
|
- }
|
|
|
- File courseCode = new File(excelDir + c.getCode() + "\\");
|
|
|
- courseCode.mkdirs();
|
|
|
- File att = new File(excelDir + c.getCode() + "\\att\\");
|
|
|
- att.mkdirs();
|
|
|
+ Map<YunkaiQuesStructType, List<KdQuestion>> qmap = new HashMap<>();
|
|
|
for (KdQuestion q : qs) {
|
|
|
- try {
|
|
|
- disposeMedia(connect, c.getIdnumber(), q, att);
|
|
|
- q.setValid(true);
|
|
|
- } catch (MediaNotFoundException e) {
|
|
|
- q.setValid(false);
|
|
|
+ List<KdQuestion> list = qmap.get(q.getQst());
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ qmap.put(q.getQst(), list);
|
|
|
}
|
|
|
+ list.add(q);
|
|
|
}
|
|
|
- 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<>();
|
|
|
- List<KdQuestion> muti = new ArrayList<>();
|
|
|
- List<KdQuestion> boo = new ArrayList<>();
|
|
|
- for (KdQuestion q : qs) {
|
|
|
- if (q.getStructType() == 1) {
|
|
|
- single.add(q);
|
|
|
- } else if (q.getStructType() == 2) {
|
|
|
- muti.add(q);
|
|
|
- } else if (q.getStructType() == 3) {
|
|
|
- boo.add(q);
|
|
|
- }
|
|
|
+ for (YunkaiQuesStructType qt : qmap.keySet()) {
|
|
|
+ createPapers(qmap.get(qt), qt, course);
|
|
|
}
|
|
|
- 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));
|
|
|
}
|
|
|
|
|
|
- private void createPapers(List<KdQuestion> qs, Course c, int structType) throws IOException {
|
|
|
+ private void createPapers(List<KdQuestion> qs, YunkaiQuesStructType qt, Course course) {
|
|
|
if (qs == null || qs.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
if (qs.size() <= maxqc) {
|
|
|
- createPaper(qs, c, structType, 1);
|
|
|
+ createPaper(qs, qt, course, 1);
|
|
|
} else {
|
|
|
int size = qs.size();
|
|
|
int len = maxqc;
|
|
@@ -341,28 +376,21 @@ public class MyConsumer extends Consumer<String> {
|
|
|
|
|
|
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);
|
|
|
+ createPaper(subList, qt, course, i + 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void createPaper(List<KdQuestion> qs, Course c, int structType, int indx) throws IOException {
|
|
|
+ private void createPaper(List<KdQuestion> qs, YunkaiQuesStructType qt, Course course, int indx) {
|
|
|
if (qs.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
- String detailName="";
|
|
|
- if (structType == 1) {
|
|
|
- detailName="单选题";
|
|
|
- } else if (structType == 2) {
|
|
|
- detailName="多选题";
|
|
|
- } else if (structType == 3) {
|
|
|
- detailName="判断题";
|
|
|
- }
|
|
|
+ String detailName = qt.getYunKaiDesc();
|
|
|
KdPaper paper = new KdPaper();
|
|
|
paper.setTotalScore((double) qs.size());
|
|
|
- paper.setName(c.getName()+paperSuff+detailName+"_"+indx);
|
|
|
- paper.setCourseCode(c.getCode());
|
|
|
+ paper.setName(course.getName() + paperSuff + detailName + "_" + indx);
|
|
|
+ paper.setCourseCode(course.getCode());
|
|
|
List<KdDetail> des = new ArrayList<>();
|
|
|
KdDetail d = new KdDetail();
|
|
|
d.setName(detailName);
|
|
@@ -373,472 +401,17 @@ public class MyConsumer extends Consumer<String> {
|
|
|
des.add(d);
|
|
|
paper.setDetails(des);
|
|
|
paper.setDetailCount(1);
|
|
|
- File paperdir = new File(excelDir + c.getCode() + "\\paper"+structType+"_"+indx+"\\");
|
|
|
+ File paperdir = new File(paperDir + course.getId() + "/" + qt.getYunKaiType() + "/");
|
|
|
paperdir.mkdirs();
|
|
|
- FileUtil.writeFile(paperdir.getAbsolutePath(), "\\paper.json", JSONObject.toJSONString(paper));
|
|
|
- }
|
|
|
-
|
|
|
- private List<KdQuestion> removeInvalidQuestion(List<KdQuestion> qs, String courseCode) {
|
|
|
- List<KdQuestion> ret = new ArrayList<>();
|
|
|
- for (KdQuestion q : qs) {
|
|
|
- if (StringUtils.isBlank(q.getAnswer())) {
|
|
|
- invalidAnswerCode.add(q.getId());
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (isEmpty(q.getBody())) {
|
|
|
- invalidAnswerCode.add(q.getId());
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (q.getStructType() == 1 || q.getStructType() == 2) {
|
|
|
- if (!checkQuestionAndRemoveInvalidOption(q)) {
|
|
|
- invalidAnswerCode.add(q.getId());
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- ret.add(q);
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean checkQuestionAndRemoveInvalidOption(KdQuestion q) {
|
|
|
- List<KdQuesOption> ret = new ArrayList<>();
|
|
|
- for (KdQuesOption op : q.getOptions()) {
|
|
|
- if (isEmpty(op.getBody())) {
|
|
|
- if (op.getSelect()) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- ret.add(op);
|
|
|
- }
|
|
|
- }
|
|
|
- if (ret.size() < 2) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- q.setOptions(ret);
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private void disposeAnswer(KdQuestion q, List<Answer> as) {
|
|
|
- if (CollectionUtils.isEmpty(as)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if ("truefalse".equals(q.getQtype())) {
|
|
|
- q.setStructType(3);
|
|
|
- for (Answer a : as) {
|
|
|
- if (a.getScore() > 0) {
|
|
|
- q.setAnswer("对".equals(a.getBody().trim()) ? "true" : "false");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- int index = 0;
|
|
|
- List<KdQuesOption> ops = new ArrayList<>();
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- for (Answer a : as) {
|
|
|
- index++;
|
|
|
- KdQuesOption op = new KdQuesOption();
|
|
|
- op.setAnswerId(a.getId());
|
|
|
- op.setNumber(index);
|
|
|
- op.setBody(disBody(a.getBody()));
|
|
|
- if (a.getScore() > 0) {
|
|
|
- op.setSelect(true);
|
|
|
- sb.append(index).append(",");
|
|
|
- } else {
|
|
|
- op.setSelect(false);
|
|
|
- }
|
|
|
- ops.add(op);
|
|
|
- }
|
|
|
- q.setOptions(ops);
|
|
|
- if (sb.length() > 0) {
|
|
|
- sb.deleteCharAt(sb.length() - 1);
|
|
|
- }
|
|
|
- if (sb.indexOf(",") > 0) {
|
|
|
- q.setStructType(2);
|
|
|
- } else {
|
|
|
- q.setStructType(1);
|
|
|
- }
|
|
|
- q.setAnswer(sb.toString());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- return b.html();
|
|
|
- }
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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();
|
|
|
-
|
|
|
- Map<String, String> imgs = findAllImg(body, q.getId(), null, courseidnumber);
|
|
|
- if (imgs.size() > 0) {
|
|
|
- for (String k : imgs.keySet()) {
|
|
|
- String img = imgs.get(k);
|
|
|
- String fileName = getFileName(img);
|
|
|
- File file = getQuestionFile(connect, q.getId(), courseidnumber, fileName);
|
|
|
- if (file == null) {
|
|
|
- ExportByCourseCode.addNotFd();
|
|
|
-// body = body.replaceAll(k, "[未找到图片文件]");
|
|
|
- throw new MediaNotFoundException();
|
|
|
- } else {
|
|
|
- ExportByCourseCode.addFd();
|
|
|
- body = body.replaceAll(img.replaceAll("\\?", "\\\\?"), FileUtil.fileToBase64Src(file));
|
|
|
- }
|
|
|
- }
|
|
|
- q.setBody(body);
|
|
|
- }
|
|
|
- Map<String, String> audios = findAllAudio(body, q.getId(), null, courseidnumber);
|
|
|
- if (audios.size() > 0) {
|
|
|
- q.setHaveAudio(true);
|
|
|
- for (String k : audios.keySet()) {
|
|
|
- String val = audios.get(k);
|
|
|
- String fileName = getFileName(val);
|
|
|
- File file = getQuestionFile(connect, q.getId(), courseidnumber, fileName);
|
|
|
- if (file == null) {
|
|
|
- ExportByCourseCode.addNotFd();
|
|
|
-// 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.replaceAll("\\?", "\\\\?"), "<a id=\"" + file.getName() + "\" name=\"" + file.getName() + "\"></a>");
|
|
|
- }
|
|
|
- }
|
|
|
- q.setBody(body);
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtils.isNotEmpty(q.getOptions())) {
|
|
|
- for (KdQuesOption o : q.getOptions()) {
|
|
|
- String obody = o.getBody();
|
|
|
-
|
|
|
- Map<String, String> oimgs = findAllImg(obody, null, o.getAnswerId(), courseidnumber);
|
|
|
- if (oimgs.size() > 0) {
|
|
|
- for (String k : oimgs.keySet()) {
|
|
|
- String img = oimgs.get(k);
|
|
|
- String fileName = getFileName(img);
|
|
|
- File file = getAnswerFile(connect, o.getAnswerId(), courseidnumber, fileName);
|
|
|
- if (file == null) {
|
|
|
- ExportByCourseCode.addNotFd();
|
|
|
-// obody = obody.replaceAll(k, "[未找到图片文件]");
|
|
|
- throw new MediaNotFoundException();
|
|
|
- } else {
|
|
|
- ExportByCourseCode.addFd();
|
|
|
- obody = obody.replaceAll(img.replaceAll("\\?", "\\\\?"), FileUtil.fileToBase64Src(file));
|
|
|
- }
|
|
|
- }
|
|
|
- o.setBody(obody);
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, String> oaudios = findAllAudio(obody, null, o.getAnswerId(), courseidnumber);
|
|
|
- if (oaudios.size() > 0) {
|
|
|
- q.setHaveAudio(true);
|
|
|
- for (String k : oaudios.keySet()) {
|
|
|
- String val = oaudios.get(k);
|
|
|
- String fileName = getFileName(val);
|
|
|
- File file = getAnswerFile(connect, o.getAnswerId(), courseidnumber, fileName);
|
|
|
- if (file == null) {
|
|
|
- ExportByCourseCode.addNotFd();
|
|
|
-// 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.replaceAll("\\?", "\\\\?"),
|
|
|
- "<a id=\"" + file.getName() + "\" name=\"" + file.getName() + "\"></a>");
|
|
|
- }
|
|
|
- }
|
|
|
- o.setBody(obody);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String, String> findAllImg(String body, Long qid, Long aid, String courseidnumber) {
|
|
|
- Map<String, String> set = new HashMap<>();
|
|
|
- Matcher m = imgPat.matcher(body);
|
|
|
- while (m.find()) {
|
|
|
- String f = m.group(1);
|
|
|
- if (f.startsWith("file:") || f.startsWith("FILE:")) {
|
|
|
- if (qid != null)
|
|
|
- file.add("questionid:" + qid + " " + courseidnumber + " " + f);
|
|
|
- if (aid != null)
|
|
|
- file.add("answerId:" + aid + " " + courseidnumber + " " + f);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (f.startsWith("http:") || f.startsWith("HTTP:")) {
|
|
|
- if (qid != null)
|
|
|
- http.add("questionid:" + qid + " " + courseidnumber + " " + f);
|
|
|
- if (aid != null)
|
|
|
- http.add("answerId:" + aid + " " + courseidnumber + " " + f);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (!f.startsWith("data:image")) {
|
|
|
- set.put(m.group(), f);
|
|
|
- }
|
|
|
- }
|
|
|
- return set;
|
|
|
- }
|
|
|
-
|
|
|
- private Map<String, String> findAllAudio(String body, Long qid, Long aid, String courseidnumber) {
|
|
|
- Map<String, String> set = new HashMap<>();
|
|
|
- Matcher m = mp3Pat.matcher(body);
|
|
|
- while (m.find()) {
|
|
|
- String f = m.group(1);
|
|
|
- if (f.startsWith("file:") || f.startsWith("FILE:")) {
|
|
|
- if (qid != null)
|
|
|
- file.add("questionid:" + qid + " " + courseidnumber + " " + f);
|
|
|
- if (aid != null)
|
|
|
- file.add("answerId:" + aid + " " + courseidnumber + " " + f);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (f.startsWith("http:") || f.startsWith("HTTP:")) {
|
|
|
- if (qid != null)
|
|
|
- http.add("questionid:" + qid + " " + courseidnumber + " " + f);
|
|
|
- if (aid != null)
|
|
|
- http.add("answerId:" + aid + " " + courseidnumber + " " + f);
|
|
|
- continue;
|
|
|
- }
|
|
|
- set.put(m.group(), f);
|
|
|
- }
|
|
|
- return set;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean hasImg(String body) {
|
|
|
- Matcher m = imgPat.matcher(body);
|
|
|
- while (m.find()) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean hasAudio(String body) {
|
|
|
- Matcher m = mp3Pat.matcher(body);
|
|
|
- while (m.find()) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- private boolean isEmpty(String html) {
|
|
|
- if (StringUtils.isBlank(html)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- if (hasImg(html) || hasAudio(html)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- Document doc = Jsoup.parse(html);
|
|
|
- Element b = doc.body();
|
|
|
- if (StringUtils.isBlank(b.wholeText())) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String getFileName(String s) throws UnsupportedEncodingException {
|
|
|
- int end = s.length();
|
|
|
- int f = s.indexOf("?");
|
|
|
- if (f != -1) {
|
|
|
- end = f;
|
|
|
- }
|
|
|
- return URLDecoder.decode(s.substring(s.lastIndexOf("/") + 1, end), "utf-8");
|
|
|
- }
|
|
|
-
|
|
|
- private File getQuestionFile(Connection connect, Long quesId, String courseidnumber, String fileName)
|
|
|
- throws Exception {
|
|
|
- PreparedStatement preState = null;
|
|
|
- ResultSet resultSet = null;
|
|
|
try {
|
|
|
- String hash = null;
|
|
|
- String sql = " select * from mdl_files where itemid = " + quesId + " and source='" + fileName
|
|
|
- + "' and component = 'question' and filearea = 'questiontext' ";
|
|
|
- preState = connect.prepareStatement(sql);
|
|
|
-
|
|
|
- resultSet = preState.executeQuery();
|
|
|
-
|
|
|
- while (resultSet.next()) {
|
|
|
- hash = resultSet.getString("contenthash");
|
|
|
- break;
|
|
|
- }
|
|
|
- if (hash == null) {
|
|
|
- qdb.add(quesId + " " + courseidnumber + " " + fileName);
|
|
|
- return null;
|
|
|
- }
|
|
|
- String suff = fileName.substring(fileName.lastIndexOf("."));
|
|
|
- File file = new File(picFiles + courseidnumber + "\\" + hash + suff);
|
|
|
- if (!file.exists()) {
|
|
|
- qzip.add(quesId + " " + courseidnumber + " " + fileName);
|
|
|
- return null;
|
|
|
- }
|
|
|
- return file;
|
|
|
- } finally {
|
|
|
- if (resultSet != null) {
|
|
|
- resultSet.close();
|
|
|
- }
|
|
|
- if (preState != null) {
|
|
|
- preState.close();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private File getAnswerFile(Connection connect, Long answerId, String courseidnumber, String fileName)
|
|
|
- throws Exception {
|
|
|
- PreparedStatement preState = null;
|
|
|
- ResultSet resultSet = null;
|
|
|
- try {
|
|
|
- String hash = null;
|
|
|
- String sql = " select * from mdl_files where itemid = " + answerId + " and source='" + fileName
|
|
|
- + "' and component = 'question' and filearea = 'answer' ";
|
|
|
- preState = connect.prepareStatement(sql);
|
|
|
-
|
|
|
- resultSet = preState.executeQuery();
|
|
|
-
|
|
|
- while (resultSet.next()) {
|
|
|
- hash = resultSet.getString("contenthash");
|
|
|
- break;
|
|
|
- }
|
|
|
- if (hash == null) {
|
|
|
- adb.add(answerId + " " + courseidnumber + " " + fileName);
|
|
|
- return null;
|
|
|
- }
|
|
|
- String suff = fileName.substring(fileName.lastIndexOf("."));
|
|
|
- File file = new File(picFiles + courseidnumber + "\\" + hash + suff);
|
|
|
- if (!file.exists()) {
|
|
|
- azip.add(answerId + " " + courseidnumber + " " + fileName);
|
|
|
- return null;
|
|
|
- }
|
|
|
- return file;
|
|
|
- } finally {
|
|
|
- if (resultSet != null) {
|
|
|
- resultSet.close();
|
|
|
- }
|
|
|
- if (preState != null) {
|
|
|
- preState.close();
|
|
|
- }
|
|
|
+ FileUtil.writeFile(paperdir.getAbsolutePath(), "/paper_" + indx + ".json", JSONObject.toJSONString(paper));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initResult() {
|
|
|
- setResult(new HashMap<>());
|
|
|
- getResult().put("qdb", qdb);
|
|
|
- getResult().put("qzip", qzip);
|
|
|
- getResult().put("adb", adb);
|
|
|
- getResult().put("azip", azip);
|
|
|
- getResult().put("invalidAnswerCode", invalidAnswerCode);
|
|
|
- getResult().put("file", file);
|
|
|
- getResult().put("http", http);
|
|
|
- getResult().put("noques", noques);
|
|
|
|
|
|
}
|
|
|
}
|