Skip to content

Commit 46d5b28

Browse files
authored
Merge pull request #214 from UruruLab/bug/213-prodcutStatusChange
공동구매 삭제 시 상품 상태 변경 로직 추가
2 parents cc2f4ee + 3fa943a commit 46d5b28

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/main/java/com/ururulab/ururu/groupBuy/scheduler/GroupBuyBatchScheduler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class GroupBuyBatchScheduler {
1616
/**
1717
* 매일 자정(00:00)에 만료된 공동구매 배치 종료
1818
*/
19-
@Scheduled(cron = "0 0 0 * * *")
19+
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
2020
public void closeExpiredGroupBuysBatch() {
2121
log.info("Starting daily batch process for expired group buys...");
2222

@@ -34,7 +34,7 @@ public void closeExpiredGroupBuysBatch() {
3434
* 시간별 헬스체크용
3535
* 매 시간마다 급하게 처리해야 할 만료된 공동구매가 있는지 확인
3636
*/
37-
@Scheduled(cron = "0 0 * * * *") // 매시간 정각
37+
@Scheduled(cron = "0 0 * * * *", zone = "Asia/Seoul") // 매시간 정각
3838
public void hourlyHealthCheck() {
3939
log.debug("Running hourly health check for group buy expiration...");
4040

src/main/java/com/ururulab/ururu/groupBuy/service/GroupBuyBatchCloseService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.ururulab.ururu.groupBuy.domain.repository.GroupBuyRepository;
77
import com.ururulab.ururu.groupBuy.domain.repository.GroupBuyStatisticsRepository;
88
import com.ururulab.ururu.groupBuy.event.GroupBuysBatchClosedEvent;
9+
import com.ururulab.ururu.product.domain.entity.Product;
10+
import com.ururulab.ururu.product.domain.entity.enumerated.Status;
911
import lombok.RequiredArgsConstructor;
1012
import lombok.extern.slf4j.Slf4j;
1113
import org.springframework.context.ApplicationEventPublisher;
@@ -89,6 +91,13 @@ private void updateGroupBuyStatusesAndPrices(List<GroupBuy> groupBuys,
8991
// 상태를 CLOSED로 변경
9092
groupBuy.updateStatus(GroupBuyStatus.CLOSED);
9193

94+
// 연관된 상품을 INACTIVE로 변경
95+
Product product = groupBuy.getProduct();
96+
if (product.getStatus() == Status.ACTIVE) {
97+
product.updateStatus(Status.INACTIVE);
98+
log.info("Product {} deactivated after GroupBuy deletion", product.getId());
99+
}
100+
92101
// 최종 할인율이 있으면 최종 판매가 업데이트
93102
if (statistics.getFinalDiscountRate() > 0) {
94103
groupBuyPriceService.updateFinalSalePrices(

src/main/java/com/ururulab/ururu/groupBuy/service/GroupBuyDeleteService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import com.ururulab.ururu.groupBuy.domain.repository.GroupBuyRepository;
88
import com.ururulab.ururu.groupBuy.event.GroupBuyDetailImageDeleteEvent;
99
import com.ururulab.ururu.groupBuy.event.GroupBuyThumbnailDeleteEvent;
10+
import com.ururulab.ururu.product.domain.entity.Product;
1011
import com.ururulab.ururu.product.domain.entity.enumerated.Status;
1112
import lombok.RequiredArgsConstructor;
13+
import lombok.extern.slf4j.Slf4j;
1214
import org.springframework.context.ApplicationEventPublisher;
1315
import org.springframework.stereotype.Service;
1416
import org.springframework.transaction.annotation.Transactional;
@@ -20,6 +22,7 @@
2022

2123
@Service
2224
@RequiredArgsConstructor
25+
@Slf4j
2326
public class GroupBuyDeleteService {
2427

2528
private final GroupBuyRepository groupBuyRepository;
@@ -39,6 +42,13 @@ public void deleteGroupBuy(Long groupBuyId, Long sellerId) {
3942
throw new BusinessException(GROUPBUY_DELETE_NOT_ALLOWED);
4043
}
4144

45+
// 연관된 상품을 INACTIVE로 변경
46+
Product product = groupBuy.getProduct();
47+
if (product.getStatus() == Status.ACTIVE) {
48+
product.updateStatus(Status.INACTIVE);
49+
log.info("Product {} deactivated after GroupBuy deletion", product.getId());
50+
}
51+
4252
// 1. 썸네일 이미지 삭제 이벤트 발행
4353
if (groupBuy.getThumbnailUrl() != null) {
4454
eventPublisher.publishEvent(new GroupBuyThumbnailDeleteEvent(

src/main/java/com/ururulab/ururu/groupBuy/service/GroupBuyRealtimeCloseService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.ururulab.ururu.groupBuy.domain.repository.GroupBuyOptionRepository;
88
import com.ururulab.ururu.groupBuy.domain.repository.GroupBuyRepository;
99
import com.ururulab.ururu.groupBuy.domain.repository.GroupBuyStatisticsRepository;
10+
import com.ururulab.ururu.product.domain.entity.Product;
11+
import com.ururulab.ururu.product.domain.entity.enumerated.Status;
1012
import lombok.RequiredArgsConstructor;
1113
import lombok.extern.slf4j.Slf4j;
1214
import org.springframework.stereotype.Service;
@@ -82,6 +84,13 @@ private void closeGroupBuyImmediately(GroupBuy groupBuy) {
8284
// 상태를 CLOSED로 변경
8385
groupBuy.updateStatus(GroupBuyStatus.CLOSED);
8486

87+
// 연관된 상품을 INACTIVE로 변경
88+
Product product = groupBuy.getProduct();
89+
if (product.getStatus() == Status.ACTIVE) {
90+
product.updateStatus(Status.INACTIVE);
91+
log.info("Product {} deactivated after GroupBuy deletion", product.getId());
92+
}
93+
8594
// 최종 할인율이 있으면 최종 판매가 업데이트
8695
if (statistics.getFinalDiscountRate() > 0) {
8796
groupBuyPriceService.updateFinalSalePrices(

0 commit comments

Comments
 (0)