Pu Zhibing
9 天以前 bc2cb25734bcf18474ed41a35ac4d54fd976f523
合并代码
5个文件已修改
84 ■■■■ 已修改文件
MessagePushTravel/src/main/java/com/sinata/push/util/URLUtil.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MessagePushTravel/src/main/java/com/sinata/push/util/applets/NettyServer0.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MessagePushTravel/src/main/java/com/sinata/push/util/applets/NettyWebSocketController.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MessagePushTravel/src/main/java/com/sinata/push/util/echo/NettyServer.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MessagePushTravel/src/main/java/com/sinata/push/util/echo/NettyServerController.java 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MessagePushTravel/src/main/java/com/sinata/push/util/URLUtil.java
@@ -9,4 +9,8 @@
     * 业务网关接口地址
     */
    String zuul = "http://192.168.110.111:5000";
    /**
     * 业务网关接口地址
     */
    String aj_zuul = "http://192.168.110.111:5000";
}
MessagePushTravel/src/main/java/com/sinata/push/util/applets/NettyServer0.java
@@ -64,7 +64,7 @@
                // ChildChannelHandler 对出入的数据进行的业务操作,其继承ChannelInitializer
                b.childHandler(new ChildChannelHandler());
                System.out.println("服务端开启等待客户端连接 ... ...");
                Channel ch = b.bind(8808).sync().channel();
                Channel ch = b.bind(8888).sync().channel();
                ch.closeFuture().sync();
            } catch (Exception e) {
                e.printStackTrace();
MessagePushTravel/src/main/java/com/sinata/push/util/applets/NettyWebSocketController.java
@@ -78,10 +78,12 @@
            if (method.equals(Method.ping)) {
                String token = jsonCon.getString("token");
                String userId1 = jsonCon.getString("userId");
                String businessType = jsonCon.getString("businessType");//1:打车,2=代驾
                String business = "1".equals(businessType) ? "dache" : "daijia";
                if (StringUtil.isNotEmpty(userId1)) {
                    //确保账号在单个设备上登录
                    if (StringUtil.isNotEmpty(token)) {
                        String token_ = redisUtil.getValue("USER_Applets_" + userId1);//获取缓存中最新的数据
                        String token_ = redisUtil.getValue(business + ":USER_Applets_" + userId1);//获取缓存中最新的数据
                        if (StringUtil.isNotEmpty(token_) && !token.equals(token_)) {//不在同一设备上登录,向其他设备发送数据
                            ChannelHandlerContext data_ = NettyChannelMap.getData_(token_.substring(token_.length() - 16));
                            JSONObject msg_ = new JSONObject();
@@ -98,13 +100,13 @@
                            }, 5000);
                        }
                        NettyChannelMap.update_(token.substring(token.length() - 16), ctx);//存储单点登录的通道
                        NettyChannelMap.update("Applets" + userId1, ctx);
                        redisUtil.setStrValue("USER_Applets_" + userId1, token);
                        NettyChannelMap.update(business + ":Applets" + userId1, ctx);
                        redisUtil.setStrValue(business + ":USER_Applets_" + userId1, token);
                    }
                    //存储业务使用的通道
                    if (null != ctx && ctx.channel().isActive()) {
                        NettyChannelMap.update("Applets" + userId1, ctx);
                        NettyChannelMap.update(business + ":Applets" + userId1, ctx);
                    }
                }
MessagePushTravel/src/main/java/com/sinata/push/util/echo/NettyServer.java
@@ -50,7 +50,7 @@
        /**
         * 获取即时通讯启动端口 
         */
        private Integer nettyPort = 9909;
        private Integer nettyPort = 9999;
        @Override
        public void run() {
            EventLoopGroup bossGroup = new NioEventLoopGroup();
MessagePushTravel/src/main/java/com/sinata/push/util/echo/NettyServerController.java
@@ -95,13 +95,15 @@
                String userId1 = jsonCon.getString("userId");
                String device = jsonCon.getString("device");
                String version = jsonCon.getString("version");
                String businessType = jsonCon.getString("businessType");//1:打车,2=代驾
                String business = "1".equals(businessType) ? "dache" : "daijia";
                if(StringUtil.isNotEmpty(userId1)){
                    //判断用户或者司机长连接
                    if(type==1){
                        //确保账号在单个设备上登录
                        if(StringUtil.isNotEmpty(token)){
                            String token_ = redisUtil.getValue("USER_APP_"+ userId1);//获取缓存中最新的数据
                            String token_ = redisUtil.getValue(business + ":USER_APP_"+ userId1);//获取缓存中最新的数据
                            if(StringUtil.isNotEmpty(token_) && !token.equals(token_)){//不在同一设备上登录,向其他设备发送数据
                                ChannelHandlerContext data_ = NettyChannelMap.getData_(token_.substring(token_.length() - 16));
                                JSONObject msg_ = new JSONObject();
@@ -121,18 +123,18 @@
                                }, 5000);
                            }
                            NettyChannelMap.update_(token.substring(token.length() - 16), ctx);
                            NettyChannelMap.update("USER" + userId1, ctx);
                            redisUtil.setStrValue("USER_APP_" + userId1, token);
                            NettyChannelMap.update(business + ":USER" + userId1, ctx);
                            redisUtil.setStrValue(business + ":USER_APP_" + userId1, token);
                        }
                        //存储通讯通道
                        if(null != ctx && ctx.channel().isActive()){
                            NettyChannelMap.update("USER" + userId1, ctx);
                            NettyChannelMap.update(business + ":USER" + userId1, ctx);
                        }
                    }else{
                        //确保账号在单个设备上登录
                        if(StringUtil.isNotEmpty(token)){//APP端登录的操作
                            String token_ = redisUtil.getValue("DRIVER_" + userId1);//缓存中拿最新数据
                            String token_ = redisUtil.getValue(business + ":DRIVER_" + userId1);//缓存中拿最新数据
                            if(StringUtil.isNotEmpty(token_) && !token.equals(token_)){//不在同一设备上登录,向当前设备发送数据
                                ChannelHandlerContext data_ = NettyChannelMap.getData_(token_.substring(token_.length() - 16));
                                if(null != data_){
@@ -147,13 +149,13 @@
                                    }
                                }
                            }
                            NettyChannelMap.update("DRIVER" + userId1, ctx);
                            NettyChannelMap.update(business + ":DRIVER" + userId1, ctx);
                            NettyChannelMap.update_(token.substring(token.length() - 16), ctx);
                            redisUtil.setStrValue("DRIVER_" + userId1, token);
                            redisUtil.setStrValue(business + ":DRIVER_" + userId1, token);
                        }
                        //存储通讯通道
                        if(null != ctx && ctx.channel().isActive()){
                            NettyChannelMap.update("DRIVER" + userId1, ctx);
                            NettyChannelMap.update(business + ":DRIVER" + userId1, ctx);
                        }
                    }
                }
@@ -166,15 +168,18 @@
            //司机上传位置
            if(method.equals(Method.location)){
                Integer driverId = jsonCon.getInteger("driverId");
                String fluid_control = redisUtil.getValue("location_" + driverId);
                String businessType = jsonCon.getString("businessType");//1:打车,2=代驾
                String business = "1".equals(businessType) ? "dache" : "daijia";
                String fluid_control = redisUtil.getValue(business + ":location_" + driverId);
                if(!StringUtils.hasLength(fluid_control)){
                    redisUtil.setStrValue("location_" + driverId, System.currentTimeMillis() + "");
                    redisUtil.setStrValue(business + ":location_" + driverId, System.currentTimeMillis() + "");
                }else{
                    long l = System.currentTimeMillis() - Long.valueOf(fluid_control);
                    if(l < 5000){
                        return;
                    }
                    redisUtil.setStrValue("location_" + driverId, System.currentTimeMillis() + "");
                    redisUtil.setStrValue(business + ":location_" + driverId, System.currentTimeMillis() + "");
                }
                
                Integer orderId = jsonCon.getInteger("orderId");
@@ -186,16 +191,44 @@
                System.out.println("司机上传位置:" + sdf.format(new Date()) + "----" + jsonCon.toJSONString());
                if(SinataUtil.isNotEmpty(driverId)){
                    if(null !=  lon && 0 != lon && null !=  lat && 0 != lat){
                        if(null != orderId && 0 != driverId && null != orderType && 0 != orderType){//开始存入数据库
                        if("dache".equals(business)){
                            if(null != orderId && 0 != driverId && null != orderType && 0 != orderType){//开始存入数据库
                                Map<String, Object> params = new HashMap<>();
                                params.put("orderType", String.valueOf(orderType));
                                params.put("orderId", String.valueOf(orderId));
                                params.put("driverId", String.valueOf(driverId));
                                params.put("lon", String.valueOf(lon));
                                params.put("lat", String.valueOf(lat));
                                params.put("directionAngle", String.valueOf(computeAzimuth));
                                params.put("altitude", String.valueOf(altitude));
                                HttpRequest post = HttpUtil.createPost(URLUtil.zuul + "/driver-server/base/savePosition");
                                post.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
                                post.form(params);
                                HttpResponse execute = post.execute();
                                if(200 != execute.getStatus()){
                                    System.err.println("调用driver-server存储位置数据出错了");
                                }
                                JSONObject jsonObject = JSON.parseObject(execute.body(), JSONObject.class);
                                if(jsonObject.getIntValue("code") != 200){
                                    System.err.println("调用driver-server存储位置数据出错了");
                                }
                            }
                        }
                        if("daijia".equals(business)){
                            HttpHeaders headers = new HttpHeaders();
                            // 以表单的方式提交
                            headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
                            //将请求头部和参数合成一个请求
                            Map<String, Object> params = new HashMap<>();
                            params.put("orderType", String.valueOf(orderType));
                            params.put("orderId", String.valueOf(orderId));
                            params.put("orderType", null == orderType ? orderType : String.valueOf(orderType));
                            params.put("orderId", null == orderId ? orderId : String.valueOf(orderId));
                            params.put("driverId", String.valueOf(driverId));
                            params.put("lon", String.valueOf(lon));
                            params.put("lat", String.valueOf(lat));
                            params.put("directionAngle", String.valueOf(computeAzimuth));
                            params.put("altitude", String.valueOf(altitude));
                            HttpRequest post = HttpUtil.createPost(URLUtil.zuul + "/driver-server/base/savePosition");
                            HttpRequest post = HttpUtil.createPost(URLUtil.aj_zuul + "/driver-server/base/driver/addDriverPosition");
                            post.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
                            post.form(params);
                            HttpResponse execute = post.execute();
@@ -207,7 +240,8 @@
                                System.err.println("调用driver-server存储位置数据出错了");
                            }
                        }
                        redisUtil.setStrValue("DRIVER" + driverId, lon + "," + lat, 30);//实时位置存入redis中
                        redisUtil.setStrValue(business + ":DRIVER" + driverId, lon + "," + lat, 30);//实时位置存入redis中
                    }else{
                        this.sendMsgToClient(ctx, "__error__" + msg.toString());
                    }