更新用户进度
This commit is contained in:
parent
568a2f7d36
commit
432d0581b7
|
@ -3,6 +3,7 @@ package com.example.catchTheLetters.service.impl;
|
||||||
import com.example.catchTheLetters.entity.Level;
|
import com.example.catchTheLetters.entity.Level;
|
||||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||||
import com.example.catchTheLetters.model.vo.RankVo;
|
import com.example.catchTheLetters.model.vo.RankVo;
|
||||||
|
import com.example.catchTheLetters.service.AuthService;
|
||||||
import com.example.catchTheLetters.service.LevelService;
|
import com.example.catchTheLetters.service.LevelService;
|
||||||
import com.example.catchTheLetters.utils.JwtUtil;
|
import com.example.catchTheLetters.utils.JwtUtil;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
@ -27,6 +28,9 @@ public class LevelServiceImpl implements LevelService {
|
||||||
@Resource
|
@Resource
|
||||||
private MongoTemplate mongoTemplate;
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthService authService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R<Level> levelDetail(String id) {
|
public R<Level> levelDetail(String id) {
|
||||||
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
|
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
|
||||||
|
@ -46,16 +50,23 @@ public class LevelServiceImpl implements LevelService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R<ScoreInfo> settle(ScoreInfo scoreInfo, String token) {
|
public R<ScoreInfo> settle(ScoreInfo scoreInfo, String token) {
|
||||||
var map = JwtUtil.getPayload(token);
|
var user = authService.verify(token);
|
||||||
String id = null;
|
if (user == null) {
|
||||||
if (map != null) {
|
|
||||||
id = map.get("id").asString().replaceAll("\"", "");
|
|
||||||
}
|
|
||||||
if (id == null) {
|
|
||||||
return R.fail("token解析失败");
|
return R.fail("token解析失败");
|
||||||
}
|
}
|
||||||
if (id.equals(scoreInfo.getUserId())) {
|
if (user.getId().equals(scoreInfo.getUserId())) {
|
||||||
|
// 比对这一关是否是用户的最新进度,如果是,就更新用户的进度
|
||||||
|
var levelRes = levelDetail(scoreInfo.getLevelId());
|
||||||
|
if (levelRes.getCode() == R.FAIL) {
|
||||||
|
return R.fail("查询关卡失败,请重试");
|
||||||
|
}
|
||||||
|
if (levelRes.getData().getOrder() > user.getProgress()) {
|
||||||
|
user.setProgress(levelRes.getData().getOrder());
|
||||||
|
authService.update(user, token);
|
||||||
|
}
|
||||||
|
|
||||||
ScoreInfo insert = mongoTemplate.insert(scoreInfo);
|
ScoreInfo insert = mongoTemplate.insert(scoreInfo);
|
||||||
|
|
||||||
return R.ok(insert);
|
return R.ok(insert);
|
||||||
}
|
}
|
||||||
return R.fail("添加失败,请重试");
|
return R.fail("添加失败,请重试");
|
||||||
|
|
Loading…
Reference in New Issue