Browse Source

调整mqtt链接,合并同地址,同端口,同账号的连接信息

liuyaowen 1 year atrás
parent
commit
619a2ef38f

+ 3 - 11
src/main/java/com/yunfeiyun/agmp/iotm/mq/service/SendToIotsMsgService.java

@@ -7,7 +7,6 @@ import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
 import com.yunfeiyun.agmp.iot.common.constant.mq.IotActionEnums;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
-import com.yunfeiyun.agmp.iot.common.domain.IotDevicetype;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
 import com.yunfeiyun.agmp.iot.common.model.mq.IotDeviceEditMqModel;
 import com.yunfeiyun.agmp.iotm.mq.provider.IotsMqProviderService;
@@ -69,7 +68,7 @@ public class SendToIotsMsgService {
      * @param iotDeviceconn
      */
     public void sendIotDeviceconnInsertMsg(IotDeviceconn iotDeviceconn) {
-        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_CREATE, iotDeviceconn, "【Iotm】to【Iots】物联网新增设备连接,同步到Iots");
+        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_CONN_CREATE, iotDeviceconn, "【Iotm】to【Iots】物联网新增设备连接,同步到Iots");
     }
 
     /**
@@ -78,7 +77,7 @@ public class SendToIotsMsgService {
      * @param iotDeviceconn
      */
     public void sendIotDeviceconnUpdateMsg(IotDeviceconn iotDeviceconn) {
-        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_UPDATE, iotDeviceconn, "【Iotm】to【Iots】物联网编辑设备连接,同步到Iots");
+        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_CONN_UPDATE, iotDeviceconn, "【Iotm】to【Iots】物联网编辑设备连接,同步到Iots");
     }
 
     /**
@@ -87,7 +86,7 @@ public class SendToIotsMsgService {
      * @param iotDeviceconn
      */
     public void sendIotDeviceconnDeleteMsg(IotDeviceconn iotDeviceconn) {
-        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_DELETE, iotDeviceconn, "【Iotm】to【Iots】物联网删除设备连接,同步到Iots");
+        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_CONN_DELETE, iotDeviceconn, "【Iotm】to【Iots】物联网删除设备连接,同步到Iots");
     }
 
     public void sendCmdMsg(CmdGroupModel cmdGroupModel){
@@ -97,13 +96,6 @@ public class SendToIotsMsgService {
     /**
      * 物联网同步所有设备信息,同步iots  ok
      * @param devTypeCode 设备型号
-     */
-    public void sendIotSynAllDeviceMsg(String devTypeCode) {
-        mqService.sendBaseDataToIots( IotActionEnums.DEVICE_COON_DELETE,devTypeCode, "【Iotm】to【Iots】物联网同步所有设备信息,同步到Iots");
-    }
-    /**
-     * 物联网同步所有设备信息,同步iots  ok
-     * @param devTypeCode 设备型号
      * @param times 时间间隔
      * @param timeUnit 时间单位
      */

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotDeviceconnService.java

@@ -20,7 +20,7 @@ public interface IIotDeviceconnService
 
     public int addDeviceconn(IotDeviceconnAddReqVo reqVo);
 
-    public int addDeviceconn(IotDeviceconnAddReqVo reqVo, boolean isCreateConnect);
+
 
     /**
      * 查询设备连接配置列表

+ 12 - 20
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotDeviceconnServiceImpl.java

@@ -56,24 +56,20 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
     private IotDeviceMapper iotDeviceMapper;
 
     @Override
-    public int addDeviceconn(IotDeviceconnAddReqVo reqVo, boolean isCreateConnect) {
+    public int addDeviceconn(IotDeviceconnAddReqVo reqVo) {
         String devconnType = reqVo.getDevconnType();
         String devtypeBid = reqVo.getDevtypeBid();
-
         TosDevicetype tosDevicetype = tosDevicetypeService.selectTosDevicetypeByDevtypeBid(devtypeBid);
         if(tosDevicetype == null){
             throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备型号不存在");
         }
         IotDeviceconn selectIotDeviceconn = new IotDeviceconn();
         selectIotDeviceconn.setDevtypeBid(devtypeBid);
-
         List<IotDeviceconn> iotDeviceconnList = selectIotDeviceconnList(selectIotDeviceconn);
         if(iotDeviceconnList != null && !iotDeviceconnList.isEmpty()){
             throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"该设备型号已存在连接配置");
         }
-
         List<IotDeviceconn> insertIotDeviceconnList = new ArrayList<>();
-
         if(IotDeviceconnTypeEnum.COMMON.getCode().equals(devconnType)){
             IotDeviceconn iotDeviceconn = new IotDeviceconn();
             String bid = reqVo.getCommonConnBid();
@@ -86,6 +82,8 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
             iotDeviceconn.setDevconnCreateddate(DateUtils.dateTimeNow());
             insertIotDeviceconnList.add(iotDeviceconn);
         }else{
+            // 租户的私有连接创建需要再iots创建连接信息
+
             List<IotDevconnConfigInfoVo> devconnConfigList = reqVo.getDevconnConfigList();
             if(devconnConfigList == null || devconnConfigList.isEmpty()){
                 throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"连接配置不能为空");
@@ -126,28 +124,22 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
                 diffName = devconnName;
             }
         }
-
         int status = insertIotDeviceconnByBatch(insertIotDeviceconnList);
-        if(isCreateConnect) {
-            // 发送消息,创建设备连接
-            for(IotDeviceconn iotDeviceconn : insertIotDeviceconnList){
-                sendToIotsMsgService.sendIotDeviceconnInsertMsg(iotDeviceconn);
-            }
+        // 发送消息,创建设备连接
+        for(IotDeviceconn iotDeviceconn : insertIotDeviceconnList){
+            sendToIotsMsgService.sendIotDeviceconnInsertMsg(iotDeviceconn);
         }
         return status;
     }
 
-    @Override
-    public int addDeviceconn(IotDeviceconnAddReqVo reqVo) {
-        return addDeviceconn(reqVo, true);
-    }
-    private int addDeviceconn(String devtypeBid,String connType,List<IotDevconnConfigInfoVo> list,String commonConnBid,boolean isCreateConnect){
+
+    private int addDeviceconn(String devtypeBid,String connType,List<IotDevconnConfigInfoVo> list,String commonConnBid){
         IotDeviceconnAddReqVo iotDeviceconnAddReqVo = new IotDeviceconnAddReqVo();
         iotDeviceconnAddReqVo.setDevtypeBid(devtypeBid);
         iotDeviceconnAddReqVo.setDevconnType(connType);
         iotDeviceconnAddReqVo.setDevconnConfigList(list);
         iotDeviceconnAddReqVo.setCommonConnBid(commonConnBid);
-        return addDeviceconn(iotDeviceconnAddReqVo,isCreateConnect);
+        return addDeviceconn(iotDeviceconnAddReqVo);
     }
 
     /**
@@ -243,7 +235,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
                 // 先删除该租户的旧的通用配置信息
                 result = result + iotDeviceconnMapper.deleteIotDeviceconnByBids(new String[]{iotDeviceconn.getDevconnBid()});
                 // 再创建该租户的新的私有连接信息
-                result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null,true);
+                result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null);
                 // TODO: 此处用于解绑设备的旧配置以及创建新配置,后续可以优化
                 for(IotDevice iotDevice : iotDeviceList){
                     IotDevice newIotDevice =new IotDevice();
@@ -296,7 +288,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
             result = result + deleteIotDeviceconnByBids(iotDeviceconnList,true);
             String newConnBid = iotDeviceQuery.getUUId();
             // 创建该租户新的通用连接
-            result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),newConnBid,true);
+            result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),newConnBid);
             for(IotDevice iotDevice : iotDeviceList){
                 iotDevice.setDevconnBid(newConnBid);
                 iotDeviceMapper.updateIotDevice(iotDevice);
@@ -316,7 +308,7 @@ public class IotDeviceconnServiceImpl implements IIotDeviceconnService
                 // 先删除该租户的旧的私有连接,该接口会自动解绑设备
                 result = result + deleteIotDeviceconnByBids(iotDeviceconnList,true);
                 // 再创建该租户的新的私有连接信息
-                result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null,true);
+                result = result + addDeviceconn(reqVo.getNewDevtypeBid(),reqVo.getDevconnType(),reqVo.getDevconnConfigList(),null);
                 // TODO: 此处用于解绑设备的旧配置以及创建新配置,后续可以优化
                 for(IotDevice iotDevice : iotDeviceList){
                     iotDevice.setDevconnBid(newConfig.getDevconnBid());