|
@@ -1,227 +1,297 @@
|
|
|
-package cn.com.qmth.dp.examcloud.oe.modules.findreduplicatequestion;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-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.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.PaperType;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
-import cn.com.qmth.dp.examcloud.oe.util.PaperUtil;
|
|
|
-import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
-
|
|
|
-@Service
|
|
|
-@Scope("prototype")
|
|
|
-public class ExportQuesReduplicateConsumer extends Consumer<Course> {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void consume(Map<String, Object> param, Course c) {
|
|
|
- String rootOrgId = (String) param.get("rootOrgId");
|
|
|
-// String paperName = (String) param.get("paperName");
|
|
|
-// List<PaperDto> papers = findPaper(rootOrgId, c.getCode(), paperName);
|
|
|
-// if (CollectionUtils.isEmpty(papers)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// List<ObjectId> paperIds = papers.stream().map(e -> new ObjectId(e.getId())).collect(Collectors.toList());
|
|
|
-// List<UnitDto> units = findUnit(paperIds);
|
|
|
-// if (CollectionUtils.isEmpty(units)) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// List<UnitDto> sin = findUnitByType(units, QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
-// if (CollectionUtils.isNotEmpty(sin)) {
|
|
|
-// check(sin, c.getName(), c.getCode());
|
|
|
-// }
|
|
|
-// List<UnitDto> mut = findUnitByType(units, QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
-// if (CollectionUtils.isNotEmpty(mut)) {
|
|
|
-// check(mut, c.getName(), c.getCode());
|
|
|
-// }
|
|
|
-// List<UnitDto> bool = findUnitByType(units, QuesStructType.BOOL_ANSWER_QUESTION);
|
|
|
-// if (CollectionUtils.isNotEmpty(bool)) {
|
|
|
-// check(bool, c.getName(), c.getCode());
|
|
|
-// }
|
|
|
-
|
|
|
- List<QuestionDto> quess = findQuestion(rootOrgId, c.getCode());
|
|
|
- if (CollectionUtils.isEmpty(quess)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Map<QuesStructType,List<QuestionDto>> map=toMap(quess);
|
|
|
- for(QuesStructType k:map.keySet()) {
|
|
|
- checkQuestion(map.get(k), c.getName(), c.getCode());
|
|
|
- }
|
|
|
- System.out.println("处理完科目:" + c.getCode());
|
|
|
- }
|
|
|
-
|
|
|
-// private List<UnitDto> findUnitByType(List<UnitDto> dtos, QuesStructType type) {
|
|
|
-// List<UnitDto> ret = new ArrayList<>();
|
|
|
-// for (UnitDto dto : dtos) {
|
|
|
-// if (type.equals(dto.getQuestionType())) {
|
|
|
-// ret.add(dto);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return ret;
|
|
|
-// }
|
|
|
-
|
|
|
- private Map<QuesStructType,List<QuestionDto>> toMap(List<QuestionDto> dtos) {
|
|
|
- Map<QuesStructType,List<QuestionDto>> ret=new HashMap<>();
|
|
|
- for (QuestionDto dto : dtos) {
|
|
|
- List<QuestionDto> tem=ret.get(dto.getQuestionType());
|
|
|
- if(tem==null) {
|
|
|
- tem=new ArrayList<>();
|
|
|
- ret.put(dto.getQuestionType(), tem);
|
|
|
- }
|
|
|
- tem.add(dto);
|
|
|
- }
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
-// private List<PaperDto> findPaper(String rootOrgId, String courseCode, String paperName) {
|
|
|
-// Query query = new Query();
|
|
|
-// query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
-// query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT.name()));
|
|
|
-// query.addCriteria(Criteria.where("course.code").is(courseCode));
|
|
|
-// query.addCriteria(Criteria.where("name").regex(".*?\\.*" + paperName + ".*"));
|
|
|
-// List<PaperDto> ret = this.mongoTemplate.find(query, PaperDto.class, "paper");
|
|
|
-// return ret;
|
|
|
-// }
|
|
|
-
|
|
|
- private List<QuestionDto> findQuestion(String rootOrgId, String courseCode) {
|
|
|
- Date day=DateUtil.parse("2024-06-13 00:00:00", "yyyy-MM-dd HH:mm:ss");
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
- query.addCriteria(Criteria.where("course.code").is(courseCode));
|
|
|
- query.addCriteria(Criteria.where("creationBy").is(646523L));
|
|
|
- query.addCriteria(Criteria.where("creationDate").gt(day));
|
|
|
- List<QuestionDto> ret = this.mongoTemplate.find(query, QuestionDto.class, "question");
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
-// private List<UnitDto> findUnit(List<ObjectId> paperIds) {
|
|
|
-// Query query = new Query();
|
|
|
-// query.addCriteria(Criteria.where("paper.$id").in(paperIds));
|
|
|
-// List<UnitDto> ret = this.mongoTemplate.find(query, UnitDto.class, "paperDetailUnit");
|
|
|
-// return ret;
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void check(List<UnitDto> dtos, String cname, String ccode) {
|
|
|
-// Set<String> checkIds = new HashSet<>();
|
|
|
-// for (UnitDto dto : dtos) {
|
|
|
-// dto.setExtractText(PaperUtil.getExtractText(dto.getQuestion()));
|
|
|
-// if (StringUtils.isEmpty(dto.getExtractText())) {
|
|
|
-// checkIds.add(dto.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// int group = 0;
|
|
|
-// for (UnitDto dto : dtos) {
|
|
|
-// if (checkIds.contains(dto.getId())) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// String quesText1 = dto.getExtractText();
|
|
|
-// boolean hasGroup = false;
|
|
|
-// for (UnitDto subdto : dtos) {
|
|
|
-// if (subdto.getId().equals(dto.getId())) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// if (checkIds.contains(subdto.getId())) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// String quesText2 = subdto.getExtractText();
|
|
|
-// double similarity = StringSimilarityUtils.getSimilarityWithCosinesBySeg(quesText1, quesText2);
|
|
|
-// if (similarity > 0.95) {
|
|
|
-// checkIds.add(dto.getId());
|
|
|
-// checkIds.add(subdto.getId());
|
|
|
-// if (!hasGroup) {
|
|
|
-// hasGroup = true;
|
|
|
-// group++;
|
|
|
-// RetDto rd = new RetDto(group, ccode, cname, dto.getPaper().getName(),
|
|
|
-// dto.getQuestionType().getName(), dto.getPaperDetail().getNumber(), dto.getNumber());
|
|
|
-// addRet(rd);
|
|
|
-// }
|
|
|
-// RetDto rd = new RetDto(group, ccode, cname, subdto.getPaper().getName(),
|
|
|
-// subdto.getQuestionType().getName(), subdto.getPaperDetail().getNumber(),
|
|
|
-// subdto.getNumber());
|
|
|
-// addRet(rd);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- private void checkQuestion(List<QuestionDto> dtos, String cname, String ccode) {
|
|
|
- Set<String> checkIds = new HashSet<>();
|
|
|
- for (QuestionDto dto : dtos) {
|
|
|
- dto.setExtractText(PaperUtil.getExtractText(dto));
|
|
|
- if (PaperUtil.hasImg(dto)||StringUtils.isEmpty(dto.getExtractText())) {
|
|
|
- checkIds.add(dto.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- int length = dtos.size();
|
|
|
- int group = 0;
|
|
|
- for (int i = 0; i < length - 1; i++) {
|
|
|
- QuestionDto dto=dtos.get(i);
|
|
|
- if (checkIds.contains(dto.getId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String quesText1 = dto.getExtractText();
|
|
|
- boolean hasGroup = false;
|
|
|
- for (int j = i + 1; j < length; j++) {
|
|
|
- QuestionDto subdto=dtos.get(j);
|
|
|
- if (checkIds.contains(subdto.getId())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String quesText2 = subdto.getExtractText();
|
|
|
-// double similarity = StringSimilarityUtils.getSimilarityWithCosinesBySeg(quesText1, quesText2);
|
|
|
-// if (similarity > 0.94) {
|
|
|
- if (StringUtils.equals(quesText1, quesText2)) {
|
|
|
- checkIds.add(dto.getId());
|
|
|
- checkIds.add(subdto.getId());
|
|
|
- if (!hasGroup) {
|
|
|
- hasGroup = true;
|
|
|
- group++;
|
|
|
- RetDto rd = new RetDto(group, ccode, cname, dto.getQuestionType().getName(),dto.getId());
|
|
|
- rd.setValid("是");
|
|
|
- fillInfo(rd);
|
|
|
- addRet(rd);
|
|
|
- }
|
|
|
- RetDto rd = new RetDto(group, ccode, cname, subdto.getQuestionType().getName(),subdto.getId());
|
|
|
- rd.setValid("否");
|
|
|
- fillInfo(rd);
|
|
|
- addRet(rd);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void fillInfo(RetDto dto) {
|
|
|
- UnitDto u=getUnit(dto.getQuestionId());
|
|
|
- dto.setPaperName(u.getPaper().getName());
|
|
|
- dto.setDetailNum(u.getPaperDetail().getNumber());
|
|
|
- dto.setUnitNum(u.getNumber());
|
|
|
- dto.setUnitId(u.getId());
|
|
|
- }
|
|
|
-
|
|
|
- private UnitDto getUnit(String questionId) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("question.$id").in(new ObjectId(questionId)));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT.name()));
|
|
|
- List<UnitDto> ret = this.mongoTemplate.find(query, UnitDto.class, "paperDetailUnit");
|
|
|
- return ret.get(0);
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.findreduplicatequestion;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+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.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.PaperType;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.enums.question.QuesStructType;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.multithread.Consumer;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.util.PaperUtil;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Scope("prototype")
|
|
|
+public class ExportQuesReduplicateConsumer extends Consumer<Course> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void consume(Map<String, Object> param, Course c) {
|
|
|
+ String rootOrgId = (String) param.get("rootOrgId");
|
|
|
+ // String paperName = (String) param.get("paperName");
|
|
|
+ // List<PaperDto> papers = findPaper(rootOrgId, c.getCode(), paperName);
|
|
|
+ // if (CollectionUtils.isEmpty(papers)) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // List<ObjectId> paperIds = papers.stream().map(e -> new
|
|
|
+ // ObjectId(e.getId())).collect(Collectors.toList());
|
|
|
+ // List<UnitDto> units = findUnit(paperIds);
|
|
|
+ // if (CollectionUtils.isEmpty(units)) {
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // List<UnitDto> sin = findUnitByType(units,
|
|
|
+ // QuesStructType.SINGLE_ANSWER_QUESTION);
|
|
|
+ // if (CollectionUtils.isNotEmpty(sin)) {
|
|
|
+ // check(sin, c.getName(), c.getCode());
|
|
|
+ // }
|
|
|
+ // List<UnitDto> mut = findUnitByType(units,
|
|
|
+ // QuesStructType.MULTIPLE_ANSWER_QUESTION);
|
|
|
+ // if (CollectionUtils.isNotEmpty(mut)) {
|
|
|
+ // check(mut, c.getName(), c.getCode());
|
|
|
+ // }
|
|
|
+ // List<UnitDto> bool = findUnitByType(units,
|
|
|
+ // QuesStructType.BOOL_ANSWER_QUESTION);
|
|
|
+ // if (CollectionUtils.isNotEmpty(bool)) {
|
|
|
+ // check(bool, c.getName(), c.getCode());
|
|
|
+ // }
|
|
|
+
|
|
|
+ List<QuestionDto> quess = findQuestion(rootOrgId, c.getCode());
|
|
|
+ if (CollectionUtils.isEmpty(quess)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<QuesStructType, List<QuestionDto>> map = toMap(quess);
|
|
|
+ for (QuesStructType k : map.keySet()) {
|
|
|
+ checkQuestion(map.get(k), c.getName(), c.getCode());
|
|
|
+ }
|
|
|
+ System.out.println("处理完科目:" + c.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ // private List<UnitDto> findUnitByType(List<UnitDto> dtos, QuesStructType
|
|
|
+ // type) {
|
|
|
+ // List<UnitDto> ret = new ArrayList<>();
|
|
|
+ // for (UnitDto dto : dtos) {
|
|
|
+ // if (type.equals(dto.getQuestionType())) {
|
|
|
+ // ret.add(dto);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return ret;
|
|
|
+ // }
|
|
|
+
|
|
|
+ private Map<QuesStructType, List<QuestionDto>> toMap(List<QuestionDto> dtos) {
|
|
|
+ Map<QuesStructType, List<QuestionDto>> ret = new HashMap<>();
|
|
|
+ for (QuestionDto dto : dtos) {
|
|
|
+ List<QuestionDto> tem = ret.get(dto.getQuestionType());
|
|
|
+ if (tem == null) {
|
|
|
+ tem = new ArrayList<>();
|
|
|
+ ret.put(dto.getQuestionType(), tem);
|
|
|
+ }
|
|
|
+ tem.add(dto);
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // private List<PaperDto> findPaper(String rootOrgId, String courseCode,
|
|
|
+ // String paperName) {
|
|
|
+ // Query query = new Query();
|
|
|
+ // query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
+ // query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT.name()));
|
|
|
+ // query.addCriteria(Criteria.where("course.code").is(courseCode));
|
|
|
+ // query.addCriteria(Criteria.where("name").regex(".*?\\.*" + paperName +
|
|
|
+ // ".*"));
|
|
|
+ // List<PaperDto> ret = this.mongoTemplate.find(query, PaperDto.class,
|
|
|
+ // "paper");
|
|
|
+ // return ret;
|
|
|
+ // }
|
|
|
+
|
|
|
+ private List<QuestionDto> findQuestion(String rootOrgId, String courseCode) {
|
|
|
+ // Date day=DateUtil.parse("2024-06-13 00:00:00", "yyyy-MM-dd
|
|
|
+ // HH:mm:ss");
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(rootOrgId));
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(courseCode));
|
|
|
+ // query.addCriteria(Criteria.where("creationBy").is(646523L));
|
|
|
+ // query.addCriteria(Criteria.where("creationDate").gt(day));
|
|
|
+ List<QuestionDto> ret = this.mongoTemplate.find(query, QuestionDto.class, "question");
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ // private List<UnitDto> findUnit(List<ObjectId> paperIds) {
|
|
|
+ // Query query = new Query();
|
|
|
+ // query.addCriteria(Criteria.where("paper.$id").in(paperIds));
|
|
|
+ // List<UnitDto> ret = this.mongoTemplate.find(query, UnitDto.class,
|
|
|
+ // "paperDetailUnit");
|
|
|
+ // return ret;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // private void check(List<UnitDto> dtos, String cname, String ccode) {
|
|
|
+ // Set<String> checkIds = new HashSet<>();
|
|
|
+ // for (UnitDto dto : dtos) {
|
|
|
+ // dto.setExtractText(PaperUtil.getExtractText(dto.getQuestion()));
|
|
|
+ // if (StringUtils.isEmpty(dto.getExtractText())) {
|
|
|
+ // checkIds.add(dto.getId());
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // int group = 0;
|
|
|
+ // for (UnitDto dto : dtos) {
|
|
|
+ // if (checkIds.contains(dto.getId())) {
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // String quesText1 = dto.getExtractText();
|
|
|
+ // boolean hasGroup = false;
|
|
|
+ // for (UnitDto subdto : dtos) {
|
|
|
+ // if (subdto.getId().equals(dto.getId())) {
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // if (checkIds.contains(subdto.getId())) {
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // String quesText2 = subdto.getExtractText();
|
|
|
+ // double similarity =
|
|
|
+ // StringSimilarityUtils.getSimilarityWithCosinesBySeg(quesText1,
|
|
|
+ // quesText2);
|
|
|
+ // if (similarity > 0.95) {
|
|
|
+ // checkIds.add(dto.getId());
|
|
|
+ // checkIds.add(subdto.getId());
|
|
|
+ // if (!hasGroup) {
|
|
|
+ // hasGroup = true;
|
|
|
+ // group++;
|
|
|
+ // RetDto rd = new RetDto(group, ccode, cname, dto.getPaper().getName(),
|
|
|
+ // dto.getQuestionType().getName(), dto.getPaperDetail().getNumber(),
|
|
|
+ // dto.getNumber());
|
|
|
+ // addRet(rd);
|
|
|
+ // }
|
|
|
+ // RetDto rd = new RetDto(group, ccode, cname, subdto.getPaper().getName(),
|
|
|
+ // subdto.getQuestionType().getName(), subdto.getPaperDetail().getNumber(),
|
|
|
+ // subdto.getNumber());
|
|
|
+ // addRet(rd);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ private void checkQuestion(List<QuestionDto> dtos, String cname, String ccode) {
|
|
|
+ List<RetDto> ret = new ArrayList<>();
|
|
|
+ Set<String> checkIds = new HashSet<>();
|
|
|
+ for (QuestionDto dto : dtos) {
|
|
|
+ dto.setExtractText(PaperUtil.getExtractText(dto));
|
|
|
+ if (PaperUtil.hasImg(dto) || StringUtils.isEmpty(dto.getExtractText())) {
|
|
|
+ checkIds.add(dto.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int length = dtos.size();
|
|
|
+ int group = 0;
|
|
|
+ for (int i = 0; i < length - 1; i++) {
|
|
|
+ QuestionDto dto = dtos.get(i);
|
|
|
+ if (checkIds.contains(dto.getId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String quesText1 = dto.getExtractText();
|
|
|
+ boolean hasGroup = false;
|
|
|
+ for (int j = i + 1; j < length; j++) {
|
|
|
+ QuestionDto subdto = dtos.get(j);
|
|
|
+ if (checkIds.contains(subdto.getId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String quesText2 = subdto.getExtractText();
|
|
|
+ // double similarity =
|
|
|
+ // StringSimilarityUtils.getSimilarityWithCosinesBySeg(quesText1,
|
|
|
+ // quesText2);
|
|
|
+ // if (similarity > 0.94) {
|
|
|
+ if (StringUtils.equals(quesText1, quesText2)) {
|
|
|
+ checkIds.add(dto.getId());
|
|
|
+ checkIds.add(subdto.getId());
|
|
|
+ if (!hasGroup) {
|
|
|
+ hasGroup = true;
|
|
|
+ group++;
|
|
|
+ RetDto rd = new RetDto(group, ccode, cname, dto.getQuestionType().getName(), dto.getId());
|
|
|
+ rd.setCreationDate(dto.getCreationDate());
|
|
|
+ // rd.setValid("是");
|
|
|
+ fillInfo(rd);
|
|
|
+ ret.add(rd);
|
|
|
+ }
|
|
|
+ RetDto rd = new RetDto(group, ccode, cname, subdto.getQuestionType().getName(), subdto.getId());
|
|
|
+ rd.setCreationDate(subdto.getCreationDate());
|
|
|
+ // rd.setValid("否");
|
|
|
+ fillInfo(rd);
|
|
|
+ // addRet(rd);
|
|
|
+ ret.add(rd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 排序
|
|
|
+ Collections.sort(ret, new Comparator<RetDto>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(RetDto o1, RetDto o2) {
|
|
|
+ Integer d1 = o1.getGroup();
|
|
|
+ Integer d2 = o2.getGroup();
|
|
|
+ if (d1 < d2) {
|
|
|
+ return -1;
|
|
|
+ } else if (d1 > d2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ Date date1 = o1.getCreationDate();
|
|
|
+ Date date2 = o2.getCreationDate();
|
|
|
+ if (date1 == null && date2 == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ if (date1 == null) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if (date2 == null) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ long l1 = date1.getTime();
|
|
|
+ long l2 = date2.getTime();
|
|
|
+ if (l1 < l2) {
|
|
|
+ return -1;
|
|
|
+ } else if (l1 > l2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ Set<Integer> groups = new HashSet<>();
|
|
|
+ for (RetDto dto : ret) {
|
|
|
+ if (!groups.contains(dto.getGroup())) {
|
|
|
+ groups.add(dto.getGroup());
|
|
|
+ dto.setValid("是");
|
|
|
+ } else {
|
|
|
+ dto.setValid("否");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (RetDto dto : ret) {
|
|
|
+ addRet(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillInfo(RetDto dto) {
|
|
|
+ UnitDto u = getUnit(dto.getQuestionId());
|
|
|
+ dto.setPaperName(u.getPaper().getName());
|
|
|
+ dto.setDetailNum(u.getPaperDetail().getNumber());
|
|
|
+ dto.setUnitNum(u.getNumber());
|
|
|
+ dto.setUnitId(u.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ private UnitDto getUnit(String questionId) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("question.$id").in(new ObjectId(questionId)));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT.name()));
|
|
|
+ List<UnitDto> ret = this.mongoTemplate.find(query, UnitDto.class, "paperDetailUnit");
|
|
|
+ return ret.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|