Compare commits
No commits in common. "e89d6d089fc20f429211486ec8d7b7a2ea0ae825" and "312f9c4ad8b51c682fc00d2ffb160667a0fa2e4d" have entirely different histories.
e89d6d089f
...
312f9c4ad8
|
@ -37,14 +37,14 @@ public class LevelController {
|
|||
@ApiOperation(value = "关卡详情")
|
||||
@GetMapping("/detail")
|
||||
@ApiParam(name = "id", value = "关卡ID")
|
||||
public R<Level> detail(String id) {
|
||||
public R<Level> detail(Long id) {
|
||||
return levelService.levelDetail(id);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡创建(web前端管理员提交)")
|
||||
@PostMapping("/create")
|
||||
public R create(@RequestBody Level level) {
|
||||
return levelService.LevelCreate(level) ? R.ok() : R.fail();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡修改(web前端管理员提交)")
|
||||
|
@ -55,15 +55,15 @@ public class LevelController {
|
|||
|
||||
@ApiOperation(value = "关卡删除(web前端管理员提交)")
|
||||
@PostMapping("/delete")
|
||||
public R delete(String id) {
|
||||
public R delete(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取某个关卡排行榜数据")
|
||||
@GetMapping("/rank")
|
||||
@ApiParam(name = "id", value = "关卡ID")
|
||||
public R<RankVo> rank(String id, @RequestHeader(value = "token", required = false)String token) {
|
||||
return R.ok(levelService.getRankInfo(id, token));
|
||||
public R<RankVo> rank(Long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡结算(游戏结束时提交,一定要鉴别token)")
|
||||
|
|
|
@ -34,8 +34,6 @@ public class Level implements Serializable {
|
|||
* 限时(可选,毫秒数)
|
||||
*/
|
||||
private Long timeLimit;
|
||||
|
||||
|
||||
/**
|
||||
* 目标分数(type=1时有效)
|
||||
*/
|
||||
|
@ -44,83 +42,4 @@ public class Level implements Serializable {
|
|||
* 单词列表
|
||||
*/
|
||||
private List<String> words;
|
||||
public Level(String id,Integer order,String name,Integer type,Long timeLimit,Integer targetScore, List<String> words){
|
||||
this.id=id;
|
||||
this.order=order;
|
||||
this.name=name;
|
||||
this.type=type;
|
||||
this.timeLimit=timeLimit;
|
||||
this.targetScore=targetScore;
|
||||
this.words=words;
|
||||
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Integer order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Long getTimeLimit() {
|
||||
return timeLimit;
|
||||
}
|
||||
|
||||
public void setTimeLimit(Long timeLimit) {
|
||||
this.timeLimit = timeLimit;
|
||||
}
|
||||
|
||||
public Integer getTargetScore() {
|
||||
return targetScore;
|
||||
}
|
||||
|
||||
public void setTargetScore(Integer targetScore) {
|
||||
this.targetScore = targetScore;
|
||||
}
|
||||
|
||||
public List<String> getWords() {
|
||||
return words;
|
||||
}
|
||||
|
||||
public void setWords(List<String> words) {
|
||||
this.words = words;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return "Level{" +
|
||||
"id=" + id +
|
||||
", order= '"+ order +'\''+
|
||||
", name= '"+ name +'\''+
|
||||
", type= '"+ type +'\''+
|
||||
", timeLimit= '"+ timeLimit +'\''+
|
||||
", targetScore= '"+ targetScore +'\''+
|
||||
", words= '"+ words +'\''+'}';
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,53 +31,4 @@ public class ScoreInfo implements Serializable {
|
|||
* 时间(UNIX时间戳)
|
||||
*/
|
||||
private Long time;
|
||||
public ScoreInfo(Long userId,Long levelId,String username,Integer score, Long time){
|
||||
this.userId=userId;
|
||||
this.levelId=levelId;
|
||||
this.username=username;
|
||||
this.score=score;
|
||||
this.time=time;
|
||||
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getLevelId() {
|
||||
return levelId;
|
||||
}
|
||||
|
||||
public void setLevelId(Long levelId) {
|
||||
this.levelId = levelId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Integer getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(Integer score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ 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;
|
||||
|
@ -14,45 +13,10 @@ import java.util.List;
|
|||
* @description
|
||||
*/
|
||||
public interface LevelService {
|
||||
/**
|
||||
* 关卡详情
|
||||
*
|
||||
* @param id 关卡ID
|
||||
* @return token
|
||||
*/
|
||||
R<Level> levelDetail(String id);
|
||||
|
||||
/**
|
||||
* 关卡列表
|
||||
*
|
||||
* @return token
|
||||
*/
|
||||
R<Level> levelDetail(Long id);
|
||||
|
||||
R<List<Level>> list();
|
||||
|
||||
/**
|
||||
* 结算
|
||||
*
|
||||
* @param scoreInfo 分数信息
|
||||
* @param token token
|
||||
* @return token
|
||||
*/
|
||||
R<ScoreInfo> settle(ScoreInfo scoreInfo, String token);
|
||||
|
||||
/**
|
||||
* 获取关卡排行信息
|
||||
*
|
||||
* @param levelId 关卡ID
|
||||
* @param token token
|
||||
* @return 关卡排行信息
|
||||
*/
|
||||
RankVo getRankInfo(String levelId, String token);
|
||||
|
||||
/**
|
||||
* 创建关卡
|
||||
*
|
||||
* @param level 关卡信息
|
||||
* @return 关卡创建是否成功
|
||||
*/
|
||||
boolean LevelCreate(Level level);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ 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;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.annotation.QueryAnnotation;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
@ -27,7 +27,7 @@ public class LevelServiceImpl implements LevelService {
|
|||
private MongoTemplate mongoTemplate;
|
||||
|
||||
@Override
|
||||
public R<Level> levelDetail(String id) {
|
||||
public R<Level> levelDetail(Long id) {
|
||||
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
|
||||
if (level == null){
|
||||
return R.fail("查询失败,请重试");
|
||||
|
@ -59,42 +59,4 @@ public class LevelServiceImpl implements LevelService {
|
|||
}
|
||||
return R.fail("添加失败,请重试");
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public boolean LevelCreate(Level level) {
|
||||
String s=level.toString();
|
||||
if (s != null) {
|
||||
|
||||
mongoTemplate.insert(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue