From d41f14d2986b46da9dd7742f6df63d9725cd29f3 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期二, 29 十月 2024 17:08:36 +0800 Subject: [PATCH] 数据采集 --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java | 44 ++++++++++++++------------------------------ 1 files changed, 14 insertions(+), 30 deletions(-) diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java similarity index 76% rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.java rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java index 51c6bae..8b1ad12 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForSS.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/ihdb/HttpCollectorForIhd.java @@ -1,6 +1,5 @@ package com.iailab.module.data.channel.http.collector.ihdb; -import cn.hutool.core.util.ArrayUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -9,7 +8,7 @@ import com.iailab.module.data.channel.http.service.HttpApiService; import com.iailab.module.data.common.enums.DataSourceType; import com.iailab.module.data.common.utils.DateUtils; -import com.iailab.module.data.common.utils.HttpsRequest; +import com.iailab.module.data.common.utils.HttpRequest; import com.iailab.module.data.common.utils.TagUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -17,30 +16,26 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; -import java.sql.Array; import java.util.*; /** * iHyperDB采集 + * * @author lirm * @Description * @createTime 2024年10月16日 */ @Slf4j @Component -public class HttpCollectorForSS { +public class HttpCollectorForIhd { private Map<String, HttpApiEntity> apiMap = new HashMap<>(); @Autowired private HttpApiService httpApiService; - @Autowired - HttpsRequest httpsRequest; + private static final String STA_TRUE = "true"; - private final String STA_TRUE = "true"; - - private final int GROUP_MAX_COUNT = 50; - + private static final int GROUP_MAX_COUNT = 50; private HttpApiEntity getHttpApi(String id) { if (apiMap.containsKey(id)) { @@ -60,12 +55,12 @@ queryParams.put("datatype", valueType); queryParams.put("dimension", dimension); queryParams.put("tagname", tagNo); - String jsonString = JSON.toJSONString(queryParams); + String jsonString = JSON.toJSONString(queryParams); tagSb.append(jsonString); tagSb.append("]"); log.info("body=====" + tagSb.toString()); - String currentDate = DateUtils.format(new Date(),"yyyyMMddHHmmss"); - String responseStr = httpsRequest.doPost(httpApi.getUrl(), tagSb.toString(), currentDate, "utf-8"); + String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); + String responseStr = HttpRequest.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); JSONObject responseObj = JSON.parseObject(responseStr); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { JSONArray tagValueList = responseObj.getJSONArray("data"); @@ -86,7 +81,7 @@ Map<Integer, List<Object[]>> measurePointsCountGroup = new HashMap<>(); int pointListSize = params.size(); - int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); + int groupCount = pointListSize / GROUP_MAX_COUNT + ((pointListSize % GROUP_MAX_COUNT) > 0 ? 1 : 0); log.info("groupCount=" + groupCount); for (int i = 0; i < groupCount; i++) { int end = (i + 1) * GROUP_MAX_COUNT; @@ -96,7 +91,7 @@ measurePointsCountGroup.put(i, params.subList(i * GROUP_MAX_COUNT, end)); } Map<String, Object> result = new HashMap<>(params.size()); - for(Map.Entry<Integer, List<Object[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { + for (Map.Entry<Integer, List<Object[]>> measurePointsItem : measurePointsCountGroup.entrySet()) { try { getByHtp(result, measurePointsItem.getValue()); } catch (Exception ex) { @@ -110,12 +105,12 @@ HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0].toString()); StringBuilder tagSb = new StringBuilder(); tagSb.append("["); - for (int i = 0; i < params.size(); i ++) { + for (int i = 0; i < params.size(); i++) { Map<String, Object> queryParams = new HashMap<>(); queryParams.put("tagname", params.get(i)[1]); queryParams.put("dimension", params.get(i)[2]); queryParams.put("datatype", params.get(i)[3]); - String jsonString = JSON.toJSONString(queryParams); + String jsonString = JSON.toJSONString(queryParams); tagSb.append(jsonString); if (i < params.size() - 1) { tagSb.append(","); @@ -123,8 +118,8 @@ } tagSb.append("]"); log.info("body=====" + tagSb.toString()); - String currentDate = DateUtils.format(new Date(),"yyyyMMddHHmmss"); - String responseStr = httpsRequest.doPost(httpApi.getUrl(), tagSb.toString(),currentDate, "utf-8"); + String currentDate = DateUtils.format(new Date(), "yyyyMMddHHmm00"); + String responseStr = HttpRequest.sendPost(httpApi.getUrl() + "/" + currentDate, tagSb.toString()); JSONObject responseObj = JSON.parseObject(responseStr); log.info("responseObj=====" + responseObj.toJSONString()); if (STA_TRUE.equals(responseObj.get("isSuccess").toString())) { @@ -136,16 +131,5 @@ } } } - - } - - public static void main(String[] args) { - Map<String, Object> queryParams = new HashMap<>(); - queryParams.put("tagname", "11"); - queryParams.put("dimension", 1); - queryParams.put("datatype", "22"); - String jsonString = JSONObject.toJSONString(queryParams); - System.out.println(jsonString); - System.out.println("[" + jsonString + "]"); } } \ No newline at end of file -- Gitblit v1.9.3