REV 接口异步
This commit is contained in:
@@ -39,13 +39,17 @@ import org.nl.acs.route.service.RouteLineService;
|
|||||||
import org.nl.acs.route.service.dto.RouteLineDto;
|
import org.nl.acs.route.service.dto.RouteLineDto;
|
||||||
import org.nl.acs.task.service.TaskService;
|
import org.nl.acs.task.service.TaskService;
|
||||||
import org.nl.acs.task.service.dto.TaskDto;
|
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.system.service.ParamService;
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
import org.nl.modules.wql.util.SpringContextHolder;
|
import org.nl.modules.wql.util.SpringContextHolder;
|
||||||
import org.openscada.opc.lib.da.Server;
|
import org.openscada.opc.lib.da.Server;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 西门子-输送机驱动
|
* 西门子-输送机驱动
|
||||||
@@ -54,6 +58,7 @@ import java.util.*;
|
|||||||
@Data
|
@Data
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||||
|
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
||||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||||
@Autowired
|
@Autowired
|
||||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
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_name", this.getDevice().getDevice_name());
|
||||||
param.put("device_type", "1");
|
param.put("device_type", "1");
|
||||||
param.put("product_area", paramService.findByCode("productArea").getValue());
|
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 + "复位请求标记:" + requireSucess);
|
||||||
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode);
|
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode);
|
||||||
}
|
}
|
||||||
@@ -417,18 +422,39 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme
|
|||||||
last_to_height = to_height;
|
last_to_height = to_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shipDeviceUpdate() {
|
public void shipDeviceUpdate() {
|
||||||
JSONObject param = new JSONObject() {{
|
CompletableFuture<String> future = new CompletableFuture<>();
|
||||||
put("device_code", device_code);
|
// 使用线程池执行异步操作
|
||||||
}};
|
EXECUTOR.submit(() -> {
|
||||||
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,参数:" + param);
|
try {
|
||||||
HttpResponse response = acsToWmsService.shipDeviceUpdate(param);
|
JSONObject param = new JSONObject() ;
|
||||||
if (response == null || response.getStatus() == 200) {
|
param.put("device_code", device_code);
|
||||||
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,接口返回:" + response.body());
|
logServer.deviceExecuteLog(this.device_code, "", "", "有货变无货请求LMS,参数:" + param);
|
||||||
this.requiresShipDeviceUpdate = true;
|
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) {
|
private void taskDeviceUpdate(int task) {
|
||||||
Instruction inst = instructionService.findByTaskcode(String.valueOf(task));
|
Instruction inst = instructionService.findByTaskcode(String.valueOf(task));
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import org.nl.acs.device_driver.DeviceDriver;
|
|||||||
|
|
||||||
public interface ExecutableDeviceDriver extends DeviceDriver {
|
public interface ExecutableDeviceDriver extends DeviceDriver {
|
||||||
default void executeAuto() {
|
default void executeAuto() {
|
||||||
// try {
|
try {
|
||||||
// this.execute();
|
|
||||||
// } catch (Throwable var6) {
|
|
||||||
// String message = "线程调用异常:" + var6.getMessage();
|
|
||||||
// Log.error(message);
|
|
||||||
// } finally {
|
|
||||||
// }
|
|
||||||
this.execute();
|
this.execute();
|
||||||
|
} catch (Throwable var6) {
|
||||||
|
String message = "线程调用异常:" + var6.getMessage();
|
||||||
|
Log.error(message);
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
// this.execute();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -419,17 +419,19 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
|||||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
|
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});
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{};信号快照:{}", new Object[]{itemId, his, value, sb});
|
||||||
} else {
|
} else {
|
||||||
if(his instanceof int[]){
|
// if(his instanceof int[]){
|
||||||
if(!Arrays.equals((long[]) his, (long[]) value)){
|
// if(!Arrays.equals((long[]) his, (long[]) value)){
|
||||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||||
}
|
// }
|
||||||
} else if(his instanceof String){
|
// } else if(his instanceof String){
|
||||||
if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
|
// if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
|
||||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
// 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});
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,10 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<appender-ref ref="FILE"/>
|
<appender-ref ref="FILE"/>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!--添加loki-->
|
<!--添加loki-->
|
||||||
<appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
|
<appender name="newlokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
|
||||||
<batchTimeoutMs>1000</batchTimeoutMs>
|
<batchTimeoutMs>1000</batchTimeoutMs>
|
||||||
<http class="com.github.loki4j.logback.ApacheHttpSender">
|
<http class="com.github.loki4j.logback.ApacheHttpSender">
|
||||||
<url>${LOKI_URL}/push</url>
|
<url>${LOKI_URL}/push</url>
|
||||||
@@ -99,6 +101,12 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
</format>
|
</format>
|
||||||
</appender>
|
</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">
|
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>error</level>
|
<level>error</level>
|
||||||
|
|||||||
Reference in New Issue
Block a user