|
1 | 1 | package com.backend.global.scheduler; |
2 | 2 |
|
| 3 | +import com.backend.domain.bid.entity.Bid; |
3 | 4 | import com.backend.domain.bid.repository.BidRepository; |
4 | 5 | import com.backend.domain.notification.service.AuctionNotificationService; |
5 | 6 | import com.backend.domain.notification.service.BidNotificationService; |
@@ -146,32 +147,31 @@ private void processAuctionEnd(Product product) { |
146 | 147 | // 경매 종료 시 개인 알림 전송 |
147 | 148 | private void sendAuctionEndNotifications(Product product, Long finalPrice) { |
148 | 149 | 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()) { |
157 | 153 | return; |
158 | 154 | } |
159 | 155 |
|
160 | | - // 최고 입찰자 (낙찰자) |
161 | | - Long winnerId = (Long) bidders.get(0)[0]; |
| 156 | + // 낙찰자 |
| 157 | + Bid winningBid = bids.get(0); |
162 | 158 |
|
163 | 159 | // 낙찰자에게 낙찰 알림 |
164 | | - bidNotificationService.notifyAuctionWon(winnerId, product, finalPrice); |
| 160 | + bidNotificationService.notifyAuctionWon(winningBid.getMember().getId(), product, finalPrice); |
165 | 161 |
|
166 | 162 | // 나머지 입찰자들에게 낙찰 실패 알림 |
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 | + ); |
171 | 171 | } |
172 | 172 |
|
173 | 173 | log.info("상품 ID: {}에 대한 경매 종료 개인 알림 전송 완료. 낙찰자: {}, 탈락자: {}명", |
174 | | - product.getId(), winnerId, bidders.size() - 1); |
| 174 | + product.getId(), winningBid.getMember().getId(), bids.size() - 1); |
175 | 175 |
|
176 | 176 | } catch (Exception e) { |
177 | 177 | log.error("경매 종료 개인 알림 전송 중 오류 발생. 상품 ID: {}, 오류: {}", |
|
0 commit comments