|
@@ -1,9 +1,9 @@
|
|
package cn.com.qmth.dp.examcloud.oe.modules.get_student_one_question_answer;
|
|
package cn.com.qmth.dp.examcloud.oe.modules.get_student_one_question_answer;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
|
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.mongodb.MongoException;
|
|
import org.bson.Document;
|
|
import org.bson.Document;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.safety.Whitelist;
|
|
import org.jsoup.safety.Whitelist;
|
|
@@ -14,15 +14,11 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
|
-import com.mongodb.MongoException;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
|
|
|
|
-import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
|
|
|
|
-import cn.com.qmth.examcloud.commons.util.ResourceLoader;
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取考生作答明细
|
|
* 获取考生作答明细
|
|
@@ -34,103 +30,109 @@ import cn.com.qmth.examcloud.commons.util.ResourceLoader;
|
|
@Service
|
|
@Service
|
|
public class GetStduentOneAnswerService {
|
|
public class GetStduentOneAnswerService {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- JdbcTemplate jdbcTemplate;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- MongoTemplate mongoTemplate;
|
|
|
|
-
|
|
|
|
- public void start(Long examId, int questionOrder, String... courseCodeLIst) throws Exception {
|
|
|
|
- for (String courseCode : courseCodeLIst) {
|
|
|
|
- start(examId, questionOrder, courseCode);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Async
|
|
|
|
- public void start(Long examId, int questionOrder, String courseCode) throws Exception {
|
|
|
|
- String sql = ResourceLoader
|
|
|
|
- .getResource("sql/get_student_one_question_answer" + "/query_exam_record_data.sql");
|
|
|
|
- Object[] args = new Object[]{examId, courseCode};
|
|
|
|
- List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, args);
|
|
|
|
-
|
|
|
|
- List<Object[]> datas = Lists.newArrayList();
|
|
|
|
- int total = result.size();
|
|
|
|
- int count = 0;
|
|
|
|
-
|
|
|
|
- for (Map<String, Object> map : result) {
|
|
|
|
- Long examRecordDataId = (Long) map.get("EXAM_RECORD_DATA_ID");
|
|
|
|
- String studentName = (String) map.get("STUDENT_NAME");
|
|
|
|
- String studentCode = (String) map.get("STUDENT_CODE");
|
|
|
|
- String curCourseCode = (String) map.get("COURSE_CODE");
|
|
|
|
- if (!curCourseCode.equals(courseCode)) {
|
|
|
|
- throw new RuntimeException("unexpected exception. courseCode=" + courseCode);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- count++;
|
|
|
|
- System.out.println("total: " + total + "; count: " + count);
|
|
|
|
-
|
|
|
|
- List<Document> answers = getAnswers(examRecordDataId);
|
|
|
|
-
|
|
|
|
- for (Document doc : answers) {
|
|
|
|
- Integer order = doc.getInteger("order");
|
|
|
|
- String studentAnswer = doc.getString("studentAnswer");
|
|
|
|
-
|
|
|
|
- if (null == order) {
|
|
|
|
- throw new RuntimeException(
|
|
|
|
- "order is null. examRecordDataId=" + examRecordDataId);
|
|
|
|
- }
|
|
|
|
- if (!order.equals(questionOrder)) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (null != studentAnswer && !studentAnswer.contains("<img")) {
|
|
|
|
- studentAnswer = Jsoup.clean(studentAnswer, Whitelist.simpleText());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Object[] row = new Object[]{String.valueOf(examId), courseCode, studentName,
|
|
|
|
- studentCode, studentAnswer};
|
|
|
|
-
|
|
|
|
- datas.add(row);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String filePath = "D:/Temp/one-answer-" + examId + "-" + courseCode + ".xlsx";
|
|
|
|
-
|
|
|
|
- final String[] EXCEL_HEADER = new String[]{"考试批次ID", "课程代码", "学生姓名", "学号",
|
|
|
|
- "第" + questionOrder + "题作答"};
|
|
|
|
-
|
|
|
|
- ExcelWriter.write(EXCEL_HEADER,
|
|
|
|
- new Class[]{String.class, String.class, String.class, String.class, String.class},
|
|
|
|
- datas, new File(filePath));
|
|
|
|
-
|
|
|
|
- System.out.println("OVER ! courseCode=" + courseCode);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取作答
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @param examRecordDataId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<Document> getAnswers(Long examRecordDataId) {
|
|
|
|
- Query query = Query.query(Criteria.where("examRecordDataId").is(examRecordDataId));
|
|
|
|
- final ObjectHolder<List<Document>> answersHolder = new ObjectHolder<List<Document>>(null);
|
|
|
|
- mongoTemplate.executeQuery(query, "examRecordQuestions", new DocumentCallbackHandler() {
|
|
|
|
-
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
- @Override
|
|
|
|
- public void processDocument(Document document)
|
|
|
|
- throws MongoException, DataAccessException {
|
|
|
|
- List<Document> answers = (List<Document>) document.get("examQuestionEntities");
|
|
|
|
- answersHolder.set(answers);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- List<Document> answers = answersHolder.get();
|
|
|
|
- return answers;
|
|
|
|
- }
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ JdbcTemplate jdbcTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
|
+
|
|
|
|
+ public void start(Long examId, int questionOrder, String... courseCodeLIst) throws Exception {
|
|
|
|
+ for (String courseCode : courseCodeLIst) {
|
|
|
|
+ start(examId, questionOrder, courseCode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // @Async
|
|
|
|
+ public void start(Long examId, int questionOrder, String courseCode) throws Exception {
|
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
|
+ sql.append("SELECT r.id AS exam_record_data_id, r.exam_id, stu.`name` AS student_name,");
|
|
|
|
+ sql.append(" r.student_code, r.identity_number, c.`code` AS course_code");
|
|
|
|
+ sql.append(" FROM ec_oe_exam_record_data r");
|
|
|
|
+ sql.append(" LEFT JOIN ec_b_course c ON c.id = r.course_id");
|
|
|
|
+ sql.append(" LEFT JOIN ec_b_student stu ON stu.id = r.student_id");
|
|
|
|
+ sql.append(" WHERE r.exam_id = ? AND c.`code` = ?");
|
|
|
|
+
|
|
|
|
+ Object[] args = new Object[]{examId, courseCode};
|
|
|
|
+ List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString(), args);
|
|
|
|
+
|
|
|
|
+ List<Object[]> datas = Lists.newArrayList();
|
|
|
|
+ int total = result.size();
|
|
|
|
+ int count = 0;
|
|
|
|
+
|
|
|
|
+ for (Map<String, Object> map : result) {
|
|
|
|
+ Long examRecordDataId = (Long) map.get("EXAM_RECORD_DATA_ID");
|
|
|
|
+ String studentName = (String) map.get("STUDENT_NAME");
|
|
|
|
+ String studentCode = (String) map.get("STUDENT_CODE");
|
|
|
|
+ String curCourseCode = (String) map.get("COURSE_CODE");
|
|
|
|
+ if (!curCourseCode.equals(courseCode)) {
|
|
|
|
+ throw new RuntimeException("unexpected exception. courseCode=" + courseCode);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ count++;
|
|
|
|
+ System.out.println("total: " + total + "; count: " + count);
|
|
|
|
+
|
|
|
|
+ List<Document> answers = getAnswers(examRecordDataId);
|
|
|
|
+
|
|
|
|
+ for (Document doc : answers) {
|
|
|
|
+ Integer order = doc.getInteger("order");
|
|
|
|
+ String studentAnswer = doc.getString("studentAnswer");
|
|
|
|
+
|
|
|
|
+ if (null == order) {
|
|
|
|
+ throw new RuntimeException(
|
|
|
|
+ "order is null. examRecordDataId=" + examRecordDataId);
|
|
|
|
+ }
|
|
|
|
+ if (!order.equals(questionOrder)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != studentAnswer && !studentAnswer.contains("<img")) {
|
|
|
|
+ studentAnswer = Jsoup.clean(studentAnswer, Whitelist.simpleText());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Object[] row = new Object[]{String.valueOf(examId), courseCode, studentName,
|
|
|
|
+ studentCode, studentAnswer};
|
|
|
|
+
|
|
|
|
+ datas.add(row);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String filePath = "/home/oa/one-answer-" + examId + "-" + courseCode + ".xlsx";
|
|
|
|
+
|
|
|
|
+ final String[] EXCEL_HEADER = new String[]{"考试批次ID", "课程代码", "学生姓名", "学号",
|
|
|
|
+ "第" + questionOrder + "题作答"};
|
|
|
|
+
|
|
|
|
+ ExcelWriter.write(EXCEL_HEADER,
|
|
|
|
+ new Class[]{String.class, String.class, String.class, String.class, String.class},
|
|
|
|
+ datas, new File(filePath));
|
|
|
|
+
|
|
|
|
+ System.out.println("OVER ! courseCode=" + courseCode);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取作答
|
|
|
|
+ *
|
|
|
|
+ * @param examRecordDataId
|
|
|
|
+ * @return
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ */
|
|
|
|
+ private List<Document> getAnswers(Long examRecordDataId) {
|
|
|
|
+ Query query = Query.query(Criteria.where("examRecordDataId").is(examRecordDataId));
|
|
|
|
+ final ObjectHolder<List<Document>> answersHolder = new ObjectHolder<List<Document>>(null);
|
|
|
|
+ mongoTemplate.executeQuery(query, "examRecordQuestions", new DocumentCallbackHandler() {
|
|
|
|
+
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ @Override
|
|
|
|
+ public void processDocument(Document document)
|
|
|
|
+ throws MongoException, DataAccessException {
|
|
|
|
+ List<Document> answers = (List<Document>) document.get("examQuestionEntities");
|
|
|
|
+ answersHolder.set(answers);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ List<Document> answers = answersHolder.get();
|
|
|
|
+ return answers;
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|