| | |
| | | sendMsgToClient(ctx, jsonMsg.toJSONString()); |
| | | } |
| | | } |
| | | //乘客上传位置,转发到用户端服务做订单校验和司机推送 |
| | | if(method.equals(Method.passengerLocation)){ |
| | | forwardPassengerLocation(ctx, jsonCon); |
| | | } |
| | | //司机上传位置 |
| | | if(method.equals(Method.location)){ |
| | | Integer driverId = jsonCon.getInteger("driverId"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 转发乘客实时定位到用户服务,由用户服务校验订单后推送给司机端 |
| | | */ |
| | | private void forwardPassengerLocation(ChannelHandlerContext ctx, JSONObject jsonCon) { |
| | | Integer userId = jsonCon.getInteger("userId"); |
| | | Integer orderId = jsonCon.getInteger("orderId"); |
| | | Integer orderType = jsonCon.getInteger("orderType"); |
| | | Double lon = jsonCon.getDouble("lon"); |
| | | Double lat = jsonCon.getDouble("lat"); |
| | | String timestamp = jsonCon.getString("timestamp"); |
| | | // 基础参数不合法时直接返回错误,不再调用后端业务接口 |
| | | if (userId == null || orderId == null || orderType == null || lon == null || lat == null || lon == 0 || lat == 0) { |
| | | this.sendMsgToClient(ctx, "__error__" + jsonCon.toJSONString()); |
| | | return; |
| | | } |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("userId", String.valueOf(userId)); |
| | | params.put("orderId", String.valueOf(orderId)); |
| | | params.put("orderType", String.valueOf(orderType)); |
| | | params.put("lon", String.valueOf(lon)); |
| | | params.put("lat", String.valueOf(lat)); |
| | | params.put("timestamp", timestamp); |
| | | HttpRequest post = HttpUtil.createPost(qytConfig.getChuxingUrl() + "/user-server/base/passenger/location/push"); |
| | | post.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("调用user-server推送乘客定位出错"); |
| | | return; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if (jsonObject.getIntValue("code") != 200) { |
| | | System.err.println("调用user-server推送乘客定位出错:" + jsonObject.getString("msg")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 向客户端发送消息 |
| | | * |
| | | * @param ctx |