From 83e0f0b80c4b3c065d194ec4ecc11b4d87b2c21b Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Tue, 28 Mar 2023 20:18:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 18 +++++++--- .../src/main/java/org/nl/acs/opc/OpcUtl.java | 1 + .../main/resources/config/application-dev.yml | 6 ++-- .../src/main/resources/log/OpcUtl.xml | 33 +++++++++++++++++++ .../src/main/resources/logback-spring.xml | 3 +- 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 acs/hd/nladmin-system/src/main/resources/log/OpcUtl.xml diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 7bd1259..a36059d 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -121,6 +121,7 @@ public class DeviceOpcProtocolRunable implements Runnable { itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); } catch (Exception e){ System.out.println("数据同步异常:"+ this.getOpcServer().getOpc_code()); + log.trace("数据同步异常:{}", this.getOpcServer().getOpc_code()); //e.printStackTrace(); } long end = System.currentTimeMillis(); @@ -130,7 +131,7 @@ public class DeviceOpcProtocolRunable implements Runnable { System.out.println("线程:"+tag + " 读取耗时:"+ duration); if (duration > 1000L) { if (!time_out) { - log.warn("{} 读取超时 : {}", tag, duration); + log.warn(" {} 读取超时 : {}", tag, duration); } time_out = true; @@ -138,7 +139,11 @@ public class DeviceOpcProtocolRunable implements Runnable { time_out = false; } -// if(ObjectUtil.isEmpty(itemStatus)) continue label97; + if(ObjectUtil.isEmpty(itemStatus)) { + System.out.println( tag + " :itemStatus is null"); + log.warn(" {} 读取异常 : {} itemStatus is null", tag); + } + Set items = itemStatus.keySet(); Iterator var18 = items.iterator(); @@ -167,12 +172,13 @@ public class DeviceOpcProtocolRunable implements Runnable { value = OpcUtl.getValue(item, itemState); his = accessor_value.getValue(item.getId()); if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { - log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); + log.warn("opc 值不健康 item: {}, 状态: {},当前读取值:{}, 系统内存值{} ", item.getId(), itemState.getQuality(), value, his); } } while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码 OpcItemDto itemDto = this.getItem(item.getId()); - if (itemDto.getNeed_log() != null && itemDto.getNeed_log()) { + //默认记录日志 + if (true) { StringBuilder sb = new StringBuilder(); //设备的ITEM项 List relate_items = itemDto.getRelate_items(); @@ -184,7 +190,7 @@ public class DeviceOpcProtocolRunable implements Runnable { sb.append("key:" + relate + "value:" + obj + ";"); } - log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb}); + log.warn("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb}); } // accessor_value.setValueWithPersistence(item.getId(),accessor_value.getValue(item.getId())); @@ -199,6 +205,7 @@ public class DeviceOpcProtocolRunable implements Runnable { try { this.server.disconnect(); } catch (Exception var25) { + log.warn("{} : server disconnect", var25); } } @@ -213,6 +220,7 @@ public class DeviceOpcProtocolRunable implements Runnable { Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); } catch (InterruptedException e) { e.printStackTrace(); + log.warn("OPC 读取线程读取异常{} :", e); // Thread.currentThread().interrupt();不会真正停止线程 } ++this.error_num; diff --git a/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java index 1bb427c..89fd758 100644 --- a/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs/hd/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -41,6 +41,7 @@ public class OpcUtl { try{ e=group.write(requests); group.write(requests); + }catch (Exception e1){ try{ e= group.write(requests); diff --git a/acs/hd/nladmin-system/src/main/resources/config/application-dev.yml b/acs/hd/nladmin-system/src/main/resources/config/application-dev.yml index fbad515..f918d49 100644 --- a/acs/hd/nladmin-system/src/main/resources/config/application-dev.yml +++ b/acs/hd/nladmin-system/src/main/resources/config/application-dev.yml @@ -13,12 +13,12 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:jn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:jn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true # url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rljn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} # password: ${DB_PWD:P@ssw0rd} -# password: ${DB_PWD:Root.123456} - password: ${DB_PWD:123456} + password: ${DB_PWD:Root.123456} +# password: ${DB_PWD:123456} # 初始连接数 initial-size: 5 # 最小连接数 diff --git a/acs/hd/nladmin-system/src/main/resources/log/OpcUtl.xml b/acs/hd/nladmin-system/src/main/resources/log/OpcUtl.xml new file mode 100644 index 0000000..3fe32e3 --- /dev/null +++ b/acs/hd/nladmin-system/src/main/resources/log/OpcUtl.xml @@ -0,0 +1,33 @@ + + + + + + + + + ${LOG_HOME}/下发KEP信号/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 2GB + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + ${log.charset} + + + + + + + + + + + diff --git a/acs/hd/nladmin-system/src/main/resources/logback-spring.xml b/acs/hd/nladmin-system/src/main/resources/logback-spring.xml index 6f59a42..0f9998a 100644 --- a/acs/hd/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/hd/nladmin-system/src/main/resources/logback-spring.xml @@ -30,7 +30,8 @@ https://juejin.cn/post/6844903775631572999 - + +