From 31ce6be2d56798d9509e6d90335999064351f7f3 Mon Sep 17 00:00:00 2001 From: luodangjia <luodangjia> Date: 星期二, 10 十二月 2024 16:06:26 +0800 Subject: [PATCH] 12.10 --- ZuulNTTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java | 97 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 65 insertions(+), 32 deletions(-) diff --git a/ZuulNTTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java b/ZuulNTTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java index 979b6a4..ade75b1 100644 --- a/ZuulNTTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java +++ b/ZuulNTTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java @@ -191,39 +191,72 @@ //确保账号在单个设备上登录 +// String value = redisUtil.getValue("DEVICE_" + userId1); +// if(StringUtil.isNotEmpty(token) && StringUtil.isEmpty(device) && StringUtil.isEmpty(value)){//APP端登录的操作 +// String token_ = redisUtil.getValue("DRIVER_" + userId1);//缓存中拿最新数据 +// if(StringUtil.isNotEmpty(token_) && !token.equals(token_)){//不在同一设备上登录,向当前设备发送数据 +// ChannelHandlerContext data_ = NettyChannelMap.getData_(token_.substring(0, 23)); +// +// JSONObject msg_ = new JSONObject(); +// msg_.put("code", 200); +// msg_.put("msg", "SUCCESS"); +// msg_.put("method", "OFFLINE"); +// msg_.put("data", new Object()); +// this.sendMsgToClient(data_, msg_.toJSONString());//给当前通道发送消息 +// TimerTask timerTask = new TimerTask() { +// @Override +// public void run() { +// NettyChannelMap.remove_(data_); +// NettyChannelMap.remove(data_); +// } +// }; +// Timer timer = new Timer(); +// timer.schedule(timerTask, 3000); +// timer.cancel(); +// } +// +// NettyChannelMap.update("DRIVER" + userId1, ctx); +// NettyChannelMap.update_(token.substring(0, 23), ctx); +// String s = NettyMsg.setMsg(Method.ok, new HashMap<String, Object>()); +// ctx.writeAndFlush(Unpooled.copiedBuffer((s).getBytes())); +// +// if(StringUtil.isEmpty(token_)){//确保登录的时候存储token失败的情况 +// redisUtil.setStrValue("DRIVER_" + userId1, token); +// } +// } + + //确保账号在单个设备上登录 String value = redisUtil.getValue("DEVICE_" + userId1); - if(StringUtil.isNotEmpty(token) && StringUtil.isEmpty(device) && StringUtil.isEmpty(value)){//APP端登录的操作 - String token_ = redisUtil.getValue("DRIVER_" + userId1);//缓存中拿最新数据 - if(StringUtil.isNotEmpty(token_) && !token.equals(token_)){//不在同一设备上登录,向当前设备发送数据 - ChannelHandlerContext data_ = NettyChannelMap.getData_(token_.substring(0, 23)); - - JSONObject msg_ = new JSONObject(); - msg_.put("code", 200); - msg_.put("msg", "SUCCESS"); - msg_.put("method", "OFFLINE"); - msg_.put("data", new Object()); - this.sendMsgToClient(data_, msg_.toJSONString());//给当前通道发送消息 - TimerTask timerTask = new TimerTask() { - @Override - public void run() { - NettyChannelMap.remove_(data_); - NettyChannelMap.remove(data_); - } - }; - Timer timer = new Timer(); - timer.schedule(timerTask, 3000); - timer.cancel(); - } - - NettyChannelMap.update("DRIVER" + userId1, ctx); - NettyChannelMap.update_(token.substring(0, 23), ctx); - String s = NettyMsg.setMsg(Method.ok, new HashMap<String, Object>()); - ctx.writeAndFlush(Unpooled.copiedBuffer((s).getBytes())); - - if(StringUtil.isEmpty(token_)){//确保登录的时候存储token失败的情况 - redisUtil.setStrValue("DRIVER_" + userId1, token); - } - } + if(StringUtil.isNotEmpty(token) && StringUtil.isEmpty(value)){//APP端登录的操作 + String token_ = redisUtil.getValue("DRIVER_" + userId1);//缓存中拿最新数据 + if(StringUtil.isNotEmpty(token_) && !token.equals(token_)){//不在同一设备上登录,向当前设备发送数据 + JSONObject msg_ = new JSONObject(); + msg_.put("code", 200); + msg_.put("msg", "SUCCESS"); + msg_.put("method", "OFFLINE"); + msg_.put("data", new Object()); + this.sendMsgToClient(ctx, msg_.toJSONString());//给当前通道发送消息 + TimerTask timerTask = new TimerTask() { + @Override + public void run() { + NettyChannelMap.remove_(ctx); + NettyChannelMap.remove(ctx); + } + }; + Timer timer = new Timer(); + timer.schedule(timerTask, 3000); + timer.cancel(); + }else{ +// System.err.println("开始存储司机通道" + userId1); + NettyChannelMap.update("DRIVER" + userId1, ctx); + NettyChannelMap.update_(token.substring(0, 23), ctx); + String s = NettyMsg.setMsg(Method.ok, new HashMap<String, Object>()); + ctx.writeAndFlush(Unpooled.copiedBuffer((s).getBytes())); + } + if(StringUtil.isEmpty(token_)){//确保登录的时候存储token失败的情况 + redisUtil.setStrValue("DRIVER_" + userId1, token); + } + } //存储通讯通道 -- Gitblit v1.7.1