|
@@ -1,9 +1,14 @@
|
|
|
package com.yaoxiang.diagnosis.service;
|
|
|
|
|
|
+import com.google.gson.reflect.TypeToken;
|
|
|
import com.yaoxiang.diagnosis.config.Constants;
|
|
|
import com.yaoxiang.diagnosis.entity.*;
|
|
|
+import com.yaoxiang.diagnosis.model.Answer;
|
|
|
+import com.yaoxiang.diagnosis.model.AnswerContrast;
|
|
|
+import com.yaoxiang.diagnosis.model.SpecialMindVo;
|
|
|
import com.yaoxiang.diagnosis.util.CommonUtil;
|
|
|
import com.yaoxiang.diagnosis.util.NumberUtil;
|
|
|
+import com.yaoxiang.diagnosis.util.ObjectUtil;
|
|
|
import io.swagger.models.auth.In;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -14,6 +19,8 @@ import javax.annotation.Resource;
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -31,6 +38,9 @@ public class SpecialReportService {
|
|
|
@Resource
|
|
|
private SpecialKnowledgeService specialKnowledgeService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SpecialMindService specialMindService;
|
|
|
+
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SpecialReportService.class);
|
|
|
|
|
|
|
|
@@ -173,6 +183,10 @@ public class SpecialReportService {
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
+ private void calcMind(List<SpecialMind> list) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private Integer getCount(List<Question> qs, List<Integer> collects) {
|
|
|
int count = 0;
|
|
|
for (Question q : qs) {
|
|
@@ -183,4 +197,111 @@ public class SpecialReportService {
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
+ public List<SpecialMindVo> generateMind(Long pid, Long uid) {
|
|
|
+ logger.info("正在生成专项诊断报告");
|
|
|
+ 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 generateMind(commit, paper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SpecialMindVo> generateMind(PaperCommit commit, Paper paper) {
|
|
|
+ PaperResult result = paperResultService.findByPidAndUid(commit.getPid(), commit.getUid());
|
|
|
+ List<SpecialMind> list = specialMindService.findByPid(paper.getId());
|
|
|
+ if (CommonUtil.isEmpty(list)) {
|
|
|
+ logger.error("未上传专项诊断思维过程,subjectId={},grade={}", paper.getSubjectId(), paper.getGrade());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String contrast = result.getWrongAnswerContrast();
|
|
|
+ List<AnswerContrast> contrasts = convertAnswerContrast(contrast);
|
|
|
+ if (CommonUtil.isEmpty(contrasts)) {
|
|
|
+ logger.info("没有错题");
|
|
|
+ }
|
|
|
+ Map<Integer, String> map = contrasts.stream().collect(Collectors.toMap(AnswerContrast::getNumber, AnswerContrast::getOptions));
|
|
|
+
|
|
|
+ Pattern pattern = Pattern.compile("(\\d+)");
|
|
|
+ for (SpecialMind mind : list) {
|
|
|
+ String qids = mind.getQids();
|
|
|
+ if (StringUtils.isBlank(qids)) {
|
|
|
+ logger.error("该问题没有考,请检查,pid={},content={}", paper.getId(), mind.getContent());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] qidss = qids.split(",");
|
|
|
+ mind.setCollectNum(qidss.length);
|
|
|
+ mind.setQuestionNum(qidss.length);
|
|
|
+
|
|
|
+ for (String s : qidss) {
|
|
|
+ if (s.matches("\\d+[A-E]")) {
|
|
|
+ Matcher matcher = pattern.matcher(s);
|
|
|
+ int number = 0;
|
|
|
+ if (matcher.find()) {
|
|
|
+ number = Integer.parseInt(matcher.group());
|
|
|
+ } else {
|
|
|
+ logger.error("未检测到题号,qids={}", qids);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String options = map.get(number);
|
|
|
+ if (s.contains(options)) {
|
|
|
+ mind.setCollectNum(mind.getCollectNum() - 1);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ int number = Integer.parseInt(s);
|
|
|
+ if (map.containsKey(number) && StringUtils.isBlank(map.get(number))) {
|
|
|
+
|
|
|
+ mind.setCollectNum(mind.getCollectNum() - 1);
|
|
|
+ } else if (map.containsKey(number)) {
|
|
|
+
|
|
|
+ String options = map.get(number);
|
|
|
+ if (s.contains(options)) {
|
|
|
+ mind.setCollectNum(mind.getCollectNum() - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mind.setMistake(!mind.getQuestionNum().equals(mind.getCollectNum()));
|
|
|
+ }
|
|
|
+ Map<String, List<SpecialMind>> group = list.stream().collect(Collectors.groupingBy(SpecialMind::getStep));
|
|
|
+ List<SpecialMindVo> vos = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<SpecialMind>> entry : group.entrySet()) {
|
|
|
+ String step = entry.getKey();
|
|
|
+ List<SpecialMind> minds = entry.getValue();
|
|
|
+ int collectNum = 0;
|
|
|
+ int questionNum = 0;
|
|
|
+ for (SpecialMind mind : minds) {
|
|
|
+ collectNum += mind.getCollectNum();
|
|
|
+ questionNum += mind.getQuestionNum();
|
|
|
+ }
|
|
|
+ if (questionNum == 0) {
|
|
|
+ logger.error("一整个步骤都没考");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ SpecialMindVo vo = new SpecialMindVo();
|
|
|
+ double master = collectNum * 100.0 / questionNum;
|
|
|
+ vo.setMasterStatus("red");
|
|
|
+ if (master >= 85) {
|
|
|
+ vo.setMasterStatus("green");
|
|
|
+ } else if (master >= 50) {
|
|
|
+ vo.setMasterStatus("yellow");
|
|
|
+ }
|
|
|
+ vo.setMaster(NumberUtil.format(master));
|
|
|
+ vo.setMinds(minds);
|
|
|
+ vo.setStep(step);
|
|
|
+ vo.setSort(minds.get(0).getSort());
|
|
|
+ vos.add(vo);
|
|
|
+ }
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AnswerContrast> convertAnswerContrast(String json) {
|
|
|
+ return ObjectUtil.getGson().fromJson(json, new TypeToken<List<AnswerContrast>>() {
|
|
|
+ }.getType());
|
|
|
+ }
|
|
|
}
|