Skip to content

feat: mps 입고#54

Merged
vivivim merged 5 commits intomainfrom
SPM-504
Nov 11, 2025
Merged

feat: mps 입고#54
vivivim merged 5 commits intomainfrom
SPM-504

Conversation

@vivivim
Copy link
Contributor

@vivivim vivivim commented Nov 11, 2025

📝 Summary

mps로 예측 생산한 재고 입고
재고 업데이트 시 상태도 업데이트
네이티브 쿼리에서 배치 저장으로 변경

🙏 Question & PR point

📬 Reference

Summary by CodeRabbit

  • 새로운 기능

    • MPS 완료 이벤트 수신 시 재고 수량을 자동 반영하도록 추가
    • 재고 상태를 안전재고·최대재고 기준으로 자동 갱신하도록 추가
    • MPS 상태 변경 이벤트 수신 지원(현재 별도 동작 없음)
  • 리팩터

    • 재고 반영 로직을 단순화하여 항목 단위로 즉시 수량을 갱신하고 변경 내역을 로깅하도록 변경
    • 안전재고 미설정 시 오류 로깅 후 처리 중단 추가

mps로 예측 생산한 재고 입고
재고 업데이트 시 상태도 업데이트
네이티브 쿼리에서 배치 저장으로 변경
@coderabbitai
Copy link

coderabbitai bot commented Nov 11, 2025

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 55e374a and dad2cb9.

📒 Files selected for processing (1)
  • src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (3 hunks)

Walkthrough

EventPayloadMapper에 MpsStatusChanged 및 MpsCompleted 매핑을 추가했고, Inventory 엔티티에 재고 갱신 및 상태 계산 메서드를 도입했으며 InventoryService에 MPS 인바운드 처리(inboundFromMps)를 추가하고 PurchaseEventConsumer에서 이를 호출하도록 통합했습니다.

Changes

코호트 / 파일(들) 변경 요약
EventPayloadMapper 이벤트 등록
src/main/java/com/sampoom/backend/api/event/service/EventPayloadMapper.java
"MpsStatusChanged""MpsCompleted" 이벤트 타입을 POEventPayload.class로 매핑 등록 추가
Inventory 엔티티 기능 확장
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java
public void updateStock(Integer dq) 추가 — 수량 증감 적용 및 updateQuantityStatus() 호출; public void updateQuantityStatus() 추가 — maxStock/safetyStock 기준으로 quantityStatus 갱신 로직 및 @Slf4j 로깅 추가
InventoryService 이벤트 처리 및 재고 적용 변경
src/main/java/com/sampoom/backend/api/inventory/service/InventoryService.java
@Slf4j 추가, public void inboundFromMps(POEventPayload payload) 공개 메서드 추가(파트별 인벤토리 조회 후 updateStock 적용), updateParts()에서 네이티브 SQL 일괄 업데이트 제거 및 인메모리 inventory.updateStock(...) 호출로 변경
PurchaseEventConsumer 이벤트 라우팅 통합
src/main/java/com/sampoom/backend/api/order/event/PurchaseEventConsumer.java
InventoryService 의존성 추가(생성자 주입), 이벤트 핸들링에 MpsCompleted 케이스 추가하여 inventoryService.inboundFromMps(payload) 호출, MpsStatusChanged 케이스 추가(현재 no-op)

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: 응답(처리 완료)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • 주의할 점:
    • Inventory.updateQuantityStatus()의 임계값/경계 조건과 null 안전성
    • inboundFromMps()의 빈/잘못된 페이로드 처리 및 영속성(저장/flush) 경로
    • updateParts()에서 네이티브 SQL 제거로 인한 트랜잭션·퍼시스턴스 컨텍스트 영향

Possibly related PRs

  • #44 — EventPayloadMapper에 PO 이벤트 매핑 추가 및 PurchaseEventConsumer/InventoryService 연동 변경과 직접 연결됨.
  • #15 — InventoryService.updateParts 관련 변경(네이티브 SQL → 인메모리 updateStock)과 코드 수준 연관이 큼.
  • #34 — InventoryService의 인벤토리 업데이트 흐름(메모리 기반 처리 및 인바운드 로직)과 변경 사항이 겹침.

Suggested labels

ready-to-merge

Suggested reviewers

  • Lee-Jong-Jin
  • Sangyoon98
  • CHOOSLA
  • taemin3
  • yangjiseonn

Poem

🐇 숲속 코드에 당근 한 톨 들고
델타를 톡, 수량이 춤추네
상태가 반짝, 로그가 웃고
토끼는 깡충, 배포는 쾌청하네 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 MPS 예측 재고 입고 기능을 명확하게 설명하며, 변경 사항의 핵심 내용과 직접적으로 관련이 있습니다.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@Lee-Jong-Jin Lee-Jong-Jin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

승읜

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2f25430 and defb2bc.

📒 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 목적과 일치합니다.

Admin added 2 commits November 11, 2025 10:44
음수 델타 검증
이벤트 기반이라 에러 시 로그 남김.
추후 공장에게 알려야 하나?
부등호 ..
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 54909f8 and 9dcfe9a.

📒 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)

계산 타입 맞춤
에러 처리
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
src/main/java/com/sampoom/backend/api/inventory/entity/Inventory.java (2)

53-56: null 검사 및 음수 재고 방지 검증을 추가하세요.

다음과 같은 문제가 있습니다:

  • dqInteger 래퍼 타입이므로 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: part null 검사와 지연 로딩 예외 처리를 추가하세요.

다음과 같은 문제가 있습니다:

  • 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9dcfe9a and 55e374a.

📒 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

업데이트 조건 단순화
@vivivim vivivim merged commit ba29e50 into main Nov 11, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants