-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ 매월 목표 금액 설정 공지 푸시 알림 배치 (#141)
* rename: notification writer -> daily_spending_notify_writer * fix: announcement enum class not_announce 타입 필터링 * fix: daily_notication dto 범용성 확장하여 announce_notification_dto로 수정 * feat: 매월 목표 금액 설정 공지 writer 작성 * feat: monthly_target_amount_notify_config job $ step impl * feat: 매월 정기 목표 금액 설정 알림 스케줄 설정 * fix: 목표 금액 알림 메시지 조회 시, title 해당 월 삽입되도록 수정 * fix: monthly_target_amount title %s누락 수정 * fix: announce notification dto 내부에서 월별 목표 금액 title 생성 시, 분기 처리
- Loading branch information
1 parent
6bd74c2
commit 9175dfa
Showing
8 changed files
with
153 additions
and
26 deletions.
There are no files selected for viewing
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
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
45 changes: 45 additions & 0 deletions
45
pennyway-batch/src/main/java/kr/co/pennyway/batch/job/MonthlyTargetAmountNotifyConfig.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,45 @@ | ||
package kr.co.pennyway.batch.job; | ||
|
||
import kr.co.pennyway.batch.common.dto.DeviceTokenOwner; | ||
import kr.co.pennyway.batch.reader.ActiveDeviceTokenReader; | ||
import kr.co.pennyway.batch.writer.MonthlyTotalAmountNotifyWriter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.Step; | ||
import org.springframework.batch.core.configuration.annotation.JobScope; | ||
import org.springframework.batch.core.job.builder.JobBuilder; | ||
import org.springframework.batch.core.repository.JobRepository; | ||
import org.springframework.batch.core.step.builder.StepBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class MonthlyTargetAmountNotifyConfig { | ||
private final JobRepository jobRepository; | ||
private final ActiveDeviceTokenReader reader; | ||
private final MonthlyTotalAmountNotifyWriter writer; | ||
|
||
@Bean | ||
public Job monthlyNotificationJob(PlatformTransactionManager transactionManager) { | ||
return new JobBuilder("monthlyNotificationJob", jobRepository) | ||
.start(monthlyNotificationStep(transactionManager)) | ||
.on("FAILED") | ||
.stopAndRestart(monthlyNotificationStep(transactionManager)) | ||
.on("*") | ||
.end() | ||
.end() | ||
.build(); | ||
} | ||
|
||
@Bean | ||
@JobScope | ||
public Step monthlyNotificationStep(PlatformTransactionManager transactionManager) { | ||
return new StepBuilder("sendMonthlyNotifyStep", jobRepository) | ||
.<DeviceTokenOwner, DeviceTokenOwner>chunk(1000, transactionManager) | ||
.reader(reader.querydslNoOffsetPagingItemReader()) | ||
.writer(writer) | ||
.build(); | ||
} | ||
} |
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
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
50 changes: 50 additions & 0 deletions
50
pennyway-batch/src/main/java/kr/co/pennyway/batch/writer/MonthlyTotalAmountNotifyWriter.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,50 @@ | ||
package kr.co.pennyway.batch.writer; | ||
|
||
import kr.co.pennyway.batch.common.dto.AnnounceNotificationDto; | ||
import kr.co.pennyway.batch.common.dto.DeviceTokenOwner; | ||
import kr.co.pennyway.domain.domains.notification.repository.NotificationRepository; | ||
import kr.co.pennyway.domain.domains.notification.type.Announcement; | ||
import kr.co.pennyway.infra.common.event.NotificationEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.batch.core.configuration.annotation.StepScope; | ||
import org.springframework.batch.item.Chunk; | ||
import org.springframework.batch.item.ItemWriter; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class MonthlyTotalAmountNotifyWriter implements ItemWriter<DeviceTokenOwner> { | ||
private final NotificationRepository notificationRepository; | ||
private final ApplicationEventPublisher publisher; | ||
|
||
@Override | ||
@StepScope | ||
@Transactional | ||
public void write(@NonNull Chunk<? extends DeviceTokenOwner> owners) throws Exception { | ||
log.info("Writer 실행: {}", owners.size()); | ||
|
||
Map<Long, AnnounceNotificationDto> notificationMap = new HashMap<>(); | ||
|
||
for (DeviceTokenOwner owner : owners) { | ||
notificationMap.computeIfAbsent(owner.userId(), k -> AnnounceNotificationDto.from(owner, Announcement.MONTHLY_TARGET_AMOUNT)).addDeviceToken(owner.deviceToken()); | ||
} | ||
|
||
List<Long> userIds = new ArrayList<>(notificationMap.keySet()); | ||
|
||
notificationRepository.saveDailySpendingAnnounceInBulk(userIds, Announcement.MONTHLY_TARGET_AMOUNT); | ||
|
||
for (AnnounceNotificationDto notification : notificationMap.values()) { | ||
publisher.publishEvent(NotificationEvent.of(notification.title(), notification.content(), notification.deviceTokensForList(), "")); | ||
} | ||
} | ||
} |
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
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