|
@@ -1,133 +1,37 @@
|
|
|
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.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
-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.aggregation.Aggregation;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
|
|
|
-import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
-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.entity.question.Course;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.entity.question.Question;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
|
|
|
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
|
|
|
/**
|
|
|
- * 按科目导出小题各题型数.单线程处理
|
|
|
+ * 按科目导出小题各题型数.多线程处理
|
|
|
*
|
|
|
* @author chenken
|
|
|
*
|
|
|
*/
|
|
|
@Service
|
|
|
public class ExportCourseQuestionsCountService {
|
|
|
-// private String rootOrgId = "371";
|
|
|
- private String rootOrgId = "1627";
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
+ private String rootOrgId = "137";
|
|
|
+ private int threadCount=20;
|
|
|
|
|
|
public void start() {
|
|
|
Date s=new Date();
|
|
|
- List<CourseQuestionsCountRetDto> ret = new ArrayList<CourseQuestionsCountRetDto>();
|
|
|
- List<Course> cs = getCourse();
|
|
|
- System.out.println("courseCount:" + cs.size());
|
|
|
- int index = 0;
|
|
|
- if (CollectionUtils.isNotEmpty(cs)) {
|
|
|
- for (Course c : cs) {
|
|
|
- index++;
|
|
|
- CourseQuestionsCountRetDto rd = new CourseQuestionsCountRetDto();
|
|
|
- ret.add(rd);
|
|
|
- rd.setCourseCode(c.getCode());
|
|
|
- rd.setCourseName(c.getName());
|
|
|
- List<QuestionTypeCount> tc = countByType(c.getCode());
|
|
|
- if (CollectionUtils.isNotEmpty(tc)) {
|
|
|
- setCount(rd, tc);
|
|
|
- }
|
|
|
- System.out.println("index:" + index);
|
|
|
- }
|
|
|
- }
|
|
|
- FileOutputStream fos = null;
|
|
|
+ ExportQuesProducer pr = SpringContextHolder.getBean(ExportQuesProducer.class);
|
|
|
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);
|
|
|
+ Map<String, Object> param=new HashMap<>();
|
|
|
+ param.put("rootOrgId", rootOrgId);
|
|
|
+ pr.startDispose(ExportQuesConsumer.class, threadCount, param);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (fos != null) {
|
|
|
- try {
|
|
|
- fos.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ throw new RuntimeException(e);
|
|
|
+
|
|
|
}
|
|
|
- System.out.println("finish! totalQuestionCount:" + getTotalQuestionCount());
|
|
|
Date e=new Date();
|
|
|
System.out.println("time:" + (e.getTime()-s.getTime()));
|
|
|
}
|
|
|
|
|
|
- private void setCount(CourseQuestionsCountRetDto rd, List<QuestionTypeCount> tc) {
|
|
|
- for (QuestionTypeCount t : tc) {
|
|
|
- if (t.getQuestionType().equals(QuesStructType.SINGLE_ANSWER_QUESTION.name())) {
|
|
|
- rd.setSingleAnswerQuestion(t.getCount());
|
|
|
- } else if (t.getQuestionType().equals(QuesStructType.MULTIPLE_ANSWER_QUESTION.name())) {
|
|
|
- rd.setMultipleAnswerQuestion(t.getCount());
|
|
|
- } else if (t.getQuestionType().equals(QuesStructType.BOOL_ANSWER_QUESTION.name())) {
|
|
|
- rd.setBoolAnswerQuestion(t.getCount());
|
|
|
- } else if (t.getQuestionType().equals(QuesStructType.FILL_BLANK_QUESTION.name())) {
|
|
|
- rd.setFillBlankQuestion(t.getCount());
|
|
|
- } else if (t.getQuestionType().equals(QuesStructType.TEXT_ANSWER_QUESTION.name())) {
|
|
|
- rd.setTextAnswerQuestion(t.getCount());
|
|
|
- } else if (t.getQuestionType().equals(QuesStructType.NESTED_ANSWER_QUESTION.name())) {
|
|
|
- rd.setNestedAnswerQuestion(t.getCount());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private long getTotalQuestionCount() {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
- long count = mongoTemplate.count(query, Question.class, "question");
|
|
|
- return count;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private List<Course> getCourse() {
|
|
|
- String sql = "select t.code,t.name,t.id from ec_b_course t where t.root_org_id=" + rootOrgId
|
|
|
- + " order by t.code";
|
|
|
- RowMapper<Course> rowMapper = new BeanPropertyRowMapper<Course>(Course.class);
|
|
|
- List<Course> ret = jdbcTemplate.query(sql, rowMapper);
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- private List<QuestionTypeCount> countByType(String courseCode) {
|
|
|
- List<AggregationOperation> operations = new ArrayList<>();
|
|
|
- operations.add(Aggregation.match(Criteria.where("orgId").is(rootOrgId).and("course.code").is(courseCode)));
|
|
|
- operations.add(Aggregation.group("questionType").count().as("count"));
|
|
|
- operations.add(Aggregation.project("count").and("questionType").previousOperation());
|
|
|
- Aggregation aggregation = Aggregation.newAggregation(operations);
|
|
|
- AggregationResults<QuestionTypeCount> outputTypeCount = mongoTemplate.aggregate(aggregation, Question.class,
|
|
|
- QuestionTypeCount.class);
|
|
|
- return outputTypeCount.getMappedResults();
|
|
|
- }
|
|
|
}
|