提交 | 用户 | 时间
|
7cbee8
|
1 |
package com.iailab.module.data.channel.http.collector.ihdb; |
19eb2e
|
2 |
|
潘 |
3 |
import com.iailab.framework.common.constant.CommonConstant; |
|
4 |
import com.iailab.module.data.channel.http.entity.HttpApiEntity; |
|
5 |
import com.iailab.module.data.channel.http.service.HttpApiService; |
|
6 |
import lombok.extern.slf4j.Slf4j; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.stereotype.Component; |
|
9 |
import org.springframework.util.CollectionUtils; |
|
10 |
|
|
11 |
import java.math.BigDecimal; |
|
12 |
import java.util.HashMap; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Map; |
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* iHyperDB采集 |
|
19 |
* |
|
20 |
* { |
|
21 |
* "data": [ |
|
22 |
* { |
|
23 |
* "tagname": "S10248500000002PS011", |
|
24 |
* "value": 2701557.4736842105263157894737, |
|
25 |
* "timeStamp": "2024-10-11T18:24:00" |
|
26 |
* } |
|
27 |
* ], |
|
28 |
* "resultMessage": "请求成功...", |
|
29 |
* "resultCode": 0, |
|
30 |
* "isSuccess": true |
|
31 |
* } |
|
32 |
* |
|
33 |
* @author PanZhibao |
|
34 |
* @Description |
|
35 |
* @createTime 2024年10月14日 |
|
36 |
*/ |
|
37 |
@Slf4j |
|
38 |
@Component |
|
39 |
public class HttpCollectorIhDB { |
|
40 |
private Map<String, HttpApiEntity> apiMap = new HashMap<>(); |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private HttpApiService httpApiService; |
|
44 |
|
|
45 |
private final boolean STA_TRUE = true; |
|
46 |
|
|
47 |
private final String IS_SUCCESS = "isSuccess"; |
|
48 |
|
|
49 |
private HttpApiEntity getHttpApi(String id) { |
|
50 |
if (apiMap.containsKey(id)) { |
|
51 |
return apiMap.get(id); |
|
52 |
} |
|
53 |
HttpApiEntity httpApi = httpApiService.info(id); |
|
54 |
apiMap.put(id, httpApi); |
|
55 |
return httpApi; |
|
56 |
} |
|
57 |
|
|
58 |
public BigDecimal getTagValue(String sourceId, String tagNo) { |
|
59 |
BigDecimal value = CommonConstant.BAD_VALUE; |
|
60 |
HttpApiEntity httpApi = this.getHttpApi(sourceId); |
|
61 |
|
|
62 |
//HttpRequest.sendPost() |
|
63 |
|
|
64 |
return value; |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
public Map<String, Object> getTagValues(List<String[]> params) { |
|
69 |
if (CollectionUtils.isEmpty(params)) { |
|
70 |
return new HashMap<>(); |
|
71 |
} |
|
72 |
|
|
73 |
/*Map<Integer, List<String[]>> measurePointsCountGroup = new HashMap<>(); |
|
74 |
int pointListSize = params.size(); |
|
75 |
int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); |
|
76 |
log.info("groupCount=" + groupCount); |
|
77 |
for (int i = 0; i < groupCount; i++) { |
|
78 |
int end = (i + 1) * GROUP_MAX_COUNT; |
|
79 |
if (end > pointListSize) { |
|
80 |
end = pointListSize; |
|
81 |
} |
|
82 |
measurePointsCountGroup.put(i, params.subList(i * GROUP_MAX_COUNT, end)); |
|
83 |
}*/ |
|
84 |
Map<String, Object> result = new HashMap<>(params.size()); |
|
85 |
/*for(Map.Entry<Integer, List<String[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { |
|
86 |
try { |
|
87 |
getByHtp(result, measurePointsItem.getValue()); |
|
88 |
} catch (Exception ex) { |
|
89 |
ex.printStackTrace(); |
|
90 |
} |
|
91 |
}*/ |
|
92 |
return result; |
|
93 |
} |
|
94 |
|
|
95 |
private void getByHtp(Map<String, Object> result, List<String[]> params) { |
|
96 |
HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0]); |
|
97 |
Map<String, String> queryParams = new HashMap<>(); |
|
98 |
StringBuilder tagSb = new StringBuilder(); |
|
99 |
for (int i = 0; i < params.size(); i ++) { |
|
100 |
tagSb.append(params.get(i)[1]); |
|
101 |
if (i < params.size() - 1) { |
|
102 |
tagSb.append(","); |
|
103 |
} |
|
104 |
} |
|
105 |
/*queryParams.put("tagstr", tagSb.toString()); |
|
106 |
String responseStr = HttpRequest.sendGet(httpApi.getUrl(), queryParams, "utf-8", ""); |
|
107 |
JSONObject responseObj = JSON.parseObject(responseStr); |
|
108 |
if (STA_TRUE.equals(responseObj.get("sta").toString())) { |
|
109 |
JSONArray tagValueList = responseObj.getJSONArray("res"); |
|
110 |
if (!CollectionUtils.isEmpty(tagValueList)) { |
|
111 |
for (int i = 0; i < tagValueList.size(); i++) { |
|
112 |
JSONObject item = tagValueList.getJSONObject(i); |
|
113 |
result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), httpApi.getCode(), item.get("Tag").toString()), item.get("Value")); |
|
114 |
} |
|
115 |
} |
|
116 |
}*/ |
|
117 |
|
|
118 |
} |
|
119 |
} |