no message
parent
fc6417acd2
commit
01b476b84b
|
|
@ -116,9 +116,7 @@ public class BatchProcessor {
|
||||||
* 批量处理分配操作
|
* 批量处理分配操作
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean batchAllocate(Map<Long, Inventory> inventoryUpdateMap, Map<Long, PickDetail> pickDetailUpdateMap, List<Task> createToTask) {
|
public boolean batchAllocate(List<Inventory> updateToInventory, List<PickDetail> updateToPickDetail, List<Task> createToTask) {
|
||||||
List<Inventory> updateToInventory = new ArrayList<>(inventoryUpdateMap.values());
|
|
||||||
List<PickDetail> updateToPickDetail = new ArrayList<>(pickDetailUpdateMap.values());
|
|
||||||
if (CollectionUtils.isNotEmpty(updateToInventory)) {
|
if (CollectionUtils.isNotEmpty(updateToInventory)) {
|
||||||
batchUtil.updateBatchInventory(updateToInventory);
|
batchUtil.updateBatchInventory(updateToInventory);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,15 @@ public class IConveyorLineServiceImpl implements IConveyorLineService {
|
||||||
public void updateResMessageAsn(ScanTrayRequest scanTrayRequest) {
|
public void updateResMessageAsn(ScanTrayRequest scanTrayRequest) {
|
||||||
ScanTrayData data = scanTrayProcessor.prepareScanTrayData(scanTrayRequest);
|
ScanTrayData data = scanTrayProcessor.prepareScanTrayData(scanTrayRequest);
|
||||||
Asn asn = data.getAsn();
|
Asn asn = data.getAsn();
|
||||||
if (asn != null) {
|
if (asn == null) {
|
||||||
if (asn.getResMessage().equals("检测成功")) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
asn.setResMessage(scanTrayRequest.getContent().getSignal().getErrorReason().toString());
|
|
||||||
asnMapper.updateById(asn);
|
|
||||||
}
|
}
|
||||||
|
if ("检测成功".equals(asn.getResMessage())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
asn.setResMessage(scanTrayRequest.getContent().getSignal().getErrorReason().toString());
|
||||||
|
asnMapper.updateById(asn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import org.cpte.modules.conveyorLine.service.processor.ScanTrayProcessor;
|
||||||
import org.cpte.modules.conveyorLine.vo.Station;
|
import org.cpte.modules.conveyorLine.vo.Station;
|
||||||
import org.cpte.modules.inventory.entity.Inventory;
|
import org.cpte.modules.inventory.entity.Inventory;
|
||||||
import org.cpte.modules.inventory.mapper.InventoryMapper;
|
import org.cpte.modules.inventory.mapper.InventoryMapper;
|
||||||
import org.cpte.modules.inventoryLog.service.IInventoryLogService;
|
|
||||||
import org.cpte.modules.serialNumber.MoveSerialNumberRule;
|
import org.cpte.modules.serialNumber.MoveSerialNumberRule;
|
||||||
import org.cpte.modules.shipping.entity.Pick;
|
import org.cpte.modules.shipping.entity.Pick;
|
||||||
import org.cpte.modules.shipping.entity.PickDetail;
|
import org.cpte.modules.shipping.entity.PickDetail;
|
||||||
|
|
@ -81,9 +80,6 @@ public class AllocateProcessor {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ITaskService taskService;
|
private ITaskService taskService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IInventoryLogService inventoryLogService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BaseCommonService baseCommonService;
|
private BaseCommonService baseCommonService;
|
||||||
|
|
||||||
|
|
@ -125,19 +121,19 @@ public class AllocateProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
//3.创建数据结构
|
//3.创建数据结构
|
||||||
Map<Long, Inventory> inventoryUpdateMap = new HashMap<>();
|
List<Inventory> updateToInventory = new ArrayList<>();
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap = new HashMap<>();
|
List<PickDetail> updateToPickDetail = new ArrayList<>();
|
||||||
List<Task> createToTask = new ArrayList<>();
|
List<Task> createToTask = new ArrayList<>();
|
||||||
List<Point> movePoints = new ArrayList<>();
|
List<Point> movePoints = new ArrayList<>();
|
||||||
|
|
||||||
//4.分配
|
//4.分配
|
||||||
allocate(data, inventoryUpdateMap, pickDetailUpdateMap, createToTask, movePoints, errorMsgSet);
|
allocate(data, updateToInventory, updateToPickDetail, createToTask, movePoints, errorMsgSet);
|
||||||
|
|
||||||
//5.生成移位任务
|
//5.生成移位任务
|
||||||
moveTask(createToTask, movePoints);
|
moveTask(createToTask, movePoints);
|
||||||
|
|
||||||
//6.批量操作
|
//6.批量操作
|
||||||
batchProcessor.batchAllocate(inventoryUpdateMap, pickDetailUpdateMap, createToTask);
|
batchProcessor.batchAllocate(updateToInventory, updateToPickDetail, createToTask);
|
||||||
|
|
||||||
//7.刷新出库单
|
//7.刷新出库单
|
||||||
refreshData(data);
|
refreshData(data);
|
||||||
|
|
@ -164,19 +160,19 @@ public class AllocateProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
//3.创建数据结构
|
//3.创建数据结构
|
||||||
Map<Long, Inventory> inventoryUpdateMap = new HashMap<>();
|
List<Inventory> updateToInventory = new ArrayList<>();
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap = new HashMap<>();
|
List<PickDetail> updateToPickDetail = new ArrayList<>();
|
||||||
List<Task> createToTask = new ArrayList<>();
|
List<Task> createToTask = new ArrayList<>();
|
||||||
List<Point> movePoints = new ArrayList<>();
|
List<Point> movePoints = new ArrayList<>();
|
||||||
|
|
||||||
//4.分配
|
//4.分配
|
||||||
allocate(data, inventoryUpdateMap, pickDetailUpdateMap, createToTask, movePoints, errorMsgSet);
|
allocate(data, updateToInventory, updateToPickDetail, createToTask, movePoints, errorMsgSet);
|
||||||
|
|
||||||
//5.生成移位任务
|
//5.生成移位任务
|
||||||
moveTask(createToTask, movePoints);
|
moveTask(createToTask, movePoints);
|
||||||
|
|
||||||
//6.批量操作
|
//6.批量操作
|
||||||
boolean result = batchProcessor.batchAllocate(inventoryUpdateMap, pickDetailUpdateMap, createToTask);
|
boolean result = batchProcessor.batchAllocate(updateToInventory, updateToPickDetail, createToTask);
|
||||||
|
|
||||||
//7.刷新出库单
|
//7.刷新出库单
|
||||||
refreshData(data);
|
refreshData(data);
|
||||||
|
|
@ -395,10 +391,10 @@ public class AllocateProcessor {
|
||||||
/**
|
/**
|
||||||
* 分配
|
* 分配
|
||||||
*/
|
*/
|
||||||
private void allocate(AllocationData data, Map<Long, Inventory> inventoryUpdateMap, Map<Long, PickDetail> pickDetailUpdateMap, List<Task> createToTask, List<Point> movePoints, Set<String> errorMsgSet) {
|
private void allocate(AllocationData data, List<Inventory> updateToInventory, List<PickDetail> updateToPickDetail, List<Task> createToTask, List<Point> movePoints, Set<String> errorMsgSet) {
|
||||||
for (PickDetail pickDetail : data.getPickDetails()) {
|
for (PickDetail pickDetail : data.getPickDetails()) {
|
||||||
try {
|
try {
|
||||||
allocatePickDetail(pickDetail, data, errorMsgSet, inventoryUpdateMap, pickDetailUpdateMap, createToTask, movePoints);
|
allocatePickDetail(pickDetail, data, errorMsgSet, updateToInventory, updateToPickDetail, createToTask, movePoints);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMsgSet.add(String.format("分配异常,明细ID:%s,原因:%s",
|
errorMsgSet.add(String.format("分配异常,明细ID:%s,原因:%s",
|
||||||
pickDetail.getId(), e.getMessage()));
|
pickDetail.getId(), e.getMessage()));
|
||||||
|
|
@ -409,16 +405,16 @@ public class AllocateProcessor {
|
||||||
/**
|
/**
|
||||||
* 分配出库明细
|
* 分配出库明细
|
||||||
*
|
*
|
||||||
* @param pickDetail 出库明细
|
* @param pickDetail 出库明细
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param errorMsgSet 错误信息
|
* @param errorMsgSet 错误信息
|
||||||
* @param inventoryUpdateMap 更新库存
|
* @param updateToInventory 更新库存
|
||||||
* @param pickDetailUpdateMap 更新出库明细
|
* @param updateToPickDetail 更新出库明细
|
||||||
* @param createToTask 创建任务
|
* @param createToTask 创建任务
|
||||||
*/
|
*/
|
||||||
private void allocatePickDetail(PickDetail pickDetail, AllocationData data,
|
private void allocatePickDetail(PickDetail pickDetail, AllocationData data,
|
||||||
Set<String> errorMsgSet, Map<Long, Inventory> inventoryUpdateMap,
|
Set<String> errorMsgSet, List<Inventory> updateToInventory,
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap, List<Task> createToTask, List<Point> movePoints) {
|
List<PickDetail> updateToPickDetail, List<Task> createToTask, List<Point> movePoints) {
|
||||||
|
|
||||||
Pick pick = data.getPickMap().get(pickDetail.getPickId());
|
Pick pick = data.getPickMap().get(pickDetail.getPickId());
|
||||||
Item item = data.getItemMap().get(pickDetail.getItemId());
|
Item item = data.getItemMap().get(pickDetail.getItemId());
|
||||||
|
|
@ -435,14 +431,14 @@ public class AllocateProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分配库存
|
// 分配库存
|
||||||
String lockKey = "allocate:" + pick.getId();
|
String lockKey = "allocate:" + pickDetail.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("分配处理中,请稍后重试");
|
||||||
}
|
}
|
||||||
allocateInventory(pickDetail, item, pick, matchedInventories, inventoryUpdateMap, pickDetailUpdateMap,
|
allocateInventory(pickDetail, item, pick, matchedInventories, updateToInventory, updateToPickDetail,
|
||||||
createToTask, movePoints, data, unAllocatedQty, errorMsgSet);
|
createToTask, movePoints, data, unAllocatedQty, errorMsgSet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("分配异常,出库单ID: {}", pick.getId(), e);
|
log.error("分配异常,出库单ID: {}", pick.getId(), e);
|
||||||
|
|
@ -510,15 +506,15 @@ public class AllocateProcessor {
|
||||||
* @param item 物料
|
* @param item 物料
|
||||||
* @param pick 拣货单
|
* @param pick 拣货单
|
||||||
* @param matchedInventories 匹配库存
|
* @param matchedInventories 匹配库存
|
||||||
* @param inventoryUpdateMap 更新库存
|
* @param updateToInventory 更新库存
|
||||||
* @param pickDetailUpdateMap 更新出库明细
|
* @param updateToPickDetail 更新出库明细
|
||||||
* @param createToTask 创建任务
|
* @param createToTask 创建任务
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param totalUnAllocatedQty 未分配数量
|
* @param totalUnAllocatedQty 未分配数量
|
||||||
*/
|
*/
|
||||||
private void allocateInventory(PickDetail pickDetail, Item item, Pick pick,
|
private void allocateInventory(PickDetail pickDetail, Item item, Pick pick,
|
||||||
List<Inventory> matchedInventories, Map<Long, Inventory> inventoryUpdateMap,
|
List<Inventory> matchedInventories, List<Inventory> updateToInventory,
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap, List<Task> createToTask, List<Point> movePoints,
|
List<PickDetail> updateToPickDetail, List<Task> createToTask, List<Point> movePoints,
|
||||||
AllocationData data, BigDecimal totalUnAllocatedQty, Set<String> errorMsgSet) {
|
AllocationData data, BigDecimal totalUnAllocatedQty, Set<String> errorMsgSet) {
|
||||||
|
|
||||||
// 智能排序库存
|
// 智能排序库存
|
||||||
|
|
@ -556,9 +552,9 @@ public class AllocateProcessor {
|
||||||
//本次分配数量(取最小值)
|
//本次分配数量(取最小值)
|
||||||
BigDecimal allocateQty = remainingQty.min(availableQty);
|
BigDecimal allocateQty = remainingQty.min(availableQty);
|
||||||
// 更新库存
|
// 更新库存
|
||||||
updateInventoryAllocation(inventory, allocateQty, inventoryUpdateMap);
|
updateInventoryAllocation(inventory, allocateQty, updateToInventory);
|
||||||
// 更新拣货明细
|
// 更新拣货明细
|
||||||
updatePickDetailAllocation(pickDetail, allocateQty, pickDetailUpdateMap);
|
updatePickDetailAllocation(pickDetail, allocateQty, updateToPickDetail);
|
||||||
// 创建任务
|
// 创建任务
|
||||||
createPickTask(pickDetail, pick, item, inventory, inventoryScore, allocateQty, createToTask, data);
|
createPickTask(pickDetail, pick, item, inventory, inventoryScore, allocateQty, createToTask, data);
|
||||||
// 获取需要移位的库位
|
// 获取需要移位的库位
|
||||||
|
|
@ -767,68 +763,67 @@ public class AllocateProcessor {
|
||||||
/**
|
/**
|
||||||
* 更新库存
|
* 更新库存
|
||||||
*
|
*
|
||||||
* @param inventory 库存
|
* @param inventory 库存
|
||||||
* @param allocateQty 分配数量
|
* @param allocateQty 分配数量
|
||||||
* @param inventoryUpdateMap 库更新集合
|
* @param updateToInventory 库更新集合
|
||||||
*/
|
*/
|
||||||
private void updateInventoryAllocation(Inventory inventory, BigDecimal allocateQty,
|
private void updateInventoryAllocation(Inventory inventory, BigDecimal allocateQty,
|
||||||
Map<Long, Inventory> inventoryUpdateMap) {
|
List<Inventory> updateToInventory) {
|
||||||
Inventory targetInventory = inventoryUpdateMap.getOrDefault(inventory.getId(), inventory);
|
BigDecimal quantity = BigDecimalUtil.add(inventory.getQuantity(), allocateQty, 0);
|
||||||
BigDecimal newQueuedQty = BigDecimalUtil.add(targetInventory.getQueuedQty(), allocateQty, 0);
|
BigDecimal queuedQty = BigDecimalUtil.add(inventory.getQueuedQty(), allocateQty, 0);
|
||||||
targetInventory.setQueuedQty(newQueuedQty);
|
inventory.setQuantity(quantity);
|
||||||
targetInventory.setStatus(InventoryStatusEnum.ALLOCATED.getValue());
|
inventory.setQueuedQty(queuedQty);
|
||||||
inventoryUpdateMap.put(targetInventory.getId(), targetInventory);
|
inventory.setStatus(InventoryStatusEnum.ALLOCATED.getValue());
|
||||||
|
updateToInventory.add(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新出库明细
|
* 更新出库明细
|
||||||
*
|
*
|
||||||
* @param pickDetail 出库明细
|
* @param pickDetail 出库明细
|
||||||
* @param allocateQty 分配数量
|
* @param allocateQty 分配数量
|
||||||
* @param pickDetailUpdateMap 拣货明细更新集合
|
* @param updateToPickDetail 拣货明细更新集合
|
||||||
*/
|
*/
|
||||||
private void updatePickDetailAllocation(PickDetail pickDetail, BigDecimal allocateQty,
|
private void updatePickDetailAllocation(PickDetail pickDetail, BigDecimal allocateQty,
|
||||||
Map<Long, PickDetail> pickDetailUpdateMap) {
|
List<PickDetail> updateToPickDetail) {
|
||||||
PickDetail targetPickDetail = pickDetailUpdateMap.getOrDefault(pickDetail.getId(), pickDetail);
|
if (pickDetail == null) {
|
||||||
BigDecimal newAllocatedQty = BigDecimalUtil.add(targetPickDetail.getAllocatedQty(), allocateQty, 0);
|
return; // 安全保护
|
||||||
Integer status = newAllocatedQty.compareTo(targetPickDetail.getOrderQty()) >= 0 ?
|
}
|
||||||
PickStatusEnum.ASSIGNED.getValue() : PickStatusEnum.PARTIAL.getValue();
|
|
||||||
targetPickDetail.setAllocatedQty(newAllocatedQty);
|
|
||||||
targetPickDetail.setStatus(status);
|
|
||||||
pickDetailUpdateMap.put(targetPickDetail.getId(), targetPickDetail);
|
|
||||||
|
|
||||||
/* PickDetail detailToUpdate = pickDetailUpdateMap.computeIfAbsent(
|
// 累加分配数量
|
||||||
pickDetail.getId(), id -> {
|
BigDecimal existingQty = pickDetail.getAllocatedQty() == null
|
||||||
// 2. 用Builder实现拷贝
|
? BigDecimal.ZERO
|
||||||
return PickDetail.builder()
|
: pickDetail.getAllocatedQty();
|
||||||
.id(pickDetail.getId())
|
|
||||||
.pickId(pickDetail.getPickId())
|
|
||||||
.itemId(pickDetail.getItemId())
|
|
||||||
.lineNo(pickDetail.getLineNo())
|
|
||||||
.unit(pickDetail.getUnit())
|
|
||||||
.project(pickDetail.getProject())
|
|
||||||
.taskNo(pickDetail.getTaskNo())
|
|
||||||
.orderQty(pickDetail.getOrderQty())
|
|
||||||
.allocatedQty(BigDecimal.ZERO)
|
|
||||||
.pickedQty(pickDetail.getPickedQty())
|
|
||||||
.status(pickDetail.getStatus())
|
|
||||||
.propC1(pickDetail.getPropC1())
|
|
||||||
.propC3(pickDetail.getPropC3())
|
|
||||||
.description(pickDetail.getDescription())
|
|
||||||
.tenantId(pickDetail.getTenantId())
|
|
||||||
.sysOrgCode(pickDetail.getSysOrgCode())
|
|
||||||
.createBy(pickDetail.getCreateBy())
|
|
||||||
.createTime(pickDetail.getCreateTime())
|
|
||||||
.build();
|
|
||||||
});
|
|
||||||
|
|
||||||
BigDecimal newAllocatedQty = BigDecimalUtil.add(detailToUpdate.getAllocatedQty(), allocateQty, 0);
|
BigDecimal newAllocateQty = existingQty.add(allocateQty);
|
||||||
detailToUpdate.setAllocatedQty(newAllocatedQty);
|
|
||||||
|
// 订单总数量
|
||||||
|
BigDecimal orderQty = pickDetail.getOrderQty() == null
|
||||||
|
? BigDecimal.ZERO
|
||||||
|
: pickDetail.getOrderQty();
|
||||||
|
|
||||||
|
// 确保 newAllocateQty 不超过 orderQty
|
||||||
|
if (newAllocateQty.compareTo(orderQty) > 0) {
|
||||||
|
newAllocateQty = orderQty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新数量
|
||||||
|
pickDetail.setAllocatedQty(newAllocateQty);
|
||||||
|
|
||||||
|
// 计算状态:是否完全拣完
|
||||||
|
Integer status;
|
||||||
|
if (newAllocateQty.compareTo(orderQty) >= 0) {
|
||||||
|
status = PickStatusEnum.ASSIGNED.getValue();
|
||||||
|
} else if (newAllocateQty.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
status = PickStatusEnum.PARTIAL.getValue();
|
||||||
|
} else {
|
||||||
|
status = pickDetail.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
pickDetail.setStatus(status);
|
||||||
|
|
||||||
|
updateToPickDetail.add(pickDetail);
|
||||||
|
|
||||||
// 更新状态
|
|
||||||
Integer status = newAllocatedQty.compareTo(detailToUpdate.getOrderQty()) >= 0 ?
|
|
||||||
PickStatusEnum.ASSIGNED.getValue() : PickStatusEnum.PARTIAL.getValue();
|
|
||||||
detailToUpdate.setStatus(status);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -987,7 +982,7 @@ public class AllocateProcessor {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(moveInventoryList)){
|
if (CollectionUtils.isNotEmpty(moveInventoryList)) {
|
||||||
inventoryMapper.updateById(moveInventoryList);
|
inventoryMapper.updateById(moveInventoryList);
|
||||||
}
|
}
|
||||||
return moveList;
|
return moveList;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue