Ver código fonte

修复设备改成批量后,http不兼容,批量和单个不兼容问题,保证了创建和删除设备没问题,但是修改设备还存问题

yf_zn 11 meses atrás
pai
commit
03a8e1ca12

+ 1 - 8
src/main/java/com/yunfeiyun/agmp/iots/cache/DeviceconnCacheService.java

@@ -71,14 +71,6 @@ public class DeviceconnCacheService {
     public IotDeviceconn getIotDeviceConnByDevconnBid(String devconnBid) {
         log.info("【设备连接缓存】查询设备连接信息,设备连接标识为:{}", devconnBid);
         IotDeviceconn iotDeviceconn = deviceConnMap.get(devconnBid);
-        if (iotDeviceconn == null) {
-            log.error("【设备连接缓存】查询设备连接信息失败,设备连接标识为:{}", devconnBid);
-            iotDeviceconn = businessCoreService.selectDevConnByConnId(devconnBid);
-            if (iotDeviceconn == null) {
-                throw new IotBizException(IotErrorCode.INVALID_DEVICE_CONN_BID);
-            }
-            setCache(iotDeviceconn);
-        }
         return iotDeviceconn;
     }
 
@@ -134,6 +126,7 @@ public class DeviceconnCacheService {
      * 【http】保存租户的http通用连接信息
      */
     public void setHttpCommonConnectionByDevtypeCode(String devconnBid, String devtypeCode) {
+        log.info(devconnBid+""+devtypeCode);
         httpDeviceConnBidListMap.computeIfAbsent(devtypeCode, k -> ConcurrentHashMap.newKeySet()).add(devconnBid);
     }
 

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iots/core/http/HttpClient.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.reqvo.IotXmznReqVo;
 import com.yunfeiyun.agmp.iots.common.modal.IotDeviceconnResVo;
+import lombok.extern.slf4j.Slf4j;
 
 import java.util.List;
 
@@ -13,6 +14,7 @@ import java.util.List;
  * 暂用 hutool的http实现, 缺点:性能估计不太行
  *
  */
+@Slf4j
 public class HttpClient {
 
 

+ 13 - 0
src/main/java/com/yunfeiyun/agmp/iots/core/http/YbqCmbService.java

@@ -17,6 +17,8 @@ import com.yunfeiyun.agmp.iots.task.YbqScheduler;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringEscapeUtils;
 
+import java.util.List;
+
 /**
  * @author zhangn
  */
@@ -142,4 +144,15 @@ public class YbqCmbService extends HttpClient {
     public void deviceCreateHandle(IotDevice iotDevice) {
         SpringUtils.getBean(YbqScheduler.class).deviceCreateHandle(iotDevice);
     }
+
+    @Override
+    public void deviceCreateByBatchHandle(List<IotDevice> iotDeviceList) {
+        for (IotDevice iotDevice : iotDeviceList) {
+            try {
+                deviceCreateHandle(iotDevice);
+            } catch (Exception e) {
+                log.info("{}", e);
+            }
+        }
+    }
 }

+ 2 - 1
src/main/java/com/yunfeiyun/agmp/iots/core/manager/ConnectionManager.java

@@ -288,6 +288,7 @@ public class ConnectionManager {
         }
         IotDeviceconnResVo iotDeviceconnResVo = new IotDeviceconnResVo();
         BeanUtils.copyProperties(iotDeviceconn, iotDeviceconnResVo);
+        iotDeviceconnResVo.setDevtypeCode(iotDeviceconn.getDevtypeBid());
         // 遍历多个配置
         for (int j = 0; j < jsonConfig.size(); j++) {
             buildConnCoreByConfig(iotDeviceconnResVo, jsonConfig.getJSONObject(j));
@@ -406,7 +407,7 @@ public class ConnectionManager {
     }
 
     private void httpDeleteDeviceHandle(IotDevice iotDevice) {
-        httpManager.deviceCreateHandle(iotDevice);
+        httpManager.deleteHttpConnection(iotDevice.getDevconnBid());
     }
 
     public void updateCommonManager(TosDevicetype tosDevicetype) {

+ 14 - 1
src/main/java/com/yunfeiyun/agmp/iots/mq/listener/IotmBaseDataChannelAwareMessageListener.java

@@ -64,7 +64,20 @@ public class IotmBaseDataChannelAwareMessageListener implements ChannelAwareMess
                     //设备创建
                     case IOT_DEVICE_CREATE:
                         JSONObject param = synGlobalTenantInfoDto.getData();
-                        connectionManager.createDeviceByBatchHandle(param.getObject("iotDeviceconn",IotDeviceconn.class),param.getList("bodyItem",IotDevice.class));
+                        if(param.toString().contains("bodyItem")){
+                            connectionManager.createDeviceByBatchHandle(param.getObject("iotDeviceconn",IotDeviceconn.class),param.getList("bodyItem",IotDevice.class));
+                        }else{
+                            connectionManager.createDeviceHandle(synGlobalTenantInfoDto.getData().to(IotDevice.class));
+                        }
+                        break;
+                    //设备创建
+                    case IOT_DEVICE_CREATE_BATCH:
+                        JSONObject param2 = synGlobalTenantInfoDto.getData();
+                        if(!param2.toString().contains("bodyItem")){
+                            connectionManager.createDeviceHandle(synGlobalTenantInfoDto.getData().to(IotDevice.class));
+                        }else{
+                            connectionManager.createDeviceByBatchHandle(param2.getObject("iotDeviceconn",IotDeviceconn.class),param2.getList("bodyItem",IotDevice.class));
+                        }
                         break;
                     //设备更新
                     case IOT_DEVICE_UPDATE: