优化
This commit is contained in:
@@ -104,7 +104,7 @@ public final class LocationDtos {
|
||||
public record OccupancyTarget(
|
||||
@Min(1) long reservationId,
|
||||
@NotNull @DecimalMin(value = "0", inclusive = false) BigDecimal allocatedVolumeCbm,
|
||||
@Min(1) Integer allocatedPackageCount
|
||||
@Min(0) Integer allocatedPackageCount
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -25,13 +25,19 @@ public final class PalletAllocationDtos {
|
||||
@NotBlank @Size(max = 128) String idempotencyKey,
|
||||
@Min(1) long operatorId,
|
||||
@NotNull @DecimalMin(value = "0", inclusive = false) @Digits(integer = 12, fraction = 6) BigDecimal totalVolumeCbm,
|
||||
@NotNull @DecimalMin(value = "0", inclusive = false) @Digits(integer = 12, fraction = 6) BigDecimal palletCapacityCbm,
|
||||
@Size(max = 32) String palletType,
|
||||
@NotNull @Size(min = 1, max = 200) List<@NotNull @jakarta.validation.Valid PalletReference> pallets,
|
||||
@NotNull LocalDateTime expiresAt,
|
||||
@NotNull Boolean measurementCompleted
|
||||
) {
|
||||
}
|
||||
|
||||
/** 一张已确认称重图片对应一托;同一托盘主数据允许重复引用。 */
|
||||
public record PalletReference(
|
||||
@Min(1) long weightResultId,
|
||||
@Min(1) long palletId
|
||||
) {
|
||||
}
|
||||
|
||||
public record ConfirmRequest(
|
||||
@Min(0) long tenantId,
|
||||
@Min(1) long warehouseId,
|
||||
@@ -39,7 +45,6 @@ public final class PalletAllocationDtos {
|
||||
@Min(1) long businessId,
|
||||
@Min(1) long operatorId,
|
||||
@NotNull @DecimalMin(value = "0", inclusive = false) @Digits(integer = 12, fraction = 6) BigDecimal totalVolumeCbm,
|
||||
@NotNull @DecimalMin(value = "0", inclusive = false) @Digits(integer = 12, fraction = 6) BigDecimal palletCapacityCbm,
|
||||
@Min(1) int packageCount
|
||||
) {
|
||||
}
|
||||
@@ -193,6 +198,7 @@ public final class PalletAllocationDtos {
|
||||
int allocationNo,
|
||||
long palletId,
|
||||
String palletCode,
|
||||
BigDecimal palletCapacityCbm,
|
||||
long locationId,
|
||||
String locationCode,
|
||||
BigDecimal allocatedVolumeCbm,
|
||||
|
||||
@@ -62,16 +62,6 @@ public class PalletRepository {
|
||||
.ne(excludedId != null, PalletEntity::getId, excludedId)) > 0;
|
||||
}
|
||||
|
||||
public List<PalletEntity> findReusable(long tenantId, long warehouseId, String palletType,
|
||||
java.math.BigDecimal capacityCbm) {
|
||||
return mapper.selectList(new LambdaQueryWrapper<PalletEntity>()
|
||||
.eq(PalletEntity::getTenantId, tenantId)
|
||||
.eq(PalletEntity::getWarehouseId, warehouseId)
|
||||
.eq(StringUtils.hasText(palletType), PalletEntity::getPalletType, palletType)
|
||||
.eq(capacityCbm != null, PalletEntity::getCapacityCbm, capacityCbm)
|
||||
.orderByAsc(PalletEntity::getPalletCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成平台作用域内下一个编码。编码序列跨仓库共用,且包含逻辑删除记录,确保编码永不复用。
|
||||
*/
|
||||
|
||||
+49
-41
@@ -32,8 +32,6 @@ import java.security.NoSuchAlgorithmException;
|
||||
*/
|
||||
@Service
|
||||
public class PalletLocationAllocationService {
|
||||
/** 测量完成后默认推荐的普通托盘类型编码。 */
|
||||
public static final String DEFAULT_PALLET_TYPE = "STANDARD";
|
||||
/** 仓库、托盘和库位属于平台公共资源域。 */
|
||||
private static final long PLATFORM_RESOURCE_TENANT_ID = 0L;
|
||||
/** 仅头程服务可结算头程入库单占用的仓储资源。 */
|
||||
@@ -41,8 +39,6 @@ public class PalletLocationAllocationService {
|
||||
@Resource
|
||||
private PalletRepository palletRepository;
|
||||
@Resource
|
||||
private PalletVolumeSplitter splitter;
|
||||
@Resource
|
||||
private LocationResourceService locationResourceService;
|
||||
@Resource
|
||||
private PalletLocationTransferOperationRepository transferOperations;
|
||||
@@ -59,74 +55,78 @@ public class PalletLocationAllocationService {
|
||||
if (!Boolean.TRUE.equals(request.measurementCompleted())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "只能使用已完成测量的总体积拆分托盘并占用库位");
|
||||
}
|
||||
var split = splitter.split(request.totalVolumeCbm(), request.palletCapacityCbm());
|
||||
List<LocationDtos.ActiveResource> existing = active(request.tenantId(), request.sourceService(), request.businessId());
|
||||
if (!existing.isEmpty()) {
|
||||
return fromActive(existing, split);
|
||||
return fromActive(request.tenantId(), request.warehouseId(), existing, request.totalVolumeCbm());
|
||||
}
|
||||
|
||||
String palletType = org.springframework.util.StringUtils.hasText(request.palletType())
|
||||
? request.palletType() : DEFAULT_PALLET_TYPE;
|
||||
List<PalletEntity> pallets = palletRepository.findReusable(request.tenantId(), request.warehouseId(),
|
||||
palletType, request.palletCapacityCbm());
|
||||
if (pallets.isEmpty()) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "未配置匹配类型和容量的托盘主数据");
|
||||
List<PalletEntity> pallets = new ArrayList<>(request.pallets().size());
|
||||
for (PalletAllocationDtos.PalletReference reference : request.pallets()) {
|
||||
PalletEntity pallet = palletRepository.findOwned(request.tenantId(), request.warehouseId(), reference.palletId());
|
||||
if (pallet == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "称重图片关联的托盘主数据不存在或不属于当前仓库");
|
||||
}
|
||||
pallets.add(pallet);
|
||||
}
|
||||
|
||||
List<LocationDtos.ReservationTarget> targets = new ArrayList<>(split.palletCount());
|
||||
for (int index = 0; index < split.palletCount(); index++) {
|
||||
PalletEntity pallet = pallets.get(index % pallets.size());
|
||||
List<LocationDtos.ReservationTarget> targets = new ArrayList<>(pallets.size());
|
||||
for (int index = 0; index < pallets.size(); index++) {
|
||||
PalletEntity pallet = pallets.get(index);
|
||||
targets.add(new LocationDtos.ReservationTarget(pallet.getId(), pallet.getPalletCode(),
|
||||
request.idempotencyKey() + ":" + (index + 1)));
|
||||
request.idempotencyKey() + ":" + request.pallets().get(index).weightResultId()));
|
||||
}
|
||||
|
||||
List<LocationDtos.ReservationResult> reservations = locationResourceService.reserveAvailable(
|
||||
new LocationDtos.ReserveCommand(request.tenantId(), request.warehouseId(), request.sourceService(),
|
||||
request.businessId(), request.inboundCode(), request.operatorId(), request.expiresAt(), targets));
|
||||
if (reservations.size() != split.palletCount()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "库位预占结果数量不一致");
|
||||
if (reservations.size() != pallets.size()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "库位预占结果数量与已确认称重图片数量不一致");
|
||||
}
|
||||
List<PalletAllocationDtos.AllocationResult> results = new ArrayList<>(reservations.size());
|
||||
for (int index = 0; index < reservations.size(); index++) {
|
||||
var item = reservations.get(index);
|
||||
results.add(new PalletAllocationDtos.AllocationResult(item.reservationId(), item.reservationNo(), index + 1,
|
||||
item.palletId(), item.palletCode(), item.locationId(), item.locationCode(),
|
||||
split.allocations().get(index).allocatedVolumeCbm(), "RESERVED"));
|
||||
item.palletId(), item.palletCode(), pallets.get(index).getCapacityCbm(),
|
||||
item.locationId(), item.locationCode(), allocatedVolume(request.totalVolumeCbm(), reservations.size(), index),
|
||||
"RESERVED"));
|
||||
}
|
||||
return new PalletAllocationDtos.BatchResult(split.palletCount(), List.copyOf(results));
|
||||
return new PalletAllocationDtos.BatchResult(results.size(), List.copyOf(results));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@BusinessAudit(event = "PALLET_LOCATION_CONFIRM", resourceType = "INBOUND", resourceId = "#request.businessId", description = "确认库位占用")
|
||||
public PalletAllocationDtos.BatchResult confirm(PalletAllocationDtos.ConfirmRequest request) {
|
||||
var split = splitter.split(request.totalVolumeCbm(), request.palletCapacityCbm());
|
||||
List<LocationDtos.ActiveResource> active = active(request.tenantId(), request.sourceService(), request.businessId());
|
||||
if (active.size() != split.palletCount()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "活动预占数量与托盘拆分数量不一致");
|
||||
}
|
||||
if (active.size() > request.packageCount()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "托盘数量超过入库单总箱数,无法为每个托盘分配至少一箱");
|
||||
if (active.isEmpty()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "入库单没有可确认的活动库位预占");
|
||||
}
|
||||
active.sort(Comparator.comparingLong(LocationDtos.ActiveResource::reservationId));
|
||||
List<LocationDtos.OccupancyTarget> targets = new ArrayList<>(active.size());
|
||||
int basePackageCount = request.packageCount() / active.size();
|
||||
int remainder = request.packageCount() % active.size();
|
||||
int packageRemainder = request.packageCount() % active.size();
|
||||
for (int index = 0; index < active.size(); index++) {
|
||||
int allocatedPackages = basePackageCount + (index < remainder ? 1 : 0);
|
||||
targets.add(new LocationDtos.OccupancyTarget(active.get(index).reservationId(),
|
||||
split.allocations().get(index).allocatedVolumeCbm(), allocatedPackages));
|
||||
allocatedVolume(request.totalVolumeCbm(), active.size(), index),
|
||||
basePackageCount + (index < packageRemainder ? 1 : 0)));
|
||||
}
|
||||
List<LocationDtos.OccupancyResult> occupied = locationResourceService.confirmOccupied(
|
||||
new LocationDtos.ConfirmCommand(request.tenantId(), request.warehouseId(), request.sourceService(),
|
||||
request.businessId(), request.operatorId(), targets));
|
||||
if (occupied.size() != active.size()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "库位占用结果数量与已确认称重图片数量不一致");
|
||||
}
|
||||
List<PalletAllocationDtos.AllocationResult> results = new ArrayList<>(occupied.size());
|
||||
for (int index = 0; index < occupied.size(); index++) {
|
||||
var item = occupied.get(index);
|
||||
PalletEntity pallet = palletRepository.findOwnedIncludingDeleted(request.tenantId(), request.warehouseId(), item.palletId());
|
||||
if (pallet == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "库位占用引用的托盘主数据不存在");
|
||||
}
|
||||
results.add(new PalletAllocationDtos.AllocationResult(item.reservationId(), active.get(index).reservationNo(), index + 1,
|
||||
item.palletId(), active.get(index).palletCode(), item.locationId(), item.locationCode(),
|
||||
split.allocations().get(index).allocatedVolumeCbm(), "OCCUPIED"));
|
||||
item.palletId(), active.get(index).palletCode(), pallet.getCapacityCbm(), item.locationId(), item.locationCode(),
|
||||
allocatedVolume(request.totalVolumeCbm(), occupied.size(), index), "OCCUPIED"));
|
||||
}
|
||||
return new PalletAllocationDtos.BatchResult(split.palletCount(), List.copyOf(results));
|
||||
return new PalletAllocationDtos.BatchResult(results.size(), List.copyOf(results));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -528,19 +528,27 @@ public class PalletLocationAllocationService {
|
||||
return locationResourceService.findOccupiedResources(tenantId, sourceService, businessId);
|
||||
}
|
||||
|
||||
private static PalletAllocationDtos.BatchResult fromActive(List<LocationDtos.ActiveResource> active,
|
||||
PalletVolumeSplitter.SplitResult split) {
|
||||
if (active.size() != split.palletCount()) {
|
||||
throw new BizException(ResultCode.CONFLICT, "幂等请求与已有托盘拆分结果不一致");
|
||||
}
|
||||
private PalletAllocationDtos.BatchResult fromActive(long tenantId, long warehouseId,
|
||||
List<LocationDtos.ActiveResource> active,
|
||||
java.math.BigDecimal totalVolumeCbm) {
|
||||
active.sort(Comparator.comparingLong(LocationDtos.ActiveResource::reservationId));
|
||||
List<PalletAllocationDtos.AllocationResult> results = new ArrayList<>(active.size());
|
||||
for (int index = 0; index < active.size(); index++) {
|
||||
var item = active.get(index);
|
||||
PalletEntity pallet = palletRepository.findOwnedIncludingDeleted(
|
||||
tenantId, warehouseId, item.palletId());
|
||||
if (pallet == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "已有库位分配引用的托盘主数据不存在");
|
||||
}
|
||||
results.add(new PalletAllocationDtos.AllocationResult(item.reservationId(), item.reservationNo(), index + 1,
|
||||
item.palletId(), item.palletCode(), item.locationId(), item.locationCode(),
|
||||
split.allocations().get(index).allocatedVolumeCbm(), item.state()));
|
||||
item.palletId(), item.palletCode(), pallet.getCapacityCbm(), item.locationId(), item.locationCode(),
|
||||
allocatedVolume(totalVolumeCbm, active.size(), index), item.state()));
|
||||
}
|
||||
return new PalletAllocationDtos.BatchResult(split.palletCount(), List.copyOf(results));
|
||||
return new PalletAllocationDtos.BatchResult(results.size(), List.copyOf(results));
|
||||
}
|
||||
|
||||
private static java.math.BigDecimal allocatedVolume(java.math.BigDecimal total, int count, int index) {
|
||||
java.math.BigDecimal base = total.divide(java.math.BigDecimal.valueOf(count), 6, java.math.RoundingMode.DOWN);
|
||||
return index == count - 1 ? total.subtract(base.multiply(java.math.BigDecimal.valueOf(count - 1L))) : base;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.baiyue.warehouse.service;
|
||||
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** 按托盘容积向上拆分入库总体积,不涉及SKU库存。 */
|
||||
@Component
|
||||
public class PalletVolumeSplitter {
|
||||
static final int MAX_PALLET_COUNT = 200;
|
||||
|
||||
public SplitResult split(BigDecimal totalVolumeCbm, BigDecimal palletCapacityCbm) {
|
||||
requirePositive(totalVolumeCbm, "总体积必须大于0");
|
||||
requirePositive(palletCapacityCbm, "托盘容积必须大于0");
|
||||
final int palletCount;
|
||||
try {
|
||||
palletCount = totalVolumeCbm.divide(palletCapacityCbm, 0, RoundingMode.CEILING).intValueExact();
|
||||
} catch (ArithmeticException exception) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "托盘拆分数量超出系统处理范围");
|
||||
}
|
||||
if (palletCount > MAX_PALLET_COUNT) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "单次最多拆分200个托盘");
|
||||
}
|
||||
|
||||
List<Allocation> allocations = new ArrayList<>(palletCount);
|
||||
for (int index = 1; index <= palletCount; index++) {
|
||||
BigDecimal allocated = index == palletCount
|
||||
? totalVolumeCbm.subtract(palletCapacityCbm.multiply(BigDecimal.valueOf(palletCount - 1L)))
|
||||
: palletCapacityCbm;
|
||||
allocations.add(new Allocation(index, allocated));
|
||||
}
|
||||
return new SplitResult(totalVolumeCbm, palletCapacityCbm, palletCount, List.copyOf(allocations));
|
||||
}
|
||||
|
||||
private static void requirePositive(BigDecimal value, String message) {
|
||||
if (value == null || value.signum() <= 0) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, message);
|
||||
}
|
||||
}
|
||||
|
||||
public record Allocation(int allocationNo, BigDecimal allocatedVolumeCbm) {
|
||||
}
|
||||
|
||||
public record SplitResult(BigDecimal totalVolumeCbm, BigDecimal palletCapacityCbm,
|
||||
int palletCount, List<Allocation> allocations) {
|
||||
}
|
||||
}
|
||||
@@ -16,14 +16,56 @@ ON DUPLICATE KEY UPDATE
|
||||
color=VALUES(color),
|
||||
remark=VALUES(remark);
|
||||
|
||||
-- 每个国内作业仓初始化一个普通库位和一个系统共享溢出位 A0。
|
||||
-- 义乌仓初始化 A-F 六个库区,每区 A1-A15 共 90 个普通库位。
|
||||
-- A0 仍是系统共享溢出位;东莞仓继续保留最小 A1 + A0 基线。
|
||||
-- 这里只创建公共资源,不初始化预占、占用或业务单据。
|
||||
INSERT INTO wh_location(
|
||||
id,tenant_id,warehouse_id,zone_code,zone_name,location_code,location_name,
|
||||
location_type,max_weight_kg,shared_overflow,status,remark,created_by,updated_by
|
||||
)
|
||||
WITH RECURSIVE
|
||||
zones AS (
|
||||
SELECT 0 AS zone_index
|
||||
UNION ALL
|
||||
SELECT zone_index + 1 FROM zones WHERE zone_index < 5
|
||||
),
|
||||
slots AS (
|
||||
SELECT 1 AS slot_number
|
||||
UNION ALL
|
||||
SELECT slot_number + 1 FROM slots WHERE slot_number < 15
|
||||
)
|
||||
SELECT
|
||||
CAST(190000000000000000 + CASE
|
||||
WHEN zones.zone_index = 0 AND slots.slot_number = 1 THEN 201
|
||||
ELSE 203 + zones.zone_index * 15 + slots.slot_number
|
||||
END AS UNSIGNED),
|
||||
0,
|
||||
190000000000000001,
|
||||
CHAR(65 + zones.zone_index),
|
||||
CONCAT(CHAR(65 + zones.zone_index), '区'),
|
||||
CONCAT(CHAR(65 + zones.zone_index), slots.slot_number),
|
||||
CONCAT(CHAR(65 + zones.zone_index), slots.slot_number, ' 普通库位'),
|
||||
'PALLET',1000.000,0,'AVAILABLE',NULL,0,0
|
||||
FROM zones
|
||||
CROSS JOIN slots
|
||||
ON DUPLICATE KEY UPDATE
|
||||
tenant_id=0,
|
||||
warehouse_id=VALUES(warehouse_id),
|
||||
zone_code=VALUES(zone_code),
|
||||
zone_name=VALUES(zone_name),
|
||||
location_name=VALUES(location_name),
|
||||
location_type=VALUES(location_type),
|
||||
max_weight_kg=VALUES(max_weight_kg),
|
||||
shared_overflow=VALUES(shared_overflow),
|
||||
status='AVAILABLE',
|
||||
remark=VALUES(remark),
|
||||
deleted=0;
|
||||
|
||||
INSERT INTO wh_location(
|
||||
id,tenant_id,warehouse_id,zone_code,zone_name,location_code,location_name,
|
||||
location_type,max_weight_kg,shared_overflow,status,remark,created_by,updated_by
|
||||
)
|
||||
VALUES
|
||||
(190000000000000201,0,190000000000000001,'A','A区','A1','A1 普通库位','PALLET',1000.000,0,'AVAILABLE',NULL,0,0),
|
||||
(190000000000000202,0,190000000000000001,'A','A区','A0','A0 共享溢出位','PALLET',NULL,1,'AVAILABLE','系统共享临时溢出位',0,0),
|
||||
(190000000000000203,0,190000000000000002,'A','A区','A1','A1 普通库位','PALLET',1000.000,0,'AVAILABLE',NULL,0,0),
|
||||
(190000000000000204,0,190000000000000002,'A','A区','A0','A0 共享溢出位','PALLET',NULL,1,'AVAILABLE','系统共享临时溢出位',0,0)
|
||||
@@ -39,3 +81,32 @@ ON DUPLICATE KEY UPDATE
|
||||
status='AVAILABLE',
|
||||
remark=VALUES(remark),
|
||||
deleted=0;
|
||||
|
||||
DROP PROCEDURE IF EXISTS assert_yiwu_location_seed;
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE assert_yiwu_location_seed()
|
||||
BEGIN
|
||||
IF (SELECT COUNT(*)
|
||||
FROM wh_location
|
||||
WHERE tenant_id=0
|
||||
AND warehouse_id=190000000000000001
|
||||
AND deleted=0
|
||||
AND shared_overflow=0
|
||||
AND zone_code IN ('A','B','C','D','E','F')
|
||||
AND location_code REGEXP '^[A-F]([1-9]|1[0-5])$'
|
||||
AND LEFT(location_code,1)=zone_code) <> 90 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='义乌仓 A-F 每区 15 个普通库位初始化不完整';
|
||||
END IF;
|
||||
IF (SELECT COUNT(*)
|
||||
FROM wh_location
|
||||
WHERE tenant_id=0
|
||||
AND warehouse_id=190000000000000001
|
||||
AND location_code='A0'
|
||||
AND shared_overflow=1
|
||||
AND deleted=0) <> 1 THEN
|
||||
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT='义乌仓系统共享溢出位 A0 初始化不完整';
|
||||
END IF;
|
||||
END//
|
||||
DELIMITER ;
|
||||
CALL assert_yiwu_location_seed();
|
||||
DROP PROCEDURE IF EXISTS assert_yiwu_location_seed;
|
||||
|
||||
+3
-2
@@ -18,9 +18,10 @@ class PalletAllocationDtosValidationTest {
|
||||
LocalDateTime expiresAt = LocalDateTime.now().plusMinutes(30);
|
||||
|
||||
assertThat(validator.validate(new PalletAllocationDtos.ReserveRequest(0L, 20L, "FIRSTLEG", 88L,
|
||||
"RK-001", "measure-88", 9L, BigDecimal.ONE, BigDecimal.ONE, "STANDARD", expiresAt, true))).isEmpty();
|
||||
"RK-001", "measure-88", 9L, BigDecimal.ONE,
|
||||
List.of(new PalletAllocationDtos.PalletReference(7001L, 30L)), expiresAt, true))).isEmpty();
|
||||
assertThat(validator.validate(new PalletAllocationDtos.ConfirmRequest(0L, 20L, "FIRSTLEG", 88L,
|
||||
9L, BigDecimal.ONE, BigDecimal.ONE, 20))).isEmpty();
|
||||
9L, BigDecimal.ONE, 20))).isEmpty();
|
||||
assertThat(validator.validate(new PalletAllocationDtos.ReleaseRequest(0L, "FIRSTLEG", 88L, 9L,
|
||||
"入库补偿"))).isEmpty();
|
||||
assertThat(validator.validate(new PalletAllocationDtos.SelectiveReleaseRequest(0L, "FIRSTLEG", 88L,
|
||||
|
||||
+10
-2
@@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class InitialWarehouseResourceSeedSqlContractTest {
|
||||
@Test
|
||||
void initializesReusablePalletMasterDataAndAvailableLocationsForBothDomesticWarehouses() throws Exception {
|
||||
void initializesReusablePalletsAndYiwuLocationGrid() throws Exception {
|
||||
assertModuleSeed(Files.readString(Path.of("src", "main", "resources", "db", "phase2-pallet-seed.sql"),
|
||||
StandardCharsets.UTF_8));
|
||||
assertUnifiedSeed(Files.readString(Path.of("..", "deploy", "sql", "头程数据库统一增量-MySQL8.sql"),
|
||||
@@ -30,7 +30,15 @@ class InitialWarehouseResourceSeedSqlContractTest {
|
||||
assertThat(sql)
|
||||
.contains("0," + yiwuId + ",'TP-001'")
|
||||
.contains("0," + dongguanId + ",'TP-002'")
|
||||
.contains("(" + idPrefix + "201,0," + yiwuId + ",'A','A区','A1'")
|
||||
.contains("WHEN zones.zone_index = 0 AND slots.slot_number = 1 THEN 201")
|
||||
.contains("ELSE 203 + zones.zone_index * 15 + slots.slot_number")
|
||||
.contains("SELECT zone_index + 1 FROM zones WHERE zone_index < 5")
|
||||
.contains("SELECT slot_number + 1 FROM slots WHERE slot_number < 15")
|
||||
.contains("CONCAT(CHAR(65 + zones.zone_index), slots.slot_number)")
|
||||
.contains("CROSS JOIN slots")
|
||||
.contains("location_code REGEXP '^[A-F]([1-9]|1[0-5])$'")
|
||||
.contains("<> 90 THEN")
|
||||
.contains("义乌仓 A-F 每区 15 个普通库位初始化不完整")
|
||||
.contains("(" + idPrefix + "202,0," + yiwuId + ",'A','A区','A0'")
|
||||
.contains("(" + idPrefix + "203,0," + dongguanId + ",'A','A区','A1'")
|
||||
.contains("(" + idPrefix + "204,0," + dongguanId + ",'A','A区','A0'")
|
||||
|
||||
+27
-38
@@ -47,50 +47,48 @@ class PalletLocationAllocationServiceTest {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class TestConfig {
|
||||
@Bean PalletVolumeSplitter splitter() { return new PalletVolumeSplitter(); }
|
||||
@Bean ObjectMapper objectMapper() { return new ObjectMapper(); }
|
||||
}
|
||||
|
||||
@Test
|
||||
void reusesOnePalletMasterForMultipleAllocations() {
|
||||
void oneConfirmedWeightImageCreatesOneAllocationWithoutCapacityMatching() {
|
||||
when(locations.findActiveResources(10001, "FIRSTLEG", 88)).thenReturn(List.of());
|
||||
when(pallets.findReusable(10001, 20, "木托盘", new BigDecimal("2")))
|
||||
.thenReturn(List.of(pallet(30, "TP-001")));
|
||||
when(pallets.findOwned(10001, 20, 30)).thenReturn(pallet(30, "TP-001"));
|
||||
when(locations.reserveAvailable(any())).thenReturn(List.of(
|
||||
new LocationDtos.ReservationResult(101, "LR101", 30, "TP-001", 40, "A-01", false,
|
||||
LocalDateTime.now().plusMinutes(30)),
|
||||
new LocationDtos.ReservationResult(102, "LR102", 30, "TP-001", 41, "A-02", false,
|
||||
LocalDateTime.now().plusMinutes(30))));
|
||||
|
||||
var request = new PalletAllocationDtos.ReserveRequest(10001, 20, "FIRSTLEG", 88, "RK-001", "measure-001",
|
||||
9001, new BigDecimal("4"), new BigDecimal("2"), "木托盘", LocalDateTime.now().plusMinutes(30), true);
|
||||
assertThat(service.reserve(request).allocations()).hasSize(2)
|
||||
.extracting(PalletAllocationDtos.AllocationResult::palletId)
|
||||
.containsOnly(30L);
|
||||
9001, new BigDecimal("4"), List.of(new PalletAllocationDtos.PalletReference(7001, 30)),
|
||||
LocalDateTime.now().plusMinutes(30), true);
|
||||
assertThat(service.reserve(request).allocations()).singleElement().satisfies(item -> {
|
||||
assertThat(item.palletId()).isEqualTo(30L);
|
||||
assertThat(item.allocatedVolumeCbm()).isEqualByComparingTo("4");
|
||||
assertThat(item.palletCapacityCbm()).isEqualByComparingTo("1.2");
|
||||
});
|
||||
|
||||
org.mockito.ArgumentCaptor<LocationDtos.ReserveCommand> command =
|
||||
org.mockito.ArgumentCaptor.forClass(LocationDtos.ReserveCommand.class);
|
||||
verify(locations).reserveAvailable(command.capture());
|
||||
assertThat(command.getValue().targets()).hasSize(2)
|
||||
.extracting(LocationDtos.ReservationTarget::palletId)
|
||||
.containsOnly(30L);
|
||||
assertThat(command.getValue().targets()).singleElement()
|
||||
.extracting(LocationDtos.ReservationTarget::palletId).isEqualTo(30L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHandleCase02() {
|
||||
when(locations.findActiveResources(10001, "FIRSTLEG", 99)).thenReturn(List.of());
|
||||
when(pallets.findReusable(10001, 20, "STANDARD", new BigDecimal("2")))
|
||||
.thenReturn(List.of(pallet(30, "TP-001")));
|
||||
when(pallets.findOwned(10001, 20, 30)).thenReturn(pallet(30, "TP-001"));
|
||||
when(locations.reserveAvailable(any())).thenReturn(List.of(
|
||||
new LocationDtos.ReservationResult(101, "LR101", 30, "TP-001", 40, "A0", true,
|
||||
LocalDateTime.now().plusMinutes(30))));
|
||||
|
||||
var request = new PalletAllocationDtos.ReserveRequest(10001, 20, "FIRSTLEG", 99, "RK-001", "measure-99",
|
||||
9001, new BigDecimal("2"), new BigDecimal("2"), null, LocalDateTime.now().plusMinutes(30), true);
|
||||
9001, new BigDecimal("2"), List.of(new PalletAllocationDtos.PalletReference(7001, 30)),
|
||||
LocalDateTime.now().plusMinutes(30), true);
|
||||
var result = service.reserve(request);
|
||||
|
||||
assertThat(result.allocations().get(0).locationCode()).isEqualTo("A0");
|
||||
verify(pallets).findReusable(10001, 20, "STANDARD", new BigDecimal("2"));
|
||||
verify(pallets).findOwned(10001, 20, 30);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +127,7 @@ class PalletLocationAllocationServiceTest {
|
||||
|
||||
assertThat(result.palletCount()).isEqualTo(1);
|
||||
assertThat(result.allocations().get(0).state()).isEqualTo("RESERVED");
|
||||
verify(pallets, never()).findReusable(any(Long.class), any(Long.class), any(), any());
|
||||
verify(pallets, never()).findOwned(anyLong(), anyLong(), anyLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,9 +137,10 @@ class PalletLocationAllocationServiceTest {
|
||||
when(locations.findActiveResources(10001L, "FIRSTLEG", 88L)).thenReturn(List.of(resource));
|
||||
when(locations.confirmOccupied(any())).thenReturn(List.of(new LocationDtos.OccupancyResult(
|
||||
301L, "OC-301", 101L, 30L, 40L, "A-01", false)));
|
||||
when(pallets.findOwnedIncludingDeleted(10001L, 20L, 30L)).thenReturn(pallet(30L, "TP-001"));
|
||||
|
||||
service.confirm(new PalletAllocationDtos.ConfirmRequest(10001L, 20L, "FIRSTLEG", 88L,
|
||||
9001L, new BigDecimal("1.0"), new BigDecimal("2.0"), 20));
|
||||
9001L, new BigDecimal("1.0"), 20));
|
||||
|
||||
org.mockito.ArgumentCaptor<LocationDtos.ConfirmCommand> command =
|
||||
org.mockito.ArgumentCaptor.forClass(LocationDtos.ConfirmCommand.class);
|
||||
@@ -152,10 +151,10 @@ class PalletLocationAllocationServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void confirmDistributesRemainderWithoutZeroPackageAllocations() {
|
||||
void confirmedImageCountDefinesPalletCountEvenWhenItExceedsPackageCount() {
|
||||
List<LocationDtos.ActiveResource> resources = new ArrayList<>();
|
||||
List<LocationDtos.OccupancyResult> occupancyResults = new ArrayList<>();
|
||||
for (int index = 1; index <= 10; index++) {
|
||||
for (int index = 1; index <= 3; index++) {
|
||||
long reservationId = 100L + index;
|
||||
long palletId = 200L + index;
|
||||
long locationId = 300L + index;
|
||||
@@ -163,33 +162,21 @@ class PalletLocationAllocationServiceTest {
|
||||
"TP-" + index, locationId, "A-" + index, false, "RESERVED"));
|
||||
occupancyResults.add(new LocationDtos.OccupancyResult(400L + index, "OC-" + index,
|
||||
reservationId, palletId, locationId, "A-" + index, false));
|
||||
PalletEntity pallet = pallet(palletId, "TP-" + index);
|
||||
when(pallets.findOwnedIncludingDeleted(10001L, 20L, palletId)).thenReturn(pallet);
|
||||
}
|
||||
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));
|
||||
9001L, new BigDecimal("12.0"), 2));
|
||||
|
||||
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());
|
||||
.containsExactly(1, 1, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -490,13 +477,15 @@ class PalletLocationAllocationServiceTest {
|
||||
|
||||
private static PalletAllocationDtos.ReserveRequest reserve(long businessId) {
|
||||
return new PalletAllocationDtos.ReserveRequest(10001, 20, "FIRSTLEG", businessId, "RK-001", "measure-001",
|
||||
9001, new BigDecimal("2"), new BigDecimal("2"), "木托盘", LocalDateTime.now().plusMinutes(30), true);
|
||||
9001, new BigDecimal("2"), List.of(new PalletAllocationDtos.PalletReference(7001, 30)),
|
||||
LocalDateTime.now().plusMinutes(30), true);
|
||||
}
|
||||
|
||||
private static PalletEntity pallet(long id, String code) {
|
||||
PalletEntity entity = new PalletEntity();
|
||||
entity.setId(id);
|
||||
entity.setPalletCode(code);
|
||||
entity.setCapacityCbm(new BigDecimal("1.2"));
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.baiyue.warehouse.service;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class PalletVolumeSplitterTest {
|
||||
private final PalletVolumeSplitter splitter = new PalletVolumeSplitter();
|
||||
|
||||
@Test
|
||||
void shouldHandleCase01() {
|
||||
var result = splitter.split(new BigDecimal("20"), new BigDecimal("2"));
|
||||
assertThat(result.palletCount()).isEqualTo(10);
|
||||
assertThat(result.allocations()).allMatch(item -> item.allocatedVolumeCbm().compareTo(new BigDecimal("2")) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHandleCase02() {
|
||||
var result = splitter.split(new BigDecimal("20.1"), new BigDecimal("2"));
|
||||
assertThat(result.palletCount()).isEqualTo(11);
|
||||
assertThat(result.allocations().get(10).allocatedVolumeCbm()).isEqualByComparingTo("0.1");
|
||||
assertThat(result.allocations()).extracting(PalletVolumeSplitter.Allocation::allocationNo)
|
||||
.containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHandleCase03() {
|
||||
assertThatThrownBy(() -> splitter.split(null, BigDecimal.ONE)).isInstanceOf(BizException.class);
|
||||
assertThatThrownBy(() -> splitter.split(BigDecimal.ZERO, BigDecimal.ONE)).isInstanceOf(BizException.class);
|
||||
assertThatThrownBy(() -> splitter.split(BigDecimal.ONE, BigDecimal.ZERO)).isInstanceOf(BizException.class);
|
||||
assertThatThrownBy(() -> splitter.split(new BigDecimal("10001"), BigDecimal.ONE)).isInstanceOf(BizException.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user