装柜修改
This commit is contained in:
+6
-4
@@ -108,13 +108,15 @@ public class PalletLocationAllocationService {
|
||||
if (active.size() != split.palletCount()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "活动预占数量与托盘拆分数量不一致");
|
||||
}
|
||||
if (active.size() > request.packageCount()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘数量超过入库单总箱数,无法为每个托盘分配至少一箱");
|
||||
}
|
||||
active.sort(Comparator.comparingLong(LocationDtos.ActiveResource::reservationId));
|
||||
List<LocationDtos.OccupancyTarget> targets = new ArrayList<>(active.size());
|
||||
int perAllocation = (int) Math.ceil((double) request.packageCount() / active.size());
|
||||
int remainingPackages = request.packageCount();
|
||||
int basePackageCount = request.packageCount() / active.size();
|
||||
int remainder = request.packageCount() % active.size();
|
||||
for (int index = 0; index < active.size(); index++) {
|
||||
int allocatedPackages = Math.min(perAllocation, remainingPackages);
|
||||
remainingPackages -= allocatedPackages;
|
||||
int allocatedPackages = basePackageCount + (index < remainder ? 1 : 0);
|
||||
targets.add(new LocationDtos.OccupancyTarget(active.get(index).reservationId(),
|
||||
split.allocations().get(index).allocatedVolumeCbm(), allocatedPackages));
|
||||
}
|
||||
|
||||
+44
@@ -21,6 +21,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -140,6 +141,49 @@ class PalletLocationAllocationServiceTest {
|
||||
.isEqualTo(20);
|
||||
}
|
||||
|
||||
@Test
|
||||
void confirmDistributesRemainderWithoutZeroPackageAllocations() {
|
||||
List<LocationDtos.ActiveResource> resources = new ArrayList<>();
|
||||
List<LocationDtos.OccupancyResult> occupancyResults = new ArrayList<>();
|
||||
for (int index = 1; index <= 10; index++) {
|
||||
long reservationId = 100L + index;
|
||||
long palletId = 200L + index;
|
||||
long locationId = 300L + index;
|
||||
resources.add(new LocationDtos.ActiveResource(reservationId, null, 20L, palletId,
|
||||
"TP-" + index, locationId, "A-" + index, false, "RESERVED"));
|
||||
occupancyResults.add(new LocationDtos.OccupancyResult(400L + index, "OC-" + index,
|
||||
reservationId, palletId, locationId, "A-" + index, false));
|
||||
when(pallets.transitionStatus(10001L, 20L, palletId, List.of("RESERVED"), "OCCUPIED"))
|
||||
.thenReturn(1);
|
||||
}
|
||||
when(locations.findActiveResources(10001L, "FIRSTLEG", 89L)).thenReturn(resources);
|
||||
when(locations.confirmOccupied(any())).thenReturn(occupancyResults);
|
||||
|
||||
service.confirm(new PalletAllocationDtos.ConfirmRequest(10001L, 20L, "FIRSTLEG", 89L,
|
||||
9001L, new BigDecimal("12.0"), new BigDecimal("1.2"), 12));
|
||||
|
||||
org.mockito.ArgumentCaptor<LocationDtos.ConfirmCommand> command =
|
||||
org.mockito.ArgumentCaptor.forClass(LocationDtos.ConfirmCommand.class);
|
||||
verify(locations).confirmOccupied(command.capture());
|
||||
assertThat(command.getValue().targets())
|
||||
.extracting(LocationDtos.OccupancyTarget::allocatedPackageCount)
|
||||
.containsExactly(2, 2, 1, 1, 1, 1, 1, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void confirmRejectsMorePalletsThanPackages() {
|
||||
List<LocationDtos.ActiveResource> resources = List.of(
|
||||
new LocationDtos.ActiveResource(101L, null, 20L, 30L, "TP-001", 40L, "A-01", false, "RESERVED"),
|
||||
new LocationDtos.ActiveResource(102L, null, 20L, 31L, "TP-002", 41L, "A-02", false, "RESERVED"));
|
||||
when(locations.findActiveResources(10001L, "FIRSTLEG", 90L)).thenReturn(resources);
|
||||
|
||||
assertThatThrownBy(() -> service.confirm(new PalletAllocationDtos.ConfirmRequest(10001L, 20L,
|
||||
"FIRSTLEG", 90L, 9001L, new BigDecimal("2.0"), new BigDecimal("1.0"), 1)))
|
||||
.isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("托盘数量超过入库单总箱数");
|
||||
verify(locations, never()).confirmOccupied(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReleaseOnlyPalletsReturnedBySelectedLocationRelease() {
|
||||
var resource = new LocationDtos.ExactSelectiveReleaseResult(
|
||||
|
||||
Reference in New Issue
Block a user