关卡创建

This commit is contained in:
石皮幼鸟 2024-04-12 10:59:19 +08:00
parent a60821429d
commit 6c2cb2b197
5 changed files with 74 additions and 80 deletions

View File

@ -44,7 +44,7 @@ public class LevelController {
@ApiOperation(value = "关卡创建web前端管理员提交")
@PostMapping("/create")
public R create(@RequestBody Level level) {
return levelService.LevelCreate(level) ? R.ok() : R.fail();
return levelService.levelCreate(level) ? R.ok() : R.fail();
}
@ApiOperation(value = "关卡修改web前端管理员提交")

View File

@ -44,83 +44,17 @@ 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 Level() {
}
public String getId() {
return id;
}
public void setId(String id) {
public Level(String id, Integer order, String name, Integer type, Long timeLimit, Integer targetScore, List<String> words) {
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

@ -53,6 +53,6 @@ public interface LevelService {
* @param level 关卡信息
* @return 关卡创建是否成功
*/
boolean LevelCreate(Level level);
boolean levelCreate(Level level);
}

View File

@ -86,15 +86,8 @@ public class LevelServiceImpl implements LevelService {
}
@Override
public boolean LevelCreate(Level level) {
String s=level.toString();
if (s != null) {
mongoTemplate.insert(s);
return true;
public boolean levelCreate(Level level) {
var insert = mongoTemplate.insert(level);
return insert.getId() != null;
}
return false;
}
}

View File

@ -0,0 +1,67 @@
package com.example.catchTheLetters;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.service.LevelService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.Random;
@SpringBootTest
class TestInsertLevel {
@Resource
private LevelService levelService;
@Test
void testInsertLevel() {
var words = new ArrayList<String>(){
{
add("apple");
add("banana");
add("cherry");
add("date");
add("elderberry");
add("fig");
add("grape");
add("honeydew");
add("imbe");
add("jackfruit");
add("kiwi");
add("lemon");
add("mango");
add("nectarine");
add("orange");
add("papaya");
add("quince");
add("raspberry");
add("strawberry");
add("tangerine");
add("ugli");
add("vanilla");
add("watermelon");
add("ximenia");
add("yuzu");
add("zucchini");
}
};
// 存20个关卡
for (int i = 0; i < 20; i++) {
var type = new Random().nextInt(2);
// 如果是1则需要设置目标分数
var targetScore = type == 1 ? new Random().nextInt(100) : null;
// 如果是0则单词列表5个就够否则15个
var wordList = new ArrayList<String>();
for (int j = 0; j < (type == 0 ? 5 : 15); j++) {
wordList.add(words.get(new Random().nextInt(words.size())));
}
// 时间全部设置为3分钟
var level = new Level(Integer.toString(i), i, "Level" + i, type, 180000L, targetScore, wordList);
levelService.levelCreate(level);
}
}
}