Explorar el Código

fix外键查询慢

xiatian hace 2 años
padre
commit
5cebbcb7bb

+ 95 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/randompaper/PaperDetailDto.java

@@ -0,0 +1,95 @@
+package cn.com.qmth.examcloud.core.questions.service.bean.randompaper;
+
+public class PaperDetailDto {
+	public String id;
+
+    private Integer number;// 大题序号
+
+    private String name;// 大题名称
+
+    private Double score;// 大题分数
+
+    private Integer unitCount;// 大题下的小题数量
+
+    private String creator;// 创建人id
+
+    private String createTime;// 创建时间
+    
+    //复制数据用
+    private Long orgId;
+    
+
+
+    public Integer getNumber() {
+        return number;
+    }
+
+    public void setNumber(Integer number) {
+        this.number = number;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Double getScore() {
+        return score;
+    }
+
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public Integer getUnitCount() {
+        return unitCount;
+    }
+
+    public void setUnitCount(Integer unitCount) {
+        this.unitCount = unitCount;
+    }
+
+    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 PaperDetailDto() {
+
+    }
+
+
+	public Long getOrgId() {
+		return orgId;
+	}
+
+	public void setOrgId(Long orgId) {
+		this.orgId = orgId;
+	}
+
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
+	
+    
+}

+ 100 - 265
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/randompaper/PaperDetailUnitDto.java

@@ -1,282 +1,101 @@
 package cn.com.qmth.examcloud.core.questions.service.bean.randompaper;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.springframework.data.mongodb.core.mapping.DBRef;
 
-import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
 import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
-import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
-import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetail;
 import cn.com.qmth.examcloud.core.questions.dao.entity.base.MongoBaseEntity;
 
 public class PaperDetailUnitDto extends MongoBaseEntity {
 
-    /**
+	/**
 	 * 
 	 */
 	private static final long serialVersionUID = 266448283780973578L;
 
-	@DBRef(lazy = false)
-    private Paper paper;// 关联的试卷
-
-    private Integer number;// 小题序号
-
-    private Double score;// 小题分数
-
-    private List<Double> subScoreList;// 对应套题的情况下,各子题的分数分布
-
-    @DBRef(lazy = false)
-    private PaperDetail paperDetail;// 关联的大题
-
-    private QuesStructType questionType;// 小题类型
-
-    @DBRef(lazy = false)
-    private QuestionDto question;// 关联试题
-
-    private String creator;// 创建人id
-
-    private String createTime;// 创建时间
-
-    private PaperType paperType;
-    //复制数据用
-    private Long orgId;
-    /**
-     * 作答限时 K12
-     */
-    private Long timeLimit;
-
-    public PaperDetailUnitDto() {
-    }
-
-    public PaperDetailUnitDto(Paper paper, PaperDetail paperDetail, QuestionDto question) {
-        this.paper = paper;
-        this.questionType = question.getQuestionType();
-        this.question = question;
-        this.createTime = CommonUtils.getCurDateTime();
-        this.paperDetail = paperDetail;
-        this.score = 0d;
-    }
-
-    public Paper getPaper() {
-        return paper;
-    }
-
-    public void setPaper(Paper paper) {
-        this.paper = paper;
-    }
-
-    public Integer getNumber() {
-        return number;
-    }
-
-    public void setNumber(Integer number) {
-        this.number = number;
-    }
-
-    public Double getScore() {
-        return score;
-    }
-
-    public void setScore(Double score) {
-        this.score = score;
-        // 非套题或试题未设置时,不做额外处理
-        if (questionType != QuesStructType.NESTED_ANSWER_QUESTION || question == null) {
-            return;
-        }
-        // 当前分数设置为空时,同时设置子题分数为空
-        if (score == null) {
-            subScoreList = null;
-            return;
-        }
-        // 总分与子题分数之和相同,则不做额外处理
-        if (subScoreList != null && subScoreList.size() > 0 && getSubScoreSum() == score) {
-            return;
-        }
-        // 根据试题与总分设置情况重置子题分数
-        if (question.getSubQuestions() != null) {
-            initSubScoreList(score, question.getSubQuestions());
-        }
-    }
-
-    public PaperDetail getPaperDetail() {
-        return paperDetail;
-    }
-
-    public void setPaperDetail(PaperDetail paperDetail) {
-        this.paperDetail = paperDetail;
-    }
-
-    public QuesStructType getQuestionType() {
-        return questionType;
-    }
-
-    public void setQuestionType(QuesStructType questionType) {
-        this.questionType = questionType;
-    }
-
-    public QuestionDto getQuestion() {
-        return question;
-    }
-
-    public void setQuestion(QuestionDto question) {
-        this.question = question;
-        // 非套题或总分未设置时,不做额外处理
-        if (questionType != QuesStructType.NESTED_ANSWER_QUESTION || score == null) {
-            return;
-        }
-        // 当前试题或子题列表为空时,同时设置子题分数为空
-        if (question == null || question.getSubQuestions() == null) {
-            subScoreList = null;
-            return;
-        }
-        // 当前试题子题数量与子题分数数量相同,不做额外处理
-        if (subScoreList != null && subScoreList.size() == question.getSubQuestions().size()) {
-            return;
-        }
-        // 根据试题与总分设置情况重置子题分数
-        initSubScoreList(score, question.getSubQuestions());
-    }
-
-    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 List<Double> getSubScoreList() {
-        return subScoreList;
-    }
-
-
-    public PaperType getPaperType() {
-        return paperType;
-    }
-
-    public void setPaperType(PaperType paperType) {
-        if (paper != null) {
-            this.paperType = paper.getPaperType();
-        } else {
-            this.paperType = paperType;
-        }
-    }
-
-    public void setSubScoreList(List<Double> subScoreList) {
-        this.subScoreList = subScoreList;
-        if (subScoreList != null) {
-            double totalScore = 0;
-            for (Double score : subScoreList) {
-                if (score == null) {
-                    score = 0d;
-                }
-                totalScore += score;
-            }
-            this.score = CommonUtils.formatDouble(totalScore);
-        }
-    }
-
-    public void setSubScoreListNew(List<Double> subScoreList) {
-        this.subScoreList = subScoreList;
-    }
-
-    public Long getTimeLimit() {
-        return timeLimit;
-    }
-
-    public void setTimeLimit(Long timeLimit) {
-        this.timeLimit = timeLimit;
-    }
-
-
-    /**
-     * 根据预设总分自动拆解套题子题的分数分布 目前采取均分后累加到最后一题的做法
-     *
-     * @param totalScore
-     * @param questionList
-     */
-    private void initSubScoreList(double totalScore, List<QuestionDto> questionList) {
-        List<Double> scoreList = new ArrayList<>();
-        int count = questionList.size();
-        if (count > 0) {
-            int baseScore = (int) (totalScore / count);
-            double leftScore = totalScore;
-            for (int i = 0; i < count; i++) {
-                scoreList.add((double) baseScore);
-                leftScore -= baseScore;
-            }
-            if (leftScore > 0) {
-                scoreList.set(count - 1, baseScore + leftScore);
-            }
-            this.subScoreList = scoreList;
-        }
-    }
-
-    private double getSubScoreSum() {
-        double totalScore = 0;
-        if (subScoreList != null) {
-            for (Double score : subScoreList) {
-                totalScore += score;
-            }
-        }
-        return CommonUtils.formatDouble(totalScore);
-    }
-
-    public int getDetailNumber() {
-    	if(this.paperDetail==null) {
-    		return -1;
-    	}
-        return this.paperDetail.getNumber();
-    }
-
-    public String getDetailId() {
-    	if(this.paperDetail==null) {
-    		return null;
-    	}
-        return this.paperDetail.getId();
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result
-                + ((question == null) ? 0 : question.getId().hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        PaperDetailUnitDto other = (PaperDetailUnitDto) obj;
-        if (question == null) {
-            if (other.question != null) {
-                return false;
-            }
-        } else if (!question.getId().equals(other.question.getId())) {
-            return false;
-        }
-        return true;
-    }
+	private Integer number;// 小题序号
+
+	@DBRef(lazy = true)
+	private PaperDetailDto paperDetail;// 关联的大题
+
+	private QuesStructType questionType;// 小题类型
+
+	@DBRef(lazy = true)
+	private QuestionDto question;// 关联试题
+
+	private String questionId;// 关联试题
+
+	private String creator;// 创建人id
+
+	private String createTime;// 创建时间
+
+	private PaperType paperType;
+	// 复制数据用
+	private Long orgId;
+	/**
+	 * 作答限时 K12
+	 */
+	private Long timeLimit;
+
+	public PaperDetailUnitDto() {
+	}
+
+	public Integer getNumber() {
+		return number;
+	}
+
+	public void setNumber(Integer number) {
+		this.number = number;
+	}
+
+
+	public PaperDetailDto getPaperDetail() {
+		return paperDetail;
+	}
+
+	public void setPaperDetail(PaperDetailDto paperDetail) {
+		this.paperDetail = paperDetail;
+	}
+
+	public QuesStructType getQuestionType() {
+		return questionType;
+	}
+
+	public void setQuestionType(QuesStructType questionType) {
+		this.questionType = questionType;
+	}
+
+	public QuestionDto getQuestion() {
+		return question;
+	}
+
+	public void setQuestion(QuestionDto question) {
+		this.question = question;
+	}
+
+	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 PaperType getPaperType() {
+		return paperType;
+	}
+
+	public void setPaperType(PaperType paperType) {
+		this.paperType = paperType;
+	}
 
 	public Long getOrgId() {
 		return orgId;
@@ -286,4 +105,20 @@ public class PaperDetailUnitDto extends MongoBaseEntity {
 		this.orgId = orgId;
 	}
 
+	public Long getTimeLimit() {
+		return timeLimit;
+	}
+
+	public void setTimeLimit(Long timeLimit) {
+		this.timeLimit = timeLimit;
+	}
+
+	public String getQuestionId() {
+		return questionId;
+	}
+
+	public void setQuestionId(String questionId) {
+		this.questionId = questionId;
+	}
+
 }

+ 10 - 6
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/bean/randompaper/QuestionDto.java

@@ -5,15 +5,11 @@ import java.util.List;
 import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
 import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
 import cn.com.qmth.examcloud.core.questions.dao.entity.QuesProperty;
-import cn.com.qmth.examcloud.core.questions.dao.entity.base.MongoBaseEntity;
 import cn.com.qmth.examcloud.question.commons.core.question.AnswerType;
 
-public class QuestionDto extends MongoBaseEntity {
+public class QuestionDto {
 
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 448493904015571457L;
+	public String id;
 
 	private QuesStructType questionType;// 试题结构类型
 	/*
@@ -149,4 +145,12 @@ public class QuestionDto extends MongoBaseEntity {
 		this.answerType = answerType;
 	}
 
+	public String getId() {
+		return id;
+	}
+
+	public void setId(String id) {
+		this.id = id;
+	}
+
 }

+ 101 - 33
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/RandomPaperServiceImpl.java

@@ -51,6 +51,7 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStruct
 import cn.com.qmth.examcloud.core.questions.service.PaperStructService;
 import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.CreateDefaultPaperParam;
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailDto;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailUnitDto;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperQuestionViewQuery;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperVo;
@@ -65,6 +66,7 @@ import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuest
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionInfo;
 import cn.com.qmth.examcloud.core.questions.service.cache.RandomPaperCache;
 import cn.com.qmth.examcloud.core.questions.service.util.BatchGetDataUtil;
+import cn.com.qmth.examcloud.core.questions.service.util.BatchSetDataUtil;
 import cn.com.qmth.examcloud.core.questions.service.util.PaperUtil;
 import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
 import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
@@ -102,7 +104,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			return Page.empty();
 		}
 		Query query;
-		List<Criteria> cs=new ArrayList<>();
+		List<Criteria> cs = new ArrayList<>();
 		cs.add(Criteria.where("rootOrgId").is(req.getRootOrgId()));
 
 		if (req.getUd().assertNeedQueryRefIds()) {
@@ -120,14 +122,14 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			String paperName = CommonUtils.escapeExprSpecialWord(req.getName());
 			cs.add(Criteria.where("name").regex(".*?\\.*" + paperName + ".*"));
 		}
-		Criteria and=new Criteria();
-		Criteria[] cas=new Criteria[cs.size()];
+		Criteria and = new Criteria();
+		Criteria[] cas = new Criteria[cs.size()];
 		if (StringUtils.isNotBlank(req.getId())) {
 			and.andOperator(cs.toArray(cas));
-			query=Query.query(new Criteria().orOperator(and,Criteria.where("id").is(req.getId())));
-		}else {
+			query = Query.query(new Criteria().orOperator(and, Criteria.where("id").is(req.getId())));
+		} else {
 			and.andOperator(cs.toArray(cas));
-			query=Query.query(and);
+			query = Query.query(and);
 		}
 
 		long total = this.mongoTemplate.count(query, RandomPaper.class);
@@ -155,10 +157,10 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			vo.setEnableStr(vo.getEnable() ? "启用" : "禁用");
 		}
 		fillUserName(paperList, req.getRootOrgId());
-		
 
 		return new PageImpl<>(paperList, pageable, total);
 	}
+
 	private void fillUserName(List<RandomPaperListVo> dtos, Long rootOrgId) {
 		if (dtos != null && dtos.size() > 0) {
 			List<Long> ids = dtos.stream().map(dto -> dto.getUpdateBy()).distinct().collect(Collectors.toList());
@@ -242,9 +244,10 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 					Integer difficultyCount = 0;
 					if (CollectionUtils.isNotEmpty(paperDetailStruct.getUnitStructs())) {
 						for (PaperDetailUnitStructDto unitStruct : paperDetailStruct.getUnitStructs()) {
-							simpleCount = simpleCount+unitStruct.getPublicSimple() + unitStruct.getNoPublicSimple();
-							mediumCount = mediumCount+unitStruct.getPublicMedium() + unitStruct.getNoPublicMedium();
-							difficultyCount = difficultyCount+unitStruct.getPublicDifficulty() + unitStruct.getNoPublicDifficulty();
+							simpleCount = simpleCount + unitStruct.getPublicSimple() + unitStruct.getNoPublicSimple();
+							mediumCount = mediumCount + unitStruct.getPublicMedium() + unitStruct.getNoPublicMedium();
+							difficultyCount = difficultyCount + unitStruct.getPublicDifficulty()
+									+ unitStruct.getNoPublicDifficulty();
 						}
 					}
 					sqinfo.setHardInfo(new StructQuestionCountInfo(difficultyCount, true));
@@ -302,11 +305,9 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 		StructInfo ret = new StructInfo();
 		ret.setValid(true);
 		PaperStruct ps = Model.of(paperStructRepo.findById(structId));
-		List<PaperDetailUnitDto> unitList = new ArrayList<>();
 		List<QuestionDto> questionList = new ArrayList<>();
-		for (String paperId : paperIds) {
-			unitList.addAll(findUnitPaperId(paperId));
-		}
+		List<PaperDetailUnitDto> unitList=findUnitByPaperIds(paperIds);
+		fillQuestionAndDetail(unitList);
 		StructQuestionCheckDto cd = new StructQuestionCheckDto();
 		cd.setQuestionList(questionList);
 		if (PaperStructType.BLUEPRINT.equals(ps.getPaperStrucType())) {
@@ -370,6 +371,69 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 		fillValid(ret);
 		return ret;
 	}
+	
+	private void fillQuestionAndDetail(List<PaperDetailUnitDto> units) {
+		if (CollectionUtils.isNotEmpty(units)) {
+            new BatchSetDataUtil<PaperDetailUnitDto>() {
+
+                @Override
+                protected void setData(List<PaperDetailUnitDto> dataList) {
+                    List<String> ids = dataList.stream().map(p -> p.getQuestion().id).collect(Collectors.toList());
+                    List<QuestionDto> temList = findQuestionByIds(ids);
+                    if (CollectionUtils.isNotEmpty(temList)) {
+                        Map<String, QuestionDto> map = new HashMap<>();
+                        for (QuestionDto vo : temList) {
+                            map.put(vo.getId(), vo);
+                        }
+                        for (PaperDetailUnitDto dto : dataList) {
+                        	dto.setQuestion(map.get(dto.getQuestion().id));
+                        }
+                    }
+                    ids = dataList.stream().map(p -> p.getPaperDetail().id).collect(Collectors.toList());
+                    List<PaperDetailDto> details=findDetailByIds(ids);
+                    if (CollectionUtils.isNotEmpty(temList)) {
+                        Map<String, PaperDetailDto> map = new HashMap<>();
+                        for (PaperDetailDto vo : details) {
+                            map.put(vo.getId(), vo);
+                        }
+                        for (PaperDetailUnitDto dto : dataList) {
+                        	dto.setPaperDetail(map.get(dto.getPaperDetail().id));
+                        }
+                    }
+                }
+            }.setDataForBatch(units, 1000);
+        }
+	}
+	
+	private List<QuestionDto> findQuestionByIds(List<String> questionIds) {
+		List<Object> ids = new ArrayList<>();
+		for (String pid : questionIds) {
+			if (pid.length() > 24) {
+				ids.add(pid);
+			} else {
+				ids.add(new ObjectId(pid));
+			}
+		}
+		Query query = new Query();
+		query.addCriteria(Criteria.where("id").in(ids));
+		List<QuestionDto> units = this.mongoTemplate.find(query, QuestionDto.class, "question");
+		return units;
+	}
+	
+	private List<PaperDetailDto> findDetailByIds(List<String> detailIds) {
+		List<Object> ids = new ArrayList<>();
+		for (String pid : detailIds) {
+			if (pid.length() > 24) {
+				ids.add(pid);
+			} else {
+				ids.add(new ObjectId(pid));
+			}
+		}
+		Query query = new Query();
+		query.addCriteria(Criteria.where("id").in(ids));
+		List<PaperDetailDto> units = this.mongoTemplate.find(query, PaperDetailDto.class, "paperDetail");
+		return units;
+	}
 
 	private void fillValid(StructInfo ret) {
 		if (CollectionUtils.isEmpty(ret.getStructQuestionInfo())) {
@@ -629,13 +693,17 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 		return false;
 	}
 
-	private List<PaperDetailUnitDto> findUnitPaperId(String paperId) {
-		Query query = new Query();
-		if (paperId.length() > 24) {
-			query.addCriteria(Criteria.where("paper.$id").is(paperId));
-		} else {
-			query.addCriteria(Criteria.where("paper.$id").is(new ObjectId(paperId)));
+	private List<PaperDetailUnitDto> findUnitByPaperIds(List<String> paperIds) {
+		List<Object> ids = new ArrayList<>();
+		for (String pid : paperIds) {
+			if (pid.length() > 24) {
+				ids.add(pid);
+			} else {
+				ids.add(new ObjectId(pid));
+			}
 		}
+		Query query = new Query();
+		query.addCriteria(Criteria.where("paper.$id").in(ids));
 		List<PaperDetailUnitDto> units = this.mongoTemplate.find(query, PaperDetailUnitDto.class, "paperDetailUnit");
 		return units;
 	}
@@ -818,15 +886,15 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 		GetUserResp ures = userCloudService.getUser(ureq);
 		vo.setUpdateByName(ures.getUserBean().getDisplayName());
 		Query query = new Query();
-		List<Object> ids=new ArrayList<>();
-		for(String pid:vo.getPaperIds()) {
-			if(pid.length()>24) {
+		List<Object> ids = new ArrayList<>();
+		for (String pid : vo.getPaperIds()) {
+			if (pid.length() > 24) {
 				ids.add(pid);
-			}else {
+			} else {
 				ids.add(new ObjectId(pid));
 			}
 		}
-        query.addCriteria(Criteria.where("id").in(ids));
+		query.addCriteria(Criteria.where("id").in(ids));
 		List<PaperVo> papers = this.mongoTemplate.find(query, PaperVo.class, "paper");
 		vo.setPapers(papers);
 		return vo;
@@ -1045,7 +1113,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 	}
 
 	private Integer[] getOption(Integer count) {
-		if(count==null) {
+		if (count == null) {
 			return null;
 		}
 		Integer[] ret = new Integer[count];
@@ -1089,20 +1157,20 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 	public boolean existStruct(String paperStructId) {
 		Query query = new Query();
 		query.addCriteria(Criteria.where("paperStructId").is(paperStructId));
-		RandomPaper rp=mongoTemplate.findOne(query,RandomPaper.class);
-		return rp!=null;
+		RandomPaper rp = mongoTemplate.findOne(query, RandomPaper.class);
+		return rp != null;
 	}
 
 	@Override
-	public boolean existPaper(Long courseId,String paperId) {
+	public boolean existPaper(Long courseId, String paperId) {
 		Query query = new Query();
 		query.addCriteria(Criteria.where("courseId").is(courseId));
-		List<RandomPaper> rps=mongoTemplate.find(query,RandomPaper.class);
-		if(CollectionUtils.isEmpty(rps)) {
+		List<RandomPaper> rps = mongoTemplate.find(query, RandomPaper.class);
+		if (CollectionUtils.isEmpty(rps)) {
 			return false;
 		}
-		for(RandomPaper rp:rps) {
-			if(rp.getPaperIds().contains(paperId)) {
+		for (RandomPaper rp : rps) {
+			if (rp.getPaperIds().contains(paperId)) {
 				return true;
 			}
 		}

+ 29 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/util/BatchSetDataUtil.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.core.questions.service.util;
+
+import java.util.List;
+
+public abstract class BatchSetDataUtil<P> {
+	/**
+	 * @param dataList 待填充的对象集合
+	 * @param batchSize 每批数量
+	 */
+	public final void setDataForBatch(List<P> dataList, int batchSize) {
+		if (dataList == null || dataList.size() == 0) {
+			return;
+		}
+		if (dataList.size() <= batchSize) {
+			setData(dataList);
+		} else {
+			int size = dataList.size();
+			int len = batchSize;
+			int count = (size + len - 1) / len;
+
+			for (int i = 0; i < count; i++) {
+				List<P> subList = dataList.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
+				setData(subList);
+			}
+		}
+	}
+
+	protected abstract void setData(List<P> dataList);
+}