d1a0018d1b
- 39 个 Controller 全部添加 @Tag/@Operation/@Parameter 中文注解(共 278 个 @Operation) - 分 3 批实施:Batch 1 AI+社区(7)、Batch 2 情绪+日记+互动(11)、Batch 3 其他(13) - 已有注解的 8 个 Controller 不重复修改 - 编译验证通过:mvn clean install -DskipTests — BUILD SUCCESS Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
190 lines
7.0 KiB
Java
190 lines
7.0 KiB
Java
package com.emotion.controller;
|
|
|
|
import com.emotion.common.PageResult;
|
|
import com.emotion.common.Result;
|
|
import com.emotion.dto.request.achievement.*;
|
|
import com.emotion.dto.response.achievement.AchievementResponse;
|
|
import com.emotion.service.AchievementService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 成就控制器
|
|
*
|
|
* @author huazhongmin
|
|
* @date 2025-09-08
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/achievement")
|
|
@Tag(name = "成就管理", description = "成就的增删改查功能")
|
|
public class AchievementController {
|
|
|
|
@Autowired
|
|
private AchievementService achievementService;
|
|
|
|
/**
|
|
* 分页查询成就
|
|
*/
|
|
@Operation(summary = "分页查询成就", description = "分页查询成就列表")
|
|
@GetMapping("/page")
|
|
public Result<PageResult<AchievementResponse>> getPage(@Validated AchievementPageRequest request) {
|
|
PageResult<AchievementResponse> pageResult = achievementService.getPageWithResponse(request);
|
|
return Result.success(pageResult);
|
|
}
|
|
|
|
/**
|
|
* 根据ID获取成就
|
|
*/
|
|
@Operation(summary = "根据ID获取成就", description = "根据ID获取成就详情")
|
|
@GetMapping("/detail")
|
|
public Result<AchievementResponse> getById(@Parameter(description = "成就 ID") @RequestParam String id) {
|
|
AchievementResponse response = achievementService.getAchievementResponseById(id);
|
|
if (response == null) {
|
|
return Result.notFound("成就不存在");
|
|
}
|
|
return Result.success(response);
|
|
}
|
|
|
|
/**
|
|
* 创建成就
|
|
*/
|
|
@Operation(summary = "创建成就", description = "创建新的成就")
|
|
@PostMapping("/create")
|
|
public Result<AchievementResponse> create(@RequestBody @Validated AchievementCreateRequest request) {
|
|
AchievementResponse response = achievementService.createAchievementWithResponse(request);
|
|
if (response == null) {
|
|
return Result.error("创建失败");
|
|
}
|
|
return Result.success("创建成功", response);
|
|
}
|
|
|
|
/**
|
|
* 更新成就
|
|
*/
|
|
@Operation(summary = "更新成就", description = "更新指定成就")
|
|
@PutMapping("/update")
|
|
public Result<AchievementResponse> update(@RequestBody @Validated AchievementUpdateRequest request) {
|
|
AchievementResponse response = achievementService.updateAchievementWithResponse(request);
|
|
if (response == null) {
|
|
return Result.error("更新失败");
|
|
}
|
|
return Result.success("更新成功", response);
|
|
}
|
|
|
|
/**
|
|
* 删除成就
|
|
*/
|
|
@Operation(summary = "删除成就", description = "删除指定成就")
|
|
@DeleteMapping("/delete")
|
|
public Result<Void> delete(@Parameter(description = "成就 ID") @RequestParam String id) {
|
|
boolean deleted = achievementService.removeById(id);
|
|
if (!deleted) {
|
|
return Result.error("删除失败");
|
|
}
|
|
return Result.success();
|
|
}
|
|
|
|
/**
|
|
* 根据分类查询成就
|
|
*/
|
|
@Operation(summary = "根据分类查询成就", description = "根据分类查询成就列表")
|
|
@GetMapping("/byCategory")
|
|
public Result<List<AchievementResponse>> getByCategory(@Parameter(description = "分类") @RequestParam String category) {
|
|
List<AchievementResponse> responses = achievementService.getByCategoryWithResponse(category);
|
|
return Result.success(responses);
|
|
}
|
|
|
|
/**
|
|
* 根据稀有度查询成就
|
|
*/
|
|
@Operation(summary = "根据稀有度查询成就", description = "根据稀有度查询成就列表")
|
|
@GetMapping("/byRarity")
|
|
public Result<List<AchievementResponse>> getByRarity(@Parameter(description = "稀有度") @RequestParam String rarity) {
|
|
List<AchievementResponse> responses = achievementService.getByRarityWithResponse(rarity);
|
|
return Result.success(responses);
|
|
}
|
|
|
|
/**
|
|
* 查询已解锁的成就
|
|
*/
|
|
@Operation(summary = "查询已解锁的成就", description = "查询已解锁的成就列表")
|
|
@GetMapping("/unlocked")
|
|
public Result<List<AchievementResponse>> getUnlockedAchievements() {
|
|
List<AchievementResponse> responses = achievementService.getUnlockedAchievementsWithResponse();
|
|
return Result.success(responses);
|
|
}
|
|
|
|
/**
|
|
* 查询未解锁的成就
|
|
*/
|
|
@Operation(summary = "查询未解锁的成就", description = "查询未解锁的成就列表")
|
|
@GetMapping("/locked")
|
|
public Result<List<AchievementResponse>> getLockedAchievements() {
|
|
List<AchievementResponse> responses = achievementService.getLockedAchievementsWithResponse();
|
|
return Result.success(responses);
|
|
}
|
|
|
|
/**
|
|
* 统计已解锁成就数量
|
|
*/
|
|
@Operation(summary = "统计已解锁成就数量", description = "统计已解锁成就数量")
|
|
@GetMapping("/unlockedCount")
|
|
public Result<Long> countUnlockedAchievements() {
|
|
Long count = achievementService.countUnlockedAchievements();
|
|
return Result.success(count);
|
|
}
|
|
|
|
/**
|
|
* 统计未解锁成就数量
|
|
*/
|
|
@Operation(summary = "统计未解锁成就数量", description = "统计未解锁成就数量")
|
|
@GetMapping("/lockedCount")
|
|
public Result<Long> countLockedAchievements() {
|
|
Long count = achievementService.countLockedAchievements();
|
|
return Result.success(count);
|
|
}
|
|
|
|
/**
|
|
* 解锁成就
|
|
*/
|
|
@Operation(summary = "解锁成就", description = "解锁指定成就")
|
|
@PutMapping("/unlock")
|
|
public Result<Void> unlockAchievement(@RequestBody @Validated AchievementUnlockRequest request) {
|
|
boolean unlocked = achievementService.unlockAchievement(request.getId(), LocalDateTime.now());
|
|
if (!unlocked) {
|
|
return Result.error("解锁失败");
|
|
}
|
|
return Result.success();
|
|
}
|
|
|
|
/**
|
|
* 更新成就进度
|
|
*/
|
|
@Operation(summary = "更新成就进度", description = "更新指定成就的进度")
|
|
@PutMapping("/updateProgress")
|
|
public Result<Void> updateProgress(@RequestBody @Validated AchievementProgressUpdateRequest request) {
|
|
boolean updated = achievementService.updateProgress(request.getId(), request.getProgress());
|
|
if (!updated) {
|
|
return Result.error("更新进度失败");
|
|
}
|
|
return Result.success();
|
|
}
|
|
|
|
/**
|
|
* 查询最近解锁的成就
|
|
*/
|
|
@Operation(summary = "查询最近解锁的成就", description = "查询最近解锁的成就列表")
|
|
@GetMapping("/recent")
|
|
public Result<List<AchievementResponse>> getRecentlyUnlocked(@Parameter(description = "排名数量限制") @RequestParam(defaultValue = "10") Integer limit) {
|
|
List<AchievementResponse> responses = achievementService.getRecentlyUnlockedWithResponse(limit);
|
|
return Result.success(responses);
|
|
}
|
|
}
|