diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java index 1b185d01f..a6be999d2 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java @@ -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 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 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)); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java index 326d18963..28e2c460f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java @@ -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(); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index c1f568ffa..091031f1d 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -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}); } } diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index 45c7f529b..d9726de06 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -82,8 +82,10 @@ https://juejin.cn/post/6844903775631572999 + + - + 1000 ${LOKI_URL}/push @@ -99,6 +101,12 @@ https://juejin.cn/post/6844903775631572999 + + 100 + 500 + + + error