chejianzheng 3 ヶ月 前
コミット
4b994344d0

+ 1 - 1
device-service-application/src/main/java/com/hfln/device/application/service/impl/DeviceEventServiceImpl.java

@@ -903,7 +903,7 @@ public class DeviceEventServiceImpl implements DeviceEventService {
                 List<Integer> pose = device.getRealtimePose();           // pose = device.realtime_pose()
                 
                 // === 发送实时位置姿态消息 (对应Python: mqtt_send.realtime_pos_msg(dev_id, raw_points, pose, targets)) ===
-                mqttGateway.sendRealtimePositionMessage(deviceId, rawPoints, pose, targets);
+                mqttGateway.sendRealtimePosMessage(deviceId, rawPoints, pose, targets);
                 
                 // === 更新停留时长 (对应Python的时间更新逻辑) ===
                 long ts = System.currentTimeMillis();  // ts = get_utc_time_ms()

+ 2 - 0
device-service-application/src/main/java/com/hfln/device/application/task/DeviceStatusCheckTask.java

@@ -73,6 +73,7 @@ public class DeviceStatusCheckTask {
     @Scheduled(fixedRate = 60000) // 60秒检查一次
     public void checkDeviceAlarmAck() {
         try {
+            log.debug("开始检查设备告警确认状态...");
             long currentTime = System.currentTimeMillis();
             Collection<Device> deviceCollection = deviceManagerService.getAllDevicesFromCache();
             List<Device> allDevices = new ArrayList<>(deviceCollection);
@@ -102,6 +103,7 @@ public class DeviceStatusCheckTask {
     @Scheduled(fixedRate = 30000) // 30秒检查一次
     public void checkAllDeviceStayTime() {
         try {
+            log.debug("开始检查所有设备停留时间...");
             long currentTime = System.currentTimeMillis();
             Collection<Device> deviceCollection = deviceManagerService.getAllDevicesFromCache();
             List<Device> allDevices = new ArrayList<>(deviceCollection);

+ 1 - 1
device-service-common/src/main/java/com/hfln/device/common/constant/mqtt/topic/MqttTopics.java

@@ -54,7 +54,7 @@ public class MqttTopics {
     public static final String DAS_KEEPALIVE_RESPONSE = "/das/+/keepalive/response";
     public static final String DAS_STATUS = "/das/status";
     public static final String DAS_CLOUDPOINT = "/das/cloudpoint";
-    public static final String DAS_REALTIME_POS = "/das/realtime_pose";
+    public static final String DAS_REALTIME_POS = "/das/realtime_pos";
     public static final String DAS_EVENT = "/das/event";
     public static final String DAS_EXIST_EVENT = "/das/existence_event";
     public static final String DAS_ALARM_EVENT = "/das/alarm_event";

+ 2 - 0
device-service-domain/src/main/java/com/hfln/device/domain/gateway/MqttGateway.java

@@ -143,6 +143,8 @@ public interface MqttGateway {
      */
     void sendRealtimePositionMessage(String deviceId, List<List<Float>> rawPoints, List<Integer> pose, List<List<Float>> targets);
 
+    void sendRealtimePosMessage(String deviceId, List<List<Float>> rawPoints, List<Integer> pose, List<List<Float>> targets);
+
     /**
      * 发送实时姿态消息
      * @param deviceId 设备ID

+ 36 - 1
device-service-infrastructure/src/main/java/com/hfln/device/infrastructure/gateway/MqttGatewayImpl.java

@@ -443,7 +443,8 @@ public class MqttGatewayImpl implements MqttGateway {
             payload.put("pose", pose);
             payload.put("RawPoints", rawPoints != null ? rawPoints : new ArrayList<>());  // 对应Python版本的RawPoints参数
             payload.put("targets", targets != null ? targets : new ArrayList<>());        // 对应Python版本的targets参数
-            
+            payload.put("target_point", targets != null ? targets : new ArrayList<>());        // 对应Python版本的targets参数
+
             // 对于确认的跌倒事件,使用QoS 2
             int qos = "fall_confirmed".equals(event) ? 2 : 0;
             sendMessage(MqttTopics.DAS_EVENT, payload, qos);
@@ -791,6 +792,40 @@ public class MqttGatewayImpl implements MqttGateway {
     }
 
     @Override
+    public void sendRealtimePosMessage(String deviceId, List<List<Float>> rawPoints, List<Integer> pose, List<List<Float>> targets) {
+        try {
+            Map<String, Object> message = new HashMap<>();
+
+            message.put("dev_id", deviceId);
+            message.put("timestamp", System.currentTimeMillis());
+            message.put("message", "notify");
+            message.put("message_type", DeviceConstants.MessageType.MSG_REALTIME_TARGET.getCode());
+
+
+            // 姿态信息 (对应Python版本的pose)
+            if (pose != null && !pose.isEmpty()) {
+                message.put("pose", pose.get(0)); // 取第一个姿态值
+            } else {
+                message.put("pose", 0); // 默认姿态
+            }
+
+            // 目标位置 (对应Python版本的targets)
+            if (targets != null) {
+                message.put("target_point", targets);
+            } else {
+                message.put("target_point", new ArrayList<>());
+            }
+
+            publishJson(MqttTopics.DAS_REALTIME_POS, message);
+            log.trace("Realtime position message sent: deviceId={}, targetCount={}",
+                    deviceId, targets != null ? targets.size() : 0);
+        } catch (Exception e) {
+            log.error("Failed to send realtime position message: deviceId={}, error={}",
+                    deviceId, e.getMessage(), e);
+        }
+    }
+
+    @Override
     public void sendExistEventMessage(String deviceId, String event) {
         try {
             Map<String, Object> payload = new HashMap<>();