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