From abea8dfd0161c966b809fe8977da7422dfe9ad98 Mon Sep 17 00:00:00 2001 From: psh Date: Fri, 10 Nov 2023 16:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E5=90=8C=E6=AD=A5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=9C=80=E6=96=B0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 345c545..71a0593 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -3,22 +3,17 @@ package org.nl.acs.opc; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import com.alicp.jetcache.anno.method.SpringCacheContext; import lombok.extern.slf4j.Slf4j; import org.nl.acs.opc.service.dto.OpcServerManageDto; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; import org.nl.acs.udw.UnifiedDataAppService; -import org.nl.config.SpringContextHolder; import org.openscada.opc.lib.da.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import java.util.*; @Slf4j -@Service public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener { List protocols; OpcServerManageDto OpcServer; @@ -31,9 +26,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC private int all_null; private Map itemSearchCache; -// @Autowired -// OpcServerService opcServerService; - public DeviceOpcProtocolRunable() { this.error_num = 0; @@ -102,11 +94,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC server.disconnect(); log.trace("清理server..."); } - OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class); - group =opcServerService.getServer(this.getOpcServer().getOpc_code()); -// this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); -// this.server.addStateListener(this); -// group = this.server.addGroup(); + +// group =opcServerService.getServer(this.getOpcServer().getOpc_code()); + this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); + this.server.addStateListener(this); + group = this.server.addGroup(); List itemsString = new ArrayList(); Iterator var3 = this.protocols.iterator(); @@ -196,7 +188,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC Object his = accessor_value.getValue(itemId); if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); - valueAllNotNull = true; + valueAllNotNull = false; } if (!UnifiedDataAppService.isEquals(value, his)) { @@ -230,7 +222,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random); } - ThreadUtl.sleep((long) (5000 + random)); + ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); + break start; } else if (this.all_null < 6) { if (log.isWarnEnabled()) { log.warn(tag + "重新创建server");