|
|
@ -38,14 +38,23 @@ public class WcsTaskServiceImpl implements WcsTaskService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void processWcsCallbackTask(WcsCallbackTask callbackTask) { |
|
|
public void processWcsCallbackTask(WcsCallbackTask callbackTask) { |
|
|
|
|
|
// 判断是否为超时恢复的任务 |
|
|
|
|
|
boolean isTimeoutRecovery = "处理中".equals(callbackTask.getStatus()); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
|
|
|
if (isTimeoutRecovery) { |
|
|
|
|
|
log.warn("检测到超时任务,尝试恢复:id={}, palletId={}, transType={}, processStartTime={}, retryCount={}", |
|
|
|
|
|
callbackTask.getId(), callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), |
|
|
|
|
|
callbackTask.getProcessStartTime(), callbackTask.getRetryCount()); |
|
|
|
|
|
} else { |
|
|
log.info("处理WCS回调任务:palletId={}, transType={}, currentStatus={}", |
|
|
log.info("处理WCS回调任务:palletId={}, transType={}, currentStatus={}", |
|
|
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), callbackTask.getStatus()); |
|
|
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), callbackTask.getStatus()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 1. 使用乐观锁更新状态为处理中(防止重复处理) |
|
|
// 1. 使用乐观锁更新状态为处理中(防止重复处理) |
|
|
int updateCount = wcsIntegrationMapper.updateWcsCallbackTaskStatusWithLock( |
|
|
int updateCount = wcsIntegrationMapper.updateWcsCallbackTaskStatusWithLock( |
|
|
callbackTask.getId(), |
|
|
callbackTask.getId(), |
|
|
callbackTask.getStatus(), // 原状态(已录入 or 处理失败) |
|
|
|
|
|
|
|
|
callbackTask.getStatus(), // 原状态(已录入 or 处理失败 or 处理中) |
|
|
"处理中", |
|
|
"处理中", |
|
|
new Date() |
|
|
new Date() |
|
|
); |
|
|
); |
|
|
@ -57,7 +66,8 @@ public class WcsTaskServiceImpl implements WcsTaskService { |
|
|
return; // 跳过,不抛异常 |
|
|
return; // 跳过,不抛异常 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info("成功锁定任务,开始处理:palletId={}", callbackTask.getPalletId()); |
|
|
|
|
|
|
|
|
log.info("成功锁定任务,开始处理:palletId={}, isTimeoutRecovery={}", |
|
|
|
|
|
callbackTask.getPalletId(), isTimeoutRecovery); |
|
|
|
|
|
|
|
|
// 3. 构建移库请求参数 |
|
|
// 3. 构建移库请求参数 |
|
|
WareHouseTransferRequest request = buildWareHouseTransferRequest(callbackTask); |
|
|
WareHouseTransferRequest request = buildWareHouseTransferRequest(callbackTask); |
|
|
@ -81,13 +91,20 @@ public class WcsTaskServiceImpl implements WcsTaskService { |
|
|
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), "已完成", null, new Date(), null); |
|
|
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), "已完成", null, new Date(), null); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("处理WCS回调任务失败:palletId={}", callbackTask.getPalletId(), e); // 记录完整堆栈 |
|
|
|
|
|
|
|
|
log.error("处理WCS回调任务失败:palletId={}, isTimeoutRecovery={}", |
|
|
|
|
|
callbackTask.getPalletId(), isTimeoutRecovery, e); // 记录完整堆栈 |
|
|
|
|
|
|
|
|
// 更新重试次数 |
|
|
|
|
|
int newRetryCount = (callbackTask.getRetryCount() == null ? 0 : callbackTask.getRetryCount()) + 1; |
|
|
|
|
|
|
|
|
// 更新重试次数(超时恢复的任务也算作一次重试) |
|
|
|
|
|
int currentRetryCount = (callbackTask.getRetryCount() == null ? 0 : callbackTask.getRetryCount()); |
|
|
|
|
|
int newRetryCount = isTimeoutRecovery ? currentRetryCount + 1 : currentRetryCount + 1; |
|
|
String status = newRetryCount >= 3 ? "处理失败" : "已录入"; // 重试3次后标记为失败 |
|
|
String status = newRetryCount >= 3 ? "处理失败" : "已录入"; // 重试3次后标记为失败 |
|
|
|
|
|
|
|
|
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), status, null, null, e.getMessage()); |
|
|
|
|
|
|
|
|
String errorMsg = (isTimeoutRecovery ? "[超时恢复]" : "") + e.getMessage(); |
|
|
|
|
|
|
|
|
|
|
|
log.warn("任务处理失败,更新状态:id={}, retryCount={}->{}, status={}", |
|
|
|
|
|
callbackTask.getId(), currentRetryCount, newRetryCount, status); |
|
|
|
|
|
|
|
|
|
|
|
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), status, null, null, errorMsg); |
|
|
wcsIntegrationMapper.updateWcsCallbackTaskRetryCount(callbackTask.getId(), newRetryCount); |
|
|
wcsIntegrationMapper.updateWcsCallbackTaskRetryCount(callbackTask.getId(), newRetryCount); |
|
|
|
|
|
|
|
|
throw new RuntimeException("处理WCS回调任务失败: " + e.getMessage(), e); |
|
|
throw new RuntimeException("处理WCS回调任务失败: " + e.getMessage(), e); |
|
|
|