no message
parent
cf04ea92e5
commit
9d1bb3fe6a
|
|
@ -155,12 +155,11 @@ public class BatchProcessor {
|
||||||
* 批量处理拣货操作
|
* 批量处理拣货操作
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@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)) {
|
if (CollectionUtils.isNotEmpty(deleteToInventory)) {
|
||||||
List<Long> deleteToInventoryIds = deleteToInventory.stream().map(Inventory::getId).toList();
|
List<Long> deleteToInventoryIds = deleteToInventory.stream().map(Inventory::getId).toList();
|
||||||
inventoryMapper.deleteByIds(deleteToInventoryIds);
|
inventoryMapper.deleteByIds(deleteToInventoryIds);
|
||||||
}
|
}
|
||||||
List<PickDetail> updateToPickDetail = new ArrayList<>(pickDetailUpdateMap.values());
|
|
||||||
if (CollectionUtils.isNotEmpty(updateToPickDetail)) {
|
if (CollectionUtils.isNotEmpty(updateToPickDetail)) {
|
||||||
batchUtil.updateBatchPickDetail(updateToPickDetail);
|
batchUtil.updateBatchPickDetail(updateToPickDetail);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,8 @@ public class InventoryLogServiceImpl extends ServiceImpl<InventoryLogMapper, Inv
|
||||||
// 出库数量为负数
|
// 出库数量为负数
|
||||||
inventoryLog.setChangeQty(changeQty.negate());
|
inventoryLog.setChangeQty(changeQty.negate());
|
||||||
log.info("库存变动日志记录成功,库存数量: {}, 拣货数量: {}", inventory.getQuantity(), changeQty);
|
log.info("库存变动日志记录成功,库存数量: {}, 拣货数量: {}", inventory.getQuantity(), changeQty);
|
||||||
inventoryLog.setBeforeQty(BigDecimalUtil.add(inventory.getQuantity(), changeQty, 0));
|
inventoryLog.setBeforeQty(inventory.getQuantity());
|
||||||
inventoryLog.setAfterQty(inventory.getQuantity());
|
inventoryLog.setAfterQty(BigDecimalUtil.subtract(inventory.getQuantity(), changeQty, 0));
|
||||||
inventoryLog.setAfterAllocatedQty(BigDecimal.ZERO);
|
inventoryLog.setAfterAllocatedQty(BigDecimal.ZERO);
|
||||||
inventoryLog.setBeforeAllocatedQty(BigDecimal.ZERO);
|
inventoryLog.setBeforeAllocatedQty(BigDecimal.ZERO);
|
||||||
inventoryLog.setFromPointId(inventory.getPointId());
|
inventoryLog.setFromPointId(inventory.getPointId());
|
||||||
|
|
|
||||||
|
|
@ -81,17 +81,16 @@ public class PickProcessor {
|
||||||
|
|
||||||
//2.创建数据结构
|
//2.创建数据结构
|
||||||
List<Inventory> deleteToInventory = new ArrayList<>();
|
List<Inventory> deleteToInventory = new ArrayList<>();
|
||||||
Map<Long, Inventory> inventoryUpdateMap = new HashMap<>();
|
List<PickDetail> updateToPickDetail = new ArrayList<>();
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap = new HashMap<>();
|
|
||||||
List<Task> updateToTask = new ArrayList<>();
|
List<Task> updateToTask = new ArrayList<>();
|
||||||
List<Stock> updateToStock = new ArrayList<>();
|
List<Stock> updateToStock = new ArrayList<>();
|
||||||
List<Point> updateToPoint = new ArrayList<>();
|
List<Point> updateToPoint = new ArrayList<>();
|
||||||
|
|
||||||
//3.拣货
|
//3.拣货
|
||||||
pickTask(data, pickDetailUpdateMap, updateToTask, deleteToInventory, inventoryUpdateMap, updateToStock, updateToPoint);
|
pickTask(data, updateToPickDetail, updateToTask, deleteToInventory, updateToStock, updateToPoint);
|
||||||
|
|
||||||
//4.批量操作
|
//4.批量操作
|
||||||
batchProcessor.batchPick(deleteToInventory, pickDetailUpdateMap, updateToTask, updateToStock, updateToPoint);
|
batchProcessor.batchPick(deleteToInventory, updateToPickDetail, updateToTask, updateToStock, updateToPoint);
|
||||||
|
|
||||||
//5.回传
|
//5.回传
|
||||||
pickBackProcessor.pickBack(data, updateToTask);
|
pickBackProcessor.pickBack(data, updateToTask);
|
||||||
|
|
@ -143,10 +142,10 @@ public class PickProcessor {
|
||||||
*
|
*
|
||||||
* @param data 数据
|
* @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()) {
|
for (Task task : data.getTasks()) {
|
||||||
try {
|
try {
|
||||||
processorTaskLock(data, task, pickDetailUpdateMap, updateToTask, deleteToInventory, inventoryUpdateMap, updateToStock, updateToPoint);
|
processorTaskLock(data, task, updateToPickDetail, updateToTask, deleteToInventory, updateToStock, updateToPoint);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("拣货异常", e);
|
log.error("拣货异常", e);
|
||||||
//记录拣货异常日志
|
//记录拣货异常日志
|
||||||
|
|
@ -158,24 +157,22 @@ public class PickProcessor {
|
||||||
/**
|
/**
|
||||||
* 处理任务
|
* 处理任务
|
||||||
*
|
*
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param task 任务
|
* @param task 任务
|
||||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
* @param updateToTask 更新任务集合
|
||||||
* @param updateToTask 更新任务集合
|
* @param deleteToInventory 删除库存集合
|
||||||
* @param deleteToInventory 删除库存集合
|
* @param updateToStock 更新容器状态集合
|
||||||
* @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:" + task.getId();
|
||||||
String lockKey = "task:" + pick.getId();
|
|
||||||
String lockValue = null;
|
String lockValue = null;
|
||||||
try {
|
try {
|
||||||
lockValue = redissonLock.tryLock(lockKey, 10);
|
lockValue = redissonLock.tryLock(lockKey, 10);
|
||||||
if (StringUtils.isEmpty(lockValue)) {
|
if (StringUtils.isEmpty(lockValue)) {
|
||||||
throw new RuntimeException("拣货处理中,请稍后重试");
|
throw new RuntimeException("拣货处理中,请稍后重试");
|
||||||
}
|
}
|
||||||
processorTask(data, task, pickDetailUpdateMap, updateToTask, deleteToInventory, inventoryUpdateMap, updateToStock, updateToPoint);
|
processorTask(data, task, updateToPickDetail, updateToTask, deleteToInventory, updateToStock, updateToPoint);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("拣货异常", e);
|
log.error("拣货异常", e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|
@ -191,14 +188,14 @@ public class PickProcessor {
|
||||||
/**
|
/**
|
||||||
* 处理任务
|
* 处理任务
|
||||||
*
|
*
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param task 任务
|
* @param task 任务
|
||||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
* @param updateToPickDetail 拣货明细更新集合
|
||||||
* @param updateToTask 更新任务集合
|
* @param updateToTask 更新任务集合
|
||||||
* @param deleteToInventory 删除库存集合
|
* @param deleteToInventory 删除库存集合
|
||||||
* @param updateToStock 更新容器状态集合
|
* @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);
|
BigDecimal pickedQty = BigDecimalUtil.subtract(task.getPlanQty(), task.getMoveQty(), 0);
|
||||||
if (pickedQty.compareTo(BigDecimal.ZERO) <= 0) {
|
if (pickedQty.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
|
|
@ -210,7 +207,7 @@ public class PickProcessor {
|
||||||
updateInventory(inventory, pickedQty,inventoryUpdateMap);*/
|
updateInventory(inventory, pickedQty,inventoryUpdateMap);*/
|
||||||
|
|
||||||
// 更新拣货数量,状态
|
// 更新拣货数量,状态
|
||||||
updatePickDetail(data, task, pickedQty, pickDetailUpdateMap);
|
updatePickDetail(data, task, pickedQty, updateToPickDetail);
|
||||||
|
|
||||||
//更新task
|
//更新task
|
||||||
updateTask(task, pickedQty, updateToTask);
|
updateTask(task, pickedQty, updateToTask);
|
||||||
|
|
@ -225,25 +222,22 @@ public class PickProcessor {
|
||||||
updateToPoint(data, task, updateToPoint);
|
updateToPoint(data, task, updateToPoint);
|
||||||
|
|
||||||
//添加库存日志
|
//添加库存日志
|
||||||
addInventoryLog(data, task, pickedQty, inventoryUpdateMap);
|
addInventoryLog(data, task, pickedQty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新库存
|
* 更新库存
|
||||||
*
|
*
|
||||||
* @param inventory 库存
|
* @param inventory 库存
|
||||||
* @param pickedQty 拣货数量
|
* @param pickedQty 拣货数量
|
||||||
* @param inventoryUpdateMap 库更新集合
|
|
||||||
*/
|
*/
|
||||||
private void updateInventory(Inventory inventory, BigDecimal pickedQty,
|
private void updateInventory(Inventory inventory, BigDecimal pickedQty) {
|
||||||
Map<Long, Inventory> inventoryUpdateMap) {
|
|
||||||
if (inventory != null) {
|
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 quantity = BigDecimalUtil.subtract(targetInventory.getQuantity(), pickedQty, 0);
|
||||||
BigDecimal queuedQty = BigDecimalUtil.subtract(targetInventory.getQueuedQty(), pickedQty, 0);
|
BigDecimal queuedQty = BigDecimalUtil.subtract(targetInventory.getQueuedQty(), pickedQty, 0);
|
||||||
targetInventory.setQuantity(quantity);
|
targetInventory.setQuantity(quantity);
|
||||||
targetInventory.setQueuedQty(queuedQty);
|
targetInventory.setQueuedQty(queuedQty);
|
||||||
inventoryUpdateMap.put(targetInventory.getId(), targetInventory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,37 +259,33 @@ public class PickProcessor {
|
||||||
/**
|
/**
|
||||||
* 更新出库明细
|
* 更新出库明细
|
||||||
*
|
*
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param pickedQty 拣货数量
|
* @param pickedQty 拣货数量
|
||||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
* @param updateToPickDetail 拣货明细更新集合
|
||||||
*/
|
*/
|
||||||
private void updatePickDetail(
|
private void updatePickDetail(
|
||||||
PickData data,
|
PickData data,
|
||||||
Task task,
|
Task task,
|
||||||
BigDecimal pickedQty,
|
BigDecimal pickedQty,
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap
|
List<PickDetail> updateToPickDetail
|
||||||
) {
|
) {
|
||||||
// 从数据中获取原始 PickDetail
|
// 从数据中获取原始 PickDetail
|
||||||
PickDetail originalPickDetail = data.getPickDetailMap().get(task.getPickDetailId());
|
PickDetail pickDetail = pickDetailMapper.selectById(task.getPickDetailId());
|
||||||
if (originalPickDetail == null) {
|
if (pickDetail == null) {
|
||||||
return; // 安全保护
|
return; // 安全保护
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 Map 获取已累积的 PickDetail(可能是已经部分更新过的)
|
|
||||||
PickDetail currentPickDetail = pickDetailUpdateMap
|
|
||||||
.computeIfAbsent(originalPickDetail.getId(), id -> clonePickDetail(originalPickDetail));
|
|
||||||
|
|
||||||
// 累加拣货数量
|
// 累加拣货数量
|
||||||
BigDecimal existingQty = currentPickDetail.getPickedQty() == null
|
BigDecimal existingQty = pickDetail.getPickedQty() == null
|
||||||
? BigDecimal.ZERO
|
? BigDecimal.ZERO
|
||||||
: currentPickDetail.getPickedQty();
|
: pickDetail.getPickedQty();
|
||||||
|
|
||||||
BigDecimal newPickedQty = existingQty.add(pickedQty);
|
BigDecimal newPickedQty = existingQty.add(pickedQty);
|
||||||
|
|
||||||
// 订单总数量
|
// 订单总数量
|
||||||
BigDecimal orderQty = currentPickDetail.getOrderQty() == null
|
BigDecimal orderQty = pickDetail.getOrderQty() == null
|
||||||
? BigDecimal.ZERO
|
? BigDecimal.ZERO
|
||||||
: currentPickDetail.getOrderQty();
|
: pickDetail.getOrderQty();
|
||||||
|
|
||||||
// 确保 newPickedQty 不超过 orderQty
|
// 确保 newPickedQty 不超过 orderQty
|
||||||
if (newPickedQty.compareTo(orderQty) > 0) {
|
if (newPickedQty.compareTo(orderQty) > 0) {
|
||||||
|
|
@ -303,7 +293,7 @@ public class PickProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新数量
|
// 更新数量
|
||||||
currentPickDetail.setPickedQty(newPickedQty);
|
pickDetail.setPickedQty(newPickedQty);
|
||||||
|
|
||||||
// 计算状态:是否完全拣完
|
// 计算状态:是否完全拣完
|
||||||
Integer status;
|
Integer status;
|
||||||
|
|
@ -311,46 +301,14 @@ public class PickProcessor {
|
||||||
status = PickStatusEnum.PICKED.getValue();
|
status = PickStatusEnum.PICKED.getValue();
|
||||||
} else if (newPickedQty.compareTo(BigDecimal.ZERO) > 0) {
|
} else if (newPickedQty.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
status = PickStatusEnum.PICKING.getValue();
|
status = PickStatusEnum.PICKING.getValue();
|
||||||
}else {
|
} else {
|
||||||
status = currentPickDetail.getStatus();
|
status = pickDetail.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPickDetail.setStatus(status);
|
pickDetail.setStatus(status);
|
||||||
|
|
||||||
// 最终写回更新 Map
|
updateToPickDetail.add(pickDetail);
|
||||||
pickDetailUpdateMap.put(currentPickDetail.getId(), currentPickDetail);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 task 任务
|
||||||
* @param pickedQty 拣货数量
|
* @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());
|
Inventory inventory = data.getInventoryMap().get(task.getInventoryId());
|
||||||
if (inventory != null) {
|
if (inventory != null) {
|
||||||
updateInventory(inventory, pickedQty, inventoryUpdateMap);
|
|
||||||
Pick pick = data.getPickMap().get(task.getPickId());
|
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