|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -21,105 +22,113 @@ 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.multithread.Consumer;
|
|
|
+import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
|
|
|
@Service
|
|
|
@Scope("prototype")
|
|
|
public class ExportQuesConsumer extends Consumer<Course> {
|
|
|
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
|
|
- @Override
|
|
|
- public void consume(Map<String, Object> param,Course c) {
|
|
|
- CourseQuestionsCountRetDto rd = new CourseQuestionsCountRetDto();
|
|
|
- String rootOrgId=(String)param.get("rootOrgId");
|
|
|
- rd.setCourseCode(c.getCode());
|
|
|
- rd.setCourseName(c.getName());
|
|
|
- List<QuestionTypeCount> tc = countByType(c.getCode(),rootOrgId);
|
|
|
- if (CollectionUtils.isNotEmpty(tc)) {
|
|
|
- setCount(rd, tc);
|
|
|
- setExtCount(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);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void consume(Map<String, Object> param, Course c) {
|
|
|
+ CourseQuestionsCountRetDto rd = new CourseQuestionsCountRetDto();
|
|
|
+ String rootOrgId = (String) param.get("rootOrgId");
|
|
|
+ rd.setCourseCode(c.getCode());
|
|
|
+ rd.setCourseName(c.getName());
|
|
|
+ List<QuestionTypeCount> tc = countByType(c.getCode(), rootOrgId);
|
|
|
+ if (CollectionUtils.isNotEmpty(tc)) {
|
|
|
+ setCount(rd, tc);
|
|
|
+ setExtCount(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 courseCode,String rootOrgId) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(rootOrgId).and("paperType").is("IMPORT").and("course.code").is(courseCode));
|
|
|
- List<IdBean> ps = mongoTemplate.find(query, IdBean.class, "paper");
|
|
|
- if(CollectionUtils.isEmpty(ps)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- List<ObjectId> ids=ps.stream().map(p->new ObjectId(p.getId())).collect(Collectors.toList());
|
|
|
- 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(CourseQuestionsCountRetDto rd,String rootOrgId) {
|
|
|
- List<ObjectId> paperIds=getPaperIds(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(String courseCode,String rootOrgId) {
|
|
|
- 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();
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
+ private List<ObjectId> getPaperIds(String courseCode, String rootOrgId) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(
|
|
|
+ Criteria.where("orgId").is(rootOrgId).and("paperType").is("IMPORT").and("course.code").is(courseCode));
|
|
|
+ List<IdBean> ps = mongoTemplate.find(query, IdBean.class, "paper");
|
|
|
+ if (CollectionUtils.isEmpty(ps)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<ObjectId> ids = ps.stream().map(p -> new ObjectId(p.getId())).collect(Collectors.toList());
|
|
|
+ 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(CourseQuestionsCountRetDto rd, String rootOrgId) {
|
|
|
+ List<ObjectId> paperIds = getPaperIds(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(String courseCode, String rootOrgId) {
|
|
|
+ List<AggregationOperation> operations = new ArrayList<>();
|
|
|
+ Date day = DateUtil.parse("2023-05-18 00:00:00", "yyyy-MM-dd HH:mm:ss");
|
|
|
+ operations.add(Aggregation.match(Criteria.where("orgId").is(rootOrgId).and("course.code").is(courseCode)
|
|
|
+ .and("creationBy").is(646523L).and("creationDate").gt(day)));
|
|
|
+ // 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();
|
|
|
+ }
|
|
|
|
|
|
}
|