|
@@ -1,11 +1,7 @@
|
|
|
package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_diff_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.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -13,30 +9,15 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
-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.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.excel.ExportUtils;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
import cn.com.qmth.dp.examcloud.oe.multithread.Producer;
|
|
|
import cn.com.qmth.dp.examcloud.oe.util.ResouceUtil;
|
|
|
|
|
|
@Service
|
|
|
public class ExportQuesDiffProducer extends Producer {
|
|
|
|
|
|
- @Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
|
|
|
@Override
|
|
|
protected void produce(Map<String, Object> param) throws Exception {
|
|
@@ -46,52 +27,10 @@ public class ExportQuesDiffProducer extends Producer {
|
|
|
offer(c);
|
|
|
}
|
|
|
}
|
|
|
- List<CourseQuestionsCountRetDto> ret = new ArrayList<CourseQuestionsCountRetDto>();
|
|
|
- int index=0;
|
|
|
- for(Consumer c:getConsumers()) {
|
|
|
- ret.addAll(c.getRet());
|
|
|
- index++;
|
|
|
- }
|
|
|
- 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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
System.out.println("courseCount:" + cs.size());
|
|
|
- System.out.println("finish! TotalQuestionCount:" + getTotalQuestionCount((String)param.get("rootOrgId")));
|
|
|
}
|
|
|
|
|
|
- private List<Course> getCourse(String rootOrgId) {
|
|
|
- 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<Course> getCourse() {
|
|
|
List<Course> list=new ArrayList<>();
|
|
@@ -123,11 +62,5 @@ public class ExportQuesDiffProducer extends Producer {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
|
|
|
}
|