Skip to content

Commit 73ab5af

Browse files
committed
[feat]: 로직 수정
1 parent 7bebf80 commit 73ab5af

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/main/java/com/backend/domain/bid/repository/BidRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ SELECT MAX(b2.bidPrice)
6161
ORDER BY b.createDate DESC
6262
""")
6363
List<Bid> findWinningBids(@Param("memberId") Long memberId);
64+
65+
// 특정 상품의 모든 입찰 내역 (입찰가 내림차순)
66+
@Query("SELECT b FROM Bid b JOIN FETCH b.member WHERE b.product.id = :productId AND b.status = 'BIDDING' ORDER BY b.bidPrice DESC")
67+
List<Bid> findAllBidsByProductOrderByPriceDesc(@Param("productId") Long productId);
6468
}

src/main/java/com/backend/global/scheduler/AuctionSchedulerService.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.backend.global.scheduler;
22

3+
import com.backend.domain.bid.entity.Bid;
34
import com.backend.domain.bid.repository.BidRepository;
45
import com.backend.domain.notification.service.AuctionNotificationService;
56
import com.backend.domain.notification.service.BidNotificationService;
@@ -146,32 +147,31 @@ private void processAuctionEnd(Product product) {
146147
// 경매 종료 시 개인 알림 전송
147148
private void sendAuctionEndNotifications(Product product, Long finalPrice) {
148149
try {
149-
// 이 상품에 입찰한 모든 사람들 조회
150-
List<Object[]> bidders = entityManager.createQuery(
151-
"SELECT b.member.id, b.bidPrice FROM Bid b WHERE b.product.id = :productId AND b.status = 'BIDDING' ORDER BY b.bidPrice DESC",
152-
Object[].class)
153-
.setParameter("productId", product.getId())
154-
.getResultList();
155-
156-
if (bidders.isEmpty()) {
150+
List<Bid> bids = bidRepository.findAllBidsByProductOrderByPriceDesc(product.getId());
151+
152+
if (bids.isEmpty()) {
157153
return;
158154
}
159155

160-
// 최고 입찰자 (낙찰자)
161-
Long winnerId = (Long) bidders.get(0)[0];
156+
// 낙찰자
157+
Bid winningBid = bids.get(0);
162158

163159
// 낙찰자에게 낙찰 알림
164-
bidNotificationService.notifyAuctionWon(winnerId, product, finalPrice);
160+
bidNotificationService.notifyAuctionWon(winningBid.getMember().getId(), product, finalPrice);
165161

166162
// 나머지 입찰자들에게 낙찰 실패 알림
167-
for (int i = 1; i < bidders.size(); i++) {
168-
Long loserId = (Long) bidders.get(i)[0];
169-
Long loserBidPrice = ((Number) bidders.get(i)[1]).longValue();
170-
bidNotificationService.notifyAuctionLost(loserId, product, finalPrice, loserBidPrice);
163+
for (int i = 1; i < bids.size(); i++) {
164+
Bid losingBid = bids.get(i);
165+
bidNotificationService.notifyAuctionLost(
166+
losingBid.getMember().getId(),
167+
product,
168+
finalPrice,
169+
losingBid.getBidPrice()
170+
);
171171
}
172172

173173
log.info("상품 ID: {}에 대한 경매 종료 개인 알림 전송 완료. 낙찰자: {}, 탈락자: {}명",
174-
product.getId(), winnerId, bidders.size() - 1);
174+
product.getId(), winningBid.getMember().getId(), bids.size() - 1);
175175

176176
} catch (Exception e) {
177177
log.error("경매 종료 개인 알림 전송 중 오류 발생. 상품 ID: {}, 오류: {}",

0 commit comments

Comments
 (0)