From 1ee76c252f2dbba62e0ec34cccf9eaac51de9083 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 23 七月 2025 16:25:23 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/netty/client/ChannelMap.java |   46 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/netty/client/ChannelMap.java b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/netty/client/ChannelMap.java
index ef8d07b..29aa78f 100644
--- a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/netty/client/ChannelMap.java
+++ b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/netty/client/ChannelMap.java
@@ -7,8 +7,8 @@
 import io.netty.channel.group.DefaultChannelGroup;
 import io.netty.util.concurrent.GlobalEventExecutor;
 
+import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * @author zhibing.pu
@@ -16,17 +16,17 @@
  */
 public class ChannelMap {
 	//存储主链路通道
-	private static final ChannelGroup SERVER_GROUP = new DefaultChannelGroup("Jtt809Server", GlobalEventExecutor.INSTANCE);
+	private static ChannelGroup SERVER_GROUP = new DefaultChannelGroup("Jtt809Server", GlobalEventExecutor.INSTANCE);
 	//存储主链路ID
-	private static final Map<Integer, ChannelId> SERVER_ID_MAP = new ConcurrentHashMap<>();
+	private static Map<Integer, ChannelId> SERVER_ID_MAP = new HashMap<>();
 	//存储从链路通道
-	private static final ChannelGroup CLIENT_GROUP = new DefaultChannelGroup("Jtt809Client", GlobalEventExecutor.INSTANCE);
+	private static ChannelGroup CLIENT_GROUP = new DefaultChannelGroup("Jtt809Client", GlobalEventExecutor.INSTANCE);
 	//存储从链路ID
-	private static final Map<Integer, ChannelId> CLIENT_ID_MAP = new ConcurrentHashMap<>();
+	private static Map<Integer, ChannelId> CLIENT_ID_MAP = new HashMap<>();
 	//存储从链路连接地址和端口号
-	private static final Map<Integer, UPConnect> IP_PORT = new ConcurrentHashMap<>();
+	private static Map<Integer, UPConnect> IP_PORT = new HashMap<>();
 	//存储从链路连接重试次数
-	private static final Map<Integer, Integer> TIMES = new ConcurrentHashMap<>();
+	private static Map<Integer, Integer> TIMES = new HashMap<>();
 	
 	/**
 	 * 保存通道
@@ -35,7 +35,13 @@
 	 * @param channel
 	 */
 	public static void addClientChannel(int key, Channel channel) {
+		if(null == CLIENT_ID_MAP){
+			CLIENT_ID_MAP = new HashMap<>();
+		}
 		CLIENT_ID_MAP.put(key, channel.id());
+		if(null == CLIENT_GROUP){
+			CLIENT_GROUP = new DefaultChannelGroup("Jtt809Client", GlobalEventExecutor.INSTANCE);
+		}
 		CLIENT_GROUP.add(channel);
 	}
 	
@@ -47,9 +53,15 @@
 	 * @return
 	 */
 	public static Channel getClientChannel(int key) {
+		if(null == CLIENT_ID_MAP){
+			CLIENT_ID_MAP = new HashMap<>();
+		}
 		ChannelId channelId = CLIENT_ID_MAP.get(key);
 		if (null == channelId) {
 			return null;
+		}
+		if(null == CLIENT_GROUP){
+			CLIENT_GROUP = new DefaultChannelGroup("Jtt809Client", GlobalEventExecutor.INSTANCE);
 		}
 		Channel channel = CLIENT_GROUP.find(channelId);
 		return channel;
@@ -63,7 +75,13 @@
 	 * @param channel
 	 */
 	public static void addServerChannel(int key, Channel channel) {
+		if(null == SERVER_ID_MAP){
+			SERVER_ID_MAP = new HashMap<>();
+		}
 		SERVER_ID_MAP.put(key, channel.id());
+		if(null == SERVER_GROUP){
+			SERVER_GROUP = new DefaultChannelGroup("Jtt809Server", GlobalEventExecutor.INSTANCE);
+		}
 		SERVER_GROUP.add(channel);
 	}
 	
@@ -91,6 +109,9 @@
 	 * @param req
 	 */
 	public static void addIpAndPort(int key, UPConnect req) {
+		if(null == IP_PORT){
+			IP_PORT = new HashMap<>();
+		}
 		IP_PORT.put(key, req);
 	}
 	
@@ -101,6 +122,9 @@
 	 * @param key
 	 */
 	public static UPConnect getIpAndPort(int key) {
+		if(null == IP_PORT){
+			IP_PORT = new HashMap<>();
+		}
 		return IP_PORT.get(key);
 	}
 	
@@ -110,7 +134,10 @@
 	 * @param key
 	 * @return
 	 */
-	public static int getTimes(int key) {
+	public static Integer getTimes(int key) {
+		if(null == TIMES){
+			TIMES = new HashMap<>();
+		}
 		return TIMES.get(key);
 	}
 	
@@ -121,6 +148,9 @@
 	 * @return
 	 */
 	public static int saveTimes(int key, int t) {
+		if(null == TIMES){
+			TIMES = new HashMap<>();
+		}
 		return TIMES.put(key, t);
 	}
 }

--
Gitblit v1.7.1