|
@@ -1,8 +1,19 @@
|
|
|
package com.yaoxiang.diagnosis.service;
|
|
|
|
|
|
+import com.yaoxiang.diagnosis.entity.*;
|
|
|
+import com.yaoxiang.diagnosis.util.CommonUtil;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.transaction.Transactional;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class SpecialReportService {
|
|
@@ -10,5 +21,76 @@ public class SpecialReportService {
|
|
|
@Resource
|
|
|
private CommitService commitService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private PaperResultService paperResultService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PaperService paperService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SpecialKnowledgeService specialKnowledgeService;
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(SpecialReportService.class);
|
|
|
+
|
|
|
+ public SpecialResult generate(Long pid, Long uid) {
|
|
|
+ Paper paper = paperService.getOnePaper(pid);
|
|
|
+ if (paper == null) {
|
|
|
+ logger.error("未找到试卷 pid={}", pid);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ PaperCommit commit = commitService.getPaperCommit(pid, uid);
|
|
|
+ if (commit == null) {
|
|
|
+ logger.error("用户未提交 pid={},uid={}", pid, uid);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return generate(commit, paper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackOn = Exception.class)
|
|
|
+ public SpecialResult generate(PaperCommit commit, Paper paper) {
|
|
|
+ PaperResult result = paperResultService.findByPidAndUid(commit.getPid(), commit.getUid());
|
|
|
+ List<SpecialKnowledge> list = specialKnowledgeService.list(paper.getSubjectId(), paper.getGrade());
|
|
|
+ //找出叶子节点
|
|
|
+ Map<String, SpecialKnowledge> map = list.stream().filter(s -> s.getCode() != null)
|
|
|
+ .collect(Collectors.toMap(SpecialKnowledge::getCode, Function.identity()));
|
|
|
+ if (CommonUtil.isEmpty(list)) {
|
|
|
+ logger.error("未上传专项诊断知识点,subjectId={},grade={}", paper.getSubjectId(), paper.getGrade());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (result == null) {
|
|
|
+ result = (PaperResult) paperResultService.parseResult(commit, paper).getT();
|
|
|
+ }
|
|
|
+ String collect = result.getCollectQuestion();
|
|
|
+ List<Integer> collects = Arrays.stream(collect.split(","))
|
|
|
+ .map(Integer::parseInt).collect(Collectors.toList());
|
|
|
+// String wrong = result.getWrongQuestion();
|
|
|
+// String wrongs[] = wrong.split(",");
|
|
|
+ List<Question> questions = paper.getQuestions();
|
|
|
+ Map<String, List<Question>> group = questions.stream().collect(Collectors.groupingBy(Question::getTag));
|
|
|
+ for (Map.Entry<String, List<Question>> entry : group.entrySet()) {
|
|
|
+ String code = entry.getKey();
|
|
|
+ List<Question> qs = entry.getValue();
|
|
|
+ SpecialKnowledge knowledge = map.get(code);
|
|
|
+ if (knowledge == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ knowledge.setQuestionNum(qs.size());
|
|
|
+ knowledge.setCollectNum(getCount(qs, collects));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SpecialKnowledge> tree = specialKnowledgeService.toTree(list);
|
|
|
+ logger.info(tree.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getCount(List<Question> qs, List<Integer> collects) {
|
|
|
+ int count = 0;
|
|
|
+ for (Question q : qs) {
|
|
|
+ if (collects.contains(q.getNumber())) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
|
|
|
}
|