@Override
public void joinResult(String userId, String examId, int score, boolean passed,String imgUrl) {
QueryWrapper<UserExam> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(UserExam::getUserId, userId)
.eq(UserExam::getExamId, examId);
UserExam record = this.getOne(wrapper, false);
if(record == null){
record = new UserExam();
record.setCreateTime(new Date());
record.setUpdateTime(new Date());
record.setUserId(userId);
record.setExamId(examId);
record.setMaxScore(score);
record.setPassed(passed);
record.setState(2);
record.setImgUrl(imgUrl);
this.save(record);
return;
}
record.setTryCount(record.getTryCount()+1);
record.setUpdateTime(new Date());
record.setState(2);
if(record.getMaxScore() < score){
record.setMaxScore(score);
record.setPassed(passed);
}
record.setImgUrl(imgUrl);
this.updateById(record);
}