优化
This commit is contained in:
+9
@@ -6,6 +6,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ReceivingContainerSessionMapper extends BaseMapper<ReceivingContainerSession> {
|
||||
@Select("SELECT * FROM ll_receiving_container_session " +
|
||||
@@ -16,6 +18,13 @@ public interface ReceivingContainerSessionMapper extends BaseMapper<ReceivingCon
|
||||
"WHERE active_operator_key=#{activeOperatorKey} LIMIT 1")
|
||||
ReceivingContainerSession findActiveByOperator(@Param("activeOperatorKey") String activeOperatorKey);
|
||||
|
||||
@Select("SELECT * FROM ll_receiving_container_session " +
|
||||
"WHERE active_container_key=#{activeContainerKey} LIMIT 1")
|
||||
ReceivingContainerSession findActiveByContainer(@Param("activeContainerKey") String activeContainerKey);
|
||||
|
||||
@Select("SELECT * FROM ll_receiving_container_session WHERE active_container_key IS NOT NULL")
|
||||
List<ReceivingContainerSession> findActiveContainers();
|
||||
|
||||
@Select("SELECT * FROM ll_receiving_container_session " +
|
||||
"WHERE active_container_key=#{activeContainerKey} LIMIT 1 FOR UPDATE")
|
||||
ReceivingContainerSession lockActiveByContainer(@Param("activeContainerKey") String activeContainerKey);
|
||||
|
||||
+13
-2
@@ -194,11 +194,22 @@ public class InboundStockReceiptService {
|
||||
}
|
||||
if (destinationCode == null) destinationCode = "";
|
||||
String operationKey = "PDA_STOCK_IN:" + task.getId() + ":" + allocation.getId() + ":" + sku.skuCode();
|
||||
String customerName = required(order.getCustomerName(),
|
||||
"Customer name snapshot is required for stock-in");
|
||||
String overseasWarehouseId = required(order.getOverseasWarehouseId(),
|
||||
"Actual overseas warehouse is required for stock-in");
|
||||
String overseasWarehouseName = required(order.getOverseasWarehouseName(),
|
||||
"Actual overseas warehouse name is required for stock-in");
|
||||
if (plan.getOverseasWarehouseId() == null
|
||||
|| !overseasWarehouseId.equals(String.valueOf(plan.getOverseasWarehouseId()))) {
|
||||
throw conflict("Inbound plan and tail-leg order overseas warehouses must match for stock-in");
|
||||
}
|
||||
if (overseasWarehouseId.equals(trim(order.getSourceWarehouseId()))) {
|
||||
throw conflict("Actual overseas warehouse must not use the domestic source warehouse");
|
||||
}
|
||||
InventoryCommandResponse result = inventory.stockIn(customerId, task.getOperatorId(),
|
||||
new InventoryCommandRequests.StockIn(null, order.getCustomerName(), overseasWarehouseId,
|
||||
null, order.getOverseasWarehouseName(), line.getDestinationWarehouseId(), destinationCode,
|
||||
new InventoryCommandRequests.StockIn(null, customerName, overseasWarehouseId,
|
||||
null, overseasWarehouseName, line.getDestinationWarehouseId(), destinationCode,
|
||||
line.getDestinationWarehouseName(), order.getId(), plan.getPlanNo(), line.getInboundCode(),
|
||||
sku.skuCode(), sku.productNameZh(), sku.productNameEn(),
|
||||
pallet.getWarehousePalletId(), pallet.getPalletNo(), plan.getPlanNo(),
|
||||
|
||||
+12
-1
@@ -103,7 +103,14 @@ public class ReceivingContainerService {
|
||||
grouped.computeIfAbsent(plan.getContainerNo(), ignored -> new ArrayList<>()).add(plan);
|
||||
}
|
||||
});
|
||||
return grouped.entrySet().stream().filter(entry -> eligible(entry.getValue(), overseasWarehouseId)).map(entry -> {
|
||||
String operatorLockKey = activeOperatorKey(operatorKey);
|
||||
Set<String> reservedByOthers = sessions.findActiveContainers().stream()
|
||||
.filter(session -> !operatorLockKey.equals(session.getActiveOperatorKey()))
|
||||
.map(ReceivingContainerSession::getActiveContainerKey).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
return grouped.entrySet().stream()
|
||||
.filter(entry -> eligible(entry.getValue(), overseasWarehouseId))
|
||||
.filter(entry -> !reservedByOthers.contains(activeContainerKey(entry.getKey())))
|
||||
.map(entry -> {
|
||||
requireSingleCustomer(entry.getValue(), entry.getKey());
|
||||
Totals totals = totals(entry.getValue());
|
||||
boolean active = current != null && entry.getKey().equals(current.getContainerNo());
|
||||
@@ -123,6 +130,10 @@ public class ReceivingContainerService {
|
||||
if (current != null && !containerNo.equals(current.getContainerNo())) {
|
||||
throw conflict("Current account is locked to another selected container");
|
||||
}
|
||||
ReceivingContainerSession reserved = sessions.findActiveByContainer(activeContainerKey(containerNo));
|
||||
if (reserved != null && !activeOperatorKey(operatorKey).equals(reserved.getActiveOperatorKey())) {
|
||||
throw conflict("Container is already signed or prepared by another account");
|
||||
}
|
||||
WarehouseResourceGateway.WarehouseReference receivingWarehouse =
|
||||
warehouse.requireActiveSharedWarehouse(overseasWarehouseId);
|
||||
return snapshot(current != null && containerNo.equals(current.getContainerNo()) ? current : waitingView(
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ public final class InventoryCommandRequests {
|
||||
|
||||
public record StockIn(
|
||||
String customerId,
|
||||
String customerName,
|
||||
@NotBlank @Size(max = 255) String customerName,
|
||||
@NotBlank String overseasWarehouseId,
|
||||
String overseasWarehouseCode,
|
||||
String overseasWarehouseName,
|
||||
@@ -39,7 +39,7 @@ public final class InventoryCommandRequests {
|
||||
}
|
||||
|
||||
public record InTransit(
|
||||
String customerName,
|
||||
@NotBlank @Size(max = 255) String customerName,
|
||||
@NotBlank String overseasWarehouseId,
|
||||
String overseasWarehouseCode,
|
||||
String overseasWarehouseName,
|
||||
|
||||
+15
-1
@@ -232,6 +232,7 @@ public class InventoryCommandService {
|
||||
String destinationWarehouseName, Long inboundOrderId, String inboundOrderNo,
|
||||
String inboundCode, String requestedSkuCode, String productNameZh,
|
||||
String productNameEn) {
|
||||
String frozenCustomerName = required(customerName, "Customer name snapshot is required");
|
||||
String skuCode = sku(requestedSkuCode);
|
||||
String destinationId = trim(destinationWarehouseId);
|
||||
String destinationCode = trim(destinationWarehouseCode);
|
||||
@@ -242,13 +243,14 @@ public class InventoryCommandService {
|
||||
InventoryBalance balance = balances.lockDimension(customerId, overseasWarehouseId,
|
||||
destinationCode, inboundOrderId, inboundCode);
|
||||
if (balance != null) {
|
||||
requireCustomerSnapshot(balance, frozenCustomerName);
|
||||
mergeSkuSnapshot(balance, skuCode);
|
||||
return balance;
|
||||
}
|
||||
balance = new InventoryBalance();
|
||||
balance.setId(IdWorker.getId());
|
||||
balance.setCustomerId(customerId);
|
||||
balance.setCustomerName(trim(customerName));
|
||||
balance.setCustomerName(frozenCustomerName);
|
||||
balance.setOverseasWarehouseId(overseasWarehouseId.trim());
|
||||
balance.setOverseasWarehouseCode(trim(overseasWarehouseCode));
|
||||
balance.setOverseasWarehouseName(trim(overseasWarehouseName));
|
||||
@@ -272,6 +274,7 @@ public class InventoryCommandService {
|
||||
InventoryBalance concurrent = balances.lockDimension(customerId, overseasWarehouseId,
|
||||
destinationCode, inboundOrderId, inboundCode);
|
||||
if (concurrent != null) {
|
||||
requireCustomerSnapshot(concurrent, frozenCustomerName);
|
||||
mergeSkuSnapshot(concurrent, skuCode);
|
||||
return concurrent;
|
||||
}
|
||||
@@ -384,6 +387,7 @@ public class InventoryCommandService {
|
||||
InventoryLedger ledger = new InventoryLedger();
|
||||
ledger.setId(IdWorker.getId());
|
||||
ledger.setCustomerId(customerId);
|
||||
ledger.setCustomerName(balance.getCustomerName());
|
||||
ledger.setBalanceId(balance.getId());
|
||||
ledger.setPositionId(position == null ? null : position.getId());
|
||||
ledger.setOverseasWarehouseId(balance.getOverseasWarehouseId());
|
||||
@@ -515,6 +519,16 @@ public class InventoryCommandService {
|
||||
if (actual < requested) throw conflict("Insufficient " + field + " packages");
|
||||
}
|
||||
|
||||
private static void requireCustomerSnapshot(InventoryBalance balance, String requestedCustomerName) {
|
||||
String frozenCustomerName = trim(balance.getCustomerName());
|
||||
if (frozenCustomerName == null) {
|
||||
throw conflict("Inventory balance customer name snapshot is missing");
|
||||
}
|
||||
if (!frozenCustomerName.equals(requestedCustomerName)) {
|
||||
throw conflict("Inventory balance customer name snapshot does not match");
|
||||
}
|
||||
}
|
||||
|
||||
private static String required(String value, String message) {
|
||||
String normalized = trim(value);
|
||||
if (normalized == null) throw badRequest(message);
|
||||
|
||||
@@ -15,6 +15,7 @@ public class InventoryLedger {
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private String customerId;
|
||||
private String customerName;
|
||||
private Long balanceId;
|
||||
private Long positionId;
|
||||
private String overseasWarehouseId;
|
||||
|
||||
+1
@@ -5,6 +5,7 @@ import java.time.LocalDateTime;
|
||||
public record InventoryLedgerView(
|
||||
Long id,
|
||||
String customerId,
|
||||
String customerName,
|
||||
String overseasWarehouseId,
|
||||
String destinationWarehouseCode,
|
||||
Long inboundOrderId,
|
||||
|
||||
+3
-3
@@ -97,11 +97,11 @@ public class InventoryQueryService {
|
||||
public byte[] exportLedgers(String customerId, InventoryQueryRequests.LedgerQuery query) {
|
||||
validateDateRange(query);
|
||||
List<String> rows = new ArrayList<>();
|
||||
rows.add("occurredAt,customerId,overseasWarehouseId,destinationWarehouseCode,inboundOrderId,inboundOrderNo," +
|
||||
rows.add("occurredAt,customerId,customerName,overseasWarehouseId,destinationWarehouseCode,inboundOrderId,inboundOrderNo," +
|
||||
"inboundCode,businessType,businessOrderNo,outboundOrderNo,palletNo,batchNo,statusFrom,statusTo," +
|
||||
"beforePackages,deltaPackages,afterPackages,operatorId,remark");
|
||||
mapper.ledgers(customerId, query, 0, EXPORT_LIMIT).stream().map(this::ledgerView).forEach(v -> rows.add(
|
||||
String.join(",", csv(v.occurredAt()), csv(v.customerId()), csv(v.overseasWarehouseId()),
|
||||
String.join(",", csv(v.occurredAt()), csv(v.customerId()), csv(v.customerName()), csv(v.overseasWarehouseId()),
|
||||
csv(v.destinationWarehouseCode()), csv(v.inboundOrderId()), csv(v.inboundOrderNo()), csv(v.inboundCode()),
|
||||
csv(v.businessType()), csv(v.businessOrderNo()), csv(v.outboundOrderNo()), csv(v.palletNo()), csv(v.batchNo()),
|
||||
csv(v.statusFrom()), csv(v.statusTo()), csv(v.beforePackages()), csv(v.deltaPackages()),
|
||||
@@ -144,7 +144,7 @@ public class InventoryQueryService {
|
||||
}
|
||||
|
||||
private InventoryLedgerView ledgerView(InventoryLedger value) {
|
||||
return new InventoryLedgerView(value.getId(), value.getCustomerId(), value.getOverseasWarehouseId(),
|
||||
return new InventoryLedgerView(value.getId(), value.getCustomerId(), value.getCustomerName(), value.getOverseasWarehouseId(),
|
||||
value.getDestinationWarehouseCode(), value.getInboundOrderId(), value.getInboundOrderNo(), value.getInboundCode(),
|
||||
value.getPalletNo(), value.getBatchNo(),
|
||||
value.getWarehouseLocationCode(), value.getSkuCode(), value.getBusinessType(), value.getBusinessOrderNo(),
|
||||
|
||||
Reference in New Issue
Block a user