TRX 1 gadu atpakaļ
vecāks
revīzija
52072db7ce

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/GateWay2UserDao.java

@@ -14,4 +14,5 @@ public interface GateWay2UserDao extends org.springframework.data.mongodb.reposi
 
     GateWay2User findTopByGateWayInfo(GateWayInfo gateWayInfo);
 
+    GateWay2User findTopByGateWayInfoOrderByCreateTimeDesc(GateWayInfo gateWayInfo);
 }

+ 6 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/GateWayUserInfoService.java

@@ -101,8 +101,8 @@ public class GateWayUserInfoService {
     public GateWayUserInfo gateWayBindMqttUser(GateWayInfo gateWayInfo) {
         GateWayUserInfo gateWayUserInfo = null;
         if (ObjectUtils.isNotEmpty(gateWayInfo)) {
-            GateWay2User gateWay2User = gateWay2UserDao.findTopByGateWayInfo(gateWayInfo);
-            if (ObjectUtils.isEmpty(gateWay2User)) {
+            GateWay2User gateWay2User = gateWay2UserDao.findTopByGateWayInfoOrderByCreateTimeDesc(gateWayInfo);
+            if (ObjectUtils.isEmpty(gateWay2User) || ObjectUtils.isEmpty(gateWay2User.getGateWayUserInfo())) {
                 GateWayUserInfoAddParam userParam = new GateWayUserInfoAddParam();
                 String userName = CommonUtil.generateRandomString(8);
                 String roleName = userName;
@@ -114,7 +114,10 @@ public class GateWayUserInfoService {
                 ResultContent<GateWayUserInfo> resultContent = addGateWayUser(userParam);
                 if (resultContent.isSuccess()) {
                     gateWayUserInfo = resultContent.getContent();
-                    gateWay2User = new GateWay2User();
+                    if(ObjectUtils.isEmpty(gateWay2User)) {
+                        gateWay2User = new GateWay2User();
+                    }
+
                     gateWay2User.setGateWayInfo(gateWayInfo);
                     gateWay2User.setGateWayId(gateWayInfo.getGateWayId());
                     gateWay2User.setGateWayUserInfo(gateWayUserInfo);