浏览代码

导出课程数、试卷数、小题数

xiatian 3 年之前
父节点
当前提交
bd848819ea

+ 1 - 1
src/main/java/cn/com/qmth/dp/examcloud/oe/entity/question/ExamPaper.java

@@ -24,7 +24,7 @@ public class ExamPaper extends IdBase {
     /**
      * 关联试卷
      */
-    @DBRef
+    @DBRef(lazy = true)
     private Paper paper;
     /**
      * 抽取试卷次数

+ 107 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_questions_data/ExportQuestionsDataService.java

@@ -0,0 +1,107 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_questions_data;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+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.stereotype.Service;
+
+import cn.com.qmth.dp.examcloud.oe.entity.question.ExtractConfig;
+import cn.com.qmth.dp.examcloud.oe.entity.question.Paper;
+import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
+
+/**
+ * 科目数、试卷数、小题数量.
+ * 
+ * @author chenken
+ *
+ */
+@Service
+public class ExportQuestionsDataService {
+	private String rootOrgId = "371";
+//	private String rootOrgId = "0";
+	private String startTime = "2019-01-01 00:00:00";
+	private String endTime = "2022-01-01 00:00:00";
+
+	@Autowired
+	private JdbcTemplate jdbcTemplate;
+	@Autowired
+	private MongoTemplate mongoTemplate;
+
+	public void start() {
+		long courseCount = 0L;
+		long paperCount = 0L;
+		long questionCount = 0L;
+		Set<String> courseCodes = getCourse();
+		if (!CollectionUtils.isEmpty(courseCodes)) {
+			courseCount = courseCodes.size();
+			paperCount = getPaper(courseCodes);
+			questionCount = getQuestion(courseCodes);
+		}
+		System.out.println("courseCount:" + courseCount);
+		System.out.println("paperCount:" + paperCount);
+		System.out.println("questionCount:" + questionCount);
+	}
+
+	private long getQuestion(Set<String> courseCodes) {
+		Query query = new Query();
+		query.addCriteria(
+				Criteria.where("orgId").is(rootOrgId).and("course.code").in(courseCodes).and("createTime").lt(endTime));
+		long count = mongoTemplate.count(query, Question.class, "question");
+		return count;
+	}
+
+	private long getPaper(Set<String> courseCodes) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("orgId").is(rootOrgId).and("paperType").is("GENERATE").and("course.code")
+				.in(courseCodes).and("createTime").lt(endTime));
+		long count = mongoTemplate.count(query, Paper.class, "paper");
+		return count;
+	}
+
+	private Set<String> getCourse() {
+		Set<String> set = new HashSet<>();
+		List<Long> examIds = getExam();
+		if (CollectionUtils.isEmpty(examIds)) {
+			return set;
+		}
+		Set<String> enc = getEnableCourse();
+		Query query = new Query();
+		query.addCriteria(Criteria.where("orgId").is(rootOrgId).and("examId").in(examIds));
+		List<ExtractConfig> ps = mongoTemplate.find(query, ExtractConfig.class, "extractConfig");
+		if (CollectionUtils.isNotEmpty(ps)) {
+			for (ExtractConfig e : ps) {
+				if (enc.contains(e.getCourseCode())) {
+					set.add(e.getCourseCode());
+				}
+			}
+		}
+		return set;
+	}
+
+	private List<Long> getExam() {
+		String sql = "select t.id from ec_e_exam t where t.root_org_id=" + rootOrgId + " and t.exam_type='ONLINE' "
+				+ " and t.creation_time>=STR_TO_DATE('" + startTime + "','%Y-%m-%d %H:%i:%s')"
+				+ " and t.creation_time<STR_TO_DATE('" + endTime + "','%Y-%m-%d %H:%i:%s')";
+		List<Long> ret = jdbcTemplate.queryForList(sql, Long.class);
+		return ret;
+	}
+
+	private Set<String> getEnableCourse() {
+		String sql = "select t.code from ec_b_course t where t.root_org_id=" + rootOrgId + " and t.enable=1";
+		List<String> ret = jdbcTemplate.queryForList(sql, String.class);
+		Set<String> set = new HashSet<>();
+		if (CollectionUtils.isNotEmpty(ret)) {
+			for (String s : ret) {
+				set.add(s);
+			}
+		}
+		return set;
+	}
+}