Skip to content

Commit 0bff535

Browse files
Merge pull request #144 from SeoyeonPark1223/trend-rank
#143 Fix: 밈코인 랭크 10분마다 업데이트 추가
2 parents 428a161 + 04b0e92 commit 0bff535

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/main/java/com/memesphere/domain/chartdata/scheduler/ChartDataScheduler.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.memesphere.domain.binance.dto.response.BinanceTickerResponse;
44
import com.memesphere.domain.binance.service.BinanceQueryService;
55
import com.memesphere.domain.chartdata.entity.ChartData;
6+
import com.memesphere.domain.chartdata.repository.ChartDataRepository;
7+
import com.memesphere.domain.dashboard.dto.response.DashboardTrendResponse;
68
import com.memesphere.domain.notification.service.PushNotificationService;
79
import com.memesphere.global.apipayload.code.status.ErrorStatus;
810
import com.memesphere.global.apipayload.exception.GeneralException;
@@ -15,6 +17,7 @@
1517
import org.springframework.stereotype.Component;
1618
import org.springframework.transaction.annotation.Transactional;
1719

20+
import java.util.ArrayList;
1821
import java.util.List;
1922
import java.util.Set;
2023

@@ -28,6 +31,7 @@ public class ChartDataScheduler {
2831
private final MemeCoinQueryService memeCoinQueryService;
2932
private final LoggedInUserStore loggedInUserStore;
3033
private final PushNotificationService pushNotificationService;
34+
private final ChartDataRepository chartDataRepository;
3135

3236
@Scheduled(cron = "0 0/10 * * * ?") // 0, 10, 20, 30, 40, 50분에 실행
3337
@Transactional
@@ -37,6 +41,9 @@ public void updateChartData() {
3741

3842
List<MemeCoin> memeCoins = memeCoinRepository.findAll();
3943

44+
// 이전에 기록된 top5 밈코인
45+
List<MemeCoin> prevCoinList = memeCoinRepository.findTop5OrderByRank();
46+
4047
for (MemeCoin memeCoin : memeCoins) {
4148
try {
4249
String symbol = memeCoin.getSymbol() + "USDT";
@@ -54,6 +61,30 @@ public void updateChartData() {
5461
for (Long userId : loggedInUsers) {
5562
pushNotificationService.send(userId);
5663
}
64+
65+
// 밈코인 랭킹 업데이트
66+
updateRank(prevCoinList);
67+
}
68+
69+
public void updateRank(List<MemeCoin> prevCoinList) {
70+
// 최신 거래량 top5 밈코인-차트데이터
71+
List<ChartData> updatedChartDataList = chartDataRepository.findTop5OrderByVolumeDesc();
72+
73+
if (prevCoinList != null) {
74+
// 현재 top5에 들지 않는 밈코인 순위 처리
75+
List<MemeCoin> currCoinList = updatedChartDataList.stream().map(ChartData::getMemeCoin).toList();
76+
for (MemeCoin prevCoin : prevCoinList) {
77+
if (!currCoinList.contains(prevCoin)) prevCoin.updateRank(null);
78+
}
79+
}
80+
81+
// 현재 top5 밈코인
82+
for (int i = 0; i < 5; i++) {
83+
MemeCoin memeCoin = updatedChartDataList.get(i).getMemeCoin();
84+
85+
Integer currRank = i + 1;
86+
memeCoin.updateRank(currRank);
87+
}
5788
}
5889
}
5990

0 commit comments

Comments
 (0)