opt:acs入库异常修改
This commit is contained in:
@@ -36,6 +36,7 @@ import org.nl.acs.route.service.RouteLineService;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.acs.task.service.dto.TaskDto;
|
||||
import org.nl.acs.utils.DeviceErrorUtil;
|
||||
import org.nl.common.utils.CodeUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.config.language.LangProcess;
|
||||
import org.nl.config.lucene.service.LuceneExecuteLogService;
|
||||
@@ -328,8 +329,8 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
try {
|
||||
|
||||
// 使用统一方法更新出库任务数并同步数据库
|
||||
updateAndSyncOutboundTaskNum(-1, true, true);
|
||||
Integer result = this.outbound_task_num;
|
||||
int result = instructionService.queryInstructionCount(this.device_code);
|
||||
updateAndSyncOutboundTaskNum(result, false, false);
|
||||
|
||||
List list1 = new ArrayList();
|
||||
Map map = new HashMap();
|
||||
@@ -434,6 +435,9 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
public synchronized boolean
|
||||
instruction_require() {
|
||||
Date date = new Date();
|
||||
if (this.move != 1) {
|
||||
return false;
|
||||
}
|
||||
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) {
|
||||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out);
|
||||
return false;
|
||||
@@ -458,17 +462,120 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
.build();
|
||||
logDto.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
HttpResponse httpResponse = acsToWmsService.applyIn(param);
|
||||
int i = 0;
|
||||
while (i < 3) {
|
||||
try {
|
||||
HttpResponse httpResponse = acsToWmsService.applyIn(param);
|
||||
JSONObject jsonObject = null;
|
||||
if (ObjectUtil.isNotEmpty(httpResponse)) {
|
||||
String body = httpResponse.body();
|
||||
jsonObject = JSONObject.parseObject(body);
|
||||
}
|
||||
message = "申请入库任务,接口返回参数:" + jsonObject;
|
||||
if (ObjectUtil.isNotNull(jsonObject) && jsonObject.getInteger("status") == 200) {
|
||||
LuceneLogDto logDto2 = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("申请入库任务成功,接口返回参数:" + jsonObject)
|
||||
.build();
|
||||
logDto2.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto2);
|
||||
List list1 = new ArrayList();
|
||||
Map map = new HashMap();
|
||||
map.put("code", "to_command");
|
||||
map.put("value", 5);
|
||||
list1.add(map);
|
||||
this.writing(list1);
|
||||
this.requireSucess = true;
|
||||
break;
|
||||
} else {
|
||||
this.iserror = true;
|
||||
message = "申请入库任务出错,接口返回参数:" + jsonObject;
|
||||
LuceneLogDto logDto2 = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("申请入库任务出错,接口返回参数:" + jsonObject)
|
||||
.build();
|
||||
logDto2.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto2);
|
||||
i++; // 先自增
|
||||
|
||||
// 如果不是最后一次失败,则等待
|
||||
if (i < 3) {
|
||||
try {
|
||||
Thread.sleep(6000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break; // 中断后退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("申请入库任务第 {} 次尝试发生异常: {}", i + 1, e.getMessage(), e);
|
||||
this.iserror = true; // 标记为错误
|
||||
i++; // 关键:异常也计入重试次数
|
||||
|
||||
// 同样,在异常后也需要等待,然后再重试
|
||||
if (i < 3) {
|
||||
try {
|
||||
Thread.sleep(6000);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
break; // 如果等待被中断,则退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//代表3次都没有成功
|
||||
if (i == 3) {
|
||||
HttpResponse httpResponse = acsToWmsService.applyInBillError(param);
|
||||
JSONObject jsonObject = null;
|
||||
if (ObjectUtil.isNotEmpty(httpResponse)) {
|
||||
String body = httpResponse.body();
|
||||
jsonObject = JSONObject.parseObject(body);
|
||||
}
|
||||
message = "申请入库申请异常功能,接口返回参数:" + jsonObject;
|
||||
if (ObjectUtil.isNotNull(jsonObject) && jsonObject.getInteger("status") == 200) {
|
||||
LuceneLogDto logDto2 = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("申请入库申请异常任务成功,接口返回参数:" + jsonObject)
|
||||
.build();
|
||||
logDto2.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto2);
|
||||
List list1 = new ArrayList();
|
||||
Map map = new HashMap();
|
||||
map.put("code", "to_command");
|
||||
map.put("value", 5);
|
||||
list1.add(map);
|
||||
this.writing(list1);
|
||||
this.requireSucess = true;
|
||||
} else {
|
||||
this.iserror = true;
|
||||
message = "申请入库申请异常任务出错,接口返回参数:" + jsonObject;
|
||||
LuceneLogDto logDto2 = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("申请入库申请异常任务出错,接口返回参数:" + jsonObject)
|
||||
.build();
|
||||
logDto2.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rfid = CodeUtil.getNewCode("INSTRUCT_NO");
|
||||
log.info("当前RFID没有读到值,无法发起任务。");
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("device_code", device_code);
|
||||
param.put("vehicle_code", rfid);
|
||||
HttpResponse httpResponse = acsToWmsService.applyInBillError(param);
|
||||
JSONObject jsonObject = null;
|
||||
if(ObjectUtil.isNotEmpty(httpResponse)){
|
||||
if (ObjectUtil.isNotEmpty(httpResponse)) {
|
||||
String body = httpResponse.body();
|
||||
jsonObject = JSONObject.parseObject(body);
|
||||
}
|
||||
message = "申请入库任务,接口返回参数:" + jsonObject;
|
||||
if (ObjectUtil.isNotNull(jsonObject) && jsonObject.getInteger("status") == 200) {
|
||||
message = "申请入库申请异常功能,接口返回参数:" + jsonObject;
|
||||
if (ObjectUtil.isNotNull(jsonObject) && jsonObject.getInteger("status") == 200) {
|
||||
LuceneLogDto logDto2 = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("申请入库任务成功,接口返回参数:" + jsonObject)
|
||||
.content("申请入库申请异常任务成功,接口返回参数:" + jsonObject)
|
||||
.build();
|
||||
logDto2.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto2);
|
||||
@@ -481,16 +588,14 @@ public class BeltConveyorDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
this.requireSucess = true;
|
||||
} else {
|
||||
this.iserror = true;
|
||||
message = "申请入库任务出错,接口返回参数:" + jsonObject;
|
||||
message = "申请入库申请异常任务出错,接口返回参数:" + jsonObject;
|
||||
LuceneLogDto logDto2 = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("申请入库任务出错,接口返回参数:" + jsonObject)
|
||||
.content("申请入库申请异常任务出错,接口返回参数:" + jsonObject)
|
||||
.build();
|
||||
logDto2.setLog_level(4);
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto2);
|
||||
}
|
||||
} else {
|
||||
log.info("当前RFID没有读到值,无法发起任务。");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,13 @@ public interface AcsToWmsService {
|
||||
*/
|
||||
HttpResponse applyIn(JSONObject param);
|
||||
|
||||
/**
|
||||
* 入库申请异常
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
HttpResponse applyInBillError(JSONObject param);
|
||||
|
||||
/**
|
||||
* 二期发货申请任务
|
||||
* @param param
|
||||
|
||||
@@ -194,6 +194,38 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResponse applyInBillError(JSONObject param) {
|
||||
HttpResponse result2 = null;
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
log.info("申请入库-----请求参数{}", param);
|
||||
String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue();
|
||||
AddressDto addressDto = addressService.findByCode("applyInBillError");
|
||||
String url = wmsurl + addressDto.getMethods_url();
|
||||
try {
|
||||
result2 = HttpRequest.post(url)
|
||||
.addInterceptor(tLogHutoolhttpInterceptor)
|
||||
.header(Header.USER_AGENT, "Hutool http")
|
||||
.header("Authorization", token)
|
||||
.body(String.valueOf(param))
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
String msg = e.getMessage();
|
||||
log.info("申请入库-----请求异常输出参数{}", msg);
|
||||
//网络不通
|
||||
}
|
||||
log.info("申请入库-----输出参数{}", result2.body());
|
||||
LuceneLogDto luceneLogDto = new LuceneLogDto(4, "applyInBillError", String.valueOf(result2.getStatus()),
|
||||
JSON.toJSONString(param), String.valueOf(result2.body()), "ACS向LMS入库异常任务");
|
||||
luceneLogService.interfaceExecuteLog(luceneLogDto);
|
||||
return result2;
|
||||
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String applySendOutTwo(JSONObject param) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user