|
@@ -4,10 +4,19 @@ import edu.math.diagnosis.dao.PaperResultRepo;
|
|
|
import edu.math.diagnosis.entity.Paper;
|
|
|
import edu.math.diagnosis.entity.PaperCommit;
|
|
|
import edu.math.diagnosis.entity.PaperResult;
|
|
|
+import edu.math.diagnosis.entity.Question;
|
|
|
+import edu.math.diagnosis.model.Answer;
|
|
|
import edu.math.diagnosis.model.Result;
|
|
|
+import edu.math.diagnosis.util.ObjectUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class PaperResultService {
|
|
@@ -17,8 +26,51 @@ public class PaperResultService {
|
|
|
@Resource
|
|
|
private PaperService paperService;
|
|
|
|
|
|
- public Result parseResult(PaperCommit paperCommit, Paper paper) {
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(PaperResultService.class);
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public Result parseResult(PaperCommit paperCommit, Paper paper) {
|
|
|
+ List<Question> questions = paper.getQuestions();
|
|
|
+ List<Answer> answers = paperCommit.getAnswers();
|
|
|
+ List<Integer> collectQuestion = new ArrayList<>();
|
|
|
+ PaperResult result = new PaperResult();
|
|
|
+ result.setPid(paperCommit.getPid());
|
|
|
+ result.setName(paperCommit.getName());
|
|
|
+ result.setUid(String.valueOf(paperCommit.getUid()));
|
|
|
+// result.setScore(0d);
|
|
|
+// result.setJsonScore("");
|
|
|
+// result.setCollectQuestion("");
|
|
|
+ //TODO 需要修改强转
|
|
|
+ Map<String,Double> pData = ObjectUtil.json2Object(paper.getJsonScore(),Map.class);
|
|
|
+ //清空value为0
|
|
|
+ pData.keySet().forEach(d->pData.put(d,0d));
|
|
|
+ int count = 0;
|
|
|
+ for (Question q:questions){
|
|
|
+ String ans = q.getAnswer();
|
|
|
+ if(StringUtils.isBlank(ans)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Answer a = answers.stream().filter(answer -> answer.getNumber() == q.getNumber())
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if(a == null || StringUtils.isBlank(a.getOptions())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(ans.equalsIgnoreCase(a.getOptions())){
|
|
|
+ count++;
|
|
|
+ collectQuestion.add(q.getNumber());
|
|
|
+ String jsonScore = q.getJsonScore();
|
|
|
+ Map<String,Double> qData = ObjectUtil.json2Object(jsonScore,Map.class);
|
|
|
+ pData.keySet().forEach(d->{
|
|
|
+ Double pData0 = qData.getOrDefault(d,0d) + pData.get(d);
|
|
|
+ pData.put(d,pData0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.setCollectQuestion(StringUtils.join(collectQuestion,","));
|
|
|
+ result.setJsonScore(ObjectUtil.object2Json(pData));
|
|
|
+ result.setScore((double) count);
|
|
|
+ paperResultRepo.save(result);
|
|
|
+ logger.info("答案分析保存成功");
|
|
|
return Result.ok();
|
|
|
}
|
|
|
|