From 905eb707fff6fc6702c1c9e8333520012dd89414 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 24 十二月 2024 18:59:58 +0800 Subject: [PATCH] 修改bug --- ZuulAHTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java | 188 +++++++++++++++++++++++----------------------- 1 files changed, 94 insertions(+), 94 deletions(-) diff --git a/ZuulAHTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java b/ZuulAHTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java index ade75b1..6ef4b0d 100644 --- a/ZuulAHTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java +++ b/ZuulAHTravel/src/main/java/com/sinata/zuul/util/echo/NettyServerController.java @@ -102,38 +102,38 @@ //判断用户或者司机长连接 if(type==1){ //确保账号在单个设备上登录 - if(StringUtil.isNotEmpty(token)){ - String token_ = redisUtil.getValue("USER_APP_"+ 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_(token.substring(0, 23), ctx); - NettyChannelMap.update("USER" + userId1, ctx); - String s = NettyMsg.setMsg(Method.ok, new HashMap<String, Object>()); - ctx.writeAndFlush(Unpooled.copiedBuffer((s).getBytes())); - - if(StringUtil.isEmpty(token_)){//确保登录的时候存储token失败的情况 - redisUtil.setStrValue("USER_APP_" + userId1, token); - } - } +// if(StringUtil.isNotEmpty(token)){ +// String token_ = redisUtil.getValue("USER_APP_"+ 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_(token.substring(0, 23), ctx); +// NettyChannelMap.update("USER" + userId1, ctx); +// String s = NettyMsg.setMsg(Method.ok, new HashMap<String, Object>()); +// ctx.writeAndFlush(Unpooled.copiedBuffer((s).getBytes())); +// +// if(StringUtil.isEmpty(token_)){//确保登录的时候存储token失败的情况 +// redisUtil.setStrValue("USER_APP_" + userId1, token); +// } +// } }else{ //添加司机在线 @@ -156,37 +156,37 @@ if(StringUtil.isNotEmpty(device) && device.equals("carDevice")){ redisUtil.setStrValue("DEVICE_" + userId1, String.valueOf(System.currentTimeMillis())); - 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 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); +// } } @@ -226,37 +226,37 @@ // } //确保账号在单个设备上登录 - String value = redisUtil.getValue("DEVICE_" + userId1); - 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); - } - } +// String value = redisUtil.getValue("DEVICE_" + userId1); +// 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