-
Notifications
You must be signed in to change notification settings - Fork 1
[UPLUS-150] 청구서 데이터 예약 알림 메시지 형식 수정 #15
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.template.worker.jobs.invoicesend.model; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| public record InvoiceNotificationEvent( | ||
| UUID eventId, | ||
| Long templateGroupId, | ||
| SubscriptionInfo subscriptionInfo, | ||
| Variables variables) { | ||
|
|
||
| public record SubscriptionInfo(Long subId, String phoneNumber, String email) {} | ||
|
|
||
| public record Variables( | ||
| String invoiceNumber, | ||
| String customerName, | ||
| String phoneNumber, | ||
| String planName, | ||
| String billingDate, | ||
| String dueDate, | ||
| Integer totalAmount, | ||
| String paymentStatus, | ||
| List<Item> items) {} | ||
|
|
||
| public record Item(String name, String detail, Integer amount) {} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,34 @@ | ||
| package com.template.worker.jobs.invoicesend.processor; | ||
|
|
||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import org.springframework.batch.core.configuration.annotation.StepScope; | ||
| import org.springframework.batch.item.ItemProcessor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.template.worker.jobs.invoicesend.model.InvoiceAggregateRecord; | ||
| import com.template.worker.jobs.invoicesend.model.InvoiceItemRecord; | ||
| import com.template.worker.jobs.invoicesend.model.InvoiceNotificationEvent; | ||
| import com.template.worker.jobs.invoicesend.model.InvoiceSendRecord; | ||
|
|
||
| @Component | ||
| @StepScope | ||
| public class InvoiceSendProcessor | ||
| implements ItemProcessor<InvoiceSendRecord, InvoiceAggregateRecord> { | ||
| implements ItemProcessor<InvoiceSendRecord, InvoiceNotificationEvent> { | ||
|
|
||
| private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
|
||
| private Long currentInvId; | ||
| private InvoiceSendRecord currentInvoice; | ||
| private List<InvoiceItemRecord> currentItems; | ||
|
|
||
| @Override | ||
| public InvoiceAggregateRecord process(InvoiceSendRecord row) { | ||
| public InvoiceNotificationEvent process(InvoiceSendRecord row) { | ||
|
|
||
| if (currentInvId == null) { | ||
| startNewInvoice(row); | ||
| start(row); | ||
| return null; | ||
| } | ||
|
|
||
|
|
@@ -33,14 +37,12 @@ public InvoiceAggregateRecord process(InvoiceSendRecord row) { | |
| return null; | ||
| } | ||
|
|
||
| InvoiceAggregateRecord finished = buildAggregate(); | ||
|
|
||
| startNewInvoice(row); | ||
|
|
||
| InvoiceNotificationEvent finished = buildEvent(); | ||
| start(row); | ||
| return finished; | ||
| } | ||
|
|
||
| private void startNewInvoice(InvoiceSendRecord row) { | ||
| private void start(InvoiceSendRecord row) { | ||
| this.currentInvId = row.invId(); | ||
| this.currentInvoice = row; | ||
| this.currentItems = new ArrayList<>(4); | ||
|
|
@@ -56,26 +58,58 @@ private void addItem(InvoiceSendRecord row) { | |
| row.itemValue().intValue())); | ||
| } | ||
|
|
||
| public InvoiceAggregateRecord flushLast() { | ||
| public InvoiceNotificationEvent flushLast() { | ||
| if (currentInvId == null) { | ||
| return null; | ||
| } | ||
| return buildAggregate(); | ||
| return buildEvent(); | ||
| } | ||
|
|
||
| private InvoiceNotificationEvent buildEvent() { | ||
|
|
||
| String planName = | ||
| currentItems.stream() | ||
| .filter(i -> "PLAN".equals(i.invoiceType())) | ||
| .map(InvoiceItemRecord::invoiceName) | ||
| .findFirst() | ||
| .orElse(null); | ||
|
|
||
| List<InvoiceNotificationEvent.Item> items = | ||
| currentItems.stream() | ||
| .map( | ||
| i -> | ||
| new InvoiceNotificationEvent.Item( | ||
| mapItemName(i.invoiceType()), | ||
| i.invoiceName(), | ||
| i.value())) | ||
| .toList(); | ||
|
|
||
| return new InvoiceNotificationEvent( | ||
| UUID.randomUUID(), | ||
| 1L, // templateGroupId 고정 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| new InvoiceNotificationEvent.SubscriptionInfo( | ||
| currentInvoice.subId(), | ||
| currentInvoice.phone_enc(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용하시는 |
||
| currentInvoice.email_enc()), | ||
| new InvoiceNotificationEvent.Variables( | ||
| currentInvoice.invNo().toString(), | ||
| currentInvoice.name(), | ||
| currentInvoice.phone_enc(), | ||
| planName, | ||
| currentInvoice.createdAt().format(DATE_FORMAT), | ||
| currentInvoice.dueDate().format(DATE_FORMAT), | ||
| currentInvoice.totalPrice(), | ||
| "PAID", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| items)); | ||
| } | ||
|
|
||
| private InvoiceAggregateRecord buildAggregate() { | ||
| return new InvoiceAggregateRecord( | ||
| 2L, | ||
| currentInvoice.invNo(), | ||
| currentInvoice.invId(), | ||
| currentInvoice.subId(), | ||
| currentInvoice.invMonth(), | ||
| currentInvoice.phone_enc(), | ||
| currentInvoice.email_enc(), | ||
| currentInvoice.name(), | ||
| currentInvoice.totalPrice(), | ||
| currentInvoice.createdAt(), | ||
| currentInvoice.dueDate(), | ||
| List.copyOf(currentItems)); | ||
| private String mapItemName(String type) { | ||
| return switch (type) { | ||
| case "PLAN" -> "기본 요금"; | ||
| case "VAS" -> "부가서비스"; | ||
| case "DISCOUNT" -> "할인"; | ||
| case "MICRO" -> "소액 결제"; | ||
| default -> "기타"; | ||
| }; | ||
| } | ||
|
Comment on lines
+106
to
114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이러한 방식은 오타에 취약하며, 새로운 타입이 추가될 때 여러 곳을 수정해야 하는 불편함이 있습니다.
개선 예시: public enum InvoiceItemType {
PLAN("기본 요금"),
VAS("부가서비스"),
DISCOUNT("할인"),
MICRO("소액 결제"),
ETC("기타");
private final String koreanName;
InvoiceItemType(String koreanName) {
this.koreanName = koreanName;
}
public String getKoreanName() {
return koreanName;
}
public static InvoiceItemType fromString(String text) {
if (text != null) {
for (InvoiceItemType b : InvoiceItemType.values()) {
if (text.equalsIgnoreCase(b.name())) {
return b;
}
}
}
return ETC;
}
}
// InvoiceSendProcessor.java
private InvoiceNotificationEvent buildEvent() {
String planName = currentItems.stream()
.filter(i -> InvoiceItemType.PLAN.name().equals(i.invoiceType())) // enum 사용
.map(InvoiceItemRecord::invoiceName)
.findFirst()
.orElse(null);
// ...
}
private String mapItemName(String type) {
return InvoiceItemType.fromString(type).getKoreanName();
} |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
templateGroupId로 사용되는2L은 의미를 알기 어려운 매직 넘버입니다. 코드의 가독성과 유지보수성을 높이기 위해, 이 값의 의미를 명확히 나타내는 상수로 정의하는 것을 고려해 보세요. 예를 들어,NotificationTemplateConstants와 같은 별도의 상수 관리 클래스에USAGE_NOTIFICATION_TEMPLATE_GROUP_ID와 같이 정의하여 사용할 수 있습니다.