120 lines
3.9 KiB
Java
120 lines
3.9 KiB
Java
package com.example.catchTheLetters.controller;
|
||
|
||
import com.example.catchTheLetters.entity.*;
|
||
import com.example.catchTheLetters.model.vo.RankVo;
|
||
import com.example.catchTheLetters.service.LevelService;
|
||
import com.example.catchTheLetters.service.VersionService;
|
||
import com.example.catchTheLetters.utils.R;
|
||
import io.swagger.annotations.Api;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import io.swagger.annotations.ApiParam;
|
||
import jakarta.annotation.Resource;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import java.io.IOException;
|
||
import java.util.List;
|
||
|
||
/**
|
||
* 关卡控制器
|
||
*
|
||
* @author spyn
|
||
*/
|
||
@RestController
|
||
@Slf4j
|
||
@Api(tags = "关卡API")
|
||
@RequestMapping("/level")
|
||
public class LevelController {
|
||
@Resource
|
||
private LevelService levelService;
|
||
|
||
@Resource
|
||
private VersionService versionService;
|
||
|
||
@ApiOperation(value = "关卡列表(只返回ID、排序、名称和类型)")
|
||
@GetMapping("/list")
|
||
public R<List<Level>> list() {
|
||
return levelService.list();
|
||
}
|
||
|
||
@ApiOperation(value = "关卡详情")
|
||
@GetMapping("/detail")
|
||
@ApiParam(name = "id", value = "关卡ID")
|
||
public R<Level> detail(String id) {
|
||
return levelService.levelDetail(id);
|
||
}
|
||
|
||
@ApiOperation(value = "关卡创建(web前端管理员提交)")
|
||
@PostMapping("/create")
|
||
public R create(@RequestBody Level level) {
|
||
var res = levelService.levelCreate(level);
|
||
// 如果创建成功,将当前UNIX时间戳作为版本号
|
||
if (res) {
|
||
versionService.setVersion("level", System.currentTimeMillis());
|
||
return R.ok();
|
||
}
|
||
return R.fail();
|
||
}
|
||
|
||
@ApiOperation(value = "关卡修改(web前端管理员提交)")
|
||
@PostMapping("/update")
|
||
public R update(@RequestBody Level level)
|
||
{
|
||
var res = levelService.update(level);
|
||
// 如果修改成功,将当前UNIX时间戳作为版本号
|
||
if (res) {
|
||
versionService.setVersion("level", System.currentTimeMillis());
|
||
return R.ok();
|
||
}
|
||
return R.fail();
|
||
}
|
||
|
||
@ApiOperation(value = "关卡删除(web前端管理员提交)")
|
||
@PostMapping("/delete")
|
||
public R delete(String id) {
|
||
var res = levelService.delete(id);
|
||
// 如果删除成功,将当前UNIX时间戳作为版本号
|
||
if (res) {
|
||
versionService.setVersion("level", System.currentTimeMillis());
|
||
return R.ok();
|
||
}
|
||
return R.fail();
|
||
}
|
||
|
||
@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));
|
||
}
|
||
|
||
@ApiOperation(value = "关卡结算(游戏结束时提交,一定要鉴别token)")
|
||
@PostMapping("/settle")
|
||
public R<ScoreInfo> settle(@RequestBody ScoreInfo scoreInfo, @RequestHeader("token")String token) {
|
||
return levelService.settle(scoreInfo, token);
|
||
}
|
||
|
||
@ApiOperation(value = "获取表版本号(用于本地数据库和服务器数据库同步)")
|
||
@GetMapping("/version")
|
||
public R<Long> version() {
|
||
return R.ok(versionService.getVersion("level"));
|
||
}
|
||
|
||
@ApiOperation(value = "分页获取某个排行榜排名")
|
||
@PostMapping("/rank-page")
|
||
public R<ScoreInfoPage> getScores(@RequestBody Page page) {
|
||
return R.ok(levelService.getScoreInfo( page.getLevelId(),page.getPage(), page.getSize()));
|
||
}
|
||
|
||
@ApiOperation(value = "获取最新5个版本")
|
||
@GetMapping("/new-version")
|
||
public R<List<VersionDownload>> getNewVersion(){
|
||
return versionService.getNewDownloads();
|
||
}
|
||
|
||
@PostMapping("/test")
|
||
public R<String> testMinio(MultipartFile file) throws Exception {
|
||
return R.ok(versionService.testMinIO(file));
|
||
}
|
||
} |