Browse Source

更新!

TRX 1 year ago
parent
commit
ad6b64fc14

+ 11 - 6
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -525,16 +525,21 @@ public class IotServiceImpl extends SuperService {
             realIotTopic = realIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
             replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
 
+            String gateWayId = "";
             DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
             if (ObjectUtils.isNotEmpty(deviceInfo)) {
-                GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(deviceInfo);
-                if (ObjectUtils.isNotEmpty(gateWay2Device) && gateWay2Device.getGateWayInfo() != null) {
-                    String gateWayId = gateWay2Device.getGateWayInfo().getDeviceId();
-                    realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
-                    replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
-                    iotMain.setGateWayId(gateWayId);
+                if (deviceInfo.getDeviceCategory() == DeviceCategory.GW) {
+                    gateWayId = deviceInfo.getDeviceId();
+                } else {
+                    GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(deviceInfo);
+                    if (ObjectUtils.isNotEmpty(gateWay2Device) && gateWay2Device.getGateWayInfo() != null) {
+                        gateWayId = gateWay2Device.getGateWayInfo().getDeviceId();
+                    }
                 }
             }
+            realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
+            replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
+            iotMain.setGateWayId(gateWayId);
 
             if (deviceInfo.getDeviceCategory() == DeviceCategory.GW) {
                 realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), deviceInfo.getDeviceId());