浏览代码

重复试题的考生信息导出

xiatian 1 月之前
父节点
当前提交
268d329276

+ 50 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/AnswerInfo.java

@@ -0,0 +1,50 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+import java.util.Objects;
+
+public class AnswerInfo {
+
+    private Integer order;
+
+    private String hasAnswer;
+
+    public Integer getOrder() {
+        return order;
+    }
+
+    public void setOrder(Integer order) {
+        this.order = order;
+    }
+
+    public String getHasAnswer() {
+        return hasAnswer;
+    }
+
+    public void setHasAnswer(String hasAnswer) {
+        this.hasAnswer = hasAnswer;
+    }
+
+    public AnswerInfo(Integer order, String hasAnswer) {
+        super();
+        this.order = order;
+        this.hasAnswer = hasAnswer;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(order);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        AnswerInfo other = (AnswerInfo) obj;
+        return Objects.equals(order, other.order);
+    }
+
+}

+ 123 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/FindDuplicateQuestionRecordConsumer.java

@@ -0,0 +1,123 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.context.annotation.Scope;
+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.stereotype.Service;
+
+import cn.com.qmth.dp.examcloud.oe.entity.question.ExamQuestionEntity;
+import cn.com.qmth.dp.examcloud.oe.entity.question.ExamRecordQuestionsEntity;
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+
+@Service
+@Scope("prototype")
+public class FindDuplicateQuestionRecordConsumer extends Consumer<Long> {
+
+    @Resource(name = "secondaryMongoTemplate")
+    private MongoTemplate oeTemplate;
+
+    @Override
+    public void consume(Map<String, Object> param, Long recordId) {
+        ExamRecordQuestionsEntity qs = getStudentAnswer(recordId);
+        if (qs == null) {
+            throw new StatusException("未找到考生作答:" + recordId);
+        }
+        InfoDto info = new InfoDto();
+        info.setRecordId(recordId);
+        Set<AnswerInfo> questionOrder = new LinkedHashSet<>();
+        info.setQuestionOrder(questionOrder);
+        boolean pick = false;
+        Map<String, ExamQuestionEntity> map = new HashMap<>();
+
+        Map<String, List<ExamQuestionEntity>> taoti = new LinkedHashMap<>();
+
+        Map<String, List<ExamQuestionEntity>> taoti2 = new LinkedHashMap<>();
+        for (ExamQuestionEntity q : qs.getExamQuestionEntities()) {
+            if (q.getOrder() >= 41 && q.getOrder() <= 55) {
+                List<ExamQuestionEntity> tem = taoti.get(q.getQuestionId());
+                if (tem == null) {
+                    tem = new ArrayList<>();
+                    taoti.put(q.getQuestionId(), tem);
+                }
+                tem.add(q);
+            } else if (q.getOrder() >= 56 && q.getOrder() <= 65) {
+                List<ExamQuestionEntity> tem = taoti2.get(q.getQuestionId());
+                if (tem == null) {
+                    tem = new ArrayList<>();
+                    taoti2.put(q.getQuestionId(), tem);
+                }
+                tem.add(q);
+            } else {
+                ExamQuestionEntity cq = map.get(q.getQuestionId());
+                if (cq == null) {
+                    map.put(q.getQuestionId(), q);
+                } else {
+                    pick = true;
+                    if (StringUtils.isBlank(cq.getStudentAnswer())) {
+                        questionOrder.add(new AnswerInfo(cq.getOrder(), "否"));
+                    } else {
+                        questionOrder.add(new AnswerInfo(cq.getOrder(), "是"));
+                    }
+                    if (StringUtils.isBlank(q.getStudentAnswer())) {
+                        questionOrder.add(new AnswerInfo(q.getOrder(), "否"));
+                    } else {
+                        questionOrder.add(new AnswerInfo(q.getOrder(), "是"));
+                    }
+                }
+            }
+        }
+        for (List<ExamQuestionEntity> list : taoti.values()) {
+            if (list.size() > 5) {
+                pick = true;
+                for (ExamQuestionEntity q : list) {
+                    if (StringUtils.isBlank(q.getStudentAnswer())) {
+                        questionOrder.add(new AnswerInfo(q.getOrder(), "否"));
+                    } else {
+                        questionOrder.add(new AnswerInfo(q.getOrder(), "是"));
+                    }
+                }
+            }
+        }
+        for (List<ExamQuestionEntity> list : taoti2.values()) {
+            if (list.size() > 10) {
+                pick = true;
+                for (ExamQuestionEntity q : list) {
+                    if (StringUtils.isBlank(q.getStudentAnswer())) {
+                        questionOrder.add(new AnswerInfo(q.getOrder(), "否"));
+                    } else {
+                        questionOrder.add(new AnswerInfo(q.getOrder(), "是"));
+                    }
+                }
+            }
+        }
+        if (pick) {
+            addRet(info);
+        }
+    }
+
+    private ExamRecordQuestionsEntity getStudentAnswer(Long recordId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("examRecordDataId").is(recordId));
+        List<ExamRecordQuestionsEntity> ret = oeTemplate.find(query, ExamRecordQuestionsEntity.class,
+                "examRecordQuestions");
+        if (CollectionUtils.isEmpty(ret)) {
+            return null;
+        }
+        return ret.get(0);
+    }
+
+}

+ 55 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/FindDuplicateQuestionRecordDto.java

@@ -0,0 +1,55 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+public class FindDuplicateQuestionRecordDto {
+
+    private String courseCode;
+
+    private String studentName;
+
+    private String identityNumber;
+
+    private String studentCode;
+
+    private Long examRecordDataId;
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getStudentCode() {
+        return studentCode;
+    }
+
+    public void setStudentCode(String studentCode) {
+        this.studentCode = studentCode;
+    }
+
+    public Long getExamRecordDataId() {
+        return examRecordDataId;
+    }
+
+    public void setExamRecordDataId(Long examRecordDataId) {
+        this.examRecordDataId = examRecordDataId;
+    }
+
+    public String getStudentName() {
+        return studentName;
+    }
+
+    public void setStudentName(String studentName) {
+        this.studentName = studentName;
+    }
+
+}

+ 43 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/FindDuplicateQuestionRecordProducer.java

@@ -0,0 +1,43 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.dp.examcloud.oe.multithread.Producer;
+
+@Service
+public class FindDuplicateQuestionRecordProducer extends Producer {
+	@Autowired
+	private JdbcTemplate jdbcTemplate;
+	
+	@Override
+	protected void produce(Map<String, Object> param) throws Exception {
+		Long examId = (Long) param.get("examId");
+		List<Long> cs = findAllRecordIds(examId);
+		System.out.println("recordCount:" + cs.size());
+		if (CollectionUtils.isNotEmpty(cs)) {
+			for (Long c : cs) {
+				offer(c);
+			}
+		}
+	}
+	
+	
+	private List<Long> findAllRecordIds(Long examId) {
+		StringBuilder sqlBuilder = new StringBuilder();
+		sqlBuilder.append(" select t.id from ec_oe_exam_record_data t ");
+		sqlBuilder.append(" where t.exam_id =" + examId);
+//		sqlBuilder.append(" and t.id=52780182");
+
+//		RowMapper<Long> rowMapper = new BeanPropertyRowMapper<Long>(Long.class);
+		List<Long> ret = jdbcTemplate.queryForList(sqlBuilder.toString(),Long.class);
+		return ret;
+	}
+	
+
+}

+ 84 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/FindDuplicateQuestionRecordRetDto.java

@@ -0,0 +1,84 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+import cn.com.qmth.dp.examcloud.oe.excel.ExcelProperty;
+
+public class FindDuplicateQuestionRecordRetDto {
+
+    @ExcelProperty(name = "课程代码", width = 25, index = 1)
+    private String courseCode;
+
+    @ExcelProperty(name = "学生名称", width = 25, index = 2)
+    private String studentName;
+
+    @ExcelProperty(name = "身份证号", width = 25, index = 3)
+    private String identityNumber;
+
+    @ExcelProperty(name = "学号", width = 25, index = 4)
+    private String studentCode;
+
+    @ExcelProperty(name = "考试记录id", width = 25, index = 5)
+    private Long examRecordDataId;
+
+    @ExcelProperty(name = "题号", width = 25, index = 6)
+    private Integer questionOrder;
+
+    @ExcelProperty(name = "是否作答", width = 25, index = 7)
+    private String hasAnswer;
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getStudentCode() {
+        return studentCode;
+    }
+
+    public void setStudentCode(String studentCode) {
+        this.studentCode = studentCode;
+    }
+
+    public Long getExamRecordDataId() {
+        return examRecordDataId;
+    }
+
+    public void setExamRecordDataId(Long examRecordDataId) {
+        this.examRecordDataId = examRecordDataId;
+    }
+
+    public String getStudentName() {
+        return studentName;
+    }
+
+    public void setStudentName(String studentName) {
+        this.studentName = studentName;
+    }
+
+    public Integer getQuestionOrder() {
+        return questionOrder;
+    }
+
+    public void setQuestionOrder(Integer questionOrder) {
+        this.questionOrder = questionOrder;
+    }
+
+    public String getHasAnswer() {
+        return hasAnswer;
+    }
+
+    public void setHasAnswer(String hasAnswer) {
+        this.hasAnswer = hasAnswer;
+    }
+
+}

+ 125 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/FindDuplicateQuestionRecordService.java

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

+ 27 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/InfoDto.java

@@ -0,0 +1,27 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+import java.util.Set;
+
+public class InfoDto {
+
+    private Long recordId;
+
+    private Set<AnswerInfo> questionOrder;
+
+    public Long getRecordId() {
+        return recordId;
+    }
+
+    public void setRecordId(Long recordId) {
+        this.recordId = recordId;
+    }
+
+    public Set<AnswerInfo> getQuestionOrder() {
+        return questionOrder;
+    }
+
+    public void setQuestionOrder(Set<AnswerInfo> questionOrder) {
+        this.questionOrder = questionOrder;
+    }
+
+}

+ 32 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/find_duplicate_question_record/QuestionTypeCount.java

@@ -0,0 +1,32 @@
+package cn.com.qmth.dp.examcloud.oe.modules.find_duplicate_question_record;
+
+public class QuestionTypeCount {
+	private String questionType;
+	private String difficulty;
+	private long count;
+
+	public long getCount() {
+		return count;
+	}
+
+	public void setCount(long count) {
+		this.count = count;
+	}
+
+	public String getQuestionType() {
+		return questionType;
+	}
+
+	public void setQuestionType(String questionType) {
+		this.questionType = questionType;
+	}
+
+	public String getDifficulty() {
+		return difficulty;
+	}
+
+	public void setDifficulty(String difficulty) {
+		this.difficulty = difficulty;
+	}
+
+}