xiatian 7 mesiacov pred
rodič
commit
6f312b7b8b
13 zmenil súbory, kde vykonal 1098 pridanie a 341 odobranie
  1. 100 98
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/CourseQuestionsCountRetDto.java
  2. 81 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportPaperSuffService.java
  3. 143 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuesBySuffConsumer.java
  4. 84 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuesBySuffProducer.java
  5. 1 1
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuesConsumer.java
  6. 122 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuestionsCountBySuffService.java
  7. 26 13
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/IdBean.java
  8. 111 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperDetailUnitDto.java
  9. 51 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperSuffConsumer.java
  10. 42 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperSuffDto.java
  11. 83 0
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperSuffProducer.java
  12. 159 154
      src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_questions_count/ExportQuestionsCountService.java
  13. 95 75
      src/main/java/cn/com/qmth/dp/examcloud/oe/multithread/Consumer.java

+ 100 - 98
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/CourseQuestionsCountRetDto.java

@@ -3,102 +3,104 @@ package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
 import cn.com.qmth.dp.examcloud.oe.excel.ExcelProperty;
 
 public class CourseQuestionsCountRetDto {
-	@ExcelProperty(name = "课程名称", width = 25, index = 1)
-	private String courseName;
-	@ExcelProperty(name = "课程代码", width = 25, index = 2)
-	private String courseCode;
-	@ExcelProperty(name = "单选", width = 15, index = 3)
-	private long singleAnswerQuestion;
-	
-	@ExcelProperty(name = "多选", width = 15, index = 4)
-	private long multipleAnswerQuestion;
-	
-	@ExcelProperty(name = "判断", width = 15, index = 5)
-	private long boolAnswerQuestion;
-	
-	@ExcelProperty(name = "填空", width = 15, index = 6)
-	private long fillBlankQuestion;
-	
-	@ExcelProperty(name = "问答", width = 15, index = 7)
-	private long textAnswerQuestion;
-	
-	@ExcelProperty(name = "套题", width = 15, index = 8)
-	private long nestedAnswerQuestion;
-	
-	@ExcelProperty(name = "案例分析", width = 15, index = 9)
-	private long ext;
-
-	public String getCourseName() {
-		return courseName;
-	}
-
-	public void setCourseName(String courseName) {
-		this.courseName = courseName;
-	}
-
-	public String getCourseCode() {
-		return courseCode;
-	}
-
-	public void setCourseCode(String courseCode) {
-		this.courseCode = courseCode;
-	}
-
-	public long getSingleAnswerQuestion() {
-		return singleAnswerQuestion;
-	}
-
-	public void setSingleAnswerQuestion(long singleAnswerQuestion) {
-		this.singleAnswerQuestion = singleAnswerQuestion;
-	}
-
-	public long getMultipleAnswerQuestion() {
-		return multipleAnswerQuestion;
-	}
-
-	public void setMultipleAnswerQuestion(long multipleAnswerQuestion) {
-		this.multipleAnswerQuestion = multipleAnswerQuestion;
-	}
-
-	public long getBoolAnswerQuestion() {
-		return boolAnswerQuestion;
-	}
-
-	public void setBoolAnswerQuestion(long boolAnswerQuestion) {
-		this.boolAnswerQuestion = boolAnswerQuestion;
-	}
-
-	public long getFillBlankQuestion() {
-		return fillBlankQuestion;
-	}
-
-	public void setFillBlankQuestion(long fillBlankQuestion) {
-		this.fillBlankQuestion = fillBlankQuestion;
-	}
-
-	public long getTextAnswerQuestion() {
-		return textAnswerQuestion;
-	}
-
-	public void setTextAnswerQuestion(long textAnswerQuestion) {
-		this.textAnswerQuestion = textAnswerQuestion;
-	}
-
-	public long getNestedAnswerQuestion() {
-		return nestedAnswerQuestion;
-	}
-
-	public void setNestedAnswerQuestion(long nestedAnswerQuestion) {
-		this.nestedAnswerQuestion = nestedAnswerQuestion;
-	}
-
-	public long getExt() {
-		return ext;
-	}
-
-	public void setExt(long ext) {
-		this.ext = ext;
-	}
-	
-	
+
+    @ExcelProperty(name = "课程名称", width = 25, index = 1)
+    private String courseName;
+
+    @ExcelProperty(name = "课程代码", width = 25, index = 2)
+    private String courseCode;
+
+    @ExcelProperty(name = "单选", width = 15, index = 3)
+    private long singleAnswerQuestion;
+
+    @ExcelProperty(name = "多选", width = 15, index = 4)
+    private long multipleAnswerQuestion;
+
+    @ExcelProperty(name = "判断", width = 15, index = 5)
+    private long boolAnswerQuestion;
+
+    @ExcelProperty(name = "填空", width = 15, index = 6)
+    private long fillBlankQuestion;
+
+    @ExcelProperty(name = "问答", width = 15, index = 7)
+    private long textAnswerQuestion;
+
+    @ExcelProperty(name = "套题", width = 15, index = 8)
+    private long nestedAnswerQuestion;
+
+    // @ExcelProperty(name = "案例分析", width = 15, index = 9)
+    private long ext;
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public long getSingleAnswerQuestion() {
+        return singleAnswerQuestion;
+    }
+
+    public void setSingleAnswerQuestion(long singleAnswerQuestion) {
+        this.singleAnswerQuestion = singleAnswerQuestion;
+    }
+
+    public long getMultipleAnswerQuestion() {
+        return multipleAnswerQuestion;
+    }
+
+    public void setMultipleAnswerQuestion(long multipleAnswerQuestion) {
+        this.multipleAnswerQuestion = multipleAnswerQuestion;
+    }
+
+    public long getBoolAnswerQuestion() {
+        return boolAnswerQuestion;
+    }
+
+    public void setBoolAnswerQuestion(long boolAnswerQuestion) {
+        this.boolAnswerQuestion = boolAnswerQuestion;
+    }
+
+    public long getFillBlankQuestion() {
+        return fillBlankQuestion;
+    }
+
+    public void setFillBlankQuestion(long fillBlankQuestion) {
+        this.fillBlankQuestion = fillBlankQuestion;
+    }
+
+    public long getTextAnswerQuestion() {
+        return textAnswerQuestion;
+    }
+
+    public void setTextAnswerQuestion(long textAnswerQuestion) {
+        this.textAnswerQuestion = textAnswerQuestion;
+    }
+
+    public long getNestedAnswerQuestion() {
+        return nestedAnswerQuestion;
+    }
+
+    public void setNestedAnswerQuestion(long nestedAnswerQuestion) {
+        this.nestedAnswerQuestion = nestedAnswerQuestion;
+    }
+
+    public long getExt() {
+        return ext;
+    }
+
+    public void setExt(long ext) {
+        this.ext = ext;
+    }
+
 }

+ 81 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportPaperSuffService.java

@@ -0,0 +1,81 @@
+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.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.stereotype.Service;
+
+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 ExportPaperSuffService {
+
+    private String rootOrgId = "17351";
+
+    private int threadCount = 20;
+
+    private int fileIndex = 0;
+
+    public void start() {
+        Date s = new Date();
+        PaperSuffProducer pr = SpringContextHolder.getBean(PaperSuffProducer.class);
+        try {
+            Map<String, Object> param = new HashMap<>();
+            param.put("rootOrgId", rootOrgId);
+            pr.startDispose(PaperSuffConsumer.class, threadCount, param);
+            Set<PaperSuffDto> ret = new HashSet<>();
+            for (Consumer c : pr.getConsumers()) {
+                ret.addAll(c.getSet());
+            }
+            FileOutputStream fos = null;
+            File file = createFile();
+            try {
+                file.createNewFile();
+                fos = new FileOutputStream(file);
+                ExportUtils.makeExcel(PaperSuffDto.class, ret, fos);
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                if (fos != null) {
+                    try {
+                        fos.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+            System.out.println("finish! file:" + file.getAbsolutePath());
+            Date e = new Date();
+            System.out.println("time:" + (e.getTime() - s.getTime()));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+
+        }
+    }
+
+    private File createFile() {
+        String suff = fileIndex == 0 ? "" : (fileIndex + "");
+        File file = new File("d:/ret" + suff + ".xlsx");
+        if (file.exists()) {
+            if (!file.delete()) {
+                fileIndex++;
+                return createFile();
+            }
+        }
+        return file;
+    }
+}

+ 143 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuesBySuffConsumer.java

@@ -0,0 +1,143 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.bson.types.ObjectId;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+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.stereotype.Service;
+
+import cn.com.qmth.dp.examcloud.oe.entity.question.Course;
+import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
+
+@Service
+@Scope("prototype")
+public class ExportQuesBySuffConsumer extends Consumer<Course> {
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Override
+    public void consume(Map<String, Object> param, Course c) {
+        CourseQuestionsCountRetDto rd = new CourseQuestionsCountRetDto();
+        String rootOrgId = (String) param.get("rootOrgId");
+        String paperSuff = (String) param.get("paperSuff");
+        rd.setCourseCode(c.getCode());
+        rd.setCourseName(c.getName());
+        List<ObjectId> pids = getPaperIds(paperSuff, c.getCode(), rootOrgId);
+        if (CollectionUtils.isEmpty(pids)) {
+            return;
+        }
+        List<QuestionTypeCount> tc = countByType(pids);
+        if (CollectionUtils.isNotEmpty(tc)) {
+            setCount(rd, tc);
+            // setExtCount(paperSuff, rd, rootOrgId);
+        }
+        if (rd.getSingleAnswerQuestion() != 0 || rd.getMultipleAnswerQuestion() != 0 || rd.getBoolAnswerQuestion() != 0
+                || rd.getFillBlankQuestion() != 0 || rd.getTextAnswerQuestion() != 0
+                || rd.getNestedAnswerQuestion() != 0 || rd.getExt() != 0) {
+            addRet(rd);
+        }
+
+    }
+
+    private List<ObjectId> getPaperIds(String paperSuff, String courseCode, String rootOrgId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("orgId").is(rootOrgId).and("paperType").is("IMPORT").and("course.code")
+                .is(courseCode).and("creationBy").is(646523L));
+        List<IdBean> ps = mongoTemplate.find(query, IdBean.class, "paper");
+        if (CollectionUtils.isEmpty(ps)) {
+            return null;
+        }
+        Pattern pa = Pattern.compile("\\(" + paperSuff + "\\)");
+        List<ObjectId> ids = new ArrayList<>();
+        for (IdBean p : ps) {
+            Matcher ma = pa.matcher(p.getName());
+            if (ma.find()) {
+                ids.add(new ObjectId(p.getId()));
+            }
+        }
+        return ids;
+    }
+
+    // private List<ObjectId> getDetailIds(List<ObjectId> ps) {
+    // Query query = new Query();
+    // query.addCriteria(Criteria.where("paper.$id").in(ps));
+    // List<Detail> ds = mongoTemplate.find(query, Detail.class, "paperDetail");
+    // if (CollectionUtils.isEmpty(ps)) {
+    // return null;
+    // }
+    // List<ObjectId> ids = new ArrayList<>();
+    // // for(Detail d:ds) {
+    // // if(d.getName().contains("案例分析")) {
+    // // ids.add(new ObjectId(d.getId()));
+    // // }
+    // // }
+    // return ids;
+    // }
+
+    // private long getExtCount(List<ObjectId> ds) {
+    // Query query = new Query();
+    // query.addCriteria(Criteria.where("paperDetail.$id").in(ds).and("questionType")
+    // .is(QuesStructType.TEXT_ANSWER_QUESTION.name()));
+    // long count = mongoTemplate.count(query, "paperDetailUnit");
+    // return count;
+    // }
+
+    // private void setExtCount(String paperSuff, CourseQuestionsCountRetDto rd,
+    // String rootOrgId) {
+    // List<ObjectId> paperIds = getPaperIds(paperSuff, rd.getCourseCode(),
+    // rootOrgId);
+    // if (CollectionUtils.isEmpty(paperIds)) {
+    // return;
+    // }
+    //
+    // List<ObjectId> detailIds = getDetailIds(paperIds);
+    // if (CollectionUtils.isEmpty(detailIds)) {
+    // return;
+    // }
+    // rd.setExt(getExtCount(detailIds));
+    // }
+
+    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 List<QuestionTypeCount> countByType(List<ObjectId> pids) {
+        List<AggregationOperation> operations = new ArrayList<>();
+        operations.add(Aggregation.match(Criteria.where("paper.$id").in(pids)));
+        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,
+                PaperDetailUnitDto.class, QuestionTypeCount.class);
+        return outputTypeCount.getMappedResults();
+    }
+
+}

+ 84 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuesBySuffProducer.java

@@ -0,0 +1,84 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+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.multithread.Producer;
+
+@Service
+@Scope("prototype")
+public class ExportQuesBySuffProducer extends Producer {
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Override
+    protected void produce(Map<String, Object> param) throws Exception {
+        String rootOrgId = (String) param.get("rootOrgId");
+        List<Course> cs = getCourse(rootOrgId);
+        System.out.println("courseCount:" + cs.size());
+        if (CollectionUtils.isNotEmpty(cs)) {
+            for (Course c : cs) {
+                offer(c);
+            }
+        }
+
+    }
+
+    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() {
+    // Set<String> set=new HashSet<>();
+    // List<Course> list=new ArrayList<>();
+    // XSSFWorkbook wb = null;
+    // try {
+    // wb = new XSSFWorkbook(ResouceUtil.getStream("subject_info.xlsx"));
+    // XSSFSheet sheet = wb.getSheetAt(0);
+    // int rows = sheet.getLastRowNum();
+    // for (int i = 1; i <= rows; i++) {
+    // Course c = new Course();
+    // XSSFRow row = sheet.getRow(i);
+    // String ecCode;
+    // try {
+    // ecCode = row.getCell(0).getStringCellValue().trim();
+    // } catch (Exception e) {
+    // ecCode = ((int)row.getCell(0).getNumericCellValue())+"";
+    // }
+    // String name = row.getCell(2).getStringCellValue().trim();
+    // c.setCode(ecCode);
+    // c.setName(name);
+    // if(!set.contains(ecCode)) {
+    // list.add(c);
+    // set.add(ecCode);
+    // }
+    //
+    // }
+    // } catch (IOException e) {
+    // throw new RuntimeException(e);
+    // } finally {
+    // if (wb != null) {
+    // try {
+    // wb.close();
+    // } catch (IOException e) {
+    // }
+    // }
+    // }
+    // return list;
+    // }
+
+}

+ 1 - 1
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuesConsumer.java

@@ -40,7 +40,7 @@ public class ExportQuesConsumer extends Consumer<Course> {
         List<QuestionTypeCount> tc = countByType(c.getCode(), rootOrgId);
         if (CollectionUtils.isNotEmpty(tc)) {
             setCount(rd, tc);
-            setExtCount(rd, rootOrgId);
+            // setExtCount(rd, rootOrgId);
         }
         if (rd.getSingleAnswerQuestion() != 0 || rd.getMultipleAnswerQuestion() != 0 || rd.getBoolAnswerQuestion() != 0
                 || rd.getFillBlankQuestion() != 0 || rd.getTextAnswerQuestion() != 0

+ 122 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportQuestionsCountBySuffService.java

@@ -0,0 +1,122 @@
+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 ExportQuestionsCountBySuffService {
+
+    private String rootOrgId = "17351";
+
+    private String[] paperSuffs = new String[] { "231205" };
+
+    private int threadCount = 20;
+
+    private int fileIndex = 0;
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    public void start() {
+        Date s = new Date();
+        for (String paperSuff : paperSuffs) {
+            oneBatch(paperSuff);
+        }
+        System.out.println("finish all! ");
+        Date e = new Date();
+        System.out.println("time:" + (e.getTime() - s.getTime()));
+    }
+
+    public void oneBatch(String suff) {
+        Date s = new Date();
+        ExportQuesBySuffProducer pr = SpringContextHolder.getBean(ExportQuesBySuffProducer.class);
+        try {
+            Map<String, Object> param = new HashMap<>();
+            param.put("rootOrgId", rootOrgId);
+            param.put("paperSuff", suff);
+            pr.startDispose(ExportQuesBySuffConsumer.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;
+            File file = createFile(suff);
+            try {
+                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("finish! TotalQuestionCount:" + getTotalQuestionCount(rootOrgId.toString()) + " | file: "
+                    + file.getAbsolutePath());
+            Date e = new Date();
+            System.out.println("time:" + (e.getTime() - s.getTime()));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+
+        }
+    }
+
+    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;
+    }
+
+    private File createFile(String name) {
+        String suff = fileIndex == 0 ? "" : (fileIndex + "");
+        File file = new File("d:/examcloud-data-export/" + name + suff + ".xlsx");
+        if (file.exists()) {
+            if (!file.delete()) {
+                fileIndex++;
+                return createFile(name);
+            }
+        }
+        return file;
+    }
+}

+ 26 - 13
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/IdBean.java

@@ -5,18 +5,31 @@ import javax.persistence.Id;
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
 
 public class IdBean implements JsonSerializable {
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = -1424624250300317437L;
-	@Id
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -1424624250300317437L;
+
+    @Id
     protected String id;
-	public String getId() {
-		return id;
-	}
-	public void setId(String id) {
-		this.id = id;
-	}
-	
-	
+
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
 }

+ 111 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperDetailUnitDto.java

@@ -0,0 +1,111 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import cn.com.qmth.dp.examcloud.oe.entity.question.MongoBaseEntity;
+import cn.com.qmth.dp.examcloud.oe.enums.question.PaperType;
+import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
+
+@Document(collection = "paperDetailUnit")
+public class PaperDetailUnitDto extends MongoBaseEntity {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 266448283780973578L;
+
+    private Integer number;// 小题序号
+
+    private Double score;// 小题分数
+
+    private QuesStructType questionType;// 小题类型
+
+    /**
+     * 选择题下option的排序,按照number排序 一般:4,2,3,1 套题下的选择题:1,2,3,4;2,3,4,1;3,2,1,4
+     * 题与题之间按分号";"分隔
+     */
+    private String optionOrder;
+
+    private String creator;// 创建人id
+
+    private String createTime;// 创建时间
+
+    private PaperType paperType;
+
+    /**
+     * 作答限时 K12
+     */
+    private Long timeLimit;
+
+    public PaperDetailUnitDto() {
+    }
+
+    public Integer getNumber() {
+        return number;
+    }
+
+    public void setNumber(Integer number) {
+        this.number = number;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public QuesStructType getQuestionType() {
+        return questionType;
+    }
+
+    public void setQuestionType(QuesStructType questionType) {
+        this.questionType = questionType;
+    }
+
+    public String getCreator() {
+        return creator;
+    }
+
+    public void setCreator(String creator) {
+        this.creator = creator;
+    }
+
+    public String getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(String createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getOptionOrder() {
+        return optionOrder;
+    }
+
+    public void setOptionOrder(String optionOrder) {
+        this.optionOrder = optionOrder;
+    }
+
+    public PaperType getPaperType() {
+        return paperType;
+    }
+
+    public void setPaperType(PaperType paperType) {
+        this.paperType = paperType;
+    }
+
+    public static double formatDouble(double number) {
+        BigDecimal formatNumber = BigDecimal.valueOf(number);
+        return formatNumber.setScale(2, RoundingMode.HALF_UP).doubleValue();
+    }
+
+    public Long getTimeLimit() {
+        return timeLimit;
+    }
+
+    public void setTimeLimit(Long timeLimit) {
+        this.timeLimit = timeLimit;
+    }
+
+}

+ 51 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperSuffConsumer.java

@@ -0,0 +1,51 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+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.Course;
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
+
+@Service
+@Scope("prototype")
+public class PaperSuffConsumer extends Consumer<Course> {
+
+    private Pattern pa = Pattern.compile("\\(([0-9]{6})\\)");
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Override
+    public void consume(Map<String, Object> param, Course c) {
+        String rootOrgId = (String) param.get("rootOrgId");
+        getPaperSuff(c.getCode(), rootOrgId);
+
+    }
+
+    private void getPaperSuff(String courseCode, String rootOrgId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("orgId").is(rootOrgId).and("paperType").is("IMPORT").and("course.code")
+                .is(courseCode).and("creationBy").is(646523L));
+        List<IdBean> ps = mongoTemplate.find(query, IdBean.class, "paper");
+        if (CollectionUtils.isEmpty(ps)) {
+            return;
+        }
+        for (IdBean n : ps) {
+            Matcher ma = pa.matcher(n.getName());
+            if (ma.find()) {
+                addSet(new PaperSuffDto(ma.group(1)));
+            }
+        }
+    }
+
+}

+ 42 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperSuffDto.java

@@ -0,0 +1,42 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import java.util.Objects;
+
+import cn.com.qmth.dp.examcloud.oe.excel.ExcelProperty;
+
+public class PaperSuffDto {
+
+    @ExcelProperty(name = "试卷前缀", width = 25, index = 1)
+    private String suff;
+
+    public String getSuff() {
+        return suff;
+    }
+
+    public void setSuff(String suff) {
+        this.suff = suff;
+    }
+
+    public PaperSuffDto(String suff) {
+        super();
+        this.suff = suff;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(suff);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        PaperSuffDto other = (PaperSuffDto) obj;
+        return Objects.equals(suff, other.suff);
+    }
+
+}

+ 83 - 0
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/PaperSuffProducer.java

@@ -0,0 +1,83 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+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.multithread.Producer;
+
+@Service
+public class PaperSuffProducer extends Producer {
+
+	@Autowired
+	private JdbcTemplate jdbcTemplate;
+	
+	@Override
+	protected void produce(Map<String, Object> param) throws Exception {
+		String rootOrgId=(String)param.get("rootOrgId");
+		List<Course> cs = getCourse(rootOrgId);
+		System.out.println("courseCount:" + cs.size());
+		if (CollectionUtils.isNotEmpty(cs)) {
+			for (Course c : cs) {
+				offer(c);
+			}
+		}
+		
+		
+	}
+	
+	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() {
+//		Set<String> set=new HashSet<>();
+//		List<Course> list=new ArrayList<>();
+//		XSSFWorkbook wb = null;
+//		try {
+//			wb = new XSSFWorkbook(ResouceUtil.getStream("subject_info.xlsx"));
+//			XSSFSheet sheet = wb.getSheetAt(0);
+//			int rows = sheet.getLastRowNum();
+//			for (int i = 1; i <= rows; i++) {
+//				Course c = new Course();
+//				XSSFRow row = sheet.getRow(i);
+//				String ecCode;
+//				try {
+//					ecCode = row.getCell(0).getStringCellValue().trim();
+//				} catch (Exception e) {
+//					ecCode = ((int)row.getCell(0).getNumericCellValue())+"";
+//				}
+//				String name = row.getCell(2).getStringCellValue().trim();
+//				c.setCode(ecCode);
+//				c.setName(name);
+//				if(!set.contains(ecCode)) {
+//					list.add(c);
+//					set.add(ecCode);
+//				}
+//				
+//			}
+//		} catch (IOException e) {
+//			throw new RuntimeException(e);
+//		} finally {
+//			if (wb != null) {
+//				try {
+//					wb.close();
+//				} catch (IOException e) {
+//				}
+//			}
+//		}
+//		return list;
+//	}
+
+}

+ 159 - 154
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_questions_count/ExportQuestionsCountService.java

@@ -28,166 +28,171 @@ import cn.com.qmth.dp.examcloud.oe.entity.question.Paper;
 import cn.com.qmth.dp.examcloud.oe.entity.question.PaperDetail;
 import cn.com.qmth.dp.examcloud.oe.excel.ExportUtils;
 
-/**大题下小题数量
+/**
+ * 大题下小题数量
+ * 
  * @author chenken
  *
  */
 @Service
 public class ExportQuestionsCountService {
 
-	@Autowired
-	MongoTemplate mongoTemplate;
+    @Autowired
+    MongoTemplate mongoTemplate;
 
-	public void start() {
-		Date start=new Date();
-		Query query = new Query();
-		query.addCriteria(Criteria.where("orgId").is("22163").and("paperType").is("IMPORT"));
-		List<Paper> ps = mongoTemplate.find(query, Paper.class, "paper");
-		if (ps != null&&ps.size()>0) {
-//			List<String> course= readCourseCode();
-//			Map<String, String> courseMap = course.stream().collect(Collectors.toMap(a -> a, a -> a,(k1,k2)->k1));
-			List<Paper> psRet=new ArrayList<>();
-			for (Paper paper : ps) {
-//				if(paper.getName().indexOf("(211)")!=-1) {
-					psRet.add(paper);
-//				}
-			}
-			if (psRet != null&&psRet.size()>0) {
-				Map<String,RetDto> map=new HashMap<>();
-				System.out.println("total:" + psRet.size());
-				int index = 0;
-				for (Paper paper : psRet) {
-					index++;
-					System.out.println("index:" + index);
-					String cName=paper.getCourseName();
-					String cCode=paper.getCourseNo();
-					Query query2 = new Query();
-//					query2.addCriteria(Criteria.where("paper.$id").is(paper.getId()));
-					query2.addCriteria(Criteria.where("paper.$id").is(new ObjectId(paper.getId())));
-					List<PaperDetail> ds = mongoTemplate.find(query2, PaperDetail.class, "paperDetail");
-					if (ds != null&&ds.size()>0) {
-						for (PaperDetail detail : ds) {
-							String qName=detail.getName();
-							Integer count=detail.getUnitCount();
-							String key=cCode+"_"+qName;
-							RetDto dto=map.get(key);
-							if(dto==null) {
-								dto=new RetDto(cName, cCode, qName,0);
-								map.put(key, dto);
-							}
-							dto.setCount(dto.getCount()+count);
-						}
-					}
-				}
-				
-				List<RetDto> ret= new ArrayList<RetDto>();
-				for(RetDto tem:map.values()) {
-					ret.add(tem);
-				}
-				Collections.sort(ret, new Comparator<RetDto>() {
-					@Override
-					public int compare(RetDto o1, RetDto 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(RetDto.class, ret, fos);
-				} catch (Exception e) {
-					e.printStackTrace();
-				} finally {
-					if(fos!=null) {
-						try {
-							fos.close();
-						} catch (IOException e) {
-							// TODO Auto-generated catch block
-							e.printStackTrace();
-						}
-					}
-				}
-			}else {
-				System.out.println("total:" + 0);
-			}
-		}else {
-			System.out.println("total:" + 0);
-		}
-		
-		Date end=new Date();
-		System.out.println("*****************end:" +((end.getTime()-start.getTime())/(1000*60))+"分钟");
-	}
-	
-//	private List<String> readCourseCode() {
-//		List<String> list = new ArrayList<String>();
-//		XSSFWorkbook wb = null;
-//		try {
-//			wb = new XSSFWorkbook("d:\\course.xlsx");
-//			XSSFSheet sheet = wb.getSheetAt(0);
-//			int rows = sheet.getLastRowNum();
-//			for (int i = 1; i <= rows; i++) {
-//				XSSFRow row = sheet.getRow(i);
-//				list.add(row.getCell(0).getStringCellValue());
-//			}
-//		} catch (IOException e) {
-//			e.printStackTrace();
-//		} finally {
-//			if (wb != null) {
-//				try {
-//					wb.close();
-//				} catch (IOException e) {
-//					// TODO Auto-generated catch block
-//					e.printStackTrace();
-//				}
-//			}
-//		}
-//		return list;
-//	}
+    public void start() {
+        Date start = new Date();
+        Query query = new Query();
+        query.addCriteria(Criteria.where("orgId").is("17351").and("paperType").is("IMPORT"));
+        List<Paper> ps = mongoTemplate.find(query, Paper.class, "paper");
+        if (ps != null && ps.size() > 0) {
+            // List<String> course= readCourseCode();
+            // Map<String, String> courseMap =
+            // course.stream().collect(Collectors.toMap(a -> a, a ->
+            // a,(k1,k2)->k1));
+            List<Paper> psRet = new ArrayList<>();
+            for (Paper paper : ps) {
+                // if(paper.getName().indexOf("(211)")!=-1) {
+                psRet.add(paper);
+                // }
+            }
+            if (psRet != null && psRet.size() > 0) {
+                Map<String, RetDto> map = new HashMap<>();
+                System.out.println("total:" + psRet.size());
+                int index = 0;
+                for (Paper paper : psRet) {
+                    index++;
+                    System.out.println("index:" + index);
+                    String cName = paper.getCourseName();
+                    String cCode = paper.getCourseNo();
+                    Query query2 = new Query();
+                    // query2.addCriteria(Criteria.where("paper.$id").is(paper.getId()));
+                    query2.addCriteria(Criteria.where("paper.$id").is(new ObjectId(paper.getId())));
+                    List<PaperDetail> ds = mongoTemplate.find(query2, PaperDetail.class, "paperDetail");
+                    if (ds != null && ds.size() > 0) {
+                        for (PaperDetail detail : ds) {
+                            String qName = detail.getName();
+                            Integer count = detail.getUnitCount();
+                            String key = cCode + "_" + qName;
+                            RetDto dto = map.get(key);
+                            if (dto == null) {
+                                dto = new RetDto(cName, cCode, qName, 0);
+                                map.put(key, dto);
+                            }
+                            dto.setCount(dto.getCount() + count);
+                        }
+                    }
+                }
 
-//	public static void main(String[] args) {
-//		List<RetDto> ret= new ArrayList<RetDto>();
-//		ret.add(new RetDto("cName1", "cCode1", "qName1",21));
-//		ret.add(new RetDto("cName2", "cCode2", "qName2",22));
-//		ret.add(new RetDto("cName3", "cCode3", "qName3",23));
-//		ret.add(new RetDto("cName4", "cCode4", "qName4",24));
-//		ret.add(new RetDto("cName5", "cCode7", "qName5",25));
-//		ret.add(new RetDto("cName1", "cCode1", "qName2",21));
-//		Collections.sort(ret, new Comparator<RetDto>() {
-//			@Override
-//			public int compare(RetDto o1, RetDto 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(RetDto.class, ret, fos);
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//		} finally {
-//			if(fos!=null) {
-//				try {
-//					fos.close();
-//				} catch (IOException e) {
-//					// TODO Auto-generated catch block
-//					e.printStackTrace();
-//				}
-//			}
-//		}
-//	}
+                List<RetDto> ret = new ArrayList<RetDto>();
+                for (RetDto tem : map.values()) {
+                    ret.add(tem);
+                }
+                Collections.sort(ret, new Comparator<RetDto>() {
+
+                    @Override
+                    public int compare(RetDto o1, RetDto 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(RetDto.class, ret, fos);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                } finally {
+                    if (fos != null) {
+                        try {
+                            fos.close();
+                        } catch (IOException e) {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            } else {
+                System.out.println("total:" + 0);
+            }
+        } else {
+            System.out.println("total:" + 0);
+        }
+
+        Date end = new Date();
+        System.out.println("*****************end:" + ((end.getTime() - start.getTime()) / (1000 * 60)) + "分钟");
+    }
+
+    // private List<String> readCourseCode() {
+    // List<String> list = new ArrayList<String>();
+    // XSSFWorkbook wb = null;
+    // try {
+    // wb = new XSSFWorkbook("d:\\course.xlsx");
+    // XSSFSheet sheet = wb.getSheetAt(0);
+    // int rows = sheet.getLastRowNum();
+    // for (int i = 1; i <= rows; i++) {
+    // XSSFRow row = sheet.getRow(i);
+    // list.add(row.getCell(0).getStringCellValue());
+    // }
+    // } catch (IOException e) {
+    // e.printStackTrace();
+    // } finally {
+    // if (wb != null) {
+    // try {
+    // wb.close();
+    // } catch (IOException e) {
+    // // TODO Auto-generated catch block
+    // e.printStackTrace();
+    // }
+    // }
+    // }
+    // return list;
+    // }
+
+    // public static void main(String[] args) {
+    // List<RetDto> ret= new ArrayList<RetDto>();
+    // ret.add(new RetDto("cName1", "cCode1", "qName1",21));
+    // ret.add(new RetDto("cName2", "cCode2", "qName2",22));
+    // ret.add(new RetDto("cName3", "cCode3", "qName3",23));
+    // ret.add(new RetDto("cName4", "cCode4", "qName4",24));
+    // ret.add(new RetDto("cName5", "cCode7", "qName5",25));
+    // ret.add(new RetDto("cName1", "cCode1", "qName2",21));
+    // Collections.sort(ret, new Comparator<RetDto>() {
+    // @Override
+    // public int compare(RetDto o1, RetDto 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(RetDto.class, ret, fos);
+    // } catch (Exception e) {
+    // e.printStackTrace();
+    // } finally {
+    // if(fos!=null) {
+    // try {
+    // fos.close();
+    // } catch (IOException e) {
+    // // TODO Auto-generated catch block
+    // e.printStackTrace();
+    // }
+    // }
+    // }
+    // }
 }

+ 95 - 75
src/main/java/cn/com/qmth/dp/examcloud/oe/multithread/Consumer.java

@@ -1,87 +1,107 @@
 package cn.com.qmth.dp.examcloud.oe.multithread;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.logging.log4j.ThreadContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+public abstract class Consumer<T> extends Thread {
 
-public abstract class Consumer<T>  extends Thread{
-	private static final Logger logger = LoggerFactory.getLogger(Consumer.class);
-	private Basket basket;
-	
-	private List<Object> ret=new ArrayList<>();
-	
-	private String traceId;
-	
-	/**
-	 * 业务参数
-	 */
-	private Map<String, Object> param;
-	
-	public Consumer() {
-	}
-	@Override
-	public void run() {
-		logger.info("*******************Consumer:"+Thread.currentThread().getId()+" start");
-		try {
-			while (true) {
-				//先判断是否有异常结束
-				if(basket.isExcuteError()) {
-					break;
-				}
-				//取消费数据
-				Object o= basket.consume();
-				//判断消费数据是否是结束
-				if(o instanceof EndObject) {
-					break;
-				}
-				@SuppressWarnings("unchecked")
-				T t=(T)o;
-//				logger.info("*******************Consumer:"+Thread.currentThread().getId()+" consume");
-				//消费数据实现
-				consume(this.param,t);
-				logger.info("已处理:"+basket.updateProcess(1));
-			}
-		} catch (Exception e) {
-			basket.setExcuteError(true);
-			logger.error("消费线程处理出错",e);
-		}finally {
-			basket.countDown();
-			logger.info("*******************Consumer:"+Thread.currentThread().getId()+" stop");
-			ThreadContext.clearAll();
-		}
-	}
-	public abstract void consume(Map<String, Object> param,T t);
-	public Basket getBasket() {
-		return basket;
-	}
-	public void setBasket(Basket basket) {
-		this.basket = basket;
-	}
-	public String getTraceId() {
-		return traceId;
-	}
-	public void setTraceId(String traceId) {
-		this.traceId = traceId;
-	}
-	public List<Object> getRet() {
-		return ret;
-	}
-	
-	public void addRet(Object r) {
-		ret.add(r);
-	}
-	protected Map<String, Object> getParam() {
-		return param;
-	}
-	protected void setParam(Map<String, Object> param) {
-		this.param = param;
-	}
-	
-	
-	
+    private static final Logger logger = LoggerFactory.getLogger(Consumer.class);
+
+    private Basket basket;
+
+    private List<Object> ret = new ArrayList<>();
+
+    private Set<Object> set = new HashSet<>();
+
+    private String traceId;
+
+    /**
+     * 业务参数
+     */
+    private Map<String, Object> param;
+
+    public Consumer() {
+    }
+
+    @Override
+    public void run() {
+        logger.info("*******************Consumer:" + Thread.currentThread().getId() + " start");
+        try {
+            while (true) {
+                // 先判断是否有异常结束
+                if (basket.isExcuteError()) {
+                    break;
+                }
+                // 取消费数据
+                Object o = basket.consume();
+                // 判断消费数据是否是结束
+                if (o instanceof EndObject) {
+                    break;
+                }
+                @SuppressWarnings("unchecked")
+                T t = (T) o;
+                // logger.info("*******************Consumer:"+Thread.currentThread().getId()+"
+                // consume");
+                // 消费数据实现
+                consume(this.param, t);
+                logger.info("已处理:" + basket.updateProcess(1));
+            }
+        } catch (Exception e) {
+            basket.setExcuteError(true);
+            logger.error("消费线程处理出错", e);
+        } finally {
+            basket.countDown();
+            logger.info("*******************Consumer:" + Thread.currentThread().getId() + " stop");
+            ThreadContext.clearAll();
+        }
+    }
+
+    public abstract void consume(Map<String, Object> param, T t);
+
+    public Basket getBasket() {
+        return basket;
+    }
+
+    public void setBasket(Basket basket) {
+        this.basket = basket;
+    }
+
+    public String getTraceId() {
+        return traceId;
+    }
+
+    public void setTraceId(String traceId) {
+        this.traceId = traceId;
+    }
+
+    public List<Object> getRet() {
+        return ret;
+    }
+
+    public void addRet(Object r) {
+        ret.add(r);
+    }
+
+    protected Map<String, Object> getParam() {
+        return param;
+    }
+
+    protected void setParam(Map<String, Object> param) {
+        this.param = param;
+    }
+
+    public Set<Object> getSet() {
+        return set;
+    }
+
+    public void addSet(Object r) {
+        set.add(r);
+    }
 }