fix: improve shadow diagnostic matching
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.algorithm.shadow;
|
||||
|
||||
public class ShadowInboundReference {
|
||||
private String requestId;
|
||||
private String warehouseId;
|
||||
private String trayNo;
|
||||
private String projectNo;
|
||||
private String productId;
|
||||
@@ -15,6 +16,14 @@ public class ShadowInboundReference {
|
||||
this.requestId = requestId;
|
||||
}
|
||||
|
||||
public String getWarehouseId() {
|
||||
return warehouseId;
|
||||
}
|
||||
|
||||
public void setWarehouseId(String warehouseId) {
|
||||
this.warehouseId = warehouseId;
|
||||
}
|
||||
|
||||
public String getTrayNo() {
|
||||
return trayNo;
|
||||
}
|
||||
|
||||
@@ -41,28 +41,30 @@ public class ShadowPlanningEngine {
|
||||
public OutboundShadowObservation planProjectOutbound(String stockoutDetailId) {
|
||||
return transactions.execute(status -> {
|
||||
ShadowStockReference reference = inputMapper.selectProjectOutboundReference(stockoutDetailId);
|
||||
String warehouseId = warehouseId();
|
||||
String warehouseId = warehouseId(reference == null ? null : reference.getWarehouseId());
|
||||
if (reference == null || isBlank(reference.getProjectNo())) {
|
||||
return OutboundShadowObservation.unavailable(warehouseId, stockoutDetailId,
|
||||
"SKIPPED_MISSING_PROJECT", "No project number was available for shadow planning");
|
||||
}
|
||||
OutboundRequest request = new OutboundRequest(stockoutDetailId, null,
|
||||
reference.getProjectNo(), reference.getProductId(), null, null, null, true);
|
||||
return toOutboundObservation(warehouseId, reference, schedulingFacade.planOutbound(warehouseId, request));
|
||||
return toOutboundObservation(warehouseId, reference.getRequestId(), reference,
|
||||
schedulingFacade.planOutbound(warehouseId, request));
|
||||
});
|
||||
}
|
||||
|
||||
public OutboundShadowObservation planExactStockOutbound(String stockoutDetailId, String stockId) {
|
||||
return transactions.execute(status -> {
|
||||
ShadowStockReference reference = inputMapper.selectStockReference(stockId);
|
||||
String warehouseId = warehouseId();
|
||||
String warehouseId = warehouseId(reference == null ? null : reference.getWarehouseId());
|
||||
if (reference == null || isBlank(reference.getTrayNo())) {
|
||||
return OutboundShadowObservation.unavailable(warehouseId, stockoutDetailId,
|
||||
"SKIPPED_MISSING_STOCK", "Selected stock was unavailable to shadow planning");
|
||||
}
|
||||
OutboundRequest request = new OutboundRequest(stockoutDetailId, reference.getTrayNo(),
|
||||
reference.getProjectNo(), reference.getProductId(), null, null, null, true);
|
||||
return toOutboundObservation(warehouseId, reference, schedulingFacade.planOutbound(warehouseId, request));
|
||||
return toOutboundObservation(warehouseId, stockoutDetailId, reference,
|
||||
schedulingFacade.planOutbound(warehouseId, request));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -73,6 +75,7 @@ public class ShadowPlanningEngine {
|
||||
comparisonCode(observation.proposedSpaceId(), legacySpaceId),
|
||||
"request=" + observation.requestId() + "; shadow=" + observation.resultCode()
|
||||
+ "; proposedSpace=" + nullSafe(observation.proposedSpaceId())
|
||||
+ "; shadowReason=" + nullSafe(observation.reason())
|
||||
+ "; legacy=" + nullSafe(legacyResultCode)
|
||||
+ "; legacySpace=" + nullSafe(legacySpaceId)));
|
||||
}
|
||||
@@ -84,12 +87,13 @@ public class ShadowPlanningEngine {
|
||||
"request=" + observation.requestId() + "; shadow=" + observation.resultCode()
|
||||
+ "; proposedStock=" + nullSafe(observation.proposedStockId())
|
||||
+ "; proposedSpace=" + nullSafe(observation.proposedSpaceId())
|
||||
+ "; shadowReason=" + nullSafe(observation.reason())
|
||||
+ "; legacy=" + nullSafe(legacyResultCode)));
|
||||
}
|
||||
|
||||
private InboundShadowObservation planInboundInsideTransaction(String taskNo, String trayNo) {
|
||||
String warehouseId = warehouseId();
|
||||
ShadowInboundReference reference = inputMapper.selectInboundInput(taskNo, trayNo);
|
||||
String warehouseId = warehouseId(reference == null ? null : reference.getWarehouseId());
|
||||
if (reference == null || isBlank(reference.getRequestId()) || isBlank(reference.getTrayNo())) {
|
||||
return InboundShadowObservation.unavailable(warehouseId, taskNo,
|
||||
"SKIPPED_MISSING_INPUT", "Inbound task details were unavailable to shadow planning");
|
||||
@@ -102,38 +106,90 @@ public class ShadowPlanningEngine {
|
||||
if (plan.assignment().isPresent()) {
|
||||
var assignment = plan.assignment().orElseThrow();
|
||||
return new InboundShadowObservation(true, warehouseId, reference.getRequestId(),
|
||||
"READY", assignment.spaceId(), assignment.reason());
|
||||
"READY", assignment.spaceId(), inboundDiagnostic(taskNo, trayNo, reference, assignment.reason()));
|
||||
}
|
||||
var rejection = plan.rejection().orElseThrow();
|
||||
return InboundShadowObservation.unavailable(warehouseId, reference.getRequestId(),
|
||||
"REJECTED_" + rejection.code().name(), rejection.reason());
|
||||
"REJECTED_" + rejection.code().name(),
|
||||
inboundDiagnostic(taskNo, trayNo, reference, rejection.reason()));
|
||||
}
|
||||
|
||||
private OutboundShadowObservation toOutboundObservation(String warehouseId,
|
||||
private OutboundShadowObservation toOutboundObservation(String warehouseId, String requestId,
|
||||
ShadowStockReference reference, OutboundPlan plan) {
|
||||
String requestId = reference.getRequestId();
|
||||
if (isBlank(requestId)) {
|
||||
requestId = plan.assignment().map(assignment -> assignment.requestId()).orElse(null);
|
||||
}
|
||||
if (plan.assignment().isPresent()) {
|
||||
var assignment = plan.assignment().orElseThrow();
|
||||
return new OutboundShadowObservation(true, warehouseId, requestId, "READY",
|
||||
reference.getStockId(), assignment.sourceSpaceId(), assignment.reason());
|
||||
reference.getStockId(), assignment.sourceSpaceId(),
|
||||
outboundDiagnostic(requestId, reference, assignment.reason()));
|
||||
}
|
||||
if (plan.waiting().isPresent()) {
|
||||
var waiting = plan.waiting().orElseThrow();
|
||||
return OutboundShadowObservation.unavailable(warehouseId, requestId,
|
||||
"WAITING_" + waiting.code().name(), waiting.reason());
|
||||
"WAITING_" + waiting.code().name(), outboundDiagnostic(requestId, reference, waiting.reason()));
|
||||
}
|
||||
var error = plan.error().orElseThrow();
|
||||
return OutboundShadowObservation.unavailable(warehouseId, requestId,
|
||||
"ERROR_" + error.code().name(), error.message());
|
||||
"ERROR_" + error.code().name(), outboundDiagnostic(requestId, reference, error.message()));
|
||||
}
|
||||
|
||||
private String warehouseId() {
|
||||
return isBlank(properties.getWarehouseId())
|
||||
private String warehouseId(String preferredWarehouseId) {
|
||||
String configuredWarehouseId = isBlank(properties.getWarehouseId())
|
||||
? schedulingFacade.defaultWarehouseId()
|
||||
: properties.getWarehouseId();
|
||||
if (!isBlank(preferredWarehouseId)) {
|
||||
String normalizedPreferred = preferredWarehouseId.trim();
|
||||
if (sameNumericWarehouse(normalizedPreferred, configuredWarehouseId)) {
|
||||
return configuredWarehouseId;
|
||||
}
|
||||
return normalizedPreferred;
|
||||
}
|
||||
return configuredWarehouseId;
|
||||
}
|
||||
|
||||
private boolean sameNumericWarehouse(String first, String second) {
|
||||
if (isBlank(first) || isBlank(second)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(first) == Integer.parseInt(second);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String outboundDiagnostic(String requestId, ShadowStockReference reference, String resultReason) {
|
||||
return "detail=" + nullSafe(requestId)
|
||||
+ "; project=" + nullSafe(reference.getProjectNo())
|
||||
+ "; product=" + nullSafe(reference.getProductId())
|
||||
+ "; tray=" + nullSafe(reference.getTrayNo())
|
||||
+ "; stock=" + nullSafe(reference.getStockId())
|
||||
+ "; snapshotSync=" + nullSafe(reference.getSnapshotSynchronizedAt())
|
||||
+ "; legacyMatches=" + numberOrUnknown(reference.getLiveMatchCount())
|
||||
+ "; shadowMatches=" + numberOrUnknown(reference.getShadowMatchCount())
|
||||
+ "; reason=" + abbreviate(nullSafe(resultReason), 600);
|
||||
}
|
||||
|
||||
private String inboundDiagnostic(String taskNo, String trayNo, ShadowInboundReference reference,
|
||||
String resultReason) {
|
||||
return "task=" + nullSafe(taskNo)
|
||||
+ "; tray=" + nullSafe(trayNo)
|
||||
+ "; request=" + nullSafe(reference.getRequestId())
|
||||
+ "; warehouse=" + nullSafe(reference.getWarehouseId())
|
||||
+ "; project=" + nullSafe(reference.getProjectNo())
|
||||
+ "; product=" + nullSafe(reference.getProductId())
|
||||
+ "; lot=" + nullSafe(reference.getLotNo())
|
||||
+ "; reason=" + abbreviate(nullSafe(resultReason), 600);
|
||||
}
|
||||
|
||||
private String numberOrUnknown(Integer value) {
|
||||
return value == null ? "" : value.toString();
|
||||
}
|
||||
|
||||
private String abbreviate(String value, int maxLength) {
|
||||
return value.length() <= maxLength ? value : value.substring(0, maxLength);
|
||||
}
|
||||
|
||||
private String comparisonCode(String shadowSpaceId, String legacySpaceId) {
|
||||
|
||||
@@ -8,6 +8,9 @@ public class ShadowStockReference {
|
||||
private String warehouseId;
|
||||
private String projectNo;
|
||||
private String productId;
|
||||
private String snapshotSynchronizedAt;
|
||||
private Integer liveMatchCount;
|
||||
private Integer shadowMatchCount;
|
||||
|
||||
public String getRequestId() {
|
||||
return requestId;
|
||||
@@ -64,4 +67,28 @@ public class ShadowStockReference {
|
||||
public void setProductId(String productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public String getSnapshotSynchronizedAt() {
|
||||
return snapshotSynchronizedAt;
|
||||
}
|
||||
|
||||
public void setSnapshotSynchronizedAt(String snapshotSynchronizedAt) {
|
||||
this.snapshotSynchronizedAt = snapshotSynchronizedAt;
|
||||
}
|
||||
|
||||
public Integer getLiveMatchCount() {
|
||||
return liveMatchCount;
|
||||
}
|
||||
|
||||
public void setLiveMatchCount(Integer liveMatchCount) {
|
||||
this.liveMatchCount = liveMatchCount;
|
||||
}
|
||||
|
||||
public Integer getShadowMatchCount() {
|
||||
return shadowMatchCount;
|
||||
}
|
||||
|
||||
public void setShadowMatchCount(Integer shadowMatchCount) {
|
||||
this.shadowMatchCount = shadowMatchCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user