From 233c0e20548cadafb77efdcb3418f38c6658bbad Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期四, 26 十月 2023 14:20:57 +0800
Subject: [PATCH] 四川省网关接口相关7

---
 src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceReport.java |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDevice.java b/src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceReport.java
similarity index 83%
rename from src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDevice.java
rename to src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceReport.java
index dce5180..b886a61 100644
--- a/src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDevice.java
+++ b/src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceReport.java
@@ -1,6 +1,7 @@
 package com.fzzy.gateway.hx2023.websocket;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fzzy.gateway.GatewayUtils;
 import com.fzzy.gateway.hx2023.ScConstant;
 import com.fzzy.gateway.hx2023.data.WebSocketPacket;
 import lombok.extern.slf4j.Slf4j;
@@ -19,7 +20,7 @@
 @Slf4j
 @Component
 @ServerEndpoint(value = "/device/{productId}/{deviceId}/message/property/report")
-public class WebSocketDevice {
+public class WebSocketDeviceReport {
 
     private static Map<String, Session> sessionPool = new ConcurrentHashMap<>();
     private static Map<String, String> sessionIds = new ConcurrentHashMap<>();
@@ -42,7 +43,7 @@
         sessionPool.put(key, session);
         sessionIds.put(session.getId(), key);
 
-        ScConstant.updateOnline(deviceId);
+        GatewayUtils.updateOnline(deviceId);
 
         log.info("new webSocket,clientId={}", key);
     }
@@ -52,9 +53,9 @@
 
         String key = sessionIds.get(session.getId());
 
-        String deviceId = key.substring(0, key.indexOf("-"));
+        String deviceId = key.substring(key.indexOf("-"));
 
-        ScConstant.updateOffOnline(deviceId);
+        GatewayUtils.updateOffOnline(deviceId);
 
         sessionPool.remove(key);
         sessionIds.remove(session.getId());
@@ -81,9 +82,9 @@
 
         String key = sessionIds.get(session.getId());
 
-        String deviceId = key.substring(0, key.indexOf("-"));
+        String deviceId = key.substring(key.indexOf("-"));
 
-        ScConstant.updateOffOnline(deviceId);
+        GatewayUtils.updateOffOnline(deviceId);
 
         sessionPool.remove(key);
         sessionIds.remove(session.getId());
@@ -96,17 +97,24 @@
      *
      * @param packet
      */
-    public static void sendByPacket(WebSocketPacket packet) {
+    public void sendByPacket(WebSocketPacket packet) {
         if (StringUtils.isEmpty(packet.getDeviceId())) {
             log.error("WebSocket淇℃伅鎺ㄩ�佸け璐ワ紝璁惧缂栫爜涓虹┖銆�");
             return;
         }
 
+
         String tag = packet.getDeviceId();
 
         // 閬嶅巻鎺ㄩ��
         Session session;
+        String productId;
         for (String key : sessionPool.keySet()) {
+
+            productId = key.substring(0, key.indexOf("-"));
+
+            packet.getHeaders().setProductId(productId);
+
             if (key.indexOf(tag) != -1) {
                 session = sessionPool.get(key);
                 session.getAsyncRemote().sendText(

--
Gitblit v1.9.3