no message
parent
cf04ea92e5
commit
9d1bb3fe6a
|
|
@ -155,12 +155,11 @@ public class BatchProcessor {
|
|||
* 批量处理拣货操作
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void batchPick(List<Inventory> deleteToInventory, Map<Long, PickDetail> pickDetailUpdateMap, List<Task> updateToTask, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
public void batchPick(List<Inventory> deleteToInventory, List<PickDetail> updateToPickDetail, List<Task> updateToTask, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
if (CollectionUtils.isNotEmpty(deleteToInventory)) {
|
||||
List<Long> deleteToInventoryIds = deleteToInventory.stream().map(Inventory::getId).toList();
|
||||
inventoryMapper.deleteByIds(deleteToInventoryIds);
|
||||
}
|
||||
List<PickDetail> updateToPickDetail = new ArrayList<>(pickDetailUpdateMap.values());
|
||||
if (CollectionUtils.isNotEmpty(updateToPickDetail)) {
|
||||
batchUtil.updateBatchPickDetail(updateToPickDetail);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,8 +106,8 @@ public class InventoryLogServiceImpl extends ServiceImpl<InventoryLogMapper, Inv
|
|||
// 出库数量为负数
|
||||
inventoryLog.setChangeQty(changeQty.negate());
|
||||
log.info("库存变动日志记录成功,库存数量: {}, 拣货数量: {}", inventory.getQuantity(), changeQty);
|
||||
inventoryLog.setBeforeQty(BigDecimalUtil.add(inventory.getQuantity(), changeQty, 0));
|
||||
inventoryLog.setAfterQty(inventory.getQuantity());
|
||||
inventoryLog.setBeforeQty(inventory.getQuantity());
|
||||
inventoryLog.setAfterQty(BigDecimalUtil.subtract(inventory.getQuantity(), changeQty, 0));
|
||||
inventoryLog.setAfterAllocatedQty(BigDecimal.ZERO);
|
||||
inventoryLog.setBeforeAllocatedQty(BigDecimal.ZERO);
|
||||
inventoryLog.setFromPointId(inventory.getPointId());
|
||||
|
|
|
|||
|
|
@ -81,17 +81,16 @@ public class PickProcessor {
|
|||
|
||||
//2.创建数据结构
|
||||
List<Inventory> deleteToInventory = new ArrayList<>();
|
||||
Map<Long, Inventory> inventoryUpdateMap = new HashMap<>();
|
||||
Map<Long, PickDetail> pickDetailUpdateMap = new HashMap<>();
|
||||
List<PickDetail> updateToPickDetail = new ArrayList<>();
|
||||
List<Task> updateToTask = new ArrayList<>();
|
||||
List<Stock> updateToStock = new ArrayList<>();
|
||||
List<Point> updateToPoint = new ArrayList<>();
|
||||
|
||||
//3.拣货
|
||||
pickTask(data, pickDetailUpdateMap, updateToTask, deleteToInventory, inventoryUpdateMap, updateToStock, updateToPoint);
|
||||
pickTask(data, updateToPickDetail, updateToTask, deleteToInventory, updateToStock, updateToPoint);
|
||||
|
||||
//4.批量操作
|
||||
batchProcessor.batchPick(deleteToInventory, pickDetailUpdateMap, updateToTask, updateToStock, updateToPoint);
|
||||
batchProcessor.batchPick(deleteToInventory, updateToPickDetail, updateToTask, updateToStock, updateToPoint);
|
||||
|
||||
//5.回传
|
||||
pickBackProcessor.pickBack(data, updateToTask);
|
||||
|
|
@ -143,10 +142,10 @@ public class PickProcessor {
|
|||
*
|
||||
* @param data 数据
|
||||
*/
|
||||
private void pickTask(PickData data, Map<Long, PickDetail> pickDetailUpdateMap, List<Task> updateToTask, List<Inventory> deleteToInventory, Map<Long, Inventory> inventoryUpdateMap, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
private void pickTask(PickData data, List<PickDetail> updateToPickDetail, List<Task> updateToTask, List<Inventory> deleteToInventory, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
for (Task task : data.getTasks()) {
|
||||
try {
|
||||
processorTaskLock(data, task, pickDetailUpdateMap, updateToTask, deleteToInventory, inventoryUpdateMap, updateToStock, updateToPoint);
|
||||
processorTaskLock(data, task, updateToPickDetail, updateToTask, deleteToInventory, updateToStock, updateToPoint);
|
||||
} catch (Exception e) {
|
||||
log.error("拣货异常", e);
|
||||
//记录拣货异常日志
|
||||
|
|
@ -160,22 +159,20 @@ public class PickProcessor {
|
|||
*
|
||||
* @param data 数据
|
||||
* @param task 任务
|
||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
||||
* @param updateToTask 更新任务集合
|
||||
* @param deleteToInventory 删除库存集合
|
||||
* @param updateToStock 更新容器状态集合
|
||||
*/
|
||||
private void processorTaskLock(PickData data, Task task, Map<Long, PickDetail> pickDetailUpdateMap, List<Task> updateToTask, List<Inventory> deleteToInventory, Map<Long, Inventory> inventoryUpdateMap, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
private void processorTaskLock(PickData data, Task task, List<PickDetail> updateToPickDetail, List<Task> updateToTask, List<Inventory> deleteToInventory, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
// 拣货处理
|
||||
Pick pick = data.getPickMap().get(task.getPickId());
|
||||
String lockKey = "task:" + pick.getId();
|
||||
String lockKey = "task:" + task.getId();
|
||||
String lockValue = null;
|
||||
try {
|
||||
lockValue = redissonLock.tryLock(lockKey, 10);
|
||||
if (StringUtils.isEmpty(lockValue)) {
|
||||
throw new RuntimeException("拣货处理中,请稍后重试");
|
||||
}
|
||||
processorTask(data, task, pickDetailUpdateMap, updateToTask, deleteToInventory, inventoryUpdateMap, updateToStock, updateToPoint);
|
||||
processorTask(data, task, updateToPickDetail, updateToTask, deleteToInventory, updateToStock, updateToPoint);
|
||||
} catch (Exception e) {
|
||||
log.error("拣货异常", e);
|
||||
throw e;
|
||||
|
|
@ -193,12 +190,12 @@ public class PickProcessor {
|
|||
*
|
||||
* @param data 数据
|
||||
* @param task 任务
|
||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
||||
* @param updateToPickDetail 拣货明细更新集合
|
||||
* @param updateToTask 更新任务集合
|
||||
* @param deleteToInventory 删除库存集合
|
||||
* @param updateToStock 更新容器状态集合
|
||||
*/
|
||||
private void processorTask(PickData data, Task task, Map<Long, PickDetail> pickDetailUpdateMap, List<Task> updateToTask, List<Inventory> deleteToInventory, Map<Long, Inventory> inventoryUpdateMap, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
private void processorTask(PickData data, Task task, List<PickDetail> updateToPickDetail, List<Task> updateToTask, List<Inventory> deleteToInventory, List<Stock> updateToStock, List<Point> updateToPoint) {
|
||||
|
||||
BigDecimal pickedQty = BigDecimalUtil.subtract(task.getPlanQty(), task.getMoveQty(), 0);
|
||||
if (pickedQty.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
|
|
@ -210,7 +207,7 @@ public class PickProcessor {
|
|||
updateInventory(inventory, pickedQty,inventoryUpdateMap);*/
|
||||
|
||||
// 更新拣货数量,状态
|
||||
updatePickDetail(data, task, pickedQty, pickDetailUpdateMap);
|
||||
updatePickDetail(data, task, pickedQty, updateToPickDetail);
|
||||
|
||||
//更新task
|
||||
updateTask(task, pickedQty, updateToTask);
|
||||
|
|
@ -225,7 +222,7 @@ public class PickProcessor {
|
|||
updateToPoint(data, task, updateToPoint);
|
||||
|
||||
//添加库存日志
|
||||
addInventoryLog(data, task, pickedQty, inventoryUpdateMap);
|
||||
addInventoryLog(data, task, pickedQty);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -233,17 +230,14 @@ public class PickProcessor {
|
|||
*
|
||||
* @param inventory 库存
|
||||
* @param pickedQty 拣货数量
|
||||
* @param inventoryUpdateMap 库更新集合
|
||||
*/
|
||||
private void updateInventory(Inventory inventory, BigDecimal pickedQty,
|
||||
Map<Long, Inventory> inventoryUpdateMap) {
|
||||
private void updateInventory(Inventory inventory, BigDecimal pickedQty) {
|
||||
if (inventory != null) {
|
||||
Inventory targetInventory = inventoryUpdateMap.getOrDefault(inventory.getId(), inventory);
|
||||
Inventory targetInventory = inventoryService.getById(inventory.getId());
|
||||
BigDecimal quantity = BigDecimalUtil.subtract(targetInventory.getQuantity(), pickedQty, 0);
|
||||
BigDecimal queuedQty = BigDecimalUtil.subtract(targetInventory.getQueuedQty(), pickedQty, 0);
|
||||
targetInventory.setQuantity(quantity);
|
||||
targetInventory.setQueuedQty(queuedQty);
|
||||
inventoryUpdateMap.put(targetInventory.getId(), targetInventory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -267,35 +261,31 @@ public class PickProcessor {
|
|||
*
|
||||
* @param data 数据
|
||||
* @param pickedQty 拣货数量
|
||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
||||
* @param updateToPickDetail 拣货明细更新集合
|
||||
*/
|
||||
private void updatePickDetail(
|
||||
PickData data,
|
||||
Task task,
|
||||
BigDecimal pickedQty,
|
||||
Map<Long, PickDetail> pickDetailUpdateMap
|
||||
List<PickDetail> updateToPickDetail
|
||||
) {
|
||||
// 从数据中获取原始 PickDetail
|
||||
PickDetail originalPickDetail = data.getPickDetailMap().get(task.getPickDetailId());
|
||||
if (originalPickDetail == null) {
|
||||
PickDetail pickDetail = pickDetailMapper.selectById(task.getPickDetailId());
|
||||
if (pickDetail == null) {
|
||||
return; // 安全保护
|
||||
}
|
||||
|
||||
// 从 Map 获取已累积的 PickDetail(可能是已经部分更新过的)
|
||||
PickDetail currentPickDetail = pickDetailUpdateMap
|
||||
.computeIfAbsent(originalPickDetail.getId(), id -> clonePickDetail(originalPickDetail));
|
||||
|
||||
// 累加拣货数量
|
||||
BigDecimal existingQty = currentPickDetail.getPickedQty() == null
|
||||
BigDecimal existingQty = pickDetail.getPickedQty() == null
|
||||
? BigDecimal.ZERO
|
||||
: currentPickDetail.getPickedQty();
|
||||
: pickDetail.getPickedQty();
|
||||
|
||||
BigDecimal newPickedQty = existingQty.add(pickedQty);
|
||||
|
||||
// 订单总数量
|
||||
BigDecimal orderQty = currentPickDetail.getOrderQty() == null
|
||||
BigDecimal orderQty = pickDetail.getOrderQty() == null
|
||||
? BigDecimal.ZERO
|
||||
: currentPickDetail.getOrderQty();
|
||||
: pickDetail.getOrderQty();
|
||||
|
||||
// 确保 newPickedQty 不超过 orderQty
|
||||
if (newPickedQty.compareTo(orderQty) > 0) {
|
||||
|
|
@ -303,7 +293,7 @@ public class PickProcessor {
|
|||
}
|
||||
|
||||
// 更新数量
|
||||
currentPickDetail.setPickedQty(newPickedQty);
|
||||
pickDetail.setPickedQty(newPickedQty);
|
||||
|
||||
// 计算状态:是否完全拣完
|
||||
Integer status;
|
||||
|
|
@ -311,46 +301,14 @@ public class PickProcessor {
|
|||
status = PickStatusEnum.PICKED.getValue();
|
||||
} else if (newPickedQty.compareTo(BigDecimal.ZERO) > 0) {
|
||||
status = PickStatusEnum.PICKING.getValue();
|
||||
}else {
|
||||
status = currentPickDetail.getStatus();
|
||||
} else {
|
||||
status = pickDetail.getStatus();
|
||||
}
|
||||
|
||||
currentPickDetail.setStatus(status);
|
||||
pickDetail.setStatus(status);
|
||||
|
||||
// 最终写回更新 Map
|
||||
pickDetailUpdateMap.put(currentPickDetail.getId(), currentPickDetail);
|
||||
}
|
||||
updateToPickDetail.add(pickDetail);
|
||||
|
||||
private PickDetail clonePickDetail(PickDetail src) {
|
||||
PickDetail dst = PickDetail.builder()
|
||||
.id(src.getId())
|
||||
.pickId(src.getPickId())
|
||||
.itemId(src.getItemId())
|
||||
.stockId(src.getStockId())
|
||||
.lineNo(src.getLineNo())
|
||||
.unit(src.getUnit())
|
||||
.project(src.getProject())
|
||||
.taskNo(src.getTaskNo())
|
||||
.orderQty(src.getOrderQty())
|
||||
.allocatedQty(src.getAllocatedQty())
|
||||
.pickedQty(src.getPickedQty())
|
||||
.status(src.getStatus())
|
||||
.propC1(src.getPropC1())
|
||||
.propC2(src.getPropC2())
|
||||
.propC3(src.getPropC3())
|
||||
.propC4(src.getPropC4())
|
||||
.propD1(src.getPropD1())
|
||||
.description(src.getDescription())
|
||||
.sourceId(src.getSourceId())
|
||||
.sourceName(src.getSourceName())
|
||||
.tenantId(src.getTenantId())
|
||||
.sysOrgCode(src.getSysOrgCode())
|
||||
.createBy(src.getCreateBy())
|
||||
.createTime(src.getCreateTime())
|
||||
.updateBy(src.getUpdateBy())
|
||||
.updateTime(src.getUpdateTime())
|
||||
.build();
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -407,12 +365,11 @@ public class PickProcessor {
|
|||
* @param task 任务
|
||||
* @param pickedQty 拣货数量
|
||||
*/
|
||||
private void addInventoryLog(PickData data, Task task, BigDecimal pickedQty, Map<Long, Inventory> inventoryUpdateMap) {
|
||||
private void addInventoryLog(PickData data, Task task, BigDecimal pickedQty) {
|
||||
Inventory inventory = data.getInventoryMap().get(task.getInventoryId());
|
||||
if (inventory != null) {
|
||||
updateInventory(inventory, pickedQty, inventoryUpdateMap);
|
||||
Pick pick = data.getPickMap().get(task.getPickId());
|
||||
inventoryLogService.addPickInventoryLog(inventoryUpdateMap.get(inventory.getId()), task.getToPointId(), pickedQty, pick.getThirdOrderNo(), task.getId(), null);
|
||||
inventoryLogService.addPickInventoryLog(inventory, task.getToPointId(), pickedQty, pick.getThirdOrderNo(), task.getId(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue