排行榜接口
This commit is contained in:
parent
792493119f
commit
e89d6d089f
|
@ -37,14 +37,14 @@ public class LevelController {
|
|||
@ApiOperation(value = "关卡详情")
|
||||
@GetMapping("/detail")
|
||||
@ApiParam(name = "id", value = "关卡ID")
|
||||
public R<Level> detail(Long id) {
|
||||
public R<Level> detail(String id) {
|
||||
return levelService.levelDetail(id);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡创建(web前端管理员提交)")
|
||||
@PostMapping("/create")
|
||||
public R create(@RequestBody Level level) {
|
||||
return null;
|
||||
return levelService.LevelCreate(level) ? R.ok() : R.fail();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡修改(web前端管理员提交)")
|
||||
|
@ -55,15 +55,15 @@ public class LevelController {
|
|||
|
||||
@ApiOperation(value = "关卡删除(web前端管理员提交)")
|
||||
@PostMapping("/delete")
|
||||
public R delete(Long id) {
|
||||
public R delete(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取某个关卡排行榜数据")
|
||||
@GetMapping("/rank")
|
||||
@ApiParam(name = "id", value = "关卡ID")
|
||||
public R<RankVo> rank(Long id) {
|
||||
return null;
|
||||
public R<RankVo> rank(String id, @RequestHeader(value = "token", required = false)String token) {
|
||||
return R.ok(levelService.getRankInfo(id, token));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡结算(游戏结束时提交,一定要鉴别token)")
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.example.catchTheLetters.service;
|
|||
|
||||
import com.example.catchTheLetters.entity.Level;
|
||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||
import com.example.catchTheLetters.model.vo.RankVo;
|
||||
import com.example.catchTheLetters.utils.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -13,31 +15,42 @@ import java.util.List;
|
|||
*/
|
||||
public interface LevelService {
|
||||
/**
|
||||
* 关卡详情
|
||||
*
|
||||
* @param id
|
||||
* @param id 关卡ID
|
||||
* @return token
|
||||
*/
|
||||
|
||||
|
||||
R<Level> levelDetail(Long id);
|
||||
R<Level> levelDetail(String id);
|
||||
|
||||
/**
|
||||
* 关卡列表
|
||||
*
|
||||
* @return token
|
||||
*/
|
||||
R<List<Level>> list();
|
||||
|
||||
/**
|
||||
* 结算
|
||||
*
|
||||
* @param scoreInfo 分数信息
|
||||
* @param token token
|
||||
* @return token
|
||||
*/
|
||||
R<ScoreInfo> settle(ScoreInfo scoreInfo, String token);
|
||||
|
||||
/**
|
||||
* @param levelId
|
||||
* 获取关卡排行信息
|
||||
*
|
||||
* @param levelId 关卡ID
|
||||
* @param token token
|
||||
* @return 关卡排行信息
|
||||
*/
|
||||
Integer getRankInfo(String levelId);
|
||||
RankVo getRankInfo(String levelId, String token);
|
||||
|
||||
/**
|
||||
* 创建关卡
|
||||
*
|
||||
* @param level
|
||||
* @param level 关卡信息
|
||||
* @return 关卡创建是否成功
|
||||
*/
|
||||
boolean LevelCreate(Level level);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.example.catchTheLetters.service.impl;
|
|||
|
||||
import com.example.catchTheLetters.entity.Level;
|
||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||
import com.example.catchTheLetters.model.vo.RankVo;
|
||||
import com.example.catchTheLetters.service.LevelService;
|
||||
import com.example.catchTheLetters.utils.JwtUtil;
|
||||
import com.example.catchTheLetters.utils.R;
|
||||
|
@ -26,7 +27,7 @@ public class LevelServiceImpl implements LevelService {
|
|||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Override
|
||||
public R<Level> levelDetail(Long id) {
|
||||
public R<Level> levelDetail(String id) {
|
||||
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
|
||||
if (level == null){
|
||||
return R.fail("查询失败,请重试");
|
||||
|
@ -60,14 +61,28 @@ public class LevelServiceImpl implements LevelService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer getRankInfo(String levelId) {
|
||||
ScoreInfo sc=mongoTemplate.findById(2,ScoreInfo.class);
|
||||
Integer infor = null;
|
||||
if(sc!=null) {
|
||||
infor = sc.getScore();
|
||||
}
|
||||
return infor;
|
||||
public RankVo getRankInfo(String levelId, String token) {
|
||||
// 在ScoreInfo表当中,查询levelId为levelId的所有数据,按照分数降序排列,取前10条数据
|
||||
var info = mongoTemplate.find(new Query(Criteria.where("levelId").is(levelId)).limit(10), ScoreInfo.class);
|
||||
|
||||
var rankVo = new RankVo();
|
||||
rankVo.setScoreInfos(info);
|
||||
|
||||
|
||||
// 如果有token,就查自己的分数数据
|
||||
if (token != null) {
|
||||
var map = JwtUtil.getPayload(token);
|
||||
String id = null;
|
||||
if (map != null) {
|
||||
id = map.get("id").asString().replaceAll("\"", "");
|
||||
}
|
||||
if (id != null) {
|
||||
var myScore = mongoTemplate.findOne(new Query(Criteria.where("userId").is(id).and("levelId").is(levelId)), ScoreInfo.class);
|
||||
rankVo.setMyScore(myScore);
|
||||
}
|
||||
}
|
||||
|
||||
return rankVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue