支持柜费按订单归属分摊

This commit is contained in:
2026-09-02 18:14:25 +08:00
parent 62855915fc
commit 596a5c925c
2 changed files with 12 additions and 5 deletions
@@ -88,9 +88,12 @@ public class ContainerFeeDetailService {
.reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
if (allocated.compareTo(total) != 0) throw conflict("柜级费用分摊合计必须等于费用总额");
Map<InboundAllocationKey, Long> ownership = new HashMap<>();
loading.items(loadingPlanId).forEach(value -> ownership.put(
new InboundAllocationKey(value.getOrderId(), text(value.getOrderNo()), value.getInboundId(),
text(value.getInboundCode())), value.getAccountId()));
Map<OrderAllocationKey, Long> orderOwnership = new HashMap<>();
loading.items(loadingPlanId).forEach(value -> {
ownership.put(new InboundAllocationKey(value.getOrderId(), text(value.getOrderNo()), value.getInboundId(),
text(value.getInboundCode())), value.getAccountId());
orderOwnership.put(new OrderAllocationKey(value.getOrderId(), text(value.getOrderNo())), value.getAccountId());
});
Set<InboundAllocationKey> unique = new HashSet<>();
long groupId = IdWorker.getId();
List<ContainerFeeDetailEntity> rows = new java.util.ArrayList<>();
@@ -101,7 +104,10 @@ public class ContainerFeeDetailService {
InboundAllocationKey key = new InboundAllocationKey(allocation.orderId(), allocation.orderNo().trim(),
allocation.inboundId(), inboundCode);
if (!unique.add(key)) throw conflict("同一业务归属不得重复分摊");
if (!allocation.customerId().equals(ownership.get(key)))
Long owner = allocation.inboundId() == null
? orderOwnership.get(new OrderAllocationKey(allocation.orderId(), allocation.orderNo().trim()))
: ownership.get(key);
if (!allocation.customerId().equals(owner))
throw conflict("分摊客户、订单及入仓信息与柜内真实归属不一致");
ContainerFeeDetailEntity value = new ContainerFeeDetailEntity();
value.setId(IdWorker.getId()); value.setTenantId(allocation.customerId());
@@ -371,4 +377,5 @@ public class ContainerFeeDetailService {
private static String text(String value) { return value == null || value.isBlank() ? null : value.trim(); }
private record InboundAllocationKey(Long orderId, String orderNo, Long inboundId, String inboundCode) { }
private record OrderAllocationKey(Long orderId, String orderNo) { }
}