puzhibing
2023-07-26 709a4a10be56952ead6340e4822fce41a66e47cd
zuul/src/main/java/com/sinata/zuul/util/applets/NettyWebSocketController.java
@@ -45,7 +45,7 @@
     * @param msg
     * @author TaoNingBo
     */
    public void JudgeOperation(ChannelHandlerContext ctx, String msg) {
    public synchronized void JudgeOperation(ChannelHandlerContext ctx, String msg) {
        try {
            // 验证即时通讯命令是否正确有效
            if (SinataUtil.isEmpty(msg)) {
@@ -83,35 +83,30 @@
                if (StringUtil.isNotEmpty(userId1)) {
                    //确保账号在单个设备上登录
                    if (StringUtil.isNotEmpty(token)) {
                        NettyChannelMap.update_(token.substring(0, 23), ctx);//存储单点登录的通道
                        String token_ = redisUtil.getValue("USER_Applets_" + userId1);//获取缓存中最新的数据
                        if (StringUtil.isNotEmpty(token_) && !token.equals(token_)) {//不在同一设备上登录,向其他设备发送数据
                            ChannelHandlerContext data_ = NettyChannelMap.getData_(token_.substring(token_.length() - 16));
                            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() {
                            this.sendMsgToClient(data_, msg_.toJSONString());
                            new Timer().schedule(new TimerTask() {
                                @Override
                                public void run() {
                                    NettyChannelMap.remove_(ctx);
                                    NettyChannelMap.remove_(data_);
                                }
                            };
                            Timer timer = new Timer();
                            timer.schedule(timerTask, 3000);
                            timer.cancel();
                            }, 5000);
                        }
                        if (StringUtil.isEmpty(token_)) {//确保登录的时候存储token失败的情况
                            redisUtil.setStrValue("USER_Applets_" + userId1, token);
                        }
                        NettyChannelMap.update_(token.substring(token.length() - 16), ctx);//存储单点登录的通道
                        NettyChannelMap.update("Applets" + userId1, ctx);
                        redisUtil.setStrValue("USER_Applets_" + userId1, token);
                    }
                    //存储业务使用的通道
                    if (null != ctx && ctx.channel().isActive()) {
                        NettyChannelMap.update("Applets" + userId1, ctx);
//                    String s = NettyMsg.setMsg(Method.ok, new HashMap<String, Object>());
//                    ctx.writeAndFlush(Unpooled.copiedBuffer((s).getBytes()));
                    }
                }