-
Notifications
You must be signed in to change notification settings - Fork 4
Feat: [BADA-364] 알림 비동기 처리 #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/TwoSeaU/BaData/domain/rental/service/RestockDeleteTargetingService.java
This file contains hidden or 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,66 @@ | ||
| package com.TwoSeaU.BaData.domain.rental.service; | ||
|
|
||
| import com.TwoSeaU.BaData.domain.rental.entity.DeviceReservation; | ||
| import com.TwoSeaU.BaData.domain.rental.entity.ReStock; | ||
| import com.TwoSeaU.BaData.domain.rental.entity.Reservation; | ||
| import com.TwoSeaU.BaData.domain.rental.repository.DeviceReservationRepository; | ||
| import com.TwoSeaU.BaData.domain.rental.repository.ReStockRepository; | ||
| import com.TwoSeaU.BaData.domain.store.entity.StoreDevice; | ||
| import com.TwoSeaU.BaData.domain.store.exception.StoreException; | ||
| import com.TwoSeaU.BaData.domain.user.entity.User; | ||
| import com.TwoSeaU.BaData.global.response.GeneralException; | ||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Propagation; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class RestockDeleteTargetingService { | ||
|
|
||
| private final ReStockRepository reStockRepository; | ||
| private final DeviceReservationRepository deviceReservationRepository; | ||
|
|
||
| @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
| public List<User> getSendTargetUser(final Reservation reservation, final List<DeviceReservation> deviceReservations) { | ||
|
|
||
| final List<User> sendUserTargets = new ArrayList<>(); | ||
|
|
||
| final LocalDateTime rentalStart = reservation.getRentalStartDate(); | ||
| final LocalDateTime rentalEnd = reservation.getRentalEndDate(); | ||
|
|
||
| for(final DeviceReservation deviceReservation : deviceReservations){ | ||
|
|
||
| final StoreDevice storeDevice = deviceReservation.getStoreDevice(); | ||
|
|
||
| // 1. 취소된 예약 기간과 겹치는 알림 신청자만 조회 | ||
| final List<ReStock> overlappedReStocks = reStockRepository.findOverlappedReStocks( | ||
| storeDevice, rentalStart, rentalEnd | ||
| ); | ||
|
|
||
| for (final ReStock reStock : overlappedReStocks) { | ||
|
|
||
| // 2. 신청자의 희망 기간 동안의 남은 수량 계산 | ||
| final Long availableCount = deviceReservationRepository.findAvailableCountsByStoreDeviceIdAndPeriod(storeDevice.getId(), rentalStart, rentalEnd) | ||
| .orElseThrow(()-> new GeneralException(StoreException.CANT_FIND_STORE_DEVICE)); | ||
|
dionisos198 marked this conversation as resolved.
|
||
|
|
||
| log.info("AvailableCount: {}, Restock DesiredCount: {}", availableCount, reStock.getDesiredCount()); | ||
|
|
||
| // 3. 남은 수량이 재입고 알림 수량 보다 큰 경우 | ||
| if (availableCount >= reStock.getDesiredCount()) { | ||
| sendUserTargets.add(reStock.getUser()); | ||
| reStockRepository.delete(reStock); | ||
| } | ||
|
dionisos198 marked this conversation as resolved.
|
||
| } | ||
|
|
||
|
dionisos198 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return sendUserTargets; | ||
| } | ||
|
dionisos198 marked this conversation as resolved.
|
||
|
|
||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/TwoSeaU/BaData/global/config/SpringAsyncConfig.java
This file contains hidden or 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,22 @@ | ||
| package com.TwoSeaU.BaData.global.config; | ||
|
|
||
| import java.util.concurrent.Executor; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.scheduling.annotation.EnableAsync; | ||
| import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
|
||
| @Configuration | ||
| @EnableAsync | ||
| public class SpringAsyncConfig { | ||
|
|
||
| @Bean(name = "threadPoolTaskExecutor") | ||
| public Executor threadPoolTaskExecutor() { | ||
| ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); | ||
| taskExecutor.setCorePoolSize(100); | ||
|
dionisos198 marked this conversation as resolved.
|
||
| taskExecutor.setQueueCapacity(Integer.MAX_VALUE); | ||
|
dionisos198 marked this conversation as resolved.
|
||
| taskExecutor.setThreadNamePrefix("Executor-"); | ||
| return taskExecutor; | ||
| } | ||
|
dionisos198 marked this conversation as resolved.
|
||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.