opt:分离二次分配请求逻辑
This commit is contained in:
@@ -107,7 +107,12 @@ public interface AcsToWmsService {
|
||||
* @return
|
||||
*/
|
||||
HttpResponse feedTaskStatus(JSONArray arr);
|
||||
|
||||
/**
|
||||
* ACS向WMS反馈任务状态
|
||||
* @param arr
|
||||
* @return
|
||||
*/
|
||||
HttpResponse feedWmsTaskStatus(JSONArray arr);
|
||||
/**
|
||||
* ACS向WMS反馈任务状态
|
||||
* @param request
|
||||
|
||||
@@ -126,6 +126,98 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
public String applyTask(BaseRequest request) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 异步链路专用反馈方法(TaskServiceImpl.feedWmsTaskStatus异步提交调用):
|
||||
* 10秒超时 + 三次请求重试(间隔递增),与0x06同步分支使用的feedTaskStatus完全隔离,
|
||||
* 重试耗时发生在独立线程池,不会阻塞AGV报文处理线程
|
||||
*/
|
||||
@Override
|
||||
public HttpResponse feedWmsTaskStatus(JSONArray data) {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue();
|
||||
if (StrUtil.isEmpty(wmsurl)) {
|
||||
log.error("feedWmsTaskStatus-----WMS地址未配置,参数{}", data);
|
||||
return null;
|
||||
}
|
||||
String task_code = "";
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject json = (JSONObject) data.get(i);
|
||||
task_code = json.getString("task_code");
|
||||
}
|
||||
TaskDto taskDto = taskService.findByCode(task_code);
|
||||
if (taskDto == null) {
|
||||
log.error("feedWmsTaskStatus-----任务不存在,task_code:{}", task_code);
|
||||
return null;
|
||||
}
|
||||
AddressDto addressDto = addressService.findByCode("feedTaskStatus");
|
||||
if (addressDto == null || StrUtil.isEmpty(addressDto.getMethods_url())) {
|
||||
log.error("feedWmsTaskStatus-----反馈地址未配置,address:feedTaskStatus");
|
||||
return null;
|
||||
}
|
||||
String methods_url = addressDto.getMethods_url();
|
||||
HttpResponse result2 = null;
|
||||
log.info("feedWmsTaskStatus-----请求参数{}", data.toString());
|
||||
//网络失败自动重试3次,间隔递增,避免偶发网络抖动导致反馈丢失
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
try {
|
||||
result2 = HttpRequest.post(wmsurl + methods_url)
|
||||
.addInterceptor(tLogHutoolhttpInterceptor)
|
||||
.header(Header.USER_AGENT, "Hutool http")
|
||||
.header("Authorization", token)
|
||||
//连接+读取超时10秒,防止网络异常时线程长时间挂起
|
||||
.timeout(10000)
|
||||
.body(String.valueOf(data))
|
||||
.execute();
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
log.error("feedWmsTaskStatus-----第{}次请求失败,原因:{}", i, e.getMessage());
|
||||
if (i < 3) {
|
||||
try {
|
||||
Thread.sleep(1000L * i);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result2 == null) {
|
||||
log.error("feedWmsTaskStatus-----重试3次后仍失败,参数{}", data);
|
||||
return null;
|
||||
}
|
||||
LuceneLogDto luceneLogDto = new LuceneLogDto(4, "feedWmsTaskStatus", String.valueOf(result2.getStatus()),
|
||||
String.valueOf(data), String.valueOf(result2.body()), "ACS向WMS反馈任务状态");
|
||||
luceneLogService.interfaceExecuteLog(luceneLogDto);
|
||||
if (result2.getStatus() == 200) {
|
||||
JSONObject jo = JSONObject.parseObject(result2.body());
|
||||
// if (!StrUtil.isEmpty(jo.getString("finish_code"))) {
|
||||
// String finish_code = jo.getString("finish_code");
|
||||
// if ("2".equals(taskDto.getCar_type())) {
|
||||
// finish_code = finish_code + "-R";
|
||||
// }
|
||||
// taskDto.setNext_point_code(finish_code);
|
||||
// taskDto.setNext_device_code(finish_code);
|
||||
// taskDto.setTask_status("1");
|
||||
// taskService.update(taskDto);
|
||||
// Instruction instruction = instructionService.findBytaskCode(taskDto.getTask_id());
|
||||
// if (instruction != null) {
|
||||
// instruction.setNext_device_code(finish_code);
|
||||
// instruction.setNext_point_code(finish_code);
|
||||
// instructionService.update(instruction);
|
||||
// }
|
||||
// //找到最新的一条指令
|
||||
// }
|
||||
log.info("feedWmsTaskStatus-----输出参数{}", jo.toString());
|
||||
return result2;
|
||||
} else {
|
||||
log.error("feedWmsTaskStatus-----返回状态异常:{}", result2.getStatus());
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1699,7 +1699,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
|
||||
ja.add(feed_jo);
|
||||
//TODO 有需要根据上位系统反馈的信息再做进一步处理
|
||||
CompletableFuture.runAsync(() -> {
|
||||
acstowmsService.feedTaskStatus(ja);
|
||||
acstowmsService.feedWmsTaskStatus(ja);
|
||||
// 异步更新任务状态
|
||||
try {
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1074,7 +1074,6 @@ public class InBillServiceImpl extends ServiceImpl<IOStorInvMapper, IOStorInv> i
|
||||
);
|
||||
}
|
||||
}
|
||||
throw new BadRequestException("未找到库位信息");
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
||||
@@ -1583,7 +1583,6 @@ public class OutBillServiceImpl extends ServiceImpl<IOStorInvMapper, IOStorInv>
|
||||
towmsmsg.setTableData(tableData);
|
||||
// iWmsToWmsService.FinishOutTask(towmsmsg);
|
||||
notifyWmsAsync(towmsmsg);
|
||||
throw new BadRequestException("未找到该托盘的物料信息,检查一下该托盘是否已出库或在操作日志中查询该物料是否被删除!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user