feat(fleet): bind quote versions and reconcile actual return quantities

This commit is contained in:
2026-10-03 13:32:55 +08:00
parent cb6c54ffe5
commit a6fd0ba3c5
60 changed files with 1363 additions and 75 deletions
@@ -0,0 +1,34 @@
package com.baiyue.lastleg.delivery.model;
import com.baiyue.lastleg.delivery.entity.DeliveryOrder;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
class DeliveryCargoQuantitiesTest {
private final LocalDateTime now = LocalDateTime.of(2026, 10, 3, 12, 0);
@Test void unsignedQuantityRemainsOpenUntilAllCargoHasActualTerminalFacts() {
var row = new DeliveryOrder(); row.setPackageCount(10);
assertThat(DeliveryCargoQuantities.from(row, List.of(receipt(1, 4, now))))
.isEqualTo(new DeliveryCargoQuantities(10, 0, 4, 6));
row.setSignedAt(now.plusMinutes(1)); row.setSignedPackages(6);
assertThat(DeliveryCargoQuantities.from(row, List.of(receipt(1, 4, now), receipt(2, 2, now.plusMinutes(2)))))
.isEqualTo(new DeliveryCargoQuantities(10, 6, 4, 0));
}
@Test void missingSignatureQuantityCannotDefaultToTheWholeShipment() {
var row = new DeliveryOrder(); row.setPackageCount(10); row.setSignedAt(now);
assertThatThrownBy(() -> DeliveryCargoQuantities.from(row, List.of())).hasMessageContaining("签收数量");
}
@Test void duplicatedSourcesOrOverReturnCannotCloseCargo() {
var row = new DeliveryOrder(); row.setPackageCount(10);
assertThatThrownBy(() -> DeliveryCargoQuantities.from(row, List.of(receipt(1, 4, now), receipt(1, 4, now))))
.hasMessageContaining("重复");
assertThatThrownBy(() -> DeliveryCargoQuantities.from(row, List.of(receipt(1, 11, now)))).hasMessageContaining("超过");
}
@Test void laterReturnCannotFillAnUnprovenGapInAnEarlierSignature() {
var row = new DeliveryOrder(); row.setPackageCount(10); row.setSignedAt(now); row.setSignedPackages(6);
assertThatThrownBy(() -> DeliveryCargoQuantities.from(row, List.of(receipt(1, 4, now.plusMinutes(1)))))
.hasMessageContaining("守恒");
}
private DeliveryReturnReceiptFact receipt(long id, long packages, LocalDateTime time) { return new DeliveryReturnReceiptFact(id, 2L, 3L, packages, time); }
}
@@ -13,7 +13,7 @@ class DeliveryStatusPolicyTest {
.containsExactly("REJECT_DELIVERY", "MARK_RETURN");
assertThat(DeliveryStatusPolicy.allowedActions("DELIVERED")).containsExactly("MARK_RETURN");
assertThat(DeliveryStatusPolicy.isEditableTarget("DELIVERED")).isFalse();
assertThat(DeliveryStatusPolicy.allowedActions("RETURN_PENDING")).isEmpty();
assertThat(DeliveryStatusPolicy.allowedActions("RETURN_PENDING")).containsExactly("MARK_RETURN");
assertThat(DeliveryStatusPolicy.allowedActions("CANCELLED")).isEmpty();
}