From eade7851c02fea9a8a282b5f722214f9348080fe Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期三, 26 三月 2025 16:10:59 +0800 Subject: [PATCH] 安信电力数据采集 --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/asdb/HttpCollectorForAsde.java | 120 ++++++++++++++++++++++++++++++++++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java | 12 ++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/SourceApiEnum.java | 3 3 files changed, 134 insertions(+), 1 deletions(-) diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/SourceApiEnum.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/SourceApiEnum.java index 608de48..4df5532 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/SourceApiEnum.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/SourceApiEnum.java @@ -12,7 +12,8 @@ @AllArgsConstructor public enum SourceApiEnum { iHyperDB("iHyperDB", "宝信IHD"), - ASDB("ASDB", "鞍钢DB"); + ASDB("ASDB", "鞍钢DB"), + ASDE("ASDB", "鞍钢电力"); private String code; private String desc; diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/asdb/HttpCollectorForAsde.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/asdb/HttpCollectorForAsde.java new file mode 100644 index 0000000..54efb72 --- /dev/null +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/http/collector/asdb/HttpCollectorForAsde.java @@ -0,0 +1,120 @@ +package com.iailab.module.data.channel.http.collector.asdb; + +import com.alibaba.fastjson.JSON; +import com.iailab.framework.common.constant.CommonConstant; +import com.iailab.framework.common.util.http.HttpUtils; +import com.iailab.module.data.channel.http.collector.asdb.vo.HttpAsdbRespDataVO; +import com.iailab.module.data.channel.http.entity.HttpApiEntity; +import com.iailab.module.data.channel.http.service.HttpApiService; +import com.iailab.module.data.common.enums.DataSourceType; +import com.iailab.module.data.common.utils.TagUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * @author PanZhibao + * @Description + * @createTime 2025年03月26日 + */ +@Slf4j +@Component +public class HttpCollectorForAsde { + private static Map<String, HttpApiEntity> apiMap = new HashMap<>(); + + @Autowired + private HttpApiService httpApiService; + + @Autowired + private RedisTemplate redisTemplate; + + public static final long offset = 10; + + private HttpApiEntity getHttpApi(String id) { + if (apiMap.containsKey(id)) { + return apiMap.get(id); + } + HttpApiEntity httpApi = httpApiService.info(id); + apiMap.put(id, httpApi); + return httpApi; + } + + public BigDecimal getTagValue(String sourceId, String tagNo) { + BigDecimal value = CommonConstant.BAD_VALUE; + HttpApiEntity httpApi = this.getHttpApi(sourceId); + //先查缓存 + String catchKey = "IailabData:" + httpApi.getCode() + ":" + tagNo; + if (redisTemplate.hasKey(catchKey)) { + log.info("查找IailabData缓存: " + catchKey); + return new BigDecimal(redisTemplate.opsForValue().get(catchKey).toString()); + } + String responseStr = HttpUtils.sendGet(httpApi.getUrl(), null, ""); + List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); + log.info("存入IailabData缓存: " + catchKey); + dataList.forEach(item -> { + redisTemplate.opsForValue().set(catchKey, item.getValue().toString(), offset, TimeUnit.SECONDS); + }); + for (HttpAsdbRespDataVO data : dataList){ + if (tagNo.equals(data.getPoint())){ + value = data.getValue(); + break; + } + } + return value; + } + + public Map<String, Object> getTagValues(String sourceId, List<String> tagNames) { + Map<String, Object> result = new HashMap<>(); + try { + if (CollectionUtils.isEmpty(tagNames)) { + return result; + } + for (String tagName : tagNames) { + result.put(tagName, getTagValue(sourceId, tagName)); + } + } catch (Exception ex) { + log.info("getCurrentValue异常"); + ex.printStackTrace(); + throw ex; + } + return result; + } + + public Map<String, Object> getTagValues(List<Object[]> params, Date collectTime) { + Map<String, Object> result = new HashMap<>(); + if (CollectionUtils.isEmpty(params)) { + return new HashMap<>(); + } + try { + HttpApiEntity httpApi = this.getHttpApi(params.get(0)[0].toString()); + this.getByHtp(httpApi.getUrl(), httpApi.getCode(), result, params); + } catch (Exception ex) { + ex.printStackTrace(); + } + return result; + } + + private void getByHtp(String url, String sourceName, Map<String, Object> result, List<Object[]> params) { + String responseStr = HttpUtils.sendGet(url, null, ""); + List<HttpAsdbRespDataVO> dataList = JSON.parseArray(responseStr, HttpAsdbRespDataVO.class); + Map<String, HttpAsdbRespDataVO> valueGroup = new HashMap<>(); + for (HttpAsdbRespDataVO data : dataList) { + valueGroup.put(data.getPoint(), data); + } + for (Object[] item : params) { + if (valueGroup.containsKey(item[1].toString())) { + HttpAsdbRespDataVO data = valueGroup.get(item[1].toString()); + result.put(TagUtils.genTagId(DataSourceType.HTTP.getCode(), sourceName, data.getPoint()), data.getValue()); + } + } + } +} \ No newline at end of file diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java index 6002f45..d3c6d26 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java @@ -3,6 +3,7 @@ import com.iailab.framework.common.util.string.StrUtils; import com.iailab.module.data.channel.http.collector.SourceApiEnum; import com.iailab.module.data.channel.http.collector.asdb.HttpCollectorForAsdb; +import com.iailab.module.data.channel.http.collector.asdb.HttpCollectorForAsde; import com.iailab.module.data.channel.http.collector.ihdb.HttpCollectorForIhd; import com.iailab.module.data.channel.opcda.collector.OpcDACollector; import com.iailab.module.data.common.enums.CommonConstant; @@ -59,6 +60,9 @@ @Autowired private HttpCollectorForAsdb httpCollectorForAsdb; + @Autowired + private HttpCollectorForAsde httpCollectorForAsde; + @Resource private DaPointService daPointService; @@ -78,6 +82,7 @@ List<String[]> kioTagIds = new ArrayList<>(); List<Object[]> httpTagIhd = new ArrayList<>(); List<Object[]> httpTagAsdb = new ArrayList<>(); + List<Object[]> httpTagAsde = new ArrayList<>(); dtos.stream().forEach(item -> { if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) { @@ -96,6 +101,10 @@ } else if (SourceApiEnum.ASDB.getCode().equals(item.getSourceName())) { if (item.getTagNo() != null && item.getDimension() != null && item.getValueType() != null) { httpTagAsdb.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); + } + } else if (SourceApiEnum.ASDE.getCode().equals(item.getSourceName())) { + if (item.getTagNo() != null && item.getDimension() != null && item.getValueType() != null) { + httpTagAsde.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()}); } } } @@ -120,6 +129,9 @@ if (!CollectionUtils.isEmpty(httpTagAsdb)) { tagValues.putAll(httpCollectorForAsdb.getTagValues(httpTagAsdb, collectTime)); } + if (!CollectionUtils.isEmpty(httpTagAsde)) { + tagValues.putAll(httpCollectorForAsde.getTagValues(httpTagAsde, collectTime)); + } this.toCommonResult(collectTime, dtos, tagValues, dataMap, result,listGood,listBad); log.info("测量点处理结束"); return result; -- Gitblit v1.9.3