Browse Source

分拣异常处理

master
常熟吴彦祖 3 months ago
parent
commit
c92bd66f4b
  1. 33
      src/main/java/com/gaotao/modules/api/service/impl/WmsMessageServiceImpl.java
  2. 232
      src/main/java/com/gaotao/modules/automatedWarehouse/service/impl/WcsTaskServiceImpl.java

33
src/main/java/com/gaotao/modules/api/service/impl/WmsMessageServiceImpl.java

@ -332,6 +332,9 @@ public class WmsMessageServiceImpl implements WmsMessageService {
case "取走栈板": case "取走栈板":
result = processPalletRemoval(inData); result = processPalletRemoval(inData);
break; break;
case "异常位处理":
result = processErrorStation(inData);
break;
default: default:
throw new RuntimeException("不支持的事务类型:" + inData.getTransTypeDesc()); throw new RuntimeException("不支持的事务类型:" + inData.getTransTypeDesc());
} }
@ -500,6 +503,14 @@ public class WmsMessageServiceImpl implements WmsMessageService {
return "取走栈板回调数据已保存,站点已更新为空闲"; return "取走栈板回调数据已保存,站点已更新为空闲";
} }
private String processErrorStation(PalletWareHouseData inData){
String toWarehouseId = BufferZoneConfig.BUFFER_WAREHOUSE_ID.getValue();
String toLocationId = BufferZoneConfig.BUFFER_LOCATION_ID.getValue();
saveWcsCallbackTaskWithRemark(inData, toWarehouseId, toLocationId,inData.getRemark());
return "异常位处理数据已保存。";
}
/** /**
* @Description 站点编码转换WCS的1099/1093映射为D1/D2- rqrq * @Description 站点编码转换WCS的1099/1093映射为D1/D2- rqrq
@ -551,6 +562,28 @@ public class WmsMessageServiceImpl implements WmsMessageService {
inData.getPalletId(), inData.getTransTypeDesc(), toWarehouseId, toLocationId); inData.getPalletId(), inData.getTransTypeDesc(), toWarehouseId, toLocationId);
} }
private void saveWcsCallbackTaskWithRemark(PalletWareHouseData inData, String toWarehouseId, String toLocationId,String remark) {
WcsCallbackTask callbackTask = new WcsCallbackTask();
callbackTask.setSite(inData.getSite());
callbackTask.setPalletId(inData.getPalletId());
callbackTask.setTransTypeDesc(inData.getTransTypeDesc());
callbackTask.setToWarehouseId(toWarehouseId);
callbackTask.setToLocationId(toLocationId);
callbackTask.setStatus("已录入"); // 等待定时任务处理 - rqrq
callbackTask.setCreatedTime(new Date());
callbackTask.setRetryCount(0);
callbackTask.setRemark(remark);
callbackTask.setTaskNo(inData.getTaskNo());
callbackTask.setItemNo(inData.getItemNo());
callbackTask.setToStation(inData.getToBarcode());
// 保存到WCS回调任务表 - rqrq
wcsIntegrationMapper.insertWcsCallbackTask(callbackTask);
log.info("WCS回调任务已保存 - rqrq:栈板={}, 类型={}, 目标位置={}-{}",
inData.getPalletId(), inData.getTransTypeDesc(), toWarehouseId, toLocationId);
}
@Override @Override
@Transactional @Transactional
public String doWareHouseForPallet(WareHouseTransferRequest request) { public String doWareHouseForPallet(WareHouseTransferRequest request) {

232
src/main/java/com/gaotao/modules/automatedWarehouse/service/impl/WcsTaskServiceImpl.java

@ -39,16 +39,16 @@ public class WcsTaskServiceImpl implements WcsTaskService {
private WcsIntegrationService wcsIntegrationService; private WcsIntegrationService wcsIntegrationService;
@Autowired @Autowired
private WcsIntegrationMapper wcsIntegrationMapper; private WcsIntegrationMapper wcsIntegrationMapper;
@Autowired @Autowired
private WmsMessageService wmsMessageService; private WmsMessageService wmsMessageService;
@Autowired @Autowired
private WcsApiService wcsApiService; private WcsApiService wcsApiService;
@Autowired @Autowired
private AutoTaskService autoTaskService; private AutoTaskService autoTaskService;
@Autowired @Autowired
private NewIssureMapper newIssureMapper; private NewIssureMapper newIssureMapper;
@Autowired @Autowired
@ -65,17 +65,17 @@ public class WcsTaskServiceImpl implements WcsTaskService {
public void processWcsCallbackTask(WcsCallbackTask callbackTask) { public void processWcsCallbackTask(WcsCallbackTask callbackTask) {
// 判断是否为超时恢复的任务 - rqrq // 判断是否为超时恢复的任务 - rqrq
boolean isTimeoutRecovery = "处理中".equals(callbackTask.getStatus()); boolean isTimeoutRecovery = "处理中".equals(callbackTask.getStatus());
try { try {
if (isTimeoutRecovery) { if (isTimeoutRecovery) {
log.warn("检测到超时任务,尝试恢复:id={}, palletId={}, transType={}, processStartTime={}, retryCount={}",
callbackTask.getId(), callbackTask.getPalletId(), callbackTask.getTransTypeDesc(),
callbackTask.getProcessStartTime(), callbackTask.getRetryCount());
log.warn("检测到超时任务,尝试恢复:id={}, palletId={}, transType={}, processStartTime={}, retryCount={}",
callbackTask.getId(), callbackTask.getPalletId(), callbackTask.getTransTypeDesc(),
callbackTask.getProcessStartTime(), callbackTask.getRetryCount());
} else { } else {
log.info("处理WCS回调任务:palletId={}, transType={}, currentStatus={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), callbackTask.getStatus());
log.info("处理WCS回调任务:palletId={}, transType={}, currentStatus={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), callbackTask.getStatus());
} }
// 获取用户名 - rqrq // 获取用户名 - rqrq
// List<WmsOrderTask> orderTasks = wcsIntegrationMapper.findOrderTasksByTaskNo( // List<WmsOrderTask> orderTasks = wcsIntegrationMapper.findOrderTasksByTaskNo(
// callbackTask.getSite(), // callbackTask.getSite(),
@ -85,25 +85,25 @@ public class WcsTaskServiceImpl implements WcsTaskService {
// if (orderTasks != null && !orderTasks.isEmpty()) { // if (orderTasks != null && !orderTasks.isEmpty()) {
// userName = orderTasks.get(0).getCreatedBy(); // userName = orderTasks.get(0).getCreatedBy();
// } // }
// 1. 使用乐观锁更新状态为处理中防止重复处理- rqrq // 1. 使用乐观锁更新状态为处理中防止重复处理- rqrq
int updateCount = wcsIntegrationMapper.updateWcsCallbackTaskStatusWithLock( int updateCount = wcsIntegrationMapper.updateWcsCallbackTaskStatusWithLock(
callbackTask.getId(),
callbackTask.getStatus(), // 原状态已录入 or 处理失败 or 处理中
"处理中",
new Date()
callbackTask.getId(),
callbackTask.getStatus(), // 原状态已录入 or 处理失败 or 处理中
"处理中",
new Date()
); );
// 2. 如果更新失败说明已被其他线程处理直接返回 - rqrq // 2. 如果更新失败说明已被其他线程处理直接返回 - rqrq
if (updateCount == 0) { if (updateCount == 0) {
log.warn("任务已被其他线程处理,跳过:id={}, palletId={}, status={}",
callbackTask.getId(), callbackTask.getPalletId(), callbackTask.getStatus());
log.warn("任务已被其他线程处理,跳过:id={}, palletId={}, status={}",
callbackTask.getId(), callbackTask.getPalletId(), callbackTask.getStatus());
return; // 跳过不抛异常 return; // 跳过不抛异常
} }
log.info("成功锁定任务,开始处理:palletId={}, transType={}, isTimeoutRecovery={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), isTimeoutRecovery);
log.info("成功锁定任务,开始处理:palletId={}, transType={}, isTimeoutRecovery={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), isTimeoutRecovery);
// 3. 根据不同的TransTypeDesc执行不同的处理逻辑 - rqrq // 3. 根据不同的TransTypeDesc执行不同的处理逻辑 - rqrq
String result = ""; String result = "";
if ("入库".equals(callbackTask.getTransTypeDesc()) || "出库".equals(callbackTask.getTransTypeDesc())) { if ("入库".equals(callbackTask.getTransTypeDesc()) || "出库".equals(callbackTask.getTransTypeDesc())) {
@ -114,11 +114,11 @@ public class WcsTaskServiceImpl implements WcsTaskService {
// 更新托盘状态 - rqrq // 更新托盘状态 - rqrq
if ("入库".equals(callbackTask.getTransTypeDesc())) { if ("入库".equals(callbackTask.getTransTypeDesc())) {
updateOrderTaskStatusForInbound(callbackTask); updateOrderTaskStatusForInbound(callbackTask);
palletMapper.updateLocationWithPalletId(request.getSite(),request.getPalletId(),request.getToStation(),request.getToStation());
palletMapper.updateLocationWithPalletId(request.getSite(), request.getPalletId(), request.getToStation(), request.getToStation());
wcsIntegrationMapper.updatePalletCallingFlag(callbackTask.getSite(), callbackTask.getPalletId(), "N", "SYS_WMS"); wcsIntegrationMapper.updatePalletCallingFlag(callbackTask.getSite(), callbackTask.getPalletId(), "N", "SYS_WMS");
} else { } else {
palletMapper.updateLocationWithPalletId(request.getSite(),request.getPalletId(),"Virtual_AS",null);
palletMapper.updateLocationWithPalletId(request.getSite(), request.getPalletId(), "Virtual_AS", null);
// wcsIntegrationMapper.updatePalletWcsLocation(callbackTask.getSite(), callbackTask.getPalletId(), null); // wcsIntegrationMapper.updatePalletWcsLocation(callbackTask.getSite(), callbackTask.getPalletId(), null);
wcsIntegrationMapper.updatePalletCallingFlag(callbackTask.getSite(), callbackTask.getPalletId(), "Y", "SYS_WMS"); wcsIntegrationMapper.updatePalletCallingFlag(callbackTask.getSite(), callbackTask.getPalletId(), "Y", "SYS_WMS");
@ -129,34 +129,37 @@ public class WcsTaskServiceImpl implements WcsTaskService {
} else if ("取走栈板".equals(callbackTask.getTransTypeDesc())) { } else if ("取走栈板".equals(callbackTask.getTransTypeDesc())) {
// 取走栈板更新站点状态 - rqrq // 取走栈板更新站点状态 - rqrq
result = processPalletRemoval(callbackTask); result = processPalletRemoval(callbackTask);
} else if ("异常位处理".equals(callbackTask.getTransTypeDesc())) {
// 取走栈板更新站点状态 - rqrq
result = processErrorStation(callbackTask);
} else { } else {
throw new RuntimeException("不支持的事务类型:" + callbackTask.getTransTypeDesc()); throw new RuntimeException("不支持的事务类型:" + callbackTask.getTransTypeDesc());
} }
log.info("WCS回调任务处理成功:palletId={}, transType={}, result={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), result);
log.info("WCS回调任务处理成功:palletId={}, transType={}, result={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), result);
// 6. 更新任务状态为已完成 - rqrq // 6. 更新任务状态为已完成 - rqrq
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={}, transType={}, isTimeoutRecovery={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), isTimeoutRecovery, e);
log.error("处理WCS回调任务失败:palletId={}, transType={}, isTimeoutRecovery={}",
callbackTask.getPalletId(), callbackTask.getTransTypeDesc(), isTimeoutRecovery, e);
// 更新重试次数超时恢复的任务也算作一次重试- rqrq // 更新重试次数超时恢复的任务也算作一次重试- rqrq
int currentRetryCount = (callbackTask.getRetryCount() == null ? 0 : callbackTask.getRetryCount()); int currentRetryCount = (callbackTask.getRetryCount() == null ? 0 : callbackTask.getRetryCount());
int newRetryCount = isTimeoutRecovery ? currentRetryCount + 1 : currentRetryCount + 1; int newRetryCount = isTimeoutRecovery ? currentRetryCount + 1 : currentRetryCount + 1;
String status = newRetryCount >= 3 ? "处理失败" : "已录入"; // 重试3次后标记为失败 String status = newRetryCount >= 3 ? "处理失败" : "已录入"; // 重试3次后标记为失败
String errorMsg = (isTimeoutRecovery ? "[超时恢复]" : "") + e.getMessage(); String errorMsg = (isTimeoutRecovery ? "[超时恢复]" : "") + e.getMessage();
log.warn("任务处理失败,更新状态:id={}, retryCount={}->{}, status={}",
callbackTask.getId(), currentRetryCount, newRetryCount, status);
log.warn("任务处理失败,更新状态:id={}, retryCount={}->{}, status={}",
callbackTask.getId(), currentRetryCount, newRetryCount, status);
// 更新失败状态到日志表 - rqrq // 更新失败状态到日志表 - rqrq
wcsIntegrationMapper.updateWcsCallbackTaskStatus(callbackTask.getId(), status, null, null, errorMsg); 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);
} }
} }
@ -171,7 +174,7 @@ public class WcsTaskServiceImpl implements WcsTaskService {
public void processWcsPalletOutTask(WmsOrderTask orderTask) { public void processWcsPalletOutTask(WmsOrderTask orderTask) {
try { try {
log.info("处理立库调栈板任务:taskNo={}, palletId={}", orderTask.getTaskNo(), orderTask.getPalletId()); log.info("处理立库调栈板任务:taskNo={}, palletId={}", orderTask.getTaskNo(), orderTask.getPalletId());
// 1. 检查重试次数避免无限重试 // 1. 检查重试次数避免无限重试
int currentRetryCount = getCurrentRetryCount(orderTask); int currentRetryCount = getCurrentRetryCount(orderTask);
if (currentRetryCount >= 3) { if (currentRetryCount >= 3) {
@ -179,29 +182,29 @@ public class WcsTaskServiceImpl implements WcsTaskService {
wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), "处理失败", "重试次数超限"); wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), "处理失败", "重试次数超限");
return; return;
} }
// 2. 更新状态为处理中 // 2. 更新状态为处理中
wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), "处理中", "调用WCS中"); wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), "处理中", "调用WCS中");
// 3. 调用WCS出库方法 // 3. 调用WCS出库方法
String result = callPalletOutWcs(orderTask); String result = callPalletOutWcs(orderTask);
log.info("立库调栈板任务处理成功:taskNo={}, result={}", orderTask.getTaskNo(), result); log.info("立库调栈板任务处理成功:taskNo={}, result={}", orderTask.getTaskNo(), result);
// 4. 更新任务状态为已完成 // 4. 更新任务状态为已完成
wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), "已下达", "WCS调用成功"); wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), "已下达", "WCS调用成功");
} catch (Exception e) { } catch (Exception e) {
log.error("处理立库调栈板任务失败:taskNo={}, error={}", orderTask.getTaskNo(), e.getMessage()); log.error("处理立库调栈板任务失败:taskNo={}, error={}", orderTask.getTaskNo(), e.getMessage());
// 更新重试次数和错误信息 // 更新重试次数和错误信息
int newRetryCount = getCurrentRetryCount(orderTask) + 1; int newRetryCount = getCurrentRetryCount(orderTask) + 1;
String status = newRetryCount >= 3 ? "处理失败" : "已创建"; // 重试3次后标记为失败 String status = newRetryCount >= 3 ? "处理失败" : "已创建"; // 重试3次后标记为失败
String wmsStatus = newRetryCount >= 3 ? "重试次数超限" : "等待重试"; String wmsStatus = newRetryCount >= 3 ? "重试次数超限" : "等待重试";
wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), status, wmsStatus); wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(orderTask.getId(), status, wmsStatus);
wcsIntegrationMapper.updateOrderTaskErrorInfo(orderTask.getId(), "WCS_CALL_ERROR", e.getMessage()); wcsIntegrationMapper.updateOrderTaskErrorInfo(orderTask.getId(), "WCS_CALL_ERROR", e.getMessage());
throw new RuntimeException("处理立库调栈板任务失败: " + e.getMessage(), e); throw new RuntimeException("处理立库调栈板任务失败: " + e.getMessage(), e);
} }
} }
@ -209,7 +212,7 @@ public class WcsTaskServiceImpl implements WcsTaskService {
@Override @Override
public WareHouseTransferRequest buildWareHouseTransferRequest(WcsCallbackTask callbackTask) { public WareHouseTransferRequest buildWareHouseTransferRequest(WcsCallbackTask callbackTask) {
WareHouseTransferRequest request = new WareHouseTransferRequest(); WareHouseTransferRequest request = new WareHouseTransferRequest();
// 从回调任务中获取基本信息 - rqrq // 从回调任务中获取基本信息 - rqrq
request.setSite(callbackTask.getSite()); request.setSite(callbackTask.getSite());
request.setPalletId(callbackTask.getPalletId()); request.setPalletId(callbackTask.getPalletId());
@ -217,7 +220,7 @@ public class WcsTaskServiceImpl implements WcsTaskService {
request.setToLocationId(callbackTask.getToLocationId()); request.setToLocationId(callbackTask.getToLocationId());
request.setTransType("移库"); request.setTransType("移库");
request.setToStation(callbackTask.getToStation()); // 立库内的站点都为* request.setToStation(callbackTask.getToStation()); // 立库内的站点都为*
// 根据transTypeDesc判断业务类型 - rqrq // 根据transTypeDesc判断业务类型 - rqrq
if ("入库".equals(callbackTask.getTransTypeDesc())) { if ("入库".equals(callbackTask.getTransTypeDesc())) {
request.setBusinessType("立库入库"); request.setBusinessType("立库入库");
@ -236,12 +239,13 @@ public class WcsTaskServiceImpl implements WcsTaskService {
} else { } else {
throw new RuntimeException("不支持的事务类型:" + callbackTask.getTransTypeDesc()); throw new RuntimeException("不支持的事务类型:" + callbackTask.getTransTypeDesc());
} }
return request; return request;
} }
/** /**
* 更新入库对应的订单任务状态 * 更新入库对应的订单任务状态
*
* @param callbackTask WCS回调任务 * @param callbackTask WCS回调任务
*/ */
private void updateOrderTaskStatusForInbound(WcsCallbackTask callbackTask) { private void updateOrderTaskStatusForInbound(WcsCallbackTask callbackTask) {
@ -251,47 +255,48 @@ public class WcsTaskServiceImpl implements WcsTaskService {
callbackTask.getSite(), callbackTask.getSite(),
callbackTask.getTaskNo() callbackTask.getTaskNo()
); );
if (orderTasks != null && !orderTasks.isEmpty()) { if (orderTasks != null && !orderTasks.isEmpty()) {
for (WmsOrderTask orderTask : orderTasks) { for (WmsOrderTask orderTask : orderTasks) {
// 更新wms_order_task的status为已完成wms_status为已完成 // 更新wms_order_task的status为已完成wms_status为已完成
wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus( wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(
orderTask.getId(), "已完成", "已完成"
orderTask.getId(), "已完成", "已完成"
); );
// 更新对应的wms_order_task_detail状态为已完成 // 更新对应的wms_order_task_detail状态为已完成
wcsIntegrationMapper.updateOrderTaskDetailStatusByTaskNo( wcsIntegrationMapper.updateOrderTaskDetailStatusByTaskNo(
orderTask.getTaskNo(), "已完成", "已完成"
orderTask.getTaskNo(), "已完成", "已完成"
); );
log.info("已更新订单任务状态:taskNo={}, palletId={}",
orderTask.getTaskNo(), callbackTask.getPalletId());
log.info("已更新订单任务状态:taskNo={}, palletId={}",
orderTask.getTaskNo(), callbackTask.getPalletId());
} }
} else { } else {
log.warn("未找到对应的组盘入库订单任务:palletId={}", callbackTask.getPalletId()); log.warn("未找到对应的组盘入库订单任务:palletId={}", callbackTask.getPalletId());
} }
} catch (Exception e) { } catch (Exception e) {
log.error("更新订单任务状态失败:palletId={}, error={}",
callbackTask.getPalletId(), e.getMessage());
log.error("更新订单任务状态失败:palletId={}, error={}",
callbackTask.getPalletId(), e.getMessage());
// 不抛出异常避免影响主流程 // 不抛出异常避免影响主流程
} }
} }
/** /**
* 调用WCS出库方法 * 调用WCS出库方法
*
* @param orderTask 订单任务 * @param orderTask 订单任务
* @return 调用结果 * @return 调用结果
*/ */
private String callPalletOutWcs(WmsOrderTask orderTask) { private String callPalletOutWcs(WmsOrderTask orderTask) {
try { try {
// 调用具体的WCS出库接口 // 调用具体的WCS出库接口
log.info("调用WCS出库接口:taskNo={}, palletId={}, fromLocation={}, toLocation={}",
orderTask.getTaskNo(), orderTask.getPalletId(), orderTask.getFromLocation(), orderTask.getToLocation());
log.info("调用WCS出库接口:taskNo={}, palletId={}, fromLocation={}, toLocation={}",
orderTask.getTaskNo(), orderTask.getPalletId(), orderTask.getFromLocation(), orderTask.getToLocation());
wcsApiService.pushWCSTaskApi(orderTask); wcsApiService.pushWCSTaskApi(orderTask);
return "WCS出库调用成功"; return "WCS出库调用成功";
} catch (Exception e) { } catch (Exception e) {
log.error("调用WCS出库接口失败:taskNo={}, error={}", orderTask.getTaskNo(), e.getMessage()); log.error("调用WCS出库接口失败:taskNo={}, error={}", orderTask.getTaskNo(), e.getMessage());
throw new RuntimeException("WCS出库调用失败:" + e.getMessage()); throw new RuntimeException("WCS出库调用失败:" + e.getMessage());
@ -300,6 +305,7 @@ public class WcsTaskServiceImpl implements WcsTaskService {
/** /**
* 获取当前任务的重试次数 * 获取当前任务的重试次数
*
* @param orderTask 订单任务 * @param orderTask 订单任务
* @return 重试次数 * @return 重试次数
*/ */
@ -319,9 +325,9 @@ public class WcsTaskServiceImpl implements WcsTaskService {
} }
/** /**
* @Description 处理取货通知 - rqrq
* @param callbackTask WCS回调任务 * @param callbackTask WCS回调任务
* @return 处理结果 * @return 处理结果
* @Description 处理取货通知 - rqrq
* @author rqrq * @author rqrq
* @date 2025/10/24 * @date 2025/10/24
*/ */
@ -341,12 +347,12 @@ public class WcsTaskServiceImpl implements WcsTaskService {
if (callbackTask.getTaskNo() != null && callbackTask.getItemNo() != null) { if (callbackTask.getTaskNo() != null && callbackTask.getItemNo() != null) {
WmsOrderTask orderTask = wcsIntegrationMapper.findOrderTasksByTaskNoItem( WmsOrderTask orderTask = wcsIntegrationMapper.findOrderTasksByTaskNoItem(
callbackTask.getSite(), callbackTask.getTaskNo(), callbackTask.getItemNo()); callbackTask.getSite(), callbackTask.getTaskNo(), callbackTask.getItemNo());
if (orderTask == null){
if (orderTask == null) {
return "取货通知处理成功"; return "取货通知处理成功";
} }
if ( !"领料申请单".equals(orderTask.getSourceType()) && !"发货通知单".equals(orderTask.getSourceType())) {
if (!"领料申请单".equals(orderTask.getSourceType()) && !"发货通知单".equals(orderTask.getSourceType())) {
wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus( wcsIntegrationMapper.updateOrderTaskStatusAndWmsStatus(
orderTask.getId(), "已完成", "已完成"); orderTask.getId(), "已完成", "已完成");
wcsIntegrationMapper.updateOrderTaskDetailStatusByTaskNoPalletId( wcsIntegrationMapper.updateOrderTaskDetailStatusByTaskNoPalletId(
@ -365,27 +371,27 @@ public class WcsTaskServiceImpl implements WcsTaskService {
callbackTask.getSite(), callbackTask.getPalletId()); callbackTask.getSite(), callbackTask.getPalletId());
if (checkIfHasNeedTask == null) { if (checkIfHasNeedTask == null) {
System.out.println("栈板{}没有预约任务,检查是否有预留物料 - rqrq"+callbackTask.getPalletId());
System.out.println("栈板{}没有预约任务,检查是否有预留物料 - rqrq" + callbackTask.getPalletId());
// 获取栈板明细 - rqrq // 获取栈板明细 - rqrq
List<PalletDetailData> palletDetailList = wcsIntegrationMapper.getPalletDetailsData( List<PalletDetailData> palletDetailList = wcsIntegrationMapper.getPalletDetailsData(
callbackTask.getSite(), callbackTask.getPalletId()); callbackTask.getSite(), callbackTask.getPalletId());
boolean hasReservePart = false; boolean hasReservePart = false;
if (palletDetailList != null && !palletDetailList.isEmpty()) { if (palletDetailList != null && !palletDetailList.isEmpty()) {
// 收集所有序列号 - rqrq // 收集所有序列号 - rqrq
List<String> serialNos = palletDetailList.stream() List<String> serialNos = palletDetailList.stream()
.map(PalletDetailData::getSerialNo) .map(PalletDetailData::getSerialNo)
.collect(Collectors.toList()); .collect(Collectors.toList());
// 查询handling_unit的reserve_order_ref信息 - rqrq // 查询handling_unit的reserve_order_ref信息 - rqrq
List<HandlingUnitReserveInfo> reserveInfoList =
List<HandlingUnitReserveInfo> reserveInfoList =
wcsIntegrationMapper.getReserveOrderRefsBySerialNos(callbackTask.getSite(), serialNos); wcsIntegrationMapper.getReserveOrderRefsBySerialNos(callbackTask.getSite(), serialNos);
// 检查是否有预留物料reserve_flag='Y'或reserve_order_ref1不为空- rqrq // 检查是否有预留物料reserve_flag='Y'或reserve_order_ref1不为空- rqrq
hasReservePart = reserveInfoList.stream() hasReservePart = reserveInfoList.stream()
.anyMatch(r -> r.getReserveOrderRef1() != null && !r.getReserveOrderRef1().isEmpty()); .anyMatch(r -> r.getReserveOrderRef1() != null && !r.getReserveOrderRef1().isEmpty());
if (hasReservePart) { if (hasReservePart) {
deliveryTaskService.createDeliveryTaskByPallet(callbackTask.getSite(), callbackTask.getPalletId()); deliveryTaskService.createDeliveryTaskByPallet(callbackTask.getSite(), callbackTask.getPalletId());
// try { // try {
@ -439,24 +445,24 @@ public class WcsTaskServiceImpl implements WcsTaskService {
// 更新SOIssueNotifyOrderMaterialList_detail的out_wcs_flag以及wms_order_task状态 - rqrq // 更新SOIssueNotifyOrderMaterialList_detail的out_wcs_flag以及wms_order_task状态 - rqrq
try { try {
log.info("开始批量更新栈板{}的申请单和任务状态 - rqrq", callbackTask.getPalletId()); log.info("开始批量更新栈板{}的申请单和任务状态 - rqrq", callbackTask.getPalletId());
// 1. 收集所有序列号已在369行收集- rqrq // 1. 收集所有序列号已在369行收集- rqrq
log.info("收集到序列号数量:{} - rqrq", serialNos.size()); log.info("收集到序列号数量:{} - rqrq", serialNos.size());
// 2. 根据序列号列表查询SOIssueNotifyOrderMaterialList_detail明细 - rqrq // 2. 根据序列号列表查询SOIssueNotifyOrderMaterialList_detail明细 - rqrq
List<com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail> notifyDetails =
wcsIntegrationMapper.getSOIssueNotifyDetailsBySerialNos(callbackTask.getSite(), serialNos);
List<com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail> notifyDetails =
wcsIntegrationMapper.getSOIssueNotifyDetailsBySerialNos(callbackTask.getSite(), serialNos);
log.info("查询到申请单明细数量:{} - rqrq", notifyDetails.size()); log.info("查询到申请单明细数量:{} - rqrq", notifyDetails.size());
// 3. 批量更新out_wcs_flag为Y性能优化一次UPDATE替代N次- rqrq
// 3. 批量更新out_wcs_flag为Y性能优化一次UPDATE替代N次- rqrq
if (!notifyDetails.isEmpty()) { if (!notifyDetails.isEmpty()) {
List<String> serialNosToUpdate = notifyDetails.stream() List<String> serialNosToUpdate = notifyDetails.stream()
.map(com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail::getSerialNo)
.collect(Collectors.toList());
.map(com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail::getSerialNo)
.collect(Collectors.toList());
wcsIntegrationMapper.batchUpdateSOIssueNotifyDetailOutWcsFlag(callbackTask.getSite(), serialNosToUpdate); wcsIntegrationMapper.batchUpdateSOIssueNotifyDetailOutWcsFlag(callbackTask.getSite(), serialNosToUpdate);
log.info("批量更新{}个序列号的out_wcs_flag为Y - rqrq", serialNosToUpdate.size()); log.info("批量更新{}个序列号的out_wcs_flag为Y - rqrq", serialNosToUpdate.size());
} }
// 4. 收集需要更新的任务明细去重task_ref+task_item+task_seq- rqrq // 4. 收集需要更新的任务明细去重task_ref+task_item+task_seq- rqrq
List<com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey> taskDetailsToUpdate = new ArrayList<>(); List<com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey> taskDetailsToUpdate = new ArrayList<>();
for (com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail notifyDetail : notifyDetails) { for (com.gaotao.modules.notify.entity.SOIssueNotifyOrderMaterialListDetail notifyDetail : notifyDetails) {
@ -465,42 +471,42 @@ public class WcsTaskServiceImpl implements WcsTaskService {
log.debug("跳过task_seq为0或null的记录,序列号={} - rqrq", notifyDetail.getSerialNo()); log.debug("跳过task_seq为0或null的记录,序列号={} - rqrq", notifyDetail.getSerialNo());
continue; continue;
} }
taskDetailsToUpdate.add(new com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey( taskDetailsToUpdate.add(new com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey(
notifyDetail.getTaskRef(),
notifyDetail.getTaskItem(),
notifyDetail.getTaskSeq()
notifyDetail.getTaskRef(),
notifyDetail.getTaskItem(),
notifyDetail.getTaskSeq()
)); ));
} }
// 5. 批量更新wms_order_task_detail状态性能优化一次UPDATE替代N次- rqrq // 5. 批量更新wms_order_task_detail状态性能优化一次UPDATE替代N次- rqrq
if (!taskDetailsToUpdate.isEmpty()) { if (!taskDetailsToUpdate.isEmpty()) {
wcsIntegrationMapper.batchUpdateWmsOrderTaskDetailStatus(callbackTask.getSite(), taskDetailsToUpdate); wcsIntegrationMapper.batchUpdateWmsOrderTaskDetailStatus(callbackTask.getSite(), taskDetailsToUpdate);
log.info("批量更新{}个任务明细状态为已完成/直接出库 - rqrq", taskDetailsToUpdate.size()); log.info("批量更新{}个任务明细状态为已完成/直接出库 - rqrq", taskDetailsToUpdate.size());
} }
// 6. 收集涉及的taskNo+itemNo组合去重- rqrq // 6. 收集涉及的taskNo+itemNo组合去重- rqrq
List<com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey> taskKeysToCheck = taskDetailsToUpdate.stream() List<com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey> taskKeysToCheck = taskDetailsToUpdate.stream()
.map(detail -> new com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey(
detail.getTaskNo(), detail.getItemNo()))
.distinct()
.collect(Collectors.toList());
.map(detail -> new com.gaotao.modules.automatedWarehouse.entity.TaskDetailKey(
detail.getTaskNo(), detail.getItemNo()))
.distinct()
.collect(Collectors.toList());
// 7. 批量更新所有已完成任务的主表状态性能优化一次UPDATE替代N次SELECT+UPDATE- rqrq // 7. 批量更新所有已完成任务的主表状态性能优化一次UPDATE替代N次SELECT+UPDATE- rqrq
if (!taskKeysToCheck.isEmpty()) { if (!taskKeysToCheck.isEmpty()) {
wcsIntegrationMapper.batchUpdateCompletedTaskStatus(callbackTask.getSite(), taskKeysToCheck); wcsIntegrationMapper.batchUpdateCompletedTaskStatus(callbackTask.getSite(), taskKeysToCheck);
log.info("批量检查并更新{}个任务主表状态为已完成 - rqrq", taskKeysToCheck.size()); log.info("批量检查并更新{}个任务主表状态为已完成 - rqrq", taskKeysToCheck.size());
} }
log.info("批量更新栈板{}的申请单和任务状态完成 - rqrq", callbackTask.getPalletId()); log.info("批量更新栈板{}的申请单和任务状态完成 - rqrq", callbackTask.getPalletId());
} catch (Exception ex) { } catch (Exception ex) {
// 更新任务状态失败不影响主流程只打印日志 - rqrq // 更新任务状态失败不影响主流程只打印日志 - rqrq
log.error("更新栈板{}的任务状态失败 - rqrq:{}", callbackTask.getPalletId(), ex.getMessage()); log.error("更新栈板{}的任务状态失败 - rqrq:{}", callbackTask.getPalletId(), ex.getMessage());
ex.printStackTrace(); ex.printStackTrace();
} }
} else { } else {
System.out.println("栈板{}无预留物料,不创建配送任务 - rqrq"+callbackTask.getPalletId());
System.out.println("栈板{}无预留物料,不创建配送任务 - rqrq" + callbackTask.getPalletId());
} }
} }
} else { } else {
@ -508,10 +514,10 @@ public class WcsTaskServiceImpl implements WcsTaskService {
} }
} }
System.out.println("处理取货通知完成 - rqrq,palletId=" + callbackTask.getPalletId()); System.out.println("处理取货通知完成 - rqrq,palletId=" + callbackTask.getPalletId());
return "取货通知处理成功"; return "取货通知处理成功";
} catch (Exception e) { } catch (Exception e) {
System.err.println("处理取货通知失败 - rqrq:" + e.getMessage()); System.err.println("处理取货通知失败 - rqrq:" + e.getMessage());
throw new RuntimeException("处理取货通知失败: " + e.getMessage(), e); throw new RuntimeException("处理取货通知失败: " + e.getMessage(), e);
@ -519,31 +525,45 @@ public class WcsTaskServiceImpl implements WcsTaskService {
} }
/** /**
* @Description 处理取走栈板 - rqrq
* @param callbackTask WCS回调任务 * @param callbackTask WCS回调任务
* @return 处理结果 * @return 处理结果
* @Description 处理取走栈板 - rqrq
* @author rqrq * @author rqrq
* @date 2025/10/24 * @date 2025/10/24
*/ */
private String processPalletRemoval(WcsCallbackTask callbackTask) { private String processPalletRemoval(WcsCallbackTask callbackTask) {
System.out.println("开始处理取走栈板 - rqrq,palletId=" + callbackTask.getPalletId() + ", toStation=" + callbackTask.getToStation()); System.out.println("开始处理取走栈板 - rqrq,palletId=" + callbackTask.getPalletId() + ", toStation=" + callbackTask.getToStation());
try { try {
// 1. 检查toStation是否以D开头滚筒对接区- rqrq // 1. 检查toStation是否以D开头滚筒对接区- rqrq
if (callbackTask.getToStation() == null || !callbackTask.getToStation().startsWith("D")) { if (callbackTask.getToStation() == null || !callbackTask.getToStation().startsWith("D")) {
throw new RuntimeException("目前只有滚筒对接区(D1/D2)可以执行取走栈板操作,当前站点:" + callbackTask.getToStation()); throw new RuntimeException("目前只有滚筒对接区(D1/D2)可以执行取走栈板操作,当前站点:" + callbackTask.getToStation());
} }
// 2. 更新站点状态为空闲 - rqrq // 2. 更新站点状态为空闲 - rqrq
// wcsIntegrationMapper.updateAgvStationStatus(callbackTask.getToStation(), 0, "空闲"); // wcsIntegrationMapper.updateAgvStationStatus(callbackTask.getToStation(), 0, "空闲");
System.out.println("处理取走栈板完成 - rqrq,palletId=" + callbackTask.getPalletId() + ", 站点" + callbackTask.getToStation() + "已更新为空闲"); System.out.println("处理取走栈板完成 - rqrq,palletId=" + callbackTask.getPalletId() + ", 站点" + callbackTask.getToStation() + "已更新为空闲");
return "取走栈板处理成功,站点已更新为空闲"; return "取走栈板处理成功,站点已更新为空闲";
} catch (Exception e) { } catch (Exception e) {
System.err.println("处理取走栈板失败 - rqrq:" + e.getMessage()); System.err.println("处理取走栈板失败 - rqrq:" + e.getMessage());
throw new RuntimeException("处理取走栈板失败: " + e.getMessage(), e); throw new RuntimeException("处理取走栈板失败: " + e.getMessage(), e);
} }
} }
}
private String processErrorStation(WcsCallbackTask callbackTask) {
System.out.println("开始处理取走栈板 - rqrq,palletId=" + callbackTask.getPalletId() + ", toStation=" + callbackTask.getToStation());
int rows = palletMapper.updatePalletToErrorStatus(
callbackTask.getSite(),
callbackTask.getPalletId(),
callbackTask.getToStation()
);
log.info("更新托盘为异常状态 - rqrq,site={},palletId={},异常处理位={}",
callbackTask.getSite(),
callbackTask.getPalletId(),
callbackTask.getToStation());
return "异常位处理成功";
}
}
Loading…
Cancel
Save