From 4310c19a73f960dfd79c90cfe960cf564b068f72 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Thu, 26 May 2022 10:03:35 +0800
Subject: [PATCH] 1、资讯模糊匹配修改

---
 src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java b/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
index 7ef33f5..9ac31b5 100644
--- a/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
+++ b/src/main/java/org/springblade/modules/webscoket/WebSocketHandler.java
@@ -1,5 +1,7 @@
 package org.springblade.modules.webscoket;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelFuture;
@@ -60,13 +62,8 @@
 		System.out.println("客户端断开连接:" + ctx.channel());
 		//用户离线状态
 		String name = ChannelSupervise.findName(ctx.channel().id().asShortText());
+		System.out.println(name);
 		if ( name != null &&!name.equals("ping") ){
-			String num="0";
-			//工作状态(0闲置,1工作中)
-			String workSt = "0";
-			webSocketHandler.suserService.updateUser(num,name,workSt);
-			//ChannelSupervise.removeChannel(ctx.channel());
-
 			NettyConfig.getChannelGroup().remove(ctx.channel());
 			removeUserId(ctx);
 		}
@@ -100,21 +97,25 @@
 
 		if (!request.equals("ping")){
 
-			NettyConfig.getUserChannelMap().put(request,ctx.channel());
+			JSONObject jsonObj = JSON.parseObject(request);
+			String type = jsonObj.get("type").toString();
 
-			//将用户id作为自定义属性加入到channel 中,方便随时channel中获取用户id
-			AttributeKey<String> key = AttributeKey.valueOf("userId");
-			ctx.channel().attr(key).setIfAbsent(request);
+			if (type != null && type.equals("login")){
+				//登录链接
+				String id = jsonObj.get("id").toString();
+				NettyConfig.getUserChannelMap().put(id,ctx.channel());
+				NettyConfig.getChannelGroup().add(ctx.channel());
 
-			//把用户信息添加到通道里
-			ChannelSupervise.addChannel(ctx.channel(),request);
-			//用户在线状态
-			this.on=request;
-			//在线状态(0掉线,1在线)
-			String num="1";
-			//工作状态(0闲置,1工作中)
-			String workSt = "0";
-			webSocketHandler.suserService.updateUser(num,request,workSt);
+				System.out.println("___________________"+jsonObj.get("type"));
+				System.out.println(jsonObj.get("id")+ "____________________________用户连接成功");
+
+				//将用户id作为自定义属性加入到channel 中,方便随时channel中获取用户id
+				AttributeKey<String> key = AttributeKey.valueOf("userId");
+				ctx.channel().attr(key).setIfAbsent(id);
+				//把用户信息添加到通道里
+				ChannelSupervise.addChannel(ctx.channel(),id);
+			}
+
 		}
 
 //		TextWebSocketFrame tws = new TextWebSocketFrame(new Date().toString()

--
Gitblit v1.9.3