deason 3 anos atrás
pai
commit
846f34055a

+ 30 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_exam_student_score/ExportAllQuestionScoreDetail.java

@@ -0,0 +1,30 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_exam_student_score;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Component;
+
+/**
+ * 导出 - 考生考试中所有题的得分明细
+ */
+@Component
+public class ExportAllQuestionScoreDetail {
+
+    private static Logger log = LoggerFactory.getLogger(ExportAllQuestionScoreDetail.class);
+
+    private static final Long MARKING_TYPE_KEY = 24L;// 阅卷方式KEY
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    public void start() {
+
+    }
+
+}

+ 262 - 268
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/get_student_answer_detail/GetStduentAnswerDetailService.java

@@ -1,11 +1,12 @@
 package cn.com.qmth.dp.examcloud.oe.modules.get_student_answer_detail;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
+import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.mongodb.MongoException;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.bson.Document;
@@ -18,18 +19,13 @@ import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-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.JsonUtil;
-import cn.com.qmth.examcloud.commons.util.ResourceLoader;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * 获取考生作答明细
@@ -41,257 +37,255 @@ import cn.com.qmth.examcloud.commons.util.ResourceLoader;
 @Service
 public class GetStduentAnswerDetailService {
 
-	@Autowired
-	JdbcTemplate jdbcTemplate;
-
-	@Autowired
-	MongoTemplate mongoTemplate;
-
-	private int sqlIndex = 1;
-
-	private boolean mustHaveScore = false;
-
-	public void start(Long examId, String... courseCodeLIst) throws Exception {
-		for (String courseCode : courseCodeLIst) {
-			start(examId, courseCode);
-		}
-	}
-
-	// @Async
-	public void start(Long examId, String courseCode) throws Exception {
-		String packageName = this.getClass().getPackage().getName();
-		String packagePath = packageName.replaceAll("\\.", "/");
-
-		// cn/com/qmth/dp/examcloud/oe/modules/get_student_answer_detail/query_exam_record_data_1.sql
-		// String sql = ResourceLoader.getResource(packagePath + "/query_exam_record_data_" + sqlIndex + ".sql");
-
-		String sql="SELECT " +
-				"t1.identity_number, " +
-				" t1.id AS exam_record_data_id, " +
-				"t3.total_score as score, " +
-				"t4.`code`  " +
-				"FROM " +
-				"ec_oe_exam_record_data t1 " +
-				"LEFT JOIN ec_oe_exam_score t3 ON t3.exam_record_data_id =  t1.id " +
-				"LEFT JOIN ec_b_course t4 ON t4.id = t1.course_id  " +
-				"WHERE " +
-				"((  t1.is_warn = 0 ) OR (  t1.is_warn = 1 AND  t1.is_audit = 1 ) )  " +
-				"AND  t1.exam_record_status != 'EXAM_INVALID'  " +
-				"AND t1.exam_id = ?  " +
-				"AND t4.`code` = ?";
-		Object[] args = new Object[]{examId, courseCode};
-		List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, args);
-
-		Map<String, Double> maxScoreOf = Maps.newHashMap();
-		Map<String, Long> examRecordDataIdOf = Maps.newHashMap();
-		Map<Long, String> identityNumberOf = Maps.newHashMap();
-
-		for (Map<String, Object> map : result) {
-			Long examRecordDataId = (Long) map.get("EXAM_RECORD_DATA_ID");
-			Double score = (Double) map.get("SCORE");
-			String identityNumber = (String) map.get("IDENTITY_NUMBER");
-			String curCourseCode = (String) map.get("CODE");
-
-			if (null == score) {
-				throw new RuntimeException("score is null. examRecordDataId=" + examRecordDataId);
-			}
-
-			if (!curCourseCode.equals(courseCode)) {
-				throw new RuntimeException("unexpected exception. courseCode=" + courseCode);
-			}
-
-			identityNumberOf.put(examRecordDataId, identityNumber);
-
-			Double maxScore = maxScoreOf.get(identityNumber);
-			if (null == maxScore || maxScore <= score) {
-				examRecordDataIdOf.put(identityNumber, examRecordDataId);
-				maxScoreOf.put(identityNumber, score);
-			}
-		}
-
-		List<Long> examRecordDataIdList = new ArrayList<>(examRecordDataIdOf.values());
-
-		List<Object[]> datas = Lists.newArrayList();
-
-		List<Object[]> noStudentScoreList = Lists.newArrayList();
-
-		int total = examRecordDataIdList.size();
-		int count = 0;
-		for (Long cur : examRecordDataIdList) {
-			count++;
-			System.out.println("total: " + total + "; count: " + count);
-
-			List<Document> answers = getAnswers(cur);
-
-			String identityNumber = identityNumberOf.get(cur);
-
-			for (Document doc : answers) {
-				Integer order = doc.getInteger("order");
-				Double studentScore = doc.getDouble("studentScore");
-				Double questionScore = doc.getDouble("questionScore");
-				String questionId = doc.getString("questionId");
-				String studentAnswer = doc.getString("studentAnswer");
-				String correctAnswer = doc.getString("correctAnswer");
-				String questionType = doc.getString("questionType");
-
-				if (null == order) {
-					throw new RuntimeException("order is null. examRecordDataId=" + cur);
-				}
-
-				if (null == questionType) {
-					throw new RuntimeException(
-							"questionType is null. examRecordDataId=" + cur + "; order=" + order);
-				}
-
-				if (null == studentScore) {
-					// 无作答时,0分
-					if (StringUtils.isBlank(studentAnswer)) {
-						studentScore = 0D;
-					}
-					// 计算分数
-					else {
-
-						if (null == questionScore) {
-							throw new RuntimeException("questionScore is null. examRecordDataId="
-									+ cur + ";courseCode=" + courseCode + ";order=" + order);
-						}
-
-						// 客观题
-						if (questionType.equals("SINGLE_CHOICE")
-								|| questionType.equals("MULTIPLE_CHOICE")
-								|| questionType.equals("TRUE_OR_FALSE")) {
-
-							// 无正确答案时
-							if (StringUtils.isBlank(correctAnswer)) {
-								noStudentScoreList.add(new Object[]{cur, courseCode, order});
-								studentScore = null;
-							}
-							// 有正确答案时
-							else {
-								if (correctAnswer.equals(studentAnswer)) {
-									studentScore = questionScore;
-								} else {
-									studentScore = 0D;
-								}
-							}
-
-						}
-						// 主观题
-						else if (questionType.equals("FILL_UP") || questionType.equals("ESSAY")) {
-							noStudentScoreList.add(new Object[]{cur, courseCode, order});
-							studentScore = null;
-						} else {
-							throw new RuntimeException("unknow questionType. questionType="
-									+ questionType + "; examRecordDataId=" + cur + ";courseCode="
-									+ courseCode + ";order=" + order);
-						}
-
-					}
-				}
-
-				if (null != studentAnswer && !studentAnswer.contains("<img")) {
-					studentAnswer = Jsoup.clean(studentAnswer, Whitelist.simpleText());
-				}
-
-				//TEMP TODO 用完即删除
-//				if (null != studentAnswer) {
-//					if (questionType.equals("SINGLE_CHOICE")
-//							|| questionType.equals("MULTIPLE_CHOICE")) {
-//						studentAnswer = studentAnswer.replaceAll("0", "A");
-//						studentAnswer = studentAnswer.replaceAll("1", "B");
-//						studentAnswer = studentAnswer.replaceAll("2", "C");
-//						studentAnswer = studentAnswer.replaceAll("3", "D");
-//						studentAnswer = studentAnswer.replaceAll("4", "E");
-//						studentAnswer = studentAnswer.replaceAll("5", "F");
-//						studentAnswer = studentAnswer.replaceAll("6", "G");
-//						studentAnswer = studentAnswer.replaceAll("7", "H");
-//						studentAnswer = studentAnswer.replaceAll("8", "I");
-//					}
-//				}
-
-				Object[] row = new Object[]{identityNumber, courseCode, String.valueOf(order),
-						questionId, studentAnswer, String.valueOf(studentScore)};
-
-				datas.add(row);
-			}
-
-		}
-
-		if (CollectionUtils.isNotEmpty(noStudentScoreList)) {
-			System.out.println("无分数 ============>");
-			Set<Long> examRecordDataIdSet = Sets.newHashSet();
-			for (Object[] objects : noStudentScoreList) {
-				examRecordDataIdSet.add((Long) objects[0]);
-				System.out.println(JsonUtil.toJson(objects));
-			}
-
-//			String sql4QueryExamStudentInfo = ResourceLoader
-//					.getResource(packagePath + "/query_exam_student_info.sql");
-			String sql4QueryExamStudentInfo=
-					"SELECT t1.student_name, t1.identity_number, " +
-					"( SELECT x.`code` FROM ec_b_course x WHERE x.id = t1.course_id ) AS course_code  " +
-					"FROM " +
-					" ec_oe_exam_record_data t1 " +
-					"WHERE " +
-					"t1.id IN ($$)";
-
-			String ids = StringUtils.join(examRecordDataIdSet, ",");
-			sql4QueryExamStudentInfo = sql4QueryExamStudentInfo.replace("$$", ids);
-
-			List<Map<String, Object>> studentInfoList = jdbcTemplate
-					.queryForList(sql4QueryExamStudentInfo);
-
-			for (Map<String, Object> curStudent : studentInfoList) {
-				System.out.println(JsonUtil.toJson(curStudent));
-			}
-
-			if (mustHaveScore) {
-				throw new RuntimeException("无分数");
-			}
-		}
-
-		String filePath = "D:/home/answers-detail-" + examId + "-" + courseCode + ".xlsx";
-
-		final String[] EXCEL_HEADER = new String[]{"身份证号码", "课程代码", "题号",
-				"题目ID", "答案", "分数"};
-
-		ExcelWriter.write(EXCEL_HEADER, new Class[]{String.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;
-	}
-
-	public void setSqlIndex(int sqlIndex) {
-		this.sqlIndex = sqlIndex;
-	}
-
-	public void setMustHaveScore(boolean mustHaveScore) {
-		this.mustHaveScore = mustHaveScore;
-	}
+    @Autowired
+    JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    MongoTemplate mongoTemplate;
+
+    private int sqlIndex = 1;
+
+    private boolean mustHaveScore = false;
+
+    public void start(Long examId, String... courseCodeLIst) throws Exception {
+        for (String courseCode : courseCodeLIst) {
+            start(examId, courseCode);
+        }
+    }
+
+    // @Async
+    public void start(Long examId, String courseCode) throws Exception {
+        String packageName = this.getClass().getPackage().getName();
+        String packagePath = packageName.replaceAll("\\.", "/");
+
+        // cn/com/qmth/dp/examcloud/oe/modules/get_student_answer_detail/query_exam_record_data_1.sql
+        // String sql = ResourceLoader.getResource(packagePath + "/query_exam_record_data_" + sqlIndex + ".sql");
+
+        String sql = "SELECT " +
+                "t1.identity_number, " +
+                " t1.id AS exam_record_data_id, " +
+                "t3.total_score as score, " +
+                "t4.`code`  " +
+                "FROM " +
+                "ec_oe_exam_record_data t1 " +
+                "LEFT JOIN ec_oe_exam_score t3 ON t3.exam_record_data_id =  t1.id " +
+                "LEFT JOIN ec_b_course t4 ON t4.id = t1.course_id  " +
+                "WHERE " +
+                "((  t1.is_warn = 0 ) OR (  t1.is_warn = 1 AND  t1.is_audit = 1 ) )  " +
+                "AND  t1.exam_record_status != 'EXAM_INVALID'  " +
+                "AND t1.exam_id = ?  " +
+                "AND t4.`code` = ?";
+        Object[] args = new Object[]{examId, courseCode};
+        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, args);
+
+        Map<String, Double> maxScoreOf = Maps.newHashMap();
+        Map<String, Long> examRecordDataIdOf = Maps.newHashMap();
+        Map<Long, String> identityNumberOf = Maps.newHashMap();
+
+        for (Map<String, Object> map : result) {
+            Long examRecordDataId = (Long) map.get("EXAM_RECORD_DATA_ID");
+            Double score = (Double) map.get("SCORE");
+            String identityNumber = (String) map.get("IDENTITY_NUMBER");
+            String curCourseCode = (String) map.get("CODE");
+
+            if (null == score) {
+                throw new RuntimeException("score is null. examRecordDataId=" + examRecordDataId);
+            }
+
+            if (!curCourseCode.equals(courseCode)) {
+                throw new RuntimeException("unexpected exception. courseCode=" + courseCode);
+            }
+
+            identityNumberOf.put(examRecordDataId, identityNumber);
+
+            Double maxScore = maxScoreOf.get(identityNumber);
+            if (null == maxScore || maxScore <= score) {
+                examRecordDataIdOf.put(identityNumber, examRecordDataId);
+                maxScoreOf.put(identityNumber, score);
+            }
+        }
+
+        List<Long> examRecordDataIdList = new ArrayList<>(examRecordDataIdOf.values());
+
+        List<Object[]> datas = Lists.newArrayList();
+
+        List<Object[]> noStudentScoreList = Lists.newArrayList();
+
+        int total = examRecordDataIdList.size();
+        int count = 0;
+        for (Long cur : examRecordDataIdList) {
+            count++;
+            System.out.println("Total size is " + total + ", curExamRecordDataId = " + cur + ", index = " + count);
+
+            List<Document> answers = getAnswers(cur);
+            String identityNumber = identityNumberOf.get(cur);
+
+            for (Document doc : answers) {
+                Integer order = doc.getInteger("order");
+                Double studentScore = doc.getDouble("studentScore");
+                Double questionScore = doc.getDouble("questionScore");
+                String questionId = doc.getString("questionId");
+                String studentAnswer = doc.getString("studentAnswer");
+                String correctAnswer = doc.getString("correctAnswer");
+                String questionType = doc.getString("questionType");
+
+                if (null == order) {
+                    throw new RuntimeException("order is null. examRecordDataId=" + cur);
+                }
+
+                if (null == questionType) {
+                    throw new RuntimeException(
+                            "questionType is null. examRecordDataId=" + cur + "; order=" + order);
+                }
+
+                if (null == studentScore) {
+                    // 无作答时,0分
+                    if (StringUtils.isBlank(studentAnswer)) {
+                        studentScore = 0D;
+                    }
+                    // 计算分数
+                    else {
+                        if (null == questionScore) {
+                            throw new RuntimeException("questionScore is null. examRecordDataId="
+                                    + cur + ";courseCode=" + courseCode + ";order=" + order);
+                        }
+
+                        // 客观题
+                        if (questionType.equals("SINGLE_CHOICE")
+                                || questionType.equals("MULTIPLE_CHOICE")
+                                || questionType.equals("TRUE_OR_FALSE")) {
+
+                            // 无正确答案时
+                            if (StringUtils.isBlank(correctAnswer)) {
+                                noStudentScoreList.add(new Object[]{cur, courseCode, order});
+                                studentScore = null;
+                            }
+                            // 有正确答案时
+                            else {
+                                if (correctAnswer.equals(studentAnswer)) {
+                                    studentScore = questionScore;
+                                } else {
+                                    studentScore = 0D;
+                                }
+                            }
+
+                        }
+                        // 主观题
+                        else if (questionType.equals("FILL_UP") || questionType.equals("ESSAY")) {
+                            noStudentScoreList.add(new Object[]{cur, courseCode, order});
+                            studentScore = null;
+                        } else {
+                            throw new RuntimeException("unknow questionType. questionType="
+                                    + questionType + "; examRecordDataId=" + cur + ";courseCode="
+                                    + courseCode + ";order=" + order);
+                        }
+
+                    }
+                }
+
+                if (null != studentAnswer && !studentAnswer.contains("<img")) {
+                    studentAnswer = Jsoup.clean(studentAnswer, Whitelist.simpleText());
+                }
+
+                //TEMP TODO 用完即删除
+                //				if (null != studentAnswer) {
+                //					if (questionType.equals("SINGLE_CHOICE")
+                //							|| questionType.equals("MULTIPLE_CHOICE")) {
+                //						studentAnswer = studentAnswer.replaceAll("0", "A");
+                //						studentAnswer = studentAnswer.replaceAll("1", "B");
+                //						studentAnswer = studentAnswer.replaceAll("2", "C");
+                //						studentAnswer = studentAnswer.replaceAll("3", "D");
+                //						studentAnswer = studentAnswer.replaceAll("4", "E");
+                //						studentAnswer = studentAnswer.replaceAll("5", "F");
+                //						studentAnswer = studentAnswer.replaceAll("6", "G");
+                //						studentAnswer = studentAnswer.replaceAll("7", "H");
+                //						studentAnswer = studentAnswer.replaceAll("8", "I");
+                //					}
+                //				}
+
+                Object[] row = new Object[]{identityNumber, courseCode, String.valueOf(order),
+                        questionId, studentAnswer, String.valueOf(studentScore)};
+
+                datas.add(row);
+            }
+
+        }
+
+        if (CollectionUtils.isNotEmpty(noStudentScoreList)) {
+            System.out.println("无分数 ============>");
+            Set<Long> examRecordDataIdSet = Sets.newHashSet();
+            for (Object[] objects : noStudentScoreList) {
+                examRecordDataIdSet.add((Long) objects[0]);
+                System.out.println(JsonUtil.toJson(objects));
+            }
+
+            //			String sql4QueryExamStudentInfo = ResourceLoader
+            //					.getResource(packagePath + "/query_exam_student_info.sql");
+            String sql4QueryExamStudentInfo =
+                    "SELECT t1.student_name, t1.identity_number, " +
+                            "( SELECT x.`code` FROM ec_b_course x WHERE x.id = t1.course_id ) AS course_code  " +
+                            "FROM " +
+                            " ec_oe_exam_record_data t1 " +
+                            "WHERE " +
+                            "t1.id IN ($$)";
+
+            String ids = StringUtils.join(examRecordDataIdSet, ",");
+            sql4QueryExamStudentInfo = sql4QueryExamStudentInfo.replace("$$", ids);
+
+            List<Map<String, Object>> studentInfoList = jdbcTemplate
+                    .queryForList(sql4QueryExamStudentInfo);
+
+            for (Map<String, Object> curStudent : studentInfoList) {
+                System.out.println(JsonUtil.toJson(curStudent));
+            }
+
+            if (mustHaveScore) {
+                throw new RuntimeException("无分数");
+            }
+        }
+
+        String filePath = "D:/home/answers-detail-" + examId + "-" + courseCode + ".xlsx";
+
+        final String[] EXCEL_HEADER = new String[]{"身份证号码", "课程代码", "题号",
+                "题目ID", "答案", "分数"};
+
+        ExcelWriter.write(EXCEL_HEADER, new Class[]{String.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;
+    }
+
+    public void setSqlIndex(int sqlIndex) {
+        this.sqlIndex = sqlIndex;
+    }
+
+    public void setMustHaveScore(boolean mustHaveScore) {
+        this.mustHaveScore = mustHaveScore;
+    }
 
 }