|
@@ -0,0 +1,125 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.jdbc.core.RowMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 查找试卷有重复试题的考试记录
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FindDuplicateQuestionRecordService {
|
|
|
+
|
|
|
+ private Long examId = 6343L;
|
|
|
+
|
|
|
+ private int threadCount = 40;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @Resource(name = "mongoTemplate")
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FindDuplicateQuestionRecordProducer pr;
|
|
|
+
|
|
|
+ public void start() {
|
|
|
+ File file = new File("e:/ret.xlsx");
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ Date s = new Date();
|
|
|
+ try {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("examId", examId);
|
|
|
+ pr.startDispose(FindDuplicateQuestionRecordConsumer.class, threadCount, param);
|
|
|
+ List<InfoDto> ret = new ArrayList<>();
|
|
|
+ for (Consumer c : pr.getConsumers()) {
|
|
|
+ ret.addAll(c.getRet());
|
|
|
+ }
|
|
|
+ System.out.println("ret count:" + ret.size());
|
|
|
+ if (ret.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (InfoDto info : ret) {
|
|
|
+ ids.add(info.getRecordId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long, FindDuplicateQuestionRecordDto> temp = findRet(ids);
|
|
|
+
|
|
|
+ List<FindDuplicateQuestionRecordRetDto> dtos = new ArrayList<>();
|
|
|
+ for (InfoDto info : ret) {
|
|
|
+ for (AnswerInfo order : info.getQuestionOrder()) {
|
|
|
+ FindDuplicateQuestionRecordRetDto tem = new FindDuplicateQuestionRecordRetDto();
|
|
|
+ dtos.add(tem);
|
|
|
+ tem.setCourseCode(temp.get(info.getRecordId()).getCourseCode());
|
|
|
+ tem.setExamRecordDataId(temp.get(info.getRecordId()).getExamRecordDataId());
|
|
|
+ tem.setIdentityNumber(temp.get(info.getRecordId()).getIdentityNumber());
|
|
|
+ tem.setQuestionOrder(order.getOrder());
|
|
|
+ tem.setHasAnswer(order.getHasAnswer());
|
|
|
+ tem.setStudentCode(temp.get(info.getRecordId()).getStudentCode());
|
|
|
+ tem.setStudentName(temp.get(info.getRecordId()).getStudentName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ try {
|
|
|
+ file.createNewFile();
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ ExportUtils.makeExcel(FindDuplicateQuestionRecordRetDto.class, dtos, fos);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ if (fos != null) {
|
|
|
+ try {
|
|
|
+ fos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+
|
|
|
+ }
|
|
|
+ Date e = new Date();
|
|
|
+ System.out.println("time:" + (e.getTime() - s.getTime()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, FindDuplicateQuestionRecordDto> findRet(List<Long> ids) {
|
|
|
+ StringBuilder sqlBuilder = new StringBuilder();
|
|
|
+ sqlBuilder.append(" select t.id examRecordDataId,f.course_code courseCode,f.student_name studentName "
|
|
|
+ + " ,f.identity_number identityNumber,f.student_code studentCode " + " from ec_oe_exam_record_data t ");
|
|
|
+ sqlBuilder.append(" left join ec_oe_exam_student f on t.exam_student_id=f.exam_student_id ");
|
|
|
+ sqlBuilder.append(" where t.id in(" + StringUtils.join(ids, ",") + ") ");
|
|
|
+
|
|
|
+ RowMapper<FindDuplicateQuestionRecordDto> rowMapper = new BeanPropertyRowMapper<>(
|
|
|
+ FindDuplicateQuestionRecordDto.class);
|
|
|
+ List<FindDuplicateQuestionRecordDto> ret = jdbcTemplate.query(sqlBuilder.toString(), rowMapper);
|
|
|
+ Map<Long, FindDuplicateQuestionRecordDto> map = new HashMap<>();
|
|
|
+ for (FindDuplicateQuestionRecordDto dto : ret) {
|
|
|
+ map.put(dto.getExamRecordDataId(), dto);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|