|
|
|
@ -10,11 +10,7 @@ import com.gaotao.modules.api.service.RfidMachineApiService; |
|
|
|
import com.gaotao.modules.api.service.WcsApiService; |
|
|
|
import com.gaotao.modules.api.service.WmsMessageService; |
|
|
|
|
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.AgvStation; |
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.CancelTaskResult; |
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.PalletDetailData; |
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.WmsTransportTask; |
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.WmsTransportTaskDetail; |
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.*; |
|
|
|
import com.gaotao.modules.automatedWarehouse.entity.tusk.TuskResponse; |
|
|
|
import com.gaotao.modules.automatedWarehouse.mapper.AgvTaskMapper; |
|
|
|
import com.gaotao.modules.automatedWarehouse.service.TuskClientService; |
|
|
|
@ -53,13 +49,13 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
private WcsApiService wcsApiService; |
|
|
|
@Autowired |
|
|
|
private WcsIntegrationMapper wcsIntegrationMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WmsMessageService wmsMessageService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PalletService palletService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private TuskClientService tuskClientService; |
|
|
|
@Autowired |
|
|
|
@ -88,7 +84,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
public List<WmsTransportTask> getNeedPalletTask() { |
|
|
|
return agvTaskMapper.getNeedPalletTask(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取待处理的预约运输栈板任务 - rqrq |
|
|
|
* @return 预约运输栈板任务列表 |
|
|
|
@ -149,10 +145,10 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
null, // 配置ID(可根据需要调整) |
|
|
|
task.getPriority() // 优先级 |
|
|
|
); |
|
|
|
|
|
|
|
log.info("成功调用AGV接口创建任务:taskNo={}, targets={}, priority={}", |
|
|
|
|
|
|
|
log.info("成功调用AGV接口创建任务:taskNo={}, targets={}, priority={}", |
|
|
|
task.getTaskNo(), targets, task.getPriority()); |
|
|
|
|
|
|
|
|
|
|
|
// 下发成功,清除错误信息(失败不影响主流程)- rqrq |
|
|
|
try { |
|
|
|
agvTaskMapper.clearTransportTaskError(task.getSite(), task.getTaskNo()); |
|
|
|
@ -160,10 +156,10 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} catch (Exception ex) { |
|
|
|
log.warn("清除错误信息失败,不影响主流程:taskNo={}, error={} - rqrq", task.getTaskNo(), ex.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("下发AGV任务失败:taskNo={}, error={}", task.getTaskNo(), e.getMessage(), e); |
|
|
|
|
|
|
|
|
|
|
|
// 记录错误信息到error_code和error_msg - rqrq |
|
|
|
String errorMsg = e.getMessage(); |
|
|
|
if (errorMsg != null && errorMsg.length() > 500) { |
|
|
|
@ -176,7 +172,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} catch (Exception ex) { |
|
|
|
log.warn("记录错误信息失败,不影响主流程:taskNo={}, error={} - rqrq", task.getTaskNo(), ex.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new RuntimeException("下发AGV任务失败:" + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -191,18 +187,18 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
public void processAgvFeedbackTask(WmsTransportTaskDetail taskDetail) { |
|
|
|
// 1. 先锁定记录,将状态改为'处理中',防止重复处理 - rqrq |
|
|
|
int lockResult = wcsIntegrationMapper.lockTaskDetailForProcessing(taskDetail.getId()); |
|
|
|
|
|
|
|
|
|
|
|
if (lockResult == 0) { |
|
|
|
// 锁定失败,说明已被其他线程处理,直接跳过 - rqrq |
|
|
|
log.info("任务明细已被其他线程处理,跳过:taskNo={}, id={}", taskDetail.getTaskNo(), taskDetail.getId()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("成功锁定任务明细,开始处理:taskNo={}, id={}", taskDetail.getTaskNo(), taskDetail.getId()); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 记录原始状态,用于失败时回滚 - rqrq |
|
|
|
String originalStatus = taskDetail.getStatus(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
WmsTransportTask checkTask = wcsIntegrationMapper.getTransportTaskByTaskNo(taskDetail.getTaskNo()); |
|
|
|
if (checkTask == null) { |
|
|
|
@ -292,14 +288,14 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
String station = null; |
|
|
|
log.info("开始处理等待询问回调 - rqrq:目标站点={}", checkTask.getToLocation()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ⚠️ 判断是否为立库站点D1或D2 - rqrq |
|
|
|
// D1、D2是立库管理的特殊站点,实际状态由立库PLC管理 |
|
|
|
// WMS通过"等待询问"机制实现动态分配 - rqrq |
|
|
|
if("400166".equals(taskDetail.getToLocation())){ |
|
|
|
//------Rfid通道机--------- |
|
|
|
log.info("目标站点为RFID通道机站点,推送订单信息到RFID通道机 - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 获取栈板明细数据(包含reserve_order_ref3工单号)- rqrq |
|
|
|
List<PalletDetailData> palletDetails = wcsIntegrationMapper.getPalletDetailsData( |
|
|
|
taskDetail.getSite(), checkTask.getPalletId()); |
|
|
|
@ -333,12 +329,12 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
checkTask.getPalletId(), palletDetails.size()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 调用RFID通道机接口(如果报错会抛出RuntimeException,等下次循环再请求)- rqrq |
|
|
|
rfidMachineApiService.pushCheckToRfid(rfidRequest); |
|
|
|
|
|
|
|
|
|
|
|
log.info("推送订单信息到RFID通道机成功 - rqrq,托盘={}", checkTask.getPalletId()); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 成功后插入新的任务明细记录 - rqrq |
|
|
|
WmsTransportTaskDetail newDetail = new WmsTransportTaskDetail(); |
|
|
|
newDetail.setSite(taskDetail.getSite()); |
|
|
|
@ -350,18 +346,18 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
newDetail.setStatus("等待中"); |
|
|
|
newDetail.setToLocation(taskDetail.getToLocation()); |
|
|
|
wcsIntegrationMapper.insertWmsTransportTaskDetail(newDetail); |
|
|
|
|
|
|
|
|
|
|
|
log.info("任务明细记录插入成功 - rqrq,actionType=等待通道机复核,status=等待中"); |
|
|
|
|
|
|
|
|
|
|
|
}else if(checkTask.getToLocation().equals("D1") || checkTask.getToLocation().equals("D2")){ |
|
|
|
log.info("目标站点为立库站点,询问立库分配放货点 - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 释放WMS的原目标站点状态记录 - rqrq |
|
|
|
// 注:此处只是释放WMS的状态记录,不影响立库PLC的实际状态 - rqrq |
|
|
|
wcsIntegrationMapper.updateAgvStationStatusWithLock(checkTask.getToLocation(),2, 0, "空闲"); |
|
|
|
log.info("原目标站点{}状态已更新为空闲(WMS相对记录)- rqrq", checkTask.getToLocation()); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 询问立库PLC分配实际可用的放货点 - rqrq |
|
|
|
// 立库PLC根据实际状态返回D1或D2 - rqrq |
|
|
|
WarehouseAskStation askStation = new WarehouseAskStation(); |
|
|
|
@ -376,60 +372,60 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
if(station == null || (!station.equals("D1") && !station.equals("D2"))){ |
|
|
|
throw new RuntimeException("立库返回放货点有误!!"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 更新立库返回的站点状态为待放货(WMS相对记录)- rqrq |
|
|
|
wcsIntegrationMapper.updateAgvStationStatus(station, 2, "待放货"); |
|
|
|
log.info("立库返回站点{},状态已更新为待放货(WMS相对记录)- rqrq", station); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
// 非立库站点,查询原目标点状态 - rqrq |
|
|
|
log.info("目标站点为普通站点,查询站点状态 - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
// 1. 查询原目标点的状态 - rqrq |
|
|
|
AgvStation targetAgvStation = wcsIntegrationMapper.getAgvStation(checkTask.getToLocation()); |
|
|
|
|
|
|
|
|
|
|
|
if (targetAgvStation == null) { |
|
|
|
throw new RuntimeException("目标站点不存在:" + checkTask.getToLocation()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Integer targetStatusDb = targetAgvStation.getStatusDb(); |
|
|
|
log.info("目标站点{}当前状态:statusDb={} - rqrq", checkTask.getToLocation(), targetStatusDb); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 判断状态是否为待放货(2)或空闲(0) - rqrq |
|
|
|
if (targetStatusDb != null && (targetStatusDb == 2 || targetStatusDb == 0)) { |
|
|
|
// 状态正常,使用原目标点 - rqrq |
|
|
|
station = checkTask.getToLocation(); |
|
|
|
log.info("目标站点状态正常,使用原目标点:{} - rqrq", station); |
|
|
|
|
|
|
|
|
|
|
|
// 如果是空闲状态,需要更新为待放货 - rqrq |
|
|
|
if (targetStatusDb == 0) { |
|
|
|
wcsIntegrationMapper.updateAgvStationStatus(station, 2, "待放货"); |
|
|
|
log.info("目标站点{}状态从空闲更新为待放货 - rqrq", station); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
// 状态异常(有货或待取货),需要在同区域查找空闲站点 - rqrq |
|
|
|
log.info("目标站点状态异常(statusDb={}),需要在同区域查找空闲站点 - rqrq", targetStatusDb); |
|
|
|
|
|
|
|
|
|
|
|
// 获取目标站点的区域 - rqrq |
|
|
|
String areaType = targetAgvStation.getAreaType(); |
|
|
|
|
|
|
|
|
|
|
|
if (areaType == null || areaType.isEmpty()) { |
|
|
|
throw new RuntimeException("目标站点区域信息为空,无法查找替代站点"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("目标站点区域:{} - rqrq", areaType); |
|
|
|
|
|
|
|
|
|
|
|
// 在同区域查找第一个空闲站点 - rqrq |
|
|
|
String freeStation = wcsIntegrationMapper.findFirstFreeStationByArea(areaType); |
|
|
|
|
|
|
|
|
|
|
|
if (freeStation == null || freeStation.isEmpty()) { |
|
|
|
throw new RuntimeException("区域【" + areaType + "】中未找到空闲站点"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
station = freeStation; |
|
|
|
log.info("在区域【{}】中找到空闲站点:{} - rqrq", areaType, station); |
|
|
|
|
|
|
|
|
|
|
|
// 更新找到的站点状态为待放货 - rqrq |
|
|
|
wcsIntegrationMapper.updateAgvStationStatus(station, 2, "待放货"); |
|
|
|
log.info("站点{}状态已更新为待放货 - rqrq", station); |
|
|
|
@ -442,15 +438,15 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
log.info("AGV任务{}放货点已修改为:{} - rqrq", taskDetail.getTaskNo(), station); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 处理成功,更新任务明细状态为已完成 - rqrq |
|
|
|
wcsIntegrationMapper.updateTransportTaskDetailStatusForId(taskDetail.getId(), "已完成"); |
|
|
|
log.info("任务明细处理成功:taskNo={}, id={}", taskDetail.getTaskNo(), taskDetail.getId()); |
|
|
|
|
|
|
|
|
|
|
|
// 4. 处理成功,清除错误信息 - rqrq |
|
|
|
wcsIntegrationMapper.clearTransportTaskDetailError(taskDetail.getId()); |
|
|
|
log.info("任务明细错误信息已清除:taskNo={}, id={}", taskDetail.getTaskNo(), taskDetail.getId()); |
|
|
|
|
|
|
|
|
|
|
|
// if("WCS运输栈板".equals(checkTask.getSourceType())){ |
|
|
|
// AgvFeedBackToWcs pushWcs=new AgvFeedBackToWcs(); |
|
|
|
// pushWcs.setPalletId(checkTask.getPalletId()); |
|
|
|
@ -464,11 +460,11 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
// } 遗弃方法 |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("处理AGV回调数据失败:taskNo={}, error={}", taskDetail.getTaskNo(), e.getMessage(), e); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 处理失败,将状态改回原始状态 - rqrq |
|
|
|
wcsIntegrationMapper.updateTransportTaskDetailStatusForId(taskDetail.getId(), originalStatus); |
|
|
|
log.info("处理失败,状态已回滚到:{}", originalStatus); |
|
|
|
|
|
|
|
|
|
|
|
// 6. 记录错误信息到error_code和error_msg - rqrq |
|
|
|
String errorMsg = e.getMessage(); |
|
|
|
if (errorMsg != null && errorMsg.length() > 500) { |
|
|
|
@ -476,7 +472,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} |
|
|
|
wcsIntegrationMapper.updateTransportTaskDetailWithError(taskDetail.getId(), "500", errorMsg); |
|
|
|
log.info("任务明细错误信息已记录:taskNo={}, id={}, errorCode=500", taskDetail.getTaskNo(), taskDetail.getId()); |
|
|
|
|
|
|
|
|
|
|
|
throw new RuntimeException("处理AGV回调任务失败: " + e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -559,7 +555,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
throw new RuntimeException("更新栈板位置失败:" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 取消AGV运输任务 - rqrq |
|
|
|
* @Title cancelAgvTask |
|
|
|
@ -573,7 +569,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public CancelTaskResult cancelAgvTask(String site, String taskNo) { |
|
|
|
System.out.println("开始取消AGV任务 - rqrq,site=" + site + ",taskNo=" + taskNo); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 1. 查询主任务 - rqrq |
|
|
|
WmsTransportTask task = agvTaskMapper.getTaskByTaskNo(site, taskNo); |
|
|
|
@ -581,7 +577,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
System.out.println("任务不存在 - rqrq,taskNo=" + taskNo); |
|
|
|
return new CancelTaskResult(false, "任务不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 检查任务状态 - rqrq |
|
|
|
if ("已完成".equals(task.getStatus())) { |
|
|
|
System.out.println("任务已完成,无法取消 - rqrq"); |
|
|
|
@ -591,15 +587,15 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
System.out.println("任务已取消 - rqrq"); |
|
|
|
return new CancelTaskResult(true, "任务已取消"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 查询任务明细,判断任务进度 - rqrq |
|
|
|
List<WmsTransportTaskDetail> details = agvTaskMapper.getTransportTaskDetails(taskNo); |
|
|
|
System.out.println("查询到任务明细数量:" + (details != null ? details.size() : 0) + " - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
boolean hasSendFinish = false; |
|
|
|
boolean hasPickupFinish = false; |
|
|
|
boolean hasWaitAsk = false; |
|
|
|
|
|
|
|
|
|
|
|
if (details != null && !details.isEmpty()) { |
|
|
|
for (WmsTransportTaskDetail detail : details) { |
|
|
|
if ("送货完成".equals(detail.getActionType())) { |
|
|
|
@ -613,21 +609,21 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 如果有送货完成记录,不允许取消 - rqrq |
|
|
|
if (hasSendFinish) { |
|
|
|
System.out.println("任务已完成,无法取消 - rqrq"); |
|
|
|
return new CancelTaskResult(false, "任务已完成,无法取消"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 5. 判断是否需要调用WCS取消接口 - rqrq |
|
|
|
// 如果任务状态是"已预约"或"已创建",说明还没有下达到AGV,不需要调用WCS接口 - rqrq |
|
|
|
boolean needCallWcs = !"已预约".equals(task.getStatus()) && !"已创建".equals(task.getStatus()); |
|
|
|
System.out.println("任务状态:" + task.getStatus() + ",是否需要调用WCS接口:" + needCallWcs + " - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
boolean wcsSuccess = false; |
|
|
|
String wcsMessage = ""; |
|
|
|
|
|
|
|
|
|
|
|
if (needCallWcs) { |
|
|
|
// 调用WCS取消接口(不抛异常,记录结果)- rqrq |
|
|
|
try { |
|
|
|
@ -646,7 +642,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
wcsMessage = "任务状态为" + task.getStatus() + ",未下达到AGV,无需调用WCS接口"; |
|
|
|
System.out.println(wcsMessage + " - rqrq"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 6. 根据不同场景处理 - rqrq |
|
|
|
CancelTaskResult result; |
|
|
|
if (hasWaitAsk) { |
|
|
|
@ -681,17 +677,80 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
//把这个site+taskNo关联出的wms_transport_task_detail的status改成 已取消 - rqrq |
|
|
|
wcsIntegrationMapper.updateTaskDetailStatusByTaskNo(site, taskNo, "已取消"); |
|
|
|
System.out.println("已更新任务明细状态为已取消 - rqrq,taskNo=" + taskNo); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("AGV任务取消完成 - rqrq,result=" + result.getMessage()); |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println("取消AGV任务异常 - rqrq:" + e.getMessage()); |
|
|
|
log.error("取消AGV任务异常", e); |
|
|
|
return new CancelTaskResult(false, "取消任务失败:" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 取消并重试分拣位补盘 - rqrq |
|
|
|
* 先按现有取消把这张运输任务停掉:已下给 AGV 的会调 TUSK,TUSK 失败也继续把 WMS 任务改成已取消并释放站点。 |
|
|
|
* 然后用任务上的目标站点、WCS 任务号,以及托盘类型主数据上的 WCS 整型,拼出补盘报文再调 wcsNeedPalletTask。 |
|
|
|
* 报文 site 固定 55,documents 固定空列表。补盘失败必须抛出,让本方法和取消写在同一个事务里一起回滚。 - rqrq |
|
|
|
* @param data 页面传来的工厂和 WMS 任务号 |
|
|
|
* @author rqrq |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void cancelAndRetryNeedPallet(CancelRetryNeedPalletData data) { |
|
|
|
if (data == null || data.getSite() == null || data.getSite().trim().isEmpty() |
|
|
|
|| data.getTaskNo() == null || data.getTaskNo().trim().isEmpty()) { |
|
|
|
throw new RuntimeException("工厂和任务号不能为空"); |
|
|
|
} |
|
|
|
String site = data.getSite().trim(); |
|
|
|
String taskNo = data.getTaskNo().trim(); |
|
|
|
|
|
|
|
// 取消前先读出原任务。取消后数据库状态会变,补盘报文要用这里记下的站点、WCS任务号和托盘类型 - rqrq |
|
|
|
WmsTransportTask task = agvTaskMapper.getTaskByTaskNo(site, taskNo); |
|
|
|
if (task == null) { |
|
|
|
throw new RuntimeException("任务不存在"); |
|
|
|
} |
|
|
|
if ("已完成".equals(task.getStatus()) || "已取消".equals(task.getStatus())) { |
|
|
|
throw new RuntimeException("已完成或已取消的任务不能取消并重试"); |
|
|
|
} |
|
|
|
if (task.getWcsTaskId() == null || task.getWcsTaskId().trim().isEmpty()) { |
|
|
|
throw new RuntimeException("任务没有WCS任务号,不能取消并重试"); |
|
|
|
} |
|
|
|
if (task.getToLocation() == null || task.getToLocation().trim().isEmpty()) { |
|
|
|
throw new RuntimeException("任务没有目标站点,不能重发补盘"); |
|
|
|
} |
|
|
|
if (task.getPalletType() == null || task.getPalletType().trim().isEmpty()) { |
|
|
|
throw new RuntimeException("任务没有托盘类型,不能重发补盘"); |
|
|
|
} |
|
|
|
|
|
|
|
// 用任务所属工厂查托盘类型主数据,取出 WCS 整型托盘类型和底托类型。查不到就不能拼报文,此时还没取消 - rqrq |
|
|
|
PalletType palletType = wcsIntegrationMapper.getPalletType(task.getSite(), task.getPalletType().trim()); |
|
|
|
if (palletType == null || palletType.getWcsPalletType() == null || palletType.getWcsBasePalletType() == null) { |
|
|
|
throw new RuntimeException("托盘类型【" + task.getPalletType().trim() + "】未配置WCS托盘类型或底托类型,不能重发补盘"); |
|
|
|
} |
|
|
|
|
|
|
|
// 走现有取消。TUSK 失败时取消结果仍是成功,WMS 任务、站点和 calling_flag 会按原逻辑处理;这里不因 TUSK 失败中断 - rqrq |
|
|
|
CancelTaskResult cancelResult = cancelAgvTask(site, taskNo); |
|
|
|
if (cancelResult == null || !cancelResult.isSuccess()) { |
|
|
|
String cancelMessage = cancelResult == null ? "取消任务失败" : cancelResult.getMessage(); |
|
|
|
throw new RuntimeException(cancelMessage); |
|
|
|
} |
|
|
|
|
|
|
|
WcsNeedPalletTask needPalletTask = new WcsNeedPalletTask(); |
|
|
|
// 补盘报文 site、空明细是约定固定值;站点、WCS任务号和两个整型来自刚取消的这张任务 - rqrq |
|
|
|
needPalletTask.setSite("55"); |
|
|
|
needPalletTask.setDocuments(new ArrayList<>()); |
|
|
|
needPalletTask.setStationCode(task.getToLocation().trim()); |
|
|
|
needPalletTask.setWcsTaskId(task.getWcsTaskId().trim()); |
|
|
|
needPalletTask.setPalletType(palletType.getWcsPalletType()); |
|
|
|
needPalletTask.setBasePalletType(palletType.getWcsBasePalletType()); |
|
|
|
|
|
|
|
// 同步重发补盘,生成新的预约取托盘并继承原 wcsTaskId。抛错会回滚上面的 WMS 取消;TUSK 已发出的取消回滚不了 - rqrq |
|
|
|
wmsMessageService.wcsNeedPalletTask(needPalletTask); |
|
|
|
log.info("取消并重试补盘完成,原任务号: {},WCS任务号: {},站点: {}", taskNo, task.getWcsTaskId(), task.getToLocation()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 处理未取货场景的取消(场景1/2)- rqrq |
|
|
|
* @param task 运输任务 |
|
|
|
@ -700,17 +759,17 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
* @return 取消结果 |
|
|
|
* @author rqrq |
|
|
|
*/ |
|
|
|
private CancelTaskResult handleNotPickupCancel(WmsTransportTask task, |
|
|
|
private CancelTaskResult handleNotPickupCancel(WmsTransportTask task, |
|
|
|
boolean wcsSuccess, String wcsMessage) { |
|
|
|
System.out.println("处理未取货场景取消 - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 1. 起始站点恢复有货 - rqrq |
|
|
|
if (task.getFromLocation() != null && !task.getFromLocation().isEmpty()) { |
|
|
|
System.out.println("恢复起始站点为有货 - rqrq:" + task.getFromLocation()); |
|
|
|
wcsIntegrationMapper.updateAgvStationStatus(task.getFromLocation(), 1, null); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 目标站点恢复空闲 - rqrq |
|
|
|
if (task.getToLocation() != null && !task.getToLocation().isEmpty()) { |
|
|
|
System.out.println("恢复目标站点为空闲 - rqrq:" + task.getToLocation()); |
|
|
|
@ -725,11 +784,11 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
wcsIntegrationMapper.updatePalletCallingFlag(task.getSite(), task.getPalletId(), "N", null, "SYS_WMS"); |
|
|
|
palletOperationLogService.logPalletOperation(task.getPalletId(), task.getSite(),"调用托盘","AGV取消任务停止调用托盘","是否调用","Y","N",username,task.getTaskNo()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 更新任务状态 - rqrq |
|
|
|
System.out.println("更新任务状态为已取消 - rqrq"); |
|
|
|
wcsIntegrationMapper.updateTransportTaskStatusByTaskNo(task.getSite(), task.getTaskNo(), "已取消"); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 构造返回消息 - rqrq |
|
|
|
String message = "任务已取消,起始站点已恢复有货,目标站点已恢复空闲"; |
|
|
|
if (wcsSuccess) { |
|
|
|
@ -737,20 +796,20 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} else { |
|
|
|
message += ",AGV小车同步取消失败:" + wcsMessage; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CancelTaskResult result = new CancelTaskResult(true, message, false, "未取货"); |
|
|
|
result.setWcsApiSuccess(wcsSuccess); |
|
|
|
result.setWcsApiMessage(wcsMessage); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("未取货场景取消处理完成 - rqrq"); |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println("未取货场景取消处理异常 - rqrq:" + e.getMessage()); |
|
|
|
throw new RuntimeException("资源恢复失败:" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 处理已取货场景的取消(场景3)- rqrq |
|
|
|
* @param task 运输任务 |
|
|
|
@ -759,10 +818,10 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
* @return 取消结果 |
|
|
|
* @author rqrq |
|
|
|
*/ |
|
|
|
private CancelTaskResult handlePickupFinishCancel(WmsTransportTask task, |
|
|
|
private CancelTaskResult handlePickupFinishCancel(WmsTransportTask task, |
|
|
|
boolean wcsSuccess, String wcsMessage) { |
|
|
|
System.out.println("处理已取货场景取消 - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 1. 起始站点空闲 - rqrq |
|
|
|
// if (task.getFromLocation() != null && !task.getFromLocation().isEmpty()) { |
|
|
|
@ -777,7 +836,7 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
wcsIntegrationMapper.updateAgvStationStatus(task.getToLocation(), 0, null); |
|
|
|
wcsIntegrationMapper.updateAgvStationAutoFlag(task.getToLocation(),"N"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 栈板清空位置 - rqrq |
|
|
|
if (task.getPalletId() != null && !task.getPalletId().isEmpty()) { |
|
|
|
// 检查栈板位置对应的区域类型是否为Z105,Z105区域不清空位置 - rqrq |
|
|
|
@ -797,11 +856,11 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
wcsIntegrationMapper.updatePalletCallingFlag(task.getSite(), task.getPalletId(), "N", null, "SYS_WMS"); |
|
|
|
palletOperationLogService.logPalletOperation(task.getPalletId(), task.getSite(),"调用托盘","AGV取消任务停止调用托盘","是否调用","Y","N",username,task.getTaskNo()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 更新任务状态 - rqrq |
|
|
|
System.out.println("更新任务状态为已取消 - rqrq"); |
|
|
|
wcsIntegrationMapper.updateTransportTaskStatusByTaskNo(task.getSite(), task.getTaskNo(), "已取消"); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 构造返回消息 - rqrq |
|
|
|
String message = "任务已取消,栈板在运输中被取消,栈板位置已清空,需人工确认AGV实际位置"; |
|
|
|
if (wcsSuccess) { |
|
|
|
@ -809,20 +868,20 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} else { |
|
|
|
message += ",AGV小车同步取消失败(WCS接口异常,需手动干预)"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CancelTaskResult result = new CancelTaskResult(true, message, true, "运输中"); |
|
|
|
result.setWcsApiSuccess(wcsSuccess); |
|
|
|
result.setWcsApiMessage(wcsMessage); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("已取货场景取消处理完成 - rqrq"); |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println("已取货场景取消处理异常 - rqrq:" + e.getMessage()); |
|
|
|
throw new RuntimeException("资源恢复失败:" + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 处理等待询问场景的取消(场景4)- rqrq |
|
|
|
* @param task 运输任务 |
|
|
|
@ -831,24 +890,24 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
* @return 取消结果 |
|
|
|
* @author rqrq |
|
|
|
*/ |
|
|
|
private CancelTaskResult handleWaitAskCancel(WmsTransportTask task, |
|
|
|
private CancelTaskResult handleWaitAskCancel(WmsTransportTask task, |
|
|
|
boolean wcsSuccess, String wcsMessage) { |
|
|
|
System.out.println("处理等待询问场景取消 - rqrq"); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 1. 起始站点空闲 - rqrq |
|
|
|
// if (task.getFromLocation() != null && !task.getFromLocation().isEmpty()) { |
|
|
|
// System.out.println("设置起始站点为空闲 - rqrq:" + task.getFromLocation()); |
|
|
|
// wcsIntegrationMapper.updateAgvStationStatus(task.getFromLocation(), 0, null); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 2. 目标站点空闲 - rqrq |
|
|
|
if (task.getToLocation() != null && !task.getToLocation().isEmpty()) { |
|
|
|
System.out.println("设置目标站点为空闲 - rqrq:" + task.getToLocation()); |
|
|
|
wcsIntegrationMapper.updateAgvStationStatus(task.getToLocation(), 0, null); |
|
|
|
wcsIntegrationMapper.updateAgvStationAutoFlag(task.getToLocation(),"N"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 栈板清空位置 - rqrq |
|
|
|
if (task.getPalletId() != null && !task.getPalletId().isEmpty()) { |
|
|
|
String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername(); |
|
|
|
@ -869,11 +928,11 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
wcsIntegrationMapper.updatePalletCallingFlag(task.getSite(), task.getPalletId(), "N", null, "SYS_WMS"); |
|
|
|
palletOperationLogService.logPalletOperation(task.getPalletId(), task.getSite(),"调用托盘","AGV取消任务停止调用托盘","是否调用","Y","N",username,task.getTaskNo()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 更新任务状态 - rqrq |
|
|
|
System.out.println("更新任务状态为已取消 - rqrq"); |
|
|
|
wcsIntegrationMapper.updateTransportTaskStatusByTaskNo(task.getSite(), task.getTaskNo(), "已取消"); |
|
|
|
|
|
|
|
|
|
|
|
// 5. 构造返回消息 - rqrq |
|
|
|
String message = "任务已取消(等待询问状态),栈板位置已清空,需人工确认AGV实际位置"; |
|
|
|
if (wcsSuccess) { |
|
|
|
@ -881,14 +940,14 @@ public class AgvTaskServiceImpl implements AgvTaskService { |
|
|
|
} else { |
|
|
|
message += ",AGV小车同步取消失败:" + wcsMessage; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CancelTaskResult result = new CancelTaskResult(true, message, true, "等待询问"); |
|
|
|
result.setWcsApiSuccess(wcsSuccess); |
|
|
|
result.setWcsApiMessage(wcsMessage); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("等待询问场景取消处理完成 - rqrq"); |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println("等待询问场景取消处理异常 - rqrq:" + e.getMessage()); |
|
|
|
throw new RuntimeException("资源恢复失败:" + e.getMessage()); |
|
|
|
|