关卡创建,获取排行榜信息

This commit is contained in:
czt 2024-04-12 08:56:48 +08:00
parent 38a35aefed
commit d5e38c8da2
4 changed files with 179 additions and 2 deletions

View File

@ -34,6 +34,8 @@ public class Level implements Serializable {
* 限时可选毫秒数
*/
private Long timeLimit;
/**
* 目标分数type=1时有效
*/
@ -42,4 +44,83 @@ 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 +'\''+'}';
}
}

View File

@ -31,4 +31,53 @@ 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;
}
}

View File

@ -2,7 +2,6 @@ package com.example.catchTheLetters.service;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.utils.R;
import java.util.List;
/**
@ -12,8 +11,32 @@ import java.util.List;
* @description
*/
public interface LevelService {
/**
*
* @param id
* @return token
*/
R<Level> levelDetail(Long id);
/**
*
* @return token
*/
R<List<Level>> list();
/**
* @param levelId
* @return 关卡排行信息
*/
Integer getRankInfo(String levelId);
/**
*
* @param level
* @return 关卡创建是否成功
*/
boolean LevelCreate(Level level);
}

View File

@ -1,10 +1,10 @@
package com.example.catchTheLetters.service.impl;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.entity.ScoreInfo;
import com.example.catchTheLetters.service.LevelService;
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;
@ -40,4 +40,28 @@ public class LevelServiceImpl implements LevelService {
List<Level> levels = mongoTemplate.find(query, Level.class);
return R.ok(levels);
}
@Override
public Integer getRankInfo(String levelId) {
ScoreInfo sc=mongoTemplate.findById(2,ScoreInfo.class);
Integer infor = null;
if(sc!=null) {
infor = sc.getScore();
}
return infor;
}
@Override
public boolean LevelCreate(Level level) {
String s=level.toString();
if (s != null) {
mongoTemplate.insert(s);
return true;
}
return false;
}
}