REV 接口异步

This commit is contained in:
USER-20220102CG\noblelift
2023-12-22 03:50:41 +08:00
parent bde94691da
commit 66e6b8f961
4 changed files with 67 additions and 31 deletions

View File

@@ -39,13 +39,17 @@ import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.route.service.dto.RouteLineDto;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.config.thread.ThreadPoolExecutorUtil;
import org.nl.modules.system.service.ParamService;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 西门子-输送机驱动
@@ -54,6 +58,7 @@ import java.util.*;
@Data
@RequiredArgsConstructor
public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
@@ -233,9 +238,9 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
param.put("device_name", this.getDevice().getDevice_name());
param.put("device_type", "1");
param.put("product_area", paramService.findByCode("productArea").getValue());
acsToWmsService.sendDeviceStatus(param);
// acsToWmsService.sendDeviceStatus(param);
sendDeviceStatus(param);
}
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode + "复位请求标记:" + requireSucess);
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
@@ -417,18 +422,39 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
last_to_height = to_height;
}
private void shipDeviceUpdate() {
JSONObject param = new JSONObject() {{
put("device_code", device_code);
}};
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,参数:" + param);
HttpResponse response = acsToWmsService.shipDeviceUpdate(param);
if (response == null || response.getStatus() == 200) {
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,接口返回:" + response.body());
this.requiresShipDeviceUpdate = true;
}
public void shipDeviceUpdate() {
CompletableFuture<String> future = new CompletableFuture<>();
// 使用线程池执行异步操作
EXECUTOR.submit(() -> {
try {
JSONObject param = new JSONObject() ;
param.put("device_code", device_code);
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,参数:" + param);
HttpResponse response = acsToWmsService.shipDeviceUpdate(param);
if (response == null || response.getStatus() == 200) {
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,接口返回:" + response.body());
}
future.complete("Async operation completed");
this.requiresShipDeviceUpdate = true;
} catch (Exception e) {
future.completeExceptionally(e);
}
});
}
public void sendDeviceStatus(JSONObject param) {
CompletableFuture<String> future = new CompletableFuture<>();
// 使用线程池执行异步操作
EXECUTOR.submit(() -> {
try {
acsToWmsService.sendDeviceStatus(param);
future.complete("Async operation completed");
this.requiresShipDeviceUpdate = true;
} catch (Exception e) {
future.completeExceptionally(e);
}
});
}
private void taskDeviceUpdate(int task) {
Instruction inst = instructionService.findByTaskcode(String.valueOf(task));

View File

@@ -5,14 +5,14 @@ import org.nl.acs.device_driver.DeviceDriver;
public interface ExecutableDeviceDriver extends DeviceDriver {
default void executeAuto() {
// try {
// this.execute();
// } catch (Throwable var6) {
// String message = "线程调用异常:" + var6.getMessage();
// Log.error(message);
// } finally {
// }
try {
this.execute();
} catch (Throwable var6) {
String message = "线程调用异常:" + var6.getMessage();
Log.error(message);
} finally {
}
// this.execute();
}

View File

@@ -419,17 +419,19 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{};信号快照:{}", new Object[]{itemId, his, value, sb});
} else {
if(his instanceof int[]){
if(!Arrays.equals((long[]) his, (long[]) value)){
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
}
} else if(his instanceof String){
if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
}
} else {
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
}
// if(his instanceof int[]){
// if(!Arrays.equals((long[]) his, (long[]) value)){
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// }
// } else if(his instanceof String){
// if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// }
// } else {
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// }
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
}
}

View File

@@ -82,8 +82,10 @@ https://juejin.cn/post/6844903775631572999
<appender-ref ref="FILE"/>
</appender>
<!--添加loki-->
<appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
<appender name="newlokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
<batchTimeoutMs>1000</batchTimeoutMs>
<http class="com.github.loki4j.logback.ApacheHttpSender">
<url>${LOKI_URL}/push</url>
@@ -99,6 +101,12 @@ https://juejin.cn/post/6844903775631572999
</format>
</appender>
<appender name="lokiAppender" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>100</discardingThreshold>
<queueSize>500</queueSize>
<appender-ref ref="newlokiAppender"/>
</appender>
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>error</level>