|
@@ -1,92 +1,97 @@
|
|
|
-package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-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.stereotype.Service;
|
|
|
-
|
|
|
-import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
-
|
|
|
-/**
|
|
|
- * 按科目导出小题各题型数.多线程处理
|
|
|
- *
|
|
|
- * @author chenken
|
|
|
- *
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class ExportCourseQuestionsCountService {
|
|
|
- private String rootOrgId = "17068";
|
|
|
- private int threadCount=20;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
- public void start() {
|
|
|
- Date s=new Date();
|
|
|
- ExportQuesProducer pr = SpringContextHolder.getBean(ExportQuesProducer.class);
|
|
|
- try {
|
|
|
- Map<String, Object> param=new HashMap<>();
|
|
|
- param.put("rootOrgId", rootOrgId);
|
|
|
- pr.startDispose(ExportQuesConsumer.class, threadCount, param);
|
|
|
- List<CourseQuestionsCountRetDto> ret = new ArrayList<CourseQuestionsCountRetDto>();
|
|
|
- for(Consumer c:pr.getConsumers()) {
|
|
|
- ret.addAll(c.getRet());
|
|
|
- }
|
|
|
- Collections.sort(ret, new Comparator<CourseQuestionsCountRetDto>() {
|
|
|
- @Override
|
|
|
- public int compare(CourseQuestionsCountRetDto o1, CourseQuestionsCountRetDto o2) {
|
|
|
- String c1 = o1.getCourseCode();
|
|
|
- String c2 = o2.getCourseCode();
|
|
|
- return c1.compareTo(c2);
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- FileOutputStream fos = null;
|
|
|
- try {
|
|
|
- File file = new File("d:/ret.xlsx");
|
|
|
- if (file.exists()) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
- file.createNewFile();
|
|
|
- fos = new FileOutputStream(file);
|
|
|
- ExportUtils.makeExcel(CourseQuestionsCountRetDto.class, ret, fos);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (fos != null) {
|
|
|
- try {
|
|
|
- fos.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
-
|
|
|
- }
|
|
|
- System.out.println("finish! TotalQuestionCount:" + getTotalQuestionCount(rootOrgId.toString()));
|
|
|
- Date e=new Date();
|
|
|
- System.out.println("time:" + (e.getTime()-s.getTime()));
|
|
|
- }
|
|
|
- private long getTotalQuestionCount(String rootOrgId) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
- long count = mongoTemplate.count(query, Question.class, "question");
|
|
|
- return count;
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+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.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 按科目导出小题各题型数.多线程处理
|
|
|
+ *
|
|
|
+ * @author chenken
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExportCourseQuestionsCountService {
|
|
|
+
|
|
|
+ private String rootOrgId = "17068";
|
|
|
+
|
|
|
+ private int threadCount = 20;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ public void start() {
|
|
|
+ Date s = new Date();
|
|
|
+ ExportQuesProducer pr = SpringContextHolder.getBean(ExportQuesProducer.class);
|
|
|
+ try {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("rootOrgId", rootOrgId);
|
|
|
+ pr.startDispose(ExportQuesConsumer.class, threadCount, param);
|
|
|
+ List<CourseQuestionsCountRetDto> ret = new ArrayList<CourseQuestionsCountRetDto>();
|
|
|
+ for (Consumer c : pr.getConsumers()) {
|
|
|
+ ret.addAll(c.getRet());
|
|
|
+ }
|
|
|
+ Collections.sort(ret, new Comparator<CourseQuestionsCountRetDto>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(CourseQuestionsCountRetDto o1, CourseQuestionsCountRetDto o2) {
|
|
|
+ String c1 = o1.getCourseCode();
|
|
|
+ String c2 = o2.getCourseCode();
|
|
|
+ return c1.compareTo(c2);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ try {
|
|
|
+ File file = new File("d:/examcloud-data-export/ret.xlsx");
|
|
|
+ if (file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ file.createNewFile();
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ ExportUtils.makeExcel(CourseQuestionsCountRetDto.class, ret, fos);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (fos != null) {
|
|
|
+ try {
|
|
|
+ fos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+
|
|
|
+ }
|
|
|
+ System.out.println("finish! TotalQuestionCount:" + getTotalQuestionCount(rootOrgId.toString()));
|
|
|
+ Date e = new Date();
|
|
|
+ System.out.println("time:" + (e.getTime() - s.getTime()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private long getTotalQuestionCount(String rootOrgId) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
+ long count = mongoTemplate.count(query, Question.class, "question");
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+}
|