更新用户进度
This commit is contained in:
parent
432d0581b7
commit
1b61e9acf6
|
@ -11,6 +11,10 @@ import java.io.Serializable;
|
|||
*/
|
||||
@Data
|
||||
public class ScoreInfo implements Serializable {
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
|
|
|
@ -60,12 +60,24 @@ public class LevelServiceImpl implements LevelService {
|
|||
if (levelRes.getCode() == R.FAIL) {
|
||||
return R.fail("查询关卡失败,请重试");
|
||||
}
|
||||
if (levelRes.getData().getOrder() > user.getProgress()) {
|
||||
if (user.getProgress() == null || levelRes.getData().getOrder() > user.getProgress()) {
|
||||
user.setProgress(levelRes.getData().getOrder());
|
||||
authService.update(user, token);
|
||||
// 这里要直接存,因为authService的update方法没有修改progress字段
|
||||
mongoTemplate.save(user);
|
||||
}
|
||||
|
||||
ScoreInfo insert = mongoTemplate.insert(scoreInfo);
|
||||
// 先获取数据库中的分数,如果有则比较,如果没有则直接插入
|
||||
var score = mongoTemplate.findOne(new Query(Criteria.where("userId").is(scoreInfo.getUserId()).and("levelId").is(scoreInfo.getLevelId())), ScoreInfo.class);
|
||||
ScoreInfo insert = new ScoreInfo();
|
||||
if (score != null) {
|
||||
if (score.getScore() < scoreInfo.getScore()) {
|
||||
score.setScore(scoreInfo.getScore());
|
||||
score.setTime(scoreInfo.getTime());
|
||||
insert = mongoTemplate.save(score);
|
||||
}
|
||||
} else {
|
||||
insert = mongoTemplate.save(scoreInfo);
|
||||
}
|
||||
|
||||
return R.ok(insert);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue