|
@@ -1,7 +1,10 @@
|
|
|
package com.yaoxiang.diagnosis.service;
|
|
|
|
|
|
import com.yaoxiang.diagnosis.config.Constants;
|
|
|
+import com.yaoxiang.diagnosis.dao.PaperRepo;
|
|
|
import com.yaoxiang.diagnosis.dao.SpecialKnowledgeRepo;
|
|
|
+import com.yaoxiang.diagnosis.entity.Paper;
|
|
|
+import com.yaoxiang.diagnosis.entity.Question;
|
|
|
import com.yaoxiang.diagnosis.entity.SpecialKnowledge;
|
|
|
import com.yaoxiang.diagnosis.model.Result;
|
|
|
import com.yaoxiang.diagnosis.util.NumberUtil;
|
|
@@ -11,10 +14,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -23,6 +23,8 @@ public class SpecialKnowledgeService {
|
|
|
|
|
|
@Resource
|
|
|
private SpecialKnowledgeRepo specialKnowledgeRepo;
|
|
|
+ @Resource
|
|
|
+ private PaperService paperService;
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SpecialKnowledgeService.class);
|
|
|
|
|
@@ -69,45 +71,62 @@ public class SpecialKnowledgeService {
|
|
|
}
|
|
|
|
|
|
public void calcCount(List<SpecialKnowledge> list) {
|
|
|
- Map<Integer,List<SpecialKnowledge>> group = list.stream().collect(Collectors.groupingBy(SpecialKnowledge::getLevel));
|
|
|
- Map<Long,SpecialKnowledge> knowledgeMap = list.stream().collect(Collectors.toMap(SpecialKnowledge::getId,Function.identity()));
|
|
|
+ Map<Integer, List<SpecialKnowledge>> group = list.stream().collect(Collectors.groupingBy(SpecialKnowledge::getLevel));
|
|
|
+ Map<Long, SpecialKnowledge> knowledgeMap = list.stream().collect(Collectors.toMap(SpecialKnowledge::getId, Function.identity()));
|
|
|
int max = group.keySet().stream().max(Comparator.naturalOrder()).orElse(0);
|
|
|
- if(max ==0){
|
|
|
+ if (max == 0) {
|
|
|
logger.warn("最大层级为0,请检查数据");
|
|
|
}
|
|
|
- for (int i = max; i>1 ;i--){
|
|
|
+ for (int i = max; i > 1; i--) {
|
|
|
|
|
|
List<SpecialKnowledge> ss = group.get(i);
|
|
|
|
|
|
- Map<Long,List<SpecialKnowledge>> map = ss.stream().collect(Collectors.groupingBy(SpecialKnowledge::getParentId));
|
|
|
+ Map<Long, List<SpecialKnowledge>> map = ss.stream().collect(Collectors.groupingBy(SpecialKnowledge::getParentId));
|
|
|
double rate = 0;
|
|
|
- for (Map.Entry<Long,List<SpecialKnowledge>> entry:map.entrySet()){
|
|
|
+ for (Map.Entry<Long, List<SpecialKnowledge>> entry : map.entrySet()) {
|
|
|
int collectCount = 0;
|
|
|
int questionNum = 0;
|
|
|
List<SpecialKnowledge> specialKnowledges = entry.getValue();
|
|
|
- for (SpecialKnowledge s:specialKnowledges){
|
|
|
- collectCount+= s.getCollectNum();
|
|
|
+ for (SpecialKnowledge s : specialKnowledges) {
|
|
|
+ collectCount += s.getCollectNum();
|
|
|
questionNum += s.getQuestionNum();
|
|
|
}
|
|
|
|
|
|
- if(specialKnowledges.size() > 0){
|
|
|
+ if (specialKnowledges.size() > 0) {
|
|
|
SpecialKnowledge parent = knowledgeMap.get(entry.getKey());
|
|
|
parent.setCollectNum(collectCount);
|
|
|
parent.setQuestionNum(questionNum);
|
|
|
|
|
|
- if(i <= 4 && questionNum > 0){
|
|
|
+ if (i <= 4 && questionNum > 0) {
|
|
|
double master = collectCount * 100.0 / questionNum;
|
|
|
parent.setMaster(NumberUtil.format(master));
|
|
|
- if(master < 0.8){
|
|
|
+ if (master < 0.8) {
|
|
|
parent.setMasterStatus(Constants.SPECIAL_KNOWLEDGE_UNMASTER);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(i >= 3){
|
|
|
- ss.forEach(s->s.setChildren(null));
|
|
|
+ if (i >= 3) {
|
|
|
+ ss.forEach(s -> s.setChildren(null));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public boolean syncKnowledgeToSpecial(Long subjectId, String grade, Long pid) {
|
|
|
+ List<SpecialKnowledge> list = list(subjectId, grade);
|
|
|
+ Paper paper = paperService.getOnePaper(pid);
|
|
|
+ Map<String, List<Question>> group = paper.getQuestions().stream().collect(Collectors.groupingBy(Question::getTag));
|
|
|
+
|
|
|
+ for (SpecialKnowledge s : list) {
|
|
|
+ s.setPid(pid);
|
|
|
+
|
|
|
+ if (s.getCode() != null && group.get(s.getCode()) != null) {
|
|
|
+ List<Integer> numbers = group.get(s.getCode()).stream().map(Question::getNumber).collect(Collectors.toList());
|
|
|
+ s.setQids(StringUtils.join(numbers, ","));
|
|
|
+ }
|
|
|
+ specialKnowledgeRepo.save(s);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|