From 3714621173c606c4c58439ed8941100ce9ddea14 Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期三, 05 十一月 2025 15:10:49 +0800
Subject: [PATCH] bug
---
backend/src/main/java/com/rongyichuang/player/service/PromotionService.java | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/backend/src/main/java/com/rongyichuang/player/service/PromotionService.java b/backend/src/main/java/com/rongyichuang/player/service/PromotionService.java
index 4ca32ea..e85c772 100644
--- a/backend/src/main/java/com/rongyichuang/player/service/PromotionService.java
+++ b/backend/src/main/java/com/rongyichuang/player/service/PromotionService.java
@@ -8,6 +8,7 @@
import com.rongyichuang.common.repository.MediaRepository;
import com.rongyichuang.message.service.MessageService;
import com.rongyichuang.player.dto.*;
+import com.rongyichuang.player.dto.response.PromotionCompetitionPageResponse;
import com.rongyichuang.player.entity.ActivityPlayer;
import com.rongyichuang.player.repository.ActivityPlayerRepository;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,11 +46,11 @@
/**
* 鑾峰彇姣旇禌鏅嬬骇鍒楄〃
*/
- public List<PromotionCompetitionResponse> getPromotionCompetitions(String name, Integer page, Integer size) {
- List<PromotionCompetitionResponse> result = new ArrayList<>();
+ public PromotionCompetitionPageResponse getPromotionCompetitions(String name, Integer page, Integer size) {
+ List<PromotionCompetitionResponse> allResults = new ArrayList<>();
// 鏌ヨ鎵�鏈夋湁鏁堢殑涓绘瘮璧涳紙pid = 0锛�
- List<Activity> competitions = activityRepository.findByPidAndStateOrderByCreateTimeAsc(0L, 1);
+ List<Activity> competitions = activityRepository.findByPidAndStateOrderByCreateTimeDesc(0L, 1);
// 濡傛灉鏈夊悕绉拌繃婊ゆ潯浠讹紝杩涜杩囨护
if (name != null && !name.trim().isEmpty()) {
@@ -60,7 +61,7 @@
// 涓烘瘡涓瘮璧涙煡璇㈠叾闃舵
for (Activity competition : competitions) {
- List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(competition.getId(), 1);
+ List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeDesc(competition.getId(), 1);
for (Activity stage : stages) {
// 缁熻褰撳墠闃舵鐨勫弬璧涗汉鏁�
@@ -68,22 +69,27 @@
Integer currentCount = playerCountLong != null ? playerCountLong.intValue() : 0;
PromotionCompetitionResponse response = new PromotionCompetitionResponse(competition, stage, currentCount);
- result.add(response);
+ allResults.add(response);
}
}
- // 绠�鍗曞垎椤靛鐞嗭紙瀹為檯椤圭洰涓缓璁娇鐢ㄦ暟鎹簱鍒嗛〉锛�
+ // 璁$畻鎬绘暟
+ long totalElements = allResults.size();
+
+ // 鍒嗛〉澶勭悊
+ List<PromotionCompetitionResponse> pagedResults = allResults;
if (page != null && size != null && page > 0 && size > 0) {
int start = (page - 1) * size;
- int end = Math.min(start + size, result.size());
- if (start < result.size()) {
- result = result.subList(start, end);
+ int end = Math.min(start + size, allResults.size());
+ if (start < allResults.size()) {
+ pagedResults = allResults.subList(start, end);
} else {
- result = new ArrayList<>();
+ pagedResults = new ArrayList<>();
}
}
- return result;
+ // 杩斿洖鍒嗛〉鍝嶅簲瀵硅薄
+ return new PromotionCompetitionPageResponse(pagedResults, totalElements, page, size);
}
/**
--
Gitblit v1.8.0