|
|
|
@ -39,20 +39,35 @@ public class WcsTaskServiceImpl implements WcsTaskService { |
|
|
|
@Override |
|
|
|
public void processWcsCallbackTask(WcsCallbackTask callbackTask) { |
|
|
|
try { |
|
|
|
log.info("处理WCS回调任务:palletId={}, transType={}", callbackTask.getPalletId(), callbackTask.getTransTypeDesc()); |
|
|
|
log.info("处理WCS回调任务:palletId={}, transType={}, currentStatus={}", |
|
|
|
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), callbackTask.getStatus()); |
|
|
|
|
|
|
|
// 1. 使用乐观锁更新状态为处理中(防止重复处理) |
|
|
|
int updateCount = wcsIntegrationMapper.updateWcsCallbackTaskStatusWithLock( |
|
|
|
callbackTask.getId(), |
|
|
|
callbackTask.getStatus(), // 原状态(已录入 or 处理失败) |
|
|
|
"处理中", |
|
|
|
new Date() |
|
|
|
); |
|
|
|
|
|
|
|
// 2. 如果更新失败,说明已被其他线程处理,直接返回 |
|
|
|
if (updateCount == 0) { |
|
|
|
log.warn("任务已被其他线程处理,跳过:id={}, palletId={}, status={}", |
|
|
|
callbackTask.getId(), callbackTask.getPalletId(), callbackTask.getStatus()); |
|
|
|
return; // 跳过,不抛异常 |
|
|
|
} |
|
|
|
|
|
|
|
// 1. 更新状态为处理中 |
|
|
|
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), "处理中", new Date(), null, null); |
|
|
|
log.info("成功锁定任务,开始处理:palletId={}", callbackTask.getPalletId()); |
|
|
|
|
|
|
|
// 2. 构建移库请求参数 |
|
|
|
// 3. 构建移库请求参数 |
|
|
|
WareHouseTransferRequest request = buildWareHouseTransferRequest(callbackTask); |
|
|
|
|
|
|
|
// 3. 调用通用移库方法(原样调用,不修改) |
|
|
|
// 4. 调用通用移库方法(原样调用,不修改) |
|
|
|
String result = wmsMessageService.doWareHouseForPallet(request); |
|
|
|
|
|
|
|
log.info("WCS回调任务处理成功:palletId={}, result={}", callbackTask.getPalletId(), result); |
|
|
|
|
|
|
|
// 4. 如果是入库,更新对应的wms_order_task状态 |
|
|
|
// 5. 如果是入库,更新对应的wms_order_task状态 |
|
|
|
if ("入库".equals(callbackTask.getTransTypeDesc())) { |
|
|
|
updateOrderTaskStatusForInbound(callbackTask); |
|
|
|
//如果更新wcs库位 |
|
|
|
@ -62,11 +77,11 @@ public class WcsTaskServiceImpl implements WcsTaskService { |
|
|
|
wcsIntegrationMapper.updatePalletWcsLocation(callbackTask.getSite(), callbackTask.getPalletId(), ""); |
|
|
|
} |
|
|
|
|
|
|
|
// 5. 更新任务状态为已完成 |
|
|
|
// 6. 更新任务状态为已完成 |
|
|
|
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), "已完成", null, new Date(), null); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("处理WCS回调任务失败:palletId={}, error={}", callbackTask.getPalletId(), e.getMessage()); |
|
|
|
log.error("处理WCS回调任务失败:palletId={}", callbackTask.getPalletId(), e); // 记录完整堆栈 |
|
|
|
|
|
|
|
// 更新重试次数 |
|
|
|
int newRetryCount = (callbackTask.getRetryCount() == null ? 0 : callbackTask.getRetryCount()) + 1; |
|
|
|
|