|
@@ -0,0 +1,133 @@
|
|
|
|
+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;
|
|
|
|
+
|
|
|
|
+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 {
|
|
|
|
+ List<Course> cs = getCourse();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(cs)) {
|
|
|
|
+ for (Course c : cs) {
|
|
|
|
+ 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<>();
|
|
|
|
+ XSSFWorkbook wb = null;
|
|
|
|
+ try {
|
|
|
|
+ wb = new XSSFWorkbook(ResouceUtil.getStream("subject_codes.xlsx"));
|
|
|
|
+ XSSFSheet sheet = wb.getSheetAt(0);
|
|
|
|
+ int rows = sheet.getLastRowNum();
|
|
|
|
+ for (int i = 2; i <= rows; i++) {
|
|
|
|
+ Course c = new Course();
|
|
|
|
+ XSSFRow row = sheet.getRow(i);
|
|
|
|
+ String ecCode = row.getCell(0).getStringCellValue().trim();
|
|
|
|
+ String name = row.getCell(1).getStringCellValue().trim();
|
|
|
|
+ c.setCode(ecCode);
|
|
|
|
+ c.setName(name);
|
|
|
|
+ list.add(c);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (wb != null) {
|
|
|
|
+ try {
|
|
|
|
+ wb.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|