|
|
@@ -2,7 +2,9 @@ package com.yunfeiyun.agmp.iots.core.manager;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
|
|
|
+import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
|
|
|
import com.yunfeiyun.agmp.iot.common.enums.IotDeviceconnTypeEnum;
|
|
|
+import com.yunfeiyun.agmp.iot.common.service.DeviceconnCacheService;
|
|
|
import com.yunfeiyun.agmp.iot.common.service.TypeCacheService;
|
|
|
import com.yunfeiyun.agmp.iots.common.annotate.HttpCore;
|
|
|
import com.yunfeiyun.agmp.iots.common.modal.IotDeviceconnResVo;
|
|
|
@@ -25,10 +27,11 @@ import java.util.Set;
|
|
|
public class HttpManager {
|
|
|
@Resource
|
|
|
private TypeCacheService typeCacheService;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private DeviceconnCacheService deviceconnCacheService;
|
|
|
private HashMap<String, HttpClient> privateHttpClientByConnBid = new HashMap<>();
|
|
|
private HashMap<String, HttpClient> commonHttpClientByTypeBid = new HashMap<>();
|
|
|
- private HashMap<String,IotDeviceconnResVo> iotDeviceconnResVoHashMap = new HashMap<>();
|
|
|
+
|
|
|
private HashMap<String,Class<? extends HttpClient>> httpClinetClassMap = new HashMap<>();
|
|
|
|
|
|
@PostConstruct
|
|
|
@@ -67,7 +70,8 @@ public class HttpManager {
|
|
|
return;
|
|
|
}
|
|
|
commonHttpClientByTypeBid.put(iotDeviceconnResVo.getDevtypeBid(),httpClient);
|
|
|
- iotDeviceconnResVoHashMap.put(iotDeviceconnResVo.getDevconnBid(),iotDeviceconnResVo);
|
|
|
+ deviceconnCacheService.setCache(iotDeviceconnResVo);
|
|
|
+
|
|
|
}
|
|
|
private void initPrivateClient(IotDeviceconnResVo iotDeviceconnResVo ,JSONObject configJson){
|
|
|
HttpClient httpClient = initHttpClient(iotDeviceconnResVo,configJson);
|
|
|
@@ -75,7 +79,7 @@ public class HttpManager {
|
|
|
return;
|
|
|
}
|
|
|
privateHttpClientByConnBid.put(iotDeviceconnResVo.getDevconnBid(),httpClient);
|
|
|
- iotDeviceconnResVoHashMap.put(iotDeviceconnResVo.getDevconnBid(),iotDeviceconnResVo);
|
|
|
+ deviceconnCacheService.setCache(iotDeviceconnResVo);
|
|
|
}
|
|
|
private HttpClient initHttpClient(IotDeviceconnResVo iotDeviceconnResVo ,JSONObject configJson){
|
|
|
//获取继承了HttpClient的所有类
|
|
|
@@ -95,8 +99,8 @@ public class HttpManager {
|
|
|
}
|
|
|
|
|
|
public HttpClient getHttpClientByDevice(IotDevice iotDevice){
|
|
|
- IotDeviceconnResVo iotDeviceconnResVo = iotDeviceconnResVoHashMap.get(iotDevice.getDevconnBid());
|
|
|
- if(IotDeviceconnTypeEnum.COMMON.getCode().equals(iotDeviceconnResVo.getDevconnType())){
|
|
|
+ IotDeviceconn iotDeviceconn = deviceconnCacheService.getIotDeviceConnByDevconnBid(iotDevice.getDevconnBid());
|
|
|
+ if(IotDeviceconnTypeEnum.COMMON.getCode().equals(iotDeviceconn.getDevconnType())){
|
|
|
return commonHttpClientByTypeBid.get(iotDevice.getDevtypeBid());
|
|
|
}else {
|
|
|
return privateHttpClientByConnBid.get(iotDevice.getDevconnBid());
|