Bläddra i källkod

自定义大题查询

xiatian 3 år sedan
förälder
incheckning
048c4e0601

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

@@ -3,27 +3,30 @@ 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 = 40, index = 1)
+	@ExcelProperty(name = "课程名称", width = 25, index = 1)
 	private String courseName;
-	@ExcelProperty(name = "课程代码", width = 40, index = 2)
+	@ExcelProperty(name = "课程代码", width = 25, index = 2)
 	private String courseCode;
-	@ExcelProperty(name = "单选", width = 40, index = 3)
+	@ExcelProperty(name = "单选", width = 15, index = 3)
 	private long singleAnswerQuestion;
 	
-	@ExcelProperty(name = "多选", width = 40, index = 4)
+	@ExcelProperty(name = "多选", width = 15, index = 4)
 	private long multipleAnswerQuestion;
 	
-	@ExcelProperty(name = "判断", width = 40, index = 5)
+	@ExcelProperty(name = "判断", width = 15, index = 5)
 	private long boolAnswerQuestion;
 	
-	@ExcelProperty(name = "填空", width = 40, index = 6)
+	@ExcelProperty(name = "填空", width = 15, index = 6)
 	private long fillBlankQuestion;
 	
-	@ExcelProperty(name = "问答", width = 40, index = 7)
+	@ExcelProperty(name = "问答", width = 15, index = 7)
 	private long textAnswerQuestion;
 	
-	@ExcelProperty(name = "套题", width = 40, index = 8)
+	@ExcelProperty(name = "套题", width = 15, index = 8)
 	private long nestedAnswerQuestion;
+	
+	@ExcelProperty(name = "案例分析", width = 15, index = 9)
+	private long ext;
 
 	public String getCourseName() {
 		return courseName;
@@ -88,6 +91,14 @@ public class CourseQuestionsCountRetDto {
 	public void setNestedAnswerQuestion(long nestedAnswerQuestion) {
 		this.nestedAnswerQuestion = nestedAnswerQuestion;
 	}
+
+	public long getExt() {
+		return ext;
+	}
+
+	public void setExt(long ext) {
+		this.ext = ext;
+	}
 	
 	
 }

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

@@ -0,0 +1,32 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+import javax.persistence.Id;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+public class Detail implements JsonSerializable {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -1424624250300317437L;
+	@Id
+    protected String 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;
+	}
+	
+	
+}

+ 12 - 108
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/export_course_questions_count/ExportCourseQuestionsCountService.java

@@ -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();
-	}
 }

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

@@ -1,38 +0,0 @@
-package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-
-/**
- * 按科目导出小题各题型数.多线程处理
- * 
- * @author chenken
- *
- */
-@Service
-public class ExportCourseQuestionsCountService2 {
-//	private String rootOrgId = "371";
-	private String rootOrgId = "1627";
-	private int threadCount=10;
-
-	public void start() {
-		Date s=new Date();
-		ExportQuesProducer pr = SpringContextHolder.getBean(ExportQuesProducer.class);
-		try {
-			Map<String, Object> param=new HashMap<>();
-			param.put("rootOrgId", rootOrgId);
-			pr.startDispose(ExportQuesConsumer.class, threadCount, param);
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-
-		}
-		Date e=new Date();
-		System.out.println("time:" + (e.getTime()-s.getTime()));
-	}
-
-}

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

@@ -3,8 +3,10 @@ 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.stream.Collectors;
 
 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;
@@ -12,6 +14,7 @@ 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;
@@ -36,9 +39,56 @@ public class ExportQuesConsumer extends Consumer<Course> {
 		List<QuestionTypeCount> tc = countByType(c.getCode(),rootOrgId);
 		if (CollectionUtils.isNotEmpty(tc)) {
 			setCount(rd, tc);
+			setExtCount(rd, rootOrgId);
 		}
 
 	}
+	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("TEXT_ANSWER_QUESTION"));
+		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())) {

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

@@ -0,0 +1,22 @@
+package cn.com.qmth.dp.examcloud.oe.modules.export_course_questions_count;
+
+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
+    protected String id;
+	public String getId() {
+		return id;
+	}
+	public void setId(String id) {
+		this.id = id;
+	}
+	
+	
+}