-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#172] feat(PromotionService): 지나간 공연에 해당하는 promotion 캐러셀 삭제하는 로직 구현
- Loading branch information
1 parent
ca3c4b4
commit a952d27
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/com/beat/domain/promotion/application/PromotionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.beat.domain.promotion.application; | ||
|
||
import com.beat.domain.performance.domain.Performance; | ||
import com.beat.domain.promotion.dao.PromotionRepository; | ||
import com.beat.domain.promotion.domain.Promotion; | ||
import com.beat.domain.schedule.application.ScheduleService; | ||
import com.beat.domain.schedule.dao.ScheduleRepository; | ||
import com.beat.domain.schedule.domain.Schedule; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PromotionService { | ||
|
||
private final PromotionRepository promotionRepository; | ||
private final ScheduleRepository scheduleRepository; | ||
private final ScheduleService scheduleService; | ||
|
||
@Scheduled(cron = "1 0 0 * * ?") | ||
@Transactional | ||
public void checkAndDeleteInvalidPromotions() { | ||
List<Promotion> promotions = promotionRepository.findAll(); | ||
|
||
for (Promotion promotion : promotions) { | ||
if (promotion.getPerformance() != null) { | ||
Performance performance = promotion.getPerformance(); | ||
|
||
List<Schedule> schedules = scheduleRepository.findByPerformanceId(performance.getId()); | ||
int minDueDate = scheduleService.getMinDueDate(schedules); | ||
|
||
// MinDueDate가 음수일 경우 Promotion 삭제 | ||
if (minDueDate < 0) { | ||
promotionRepository.delete(promotion); | ||
} | ||
} | ||
} | ||
} | ||
} |