Conversation
mps로 예측 생산한 재고 입고 재고 업데이트 시 상태도 업데이트 네이티브 쿼리에서 배치 저장으로 변경
|
Warning Rate limit exceeded@vivivim has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 49 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughEventPayloadMapper에 MpsStatusChanged 및 MpsCompleted 매핑을 추가했고, Inventory 엔티티에 재고 갱신 및 상태 계산 메서드를 도입했으며 InventoryService에 MPS 인바운드 처리(inboundFromMps)를 추가하고 PurchaseEventConsumer에서 이를 호출하도록 통합했습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant EC as 외부 이벤트 소스
participant PEC as PurchaseEventConsumer
participant IS as InventoryService
participant IR as InventoryRepository
participant IE as InventoryEntity
EC->>PEC: MpsCompleted 이벤트 (POEventPayload)
PEC->>IS: inboundFromMps(payload)
IS->>IR: findAllByPartIdIn(partIds)
IR-->>IS: inventories 리스트
rect rgb(220,245,230)
note right of IS: 파트별 델타 적용
IS->>IE: inventory.updateStock(delta)
IE->>IE: quantity += delta
IE->>IE: updateQuantityStatus()
end
IS-->>PEC: 처리 완료
PEC-->>EC: 응답(처리 완료)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (2)
51-54: 기존 updateQuantity 메서드와의 일관성을 고려하세요.새로운
updateStock메서드는 재고량 업데이트와 함께 상태도 갱신하는 반면, 기존updateQuantity메서드(33-35번 줄)는 상태를 갱신하지 않습니다. 두 메서드의 공존이 혼란을 야기할 수 있습니다.다음 중 하나를 고려해보세요:
- 기존
updateQuantity메서드를updateStock으로 통합하고 모든 사용처를 마이그레이션- 또는
updateQuantity를@Deprecated처리하고 점진적으로 제거
56-66: DANGER 조건의 명확성을 개선할 수 있습니다.64번 줄의 조건이
<=를 사용하고 있지만, 이전 else-if 체인에서quantity == safetyStock케이스는 이미 SHORT로 처리됩니다. 논리적 오류는 아니지만, 명확성을 위해<로 변경하는 것을 고려해보세요.- else if (this.quantity <= this.part.getSafetyStock()) + else this.quantityStatus = QuantityStatus.DANGER;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/java/com/sampoom/backend/api/event/service/EventPayloadMapper.java(1 hunks)src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java(1 hunks)src/main/java/com/sampoom/backend/api/inventory/service/InventoryService.java(5 hunks)src/main/java/com/sampoom/backend/api/order/event/PurchaseEventConsumer.java(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (5)
src/main/java/com/sampoom/backend/api/event/service/EventPayloadMapper.java (1)
34-36: LGTM!MPS 이벤트를 기존 POEventPayload 클래스에 매핑한 것이 적절합니다. PurchaseEventConsumer에서 이 이벤트들을 올바르게 처리하고 있습니다.
src/main/java/com/sampoom/backend/api/order/event/PurchaseEventConsumer.java (2)
6-6: LGTM!InventoryService 의존성 추가가 적절하며, MPS 완료 이벤트 처리를 위해 필요한 변경입니다.
Also applies to: 22-22
52-53: MpsStatusChanged의 no-op 처리가 의도적인지 확인하세요.
MpsStatusChanged이벤트에 대한 빈 케이스 블록이 있습니다. 이것이 의도적인 것인지, 아니면 향후 구현이 필요한지 확인해주세요. 의도적이라면 주석으로 이유를 명시하는 것이 좋습니다.src/main/java/com/sampoom/backend/api/inventory/service/InventoryService.java (2)
10-11: LGTM!새로운 MPS 입고 기능을 위한 필요한 임포트 및 로깅 설정이 적절하게 추가되었습니다.
Also applies to: 32-32, 45-45
147-147: 좋은 개선입니다!
updateQuantity에서updateStock으로 변경하여 재고 업데이트 시 상태도 자동으로 갱신되도록 개선되었습니다. PR 목적과 일치합니다.
src/main/java/com/sampoom/backend/api/inventory/service/InventoryService.java
Show resolved
Hide resolved
음수 델타 검증 이벤트 기반이라 에러 시 로그 남김. 추후 공장에게 알려야 하나?
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (1)
33-35: 메서드 역할을 명확히 하거나 통합을 고려하세요.
updateQuantity(33-35번 줄)와updateStock(51-54번 줄) 메서드가 유사한 기능을 수행하여 혼란을 야기할 수 있습니다.두 가지 옵션을 고려하세요:
- 옵션 1:
updateStock을 사용하도록 통합하고updateQuantity를 제거하거나 deprecated 처리- 옵션 2: 각 메서드의 용도를 JavaDoc으로 명확히 문서화 (예: updateQuantity는 상태 업데이트 없이 수량만 변경, updateStock은 상태도 함께 업데이트)
옵션 1 적용 시 (기존 updateQuantity 제거):
-public void updateQuantity(int dq) { - this.quantity += dq; -}옵션 2 적용 시 (JavaDoc 추가):
+/** + * 재고 수량만 업데이트합니다 (상태 업데이트 없음). + * @param dq 변경할 수량 + */ public void updateQuantity(int dq) { this.quantity += dq; } +/** + * 재고 수량을 업데이트하고 재고 상태도 함께 갱신합니다. + * @param dq 변경할 수량 + */ public void updateStock(Integer dq) { this.quantity += dq; this.updateQuantityStatus(); }Also applies to: 51-54
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (java-kotlin)
계산 타입 맞춤 에러 처리
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (2)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (2)
53-56: null 검사 및 음수 재고 방지 검증을 추가하세요.다음과 같은 문제가 있습니다:
dq가Integer래퍼 타입이므로 null일 경우 NPE가 발생합니다.- 재고 수량이 음수가 되지 않도록 하는 검증이 없습니다.
- 기존
updateQuantity메서드(35-37번 줄)와 로직이 중복됩니다.다음 diff를 적용하여 검증을 추가하세요:
public void updateStock(Integer dq) { + if (dq == null) { + throw new IllegalArgumentException("Delta quantity cannot be null"); + } + if (this.quantity + dq < 0) { + throw new IllegalStateException("Inventory quantity cannot be negative"); + } this.quantity += dq; this.updateQuantityStatus(); }
58-64:partnull 검사와 지연 로딩 예외 처리를 추가하세요.다음과 같은 문제가 있습니다:
this.part가 null인지 확인하지 않고part.getSafetyStock()을 호출하면 NPE가 발생할 수 있습니다.part는 지연 로딩(@ManyToOne(fetch = FetchType.LAZY))이므로, 영속성 컨텍스트 외부에서 접근 시LazyInitializationException이 발생할 수 있습니다.다음 diff를 적용하여 검증을 추가하세요:
public void updateQuantityStatus() { + if (this.part == null) { + log.error("Part is null. quantityStatus cannot be changed: warehouseID={}", this.id); + return; + } Integer safetyStock = this.part.getSafetyStock(); if (safetyStock == null) { log.error("Part safety stock is null. quantityStatus cannot changed: warehouseID={} partId={}", this.id, this.part.getId()); return; }
🧹 Nitpick comments (1)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (1)
65-74: 중복 조건을 제거하고 로직을 단순화하세요.safetyStock null 검사 및 int 캐스팅 추가는 좋은 개선입니다. 하지만 69-71번 줄의 조건이 중복됩니다:
- 이
else if에 도달했다면 이미quantity >= safetyStock이고quantity < safetyStock * 1.5가 보장됩니다(67번 줄의 조건에 의해).다음 diff를 적용하여 조건을 단순화하세요:
if (this.quantity >= (int)(this.maxStock * 0.8)) this.quantityStatus = QuantityStatus.OVER; else if (this.quantity >= (int)(safetyStock * 1.5)) this.quantityStatus = QuantityStatus.ENOUGH; - else if (this.quantity >= safetyStock && - this.quantity < (int)(safetyStock * 1.5)) + else if (this.quantity >= safetyStock) this.quantityStatus = QuantityStatus.SHORT; - else if (this.quantity < safetyStock) + else this.quantityStatus = QuantityStatus.DANGER;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (java-kotlin)
🔇 Additional comments (1)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (1)
9-9: 로깅 지원 추가가 적절합니다.
@Slf4j애노테이션 추가로 로깅 기능이 정상적으로 통합되었습니다.Also applies to: 18-18
업데이트 조건 단순화
📝 Summary
mps로 예측 생산한 재고 입고
재고 업데이트 시 상태도 업데이트
네이티브 쿼리에서 배치 저장으로 변경
🙏 Question & PR point
📬 Reference
Summary by CodeRabbit
새로운 기능
리팩터