parent
6e61ffd198
commit
a7442babbe
|
@ -3,10 +3,12 @@ package com.example.catchTheLetters.controller;
|
||||||
import com.example.catchTheLetters.entity.Level;
|
import com.example.catchTheLetters.entity.Level;
|
||||||
import com.example.catchTheLetters.model.vo.RankVo;
|
import com.example.catchTheLetters.model.vo.RankVo;
|
||||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||||
|
import com.example.catchTheLetters.service.LevelService;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -20,6 +22,9 @@ import org.springframework.web.bind.annotation.*;
|
||||||
@Api(tags = "关卡API")
|
@Api(tags = "关卡API")
|
||||||
@RequestMapping("/level")
|
@RequestMapping("/level")
|
||||||
public class LevelController {
|
public class LevelController {
|
||||||
|
@Resource
|
||||||
|
private LevelService levelService;
|
||||||
|
|
||||||
@ApiOperation(value = "关卡列表(只返回ID、名称和类型)")
|
@ApiOperation(value = "关卡列表(只返回ID、名称和类型)")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public R<Level> list() {
|
public R<Level> list() {
|
||||||
|
@ -41,14 +46,15 @@ public class LevelController {
|
||||||
|
|
||||||
@ApiOperation(value = "关卡修改(web前端管理员提交)")
|
@ApiOperation(value = "关卡修改(web前端管理员提交)")
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public R update(@RequestBody Level level) {
|
public R update(@RequestBody Level level)
|
||||||
return null;
|
{
|
||||||
|
return levelService.update(level) ? R.ok() : R.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "关卡删除(web前端管理员提交)")
|
@ApiOperation(value = "关卡删除(web前端管理员提交)")
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public R delete(Long id) {
|
public R delete(String id) {
|
||||||
return null;
|
return levelService.delete(id) ? R.ok() : R.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "获取某个关卡排行榜数据")
|
@ApiOperation(value = "获取某个关卡排行榜数据")
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.example.catchTheLetters.service;
|
package com.example.catchTheLetters.service;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.entity.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 慕华
|
* @author 慕华
|
||||||
* @date 2024/4/10
|
* @date 2024/4/10
|
||||||
|
@ -7,4 +9,19 @@ package com.example.catchTheLetters.service;
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
public interface LevelService {
|
public interface LevelService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除关卡
|
||||||
|
* @param id 关卡id
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean delete(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新关卡
|
||||||
|
* @param level 关卡
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean update(Level level);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,19 @@
|
||||||
package com.example.catchTheLetters.service.impl;
|
package com.example.catchTheLetters.service.impl;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.constant.CommonConstant;
|
||||||
|
import com.example.catchTheLetters.entity.Level;
|
||||||
|
import com.example.catchTheLetters.service.LevelService;
|
||||||
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
import com.github.yulichang.method.mp.Delete;
|
||||||
|
import com.mongodb.client.result.DeleteResult;
|
||||||
|
import com.mongodb.client.result.UpdateResult;
|
||||||
|
import com.mongodb.internal.bulk.DeleteRequest;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,5 +23,38 @@ import org.springframework.stereotype.Service;
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class LevelServiceImpl {
|
public class LevelServiceImpl implements LevelService {
|
||||||
|
@Resource
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(String id) {
|
||||||
|
Level level = new Level();
|
||||||
|
level.setId(id);
|
||||||
|
DeleteResult deleteRequest = mongoTemplate.remove(level);
|
||||||
|
if (deleteRequest.getDeletedCount() > 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean update(Level level) {
|
||||||
|
Query query=Query.query(Criteria.where("id").is(level.getId()));
|
||||||
|
Update update = new Update();
|
||||||
|
update.set("order",level.getOrder());
|
||||||
|
update.set("name",level.getName());
|
||||||
|
update.set("type",level.getType());
|
||||||
|
update.set("timeLimit",level.getTimeLimit());
|
||||||
|
update.set("targetScore",level.getTargetScore());
|
||||||
|
update.set("words",level.getWords());
|
||||||
|
|
||||||
|
UpdateResult updateResult=mongoTemplate.updateFirst(query, update, Level.class);
|
||||||
|
if (updateResult.getModifiedCount() > 0) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue