xuhy
2026-04-23 d9e201f71882d7d6faac88f1f2f69b31f5fb29f1
xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/webSocket/handler/WebSocketTextFrameHandler.java
@@ -165,23 +165,16 @@
        if (appUserId != null) {
            log.info("收到用户 {} 的业务消息: {}", appUserId, messageObj.toJSONString());
            businessMsgHandlers.get(messageObj.getString("type")).handle(appUserId, messageObj.getString("message"));
            //判断处理用户实时位置
            if ("location".equals(messageObj.getString("type"))) {
                log.info("收到用户 {} 的实时位置消息: {}", appUserId, messageObj.toJSONString());
                Double latitude = messageObj.getDouble("latitude");
                Double longitude = messageObj.getDouble("longitude");
                saveAppUserLocation(Long.parseLong(appUserId), latitude, longitude);
            }
            businessMsgHandlers.get(messageObj.getString("type")).handle(appUserId, messageObj.toJSONString());
            // 回复消息
            JSONObject response = new JSONObject();
            response.put("type", "message_response");
            response.put("appUserId", appUserId);
            response.put("originalMessage", messageObj);
            response.put("serverTime", LocalDateTime.now().toString());
            ctx.channel().writeAndFlush(new TextWebSocketFrame(response.toJSONString()));
//            JSONObject response = new JSONObject();
//            response.put("type", "message_response");
//            response.put("appUserId", appUserId);
//            response.put("originalMessage", messageObj);
//            response.put("serverTime", LocalDateTime.now().toString());
//
//            ctx.channel().writeAndFlush(new TextWebSocketFrame(response.toJSONString()));
        } else {
            log.warn("收到未认证连接的业务消息: {}", messageObj.toJSONString());
@@ -224,20 +217,4 @@
        ctx.channel().close();
    }
    private void saveAppUserLocation(Long appUserId, Double latitude, Double longitude) {
        AppUserPosition userPosition = mongoTemplate.findOne(Query.query(Criteria.where("appUserId").is(appUserId)), AppUserPosition.class);
        GeoJsonPoint point = new GeoJsonPoint(longitude, latitude);
        if(null != userPosition){
            mongoTemplate.updateFirst(Query.query(Criteria.where("appUserId").is(appUserId)),
                    Update.update("point", point).set("addTime", System.currentTimeMillis()), AppUserPosition.class);
        }else{
            userPosition = new AppUserPosition();
            userPosition.setAppUserId(appUserId);
            userPosition.setPoint(point);
            userPosition.setAddTime(System.currentTimeMillis());
            mongoTemplate.save(userPosition);
        }
    }
}