|
@@ -41,35 +41,37 @@ public class PaperResultService {
|
|
|
// result.setJsonScore("");
|
|
|
// result.setCollectQuestion("");
|
|
|
//TODO 需要修改强转
|
|
|
- Map<String,Double> pData = ObjectUtil.json2Object(paper.getJsonScore(),Map.class);
|
|
|
+ Map<String, Double> pData = ObjectUtil.json2Object(paper.getJsonScore(), Map.class);
|
|
|
//清空value为0
|
|
|
- pData.keySet().forEach(d->pData.put(d,0d));
|
|
|
+ pData.keySet().forEach(d -> pData.put(d, 0d));
|
|
|
final Double[] score = {0d};
|
|
|
- for (Question q:questions){
|
|
|
+ for (Question q : questions) {
|
|
|
String ans = q.getAnswer();
|
|
|
- if(StringUtils.isBlank(ans)){
|
|
|
+ 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())){
|
|
|
+ if (a == null || StringUtils.isBlank(a.getOptions())) {
|
|
|
continue;
|
|
|
}
|
|
|
- if(ans.equalsIgnoreCase(a.getOptions())){
|
|
|
+ if (ans.equalsIgnoreCase(a.getOptions())) {
|
|
|
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);
|
|
|
- score[0] +=qData.getOrDefault(d,0d);
|
|
|
- pData.put(d,pData0);
|
|
|
+ Map<String, Double> qData = ObjectUtil.json2Object(jsonScore, Map.class);
|
|
|
+ pData.keySet().forEach(d -> {
|
|
|
+ Double pData0 = qData.getOrDefault(d, 0d) + pData.get(d);
|
|
|
+ score[0] += qData.getOrDefault(d, 0d);
|
|
|
+ pData.put(d, pData0);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- result.setCollectQuestion(StringUtils.join(collectQuestion,","));
|
|
|
+ result.setCollectQuestion(StringUtils.join(collectQuestion, ","));
|
|
|
result.setJsonScore(ObjectUtil.object2Json(pData));
|
|
|
- result.setScore(score[0]);
|
|
|
- result.setTotalScore(Double.valueOf(paper.getTotalScore()));
|
|
|
+ //转换分数为百分制
|
|
|
+ double totalScore = paper.getTotalScore();
|
|
|
+ result.setScore(totalScore == 0 ? score[0] : score[0] / totalScore);
|
|
|
+ result.setTotalScore(totalScore);
|
|
|
paperResultRepo.save(result);
|
|
|
logger.info("答案分析保存成功");
|
|
|
return Result.ok(result);
|
|
@@ -79,11 +81,11 @@ public class PaperResultService {
|
|
|
return paperResultRepo.save(result);
|
|
|
}
|
|
|
|
|
|
- public PaperResult get(Long resultId){
|
|
|
+ public PaperResult get(Long resultId) {
|
|
|
return paperResultRepo.getOne(resultId);
|
|
|
}
|
|
|
|
|
|
- public List<PaperResult> findByUidAndPid(String pid,String uid){
|
|
|
- return paperResultRepo.findByPidAndUid(pid,uid);
|
|
|
+ public List<PaperResult> findByUidAndPid(String pid, String uid) {
|
|
|
+ return paperResultRepo.findByPidAndUid(pid, uid);
|
|
|
}
|
|
|
}
|