fix(lastleg): preserve mixed SKU balances when splitting return relabel stock
This commit is contained in:
+14
-8
@@ -375,14 +375,20 @@ public class PdaPalletOperationService {
|
||||
.eq("application_id", application.getId()).eq("return_carton_id", source.getId())).size() != 1)
|
||||
throw conflict("来源托盘包含多项换标任务,不能按单 SKU 拆分,请核对库存");
|
||||
List<ReturnInventoryCartonItem> lines = returnCartonItems.lockCarton(source.getId());
|
||||
if (lines.size() != 1 || !item.getSkuCode().equalsIgnoreCase(lines.get(0).getSkuCode())
|
||||
|| value(lines.get(0).getQuantity()) != value(source.getTotalQuantity()))
|
||||
throw conflict("来源托盘包含其他 SKU,不能按单 SKU 拆分,请核对库存");
|
||||
List<ReturnInventoryCartonItem> matching = lines.stream()
|
||||
.filter(line -> item.getSkuCode().equalsIgnoreCase(line.getSkuCode())).toList();
|
||||
if (matching.size() != 1 || quantity <= 0 || quantity > value(matching.get(0).getQuantity())
|
||||
|| lines.stream().anyMatch(line -> value(line.getQuantity()) <= 0)
|
||||
|| lines.stream().mapToLong(line -> value(line.getQuantity())).sum() != value(source.getTotalQuantity()))
|
||||
throw conflict("来源托盘SKU数量不一致,请核对库存");
|
||||
long remaining = value(source.getTotalQuantity()) - quantity;
|
||||
ReturnInventoryCartonItem sourceLine = lines.get(0);
|
||||
sourceLine.setQuantity(remaining);
|
||||
if (returnCartonItems.updateById(sourceLine) != 1
|
||||
|| returnCartons.releasePartial(source.getId(), application.getCustomerId(), application.getId(), remaining) != 1)
|
||||
ReturnInventoryCartonItem sourceLine = matching.get(0);
|
||||
long skuRemaining = value(sourceLine.getQuantity()) - quantity;
|
||||
int remainingSkuTypes = lines.size() - (skuRemaining == 0 ? 1 : 0);
|
||||
sourceLine.setQuantity(skuRemaining);
|
||||
int changed = skuRemaining == 0 ? returnCartonItems.deleteById(sourceLine.getId()) : returnCartonItems.updateById(sourceLine);
|
||||
if (changed != 1
|
||||
|| returnCartons.releasePartial(source.getId(), application.getCustomerId(), application.getId(), remaining, remainingSkuTypes) != 1)
|
||||
throw conflict("来源托盘数量已变化,请刷新后重试");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
long targetId = IdWorker.getId();
|
||||
@@ -403,7 +409,7 @@ public class PdaPalletOperationService {
|
||||
targetLine.setProductNameZh(sourceLine.getProductNameZh()); targetLine.setQuantity(quantity);
|
||||
if (returnCartonItems.insert(targetLine) != 1
|
||||
|| returnBalances.adjustCartonQuantity(source.getCustomerId(), source.getOverseasWarehouseId(),
|
||||
sourceLine.getSkuCode(), 1) != 1) throw conflict("退货库存拆分记账失败");
|
||||
sourceLine.getSkuCode(), skuRemaining == 0 ? 0 : 1) != 1) throw conflict("退货库存拆分记账失败");
|
||||
item.setReturnCartonId(targetId);
|
||||
if (relabelItems.updateById(item) != 1) throw conflict("换标单来源托盘更新失败");
|
||||
}
|
||||
|
||||
+3
-2
@@ -36,12 +36,13 @@ public interface ReturnInventoryCartonMapper extends BaseMapper<ReturnInventoryC
|
||||
@Select("SELECT * FROM ll_return_inventory_carton WHERE id=#{id} FOR UPDATE")
|
||||
ReturnInventoryCarton lockId(@Param("id") long id);
|
||||
|
||||
@Update("UPDATE ll_return_inventory_carton SET total_quantity=#{remaining},sku_types=1,status='AVAILABLE'," +
|
||||
@Update("UPDATE ll_return_inventory_carton SET total_quantity=#{remaining},sku_types=#{skuTypes},status='AVAILABLE'," +
|
||||
"relabel_application_id=NULL,relabel_no=NULL,relabel_status=NULL,updated_at=NOW(3) " +
|
||||
"WHERE id=#{id} AND customer_id=#{customerId} AND relabel_application_id=#{applicationId} " +
|
||||
"AND status='RELABEL_PENDING' AND total_quantity>#{remaining}")
|
||||
int releasePartial(@Param("id") long id, @Param("customerId") String customerId,
|
||||
@Param("applicationId") long applicationId, @Param("remaining") long remaining);
|
||||
@Param("applicationId") long applicationId, @Param("remaining") long remaining,
|
||||
@Param("skuTypes") int skuTypes);
|
||||
|
||||
@Select("SELECT * FROM ll_return_inventory_carton WHERE source_receipt_id=#{receiptId} LIMIT 1")
|
||||
ReturnInventoryCarton findReceipt(@Param("receiptId") long receiptId);
|
||||
|
||||
Reference in New Issue
Block a user