From afeeed281e60466b576fbe74d339634cc5d07b82 Mon Sep 17 00:00:00 2001 From: Codex Assistant <codex@example.com> Date: 星期三, 08 十月 2025 08:56:42 +0800 Subject: [PATCH] 修复评审功能和用户认证问题 --- backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerRatingService.java | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 42 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerRatingService.java b/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerRatingService.java index 3ddffc1..94615e1 100644 --- a/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerRatingService.java +++ b/backend/src/main/java/com/rongyichuang/player/service/ActivityPlayerRatingService.java @@ -206,7 +206,10 @@ */ public CurrentJudgeRatingResponse getCurrentJudgeRating(Long activityPlayerId) { Long currentJudgeId = userContextUtil.getCurrentJudgeId(); + log.info("getCurrentJudgeRating - activityPlayerId: {}, currentJudgeId: {}", activityPlayerId, currentJudgeId); + if (currentJudgeId == null) { + log.warn("getCurrentJudgeRating - currentJudgeId is null"); return null; } @@ -214,8 +217,11 @@ .findByActivityPlayerIdAndJudgeId(activityPlayerId, currentJudgeId); if (!ratingOpt.isPresent()) { + log.info("getCurrentJudgeRating - No rating found for activityPlayerId: {} and judgeId: {}", activityPlayerId, currentJudgeId); return null; } + + log.info("getCurrentJudgeRating - Found rating with id: {}", ratingOpt.get().getId()); ActivityPlayerRating rating = ratingOpt.get(); CurrentJudgeRatingResponse response = new CurrentJudgeRatingResponse(); @@ -227,16 +233,35 @@ // 鑾峰彇璇勫垎椤� List<ActivityPlayerRatingItem> items = activityPlayerRatingItemRepository .findByActivityPlayerRatingId(rating.getId()); - - List<CurrentJudgeRatingResponse.CurrentJudgeRatingItemResponse> itemResponses = items.stream() - .map(item -> new CurrentJudgeRatingResponse.CurrentJudgeRatingItemResponse( - item.getRatingItemId(), - "", // 璇勫垎椤瑰悕绉版殏鏃朵负绌� - item.getScore(), - item.getScore() // 浣跨敤寰楀垎浣滀负鍔犳潈寰楀垎 - )) + + List<Long> ratingItemIds = items.stream() + .map(ActivityPlayerRatingItem::getRatingItemId) + .filter(java.util.Objects::nonNull) + .distinct() .collect(java.util.stream.Collectors.toList()); - + + java.util.Map<Long, RatingItem> ratingItemMap = ratingItemIds.isEmpty() + ? java.util.Collections.emptyMap() + : ratingItemRepository.findAllById(ratingItemIds).stream() + .collect(java.util.stream.Collectors.toMap(RatingItem::getId, java.util.function.Function.identity())); + + List<CurrentJudgeRatingResponse.CurrentJudgeRatingItemResponse> itemResponses = items.stream() + .map(item -> { + RatingItem ratingItem = ratingItemMap.get(item.getRatingItemId()); + String name = ratingItem != null ? ratingItem.getName() : ""; + BigDecimal maxScore = ratingItem != null && ratingItem.getMaxScore() != null + ? BigDecimal.valueOf(ratingItem.getMaxScore()) : null; + return new CurrentJudgeRatingResponse.CurrentJudgeRatingItemResponse( + item.getRatingItemId(), + name, + item.getScore(), + item.getScore(), + maxScore + ); + }) + .collect(java.util.stream.Collectors.toList()); + + response.setRatedAt(rating.getUpdateTime() != null ? rating.getUpdateTime().toString() : null); response.setItems(itemResponses); return response; } @@ -397,7 +422,12 @@ ((Number) row.get("rating_item_id")).longValue(), (String) row.get("rating_item_name"), (BigDecimal) row.get("score"), - (BigDecimal) row.get("score") // weightedScore 鏆傛椂浣跨敤鐩稿悓鍊� + (BigDecimal) row.get("score"), + row.get("max_score") instanceof BigDecimal + ? (BigDecimal) row.get("max_score") + : row.get("max_score") instanceof Number + ? BigDecimal.valueOf(((Number) row.get("max_score")).doubleValue()) + : null )) .collect(java.util.stream.Collectors.toList()); @@ -406,6 +436,7 @@ response.setTotalScore(rating.getTotalScore()); response.setStatus(rating.getState()); response.setRemark(rating.getFeedback()); + response.setRatedAt(rating.getUpdateTime() != null ? rating.getUpdateTime().toString() : null); response.setItems(items); return response; @@ -415,4 +446,4 @@ return null; } } -} \ No newline at end of file +} -- Gitblit v1.8.0