|
|
@ -132,12 +132,8 @@ public class BrainService implements IBrainService { |
|
|
|
@Override |
|
|
|
public void saveAnswer(BrainDto.Answer param, Long userId) { |
|
|
|
Long now = System.currentTimeMillis(); |
|
|
|
if (CollectionUtil.isEmpty(param.getQuestions())) { |
|
|
|
log.info("保存答案时没有保存题目的信息"); |
|
|
|
throw new BaseException(BrainTrainingCodeError.PARAM_ERROR); |
|
|
|
} |
|
|
|
// 判断有无正在进行的分数保存
|
|
|
|
String key = StrUtil.format(BrainTrainingConstant.Train.REDIS_SAVE_ANSWER, param.getActiveUserId(), param.getClassifyId(), param.getQuestions().get(0).getQuestionId()); |
|
|
|
String key = StrUtil.format(BrainTrainingConstant.Train.REDIS_SAVE_ANSWER, param.getActiveUserId(), param.getClassifyId(), CollectionUtil.isEmpty(param.getQuestions()) ? 0 : param.getQuestions().get(0).getQuestionId()); |
|
|
|
Object o = redisUtil.get(key); |
|
|
|
if (o != null) { |
|
|
|
throw new BaseException(BrainTrainingCodeError.BRAIN_ACTIVE_QUESTION_ANSWER_SAVING); |
|
|
@ -168,10 +164,17 @@ public class BrainService implements IBrainService { |
|
|
|
log.info("没有找到用户活动信息:{}", param.getActiveUserId()); |
|
|
|
throw new BaseException(BrainTrainingCodeError.PARAM_ERROR); |
|
|
|
} |
|
|
|
// 查询类型计分规则
|
|
|
|
TrainRuleScore ruleScore = getTrainRuleScore(activeUser.getActiveId(), param.getClassifyId()); |
|
|
|
// 分数计算
|
|
|
|
List<TrainActiveScore> scores = getTrainActiveScores(param, now, answerParams, ruleScore); |
|
|
|
List<TrainActiveScore> scores; |
|
|
|
if (CollectionUtil.isEmpty(param.getQuestions())) { |
|
|
|
// 没有答案算0分
|
|
|
|
scores = new ArrayList<>(); |
|
|
|
scores.add(initScore(param.getActiveUserId(), param.getClassifyId(), 0L, new BigDecimal(0))); |
|
|
|
} else { |
|
|
|
// 查询类型计分规则
|
|
|
|
TrainRuleScore ruleScore = getTrainRuleScore(activeUser.getActiveId(), param.getClassifyId()); |
|
|
|
// 分数计算
|
|
|
|
scores = getTrainActiveScores(param, now, answerParams, ruleScore); |
|
|
|
} |
|
|
|
|
|
|
|
//存储分数
|
|
|
|
if (CollectionUtil.isNotEmpty(scores)) { |
|
|
@ -462,7 +465,9 @@ public class BrainService implements IBrainService { |
|
|
|
} |
|
|
|
|
|
|
|
private void initNeedData(TrainClassify classify, BrainDto.Answer param, Long userId, List<BrainDto.QuestionAnswer> answerParams, List<TrainActiveLog> logs, List<TrainActiveQuestion> activeQuestions) { |
|
|
|
|
|
|
|
if (CollectionUtil.isEmpty(param.getQuestions())) { |
|
|
|
return; |
|
|
|
} |
|
|
|
param.getQuestions().forEach(question -> { |
|
|
|
question.getTimeAndOptions().forEach(optionTime -> { |
|
|
|
BrainDto.QuestionAnswer answer = new BrainDto.QuestionAnswer(); |
|
|
|