潘志宝
7 天以前 bbe7acfbe5a4c08d6edc91eaf81dcecf9d630e18
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -1,5 +1,8 @@
package com.iailab.module.data.point.collection.handler;
import com.iailab.module.data.channel.http.collector.SourceApiEnum;
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;
import com.iailab.module.data.common.enums.DataSourceType;
import com.iailab.module.data.common.enums.DataTypeEnum;
@@ -11,11 +14,11 @@
import com.iailab.module.data.point.common.PointDataTypeEnum;
import com.iailab.module.data.point.dto.DaPointDTO;
import com.iailab.module.data.point.service.DaPointService;
import com.iailab.module.data.http.collector.HttpCollectorForZxzk;
import com.iailab.module.data.http.service.impl.HttpTagCollector;
import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@@ -46,11 +49,11 @@
    @Resource
    private OpcUaCollector opcUaCollector;
    @Resource
    private HttpTagCollector httpTagCollector;
    @Autowired
    private OpcDACollector opcDACollector;
    @Resource
    private HttpCollectorForZxzk httpCollectorForZxzk;
    @Autowired
    private HttpCollectorForIhd httpCollectorForIhd;
    @Resource
    private DaPointService daPointService;
@@ -62,21 +65,16 @@
            return result;
        }
        List<String[]> opcuaTagIds = new ArrayList<>();
        List<String[]> opcUaTagIds = new ArrayList<>();
        List<String[]> opcDaTagIds = new ArrayList<>();
        List<String[]> modbusTagIds = new ArrayList<>();
        List<String[]> kioTagIds = new ArrayList<>();
        List<String[]> httpTagZxzk = new ArrayList<>();
        List<Object[]> httpTagIhd = new ArrayList<>();
        List<String> tagYearPeiIds = new ArrayList<>();
        List<String> tagCurrentPerformanceIds = new ArrayList<>();
        List<String> tagCurrentSaleIds = new ArrayList<>();
        List<String> tagPrdTimeDistIds = new ArrayList<>();
        dtos.stream().forEach(item -> {
            if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) {
                opcuaTagIds.add(new String[]{item.getSourceId(), item.getTagNo()});
                opcUaTagIds.add(new String[]{item.getSourceId(), item.getTagNo()});
            } else if (DataSourceType.OPCDA.getCode().equals(item.getSourceType())) {
                opcDaTagIds.add(new String[]{item.getSourceId(), item.getTagNo()});
            } else if (DataSourceType.ModBus.getCode().equals(item.getSourceType())) {
@@ -84,52 +82,31 @@
            } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) {
                kioTagIds.add(new String[]{item.getSourceId(), item.getTagNo()});
            } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) {
                if (CommonConstant.YEAR_PEI_HTTP_TAG.equals(item.getSourceId())) {
                    tagYearPeiIds.add(item.getTagNo());
                } else if (CommonConstant.CURRENT_PERFORMANCE_HTTP_TAG.equals(item.getSourceId())) {
                    tagCurrentPerformanceIds.add(item.getTagNo());
                } else if (CommonConstant.CURRENT_SALE_HTTP_TAG.equals(item.getSourceId())) {
                    tagCurrentSaleIds.add(item.getTagNo());
                } else if (CommonConstant.PRD_TIME_DIST_HTTP_TAG.equals(item.getSourceId())) {
                    tagPrdTimeDistIds.add(item.getTagNo());
                } else if (CommonConstant.HTTP_API_ZXZK_IH.equals(item.getSourceName())) {
                    httpTagZxzk.add(new String[]{item.getSourceId(), item.getTagNo()});
                if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) {
                    if (item.getTagNo() != null && item.getDimension() != null && item.getValueType() != null) {
                        httpTagIhd.add(new Object[]{item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()});
                    }
                }
            }
        });
        if (!CollectionUtils.isEmpty(opcuaTagIds)) {
            Map<String, Object> tagValues = opcUaCollector.getTagValues(opcuaTagIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        Map<String, Object> tagValues = new HashMap<>();
        if (!CollectionUtils.isEmpty(opcUaTagIds)) {
            tagValues.putAll(opcUaCollector.getTagValues(opcUaTagIds));
        }
        if (!CollectionUtils.isEmpty(opcDaTagIds)) {
            tagValues.putAll(opcDACollector.getTagValues(modbusTagIds));
        }
        if (!CollectionUtils.isEmpty(modbusTagIds)) {
            Map<String, Object> tagValues = modBusCollector.getTagValues(modbusTagIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
            tagValues.putAll(modBusCollector.getTagValues(modbusTagIds));
        }
        if (!CollectionUtils.isEmpty(kioTagIds)) {
            Map<String, Object> tagValues = kingIOCollector.getTagValues(kioTagIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
            tagValues.putAll(kingIOCollector.getTagValues(kioTagIds));
        }
        if (!CollectionUtils.isEmpty(httpTagZxzk)) {
            Map<String, Object> tagValues = httpCollectorForZxzk.getTagValues(httpTagZxzk);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        if (!CollectionUtils.isEmpty(httpTagIhd)) {
            tagValues.putAll(httpCollectorForIhd.getTagValues(httpTagIhd, collectTime));
        }
        if (!CollectionUtils.isEmpty(tagYearPeiIds)) {
            Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.YEAR_PEI_HTTP_TAG, tagYearPeiIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        } else if (!CollectionUtils.isEmpty(tagCurrentPerformanceIds)) {
            Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.CURRENT_PERFORMANCE_HTTP_TAG, tagCurrentPerformanceIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        } else if (!CollectionUtils.isEmpty(tagCurrentSaleIds)) {
            Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.CURRENT_SALE_HTTP_TAG, tagCurrentSaleIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        } else if (!CollectionUtils.isEmpty(tagPrdTimeDistIds)) {
            Map<String, Object> tagValues = httpTagCollector.collect(CommonConstant.PRD_TIME_DIST_HTTP_TAG, tagPrdTimeDistIds);
            this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        }
        this.toCommonResult(collectTime, dtos, tagValues, dataMap, result);
        log.info("测量点处理结束");
        return result;
    }
@@ -158,12 +135,17 @@
    private Object handleData(DaPointDTO dto, Object value) {
        Object result = value;
        try {
            if (value == null) {
                return CommonConstant.BAD_VALUE;
            }
            if (DataTypeEnum.FLOAT.getCode().equals(dto.getDataType()) || DataTypeEnum.INT.getCode().equals(dto.getDataType())) {
                BigDecimal rawValue = new BigDecimal(value.toString());
                if(CommonConstant.BAD_VALUE.compareTo(rawValue) == 0) {
                    return CommonConstant.BAD_VALUE;
                }
                // 异常值处理
                if (rawValue.compareTo(maxValue) > 0 || rawValue.compareTo(minValue) < 0) {
                    rawValue = CommonConstant.BAD_VALUE;
                    return CommonConstant.BAD_VALUE;
                }
                BigDecimal coefficient = dto.getUnittransfactor() == null ? BigDecimal.ONE : dto.getUnittransfactor();
                BigDecimal calValue = rawValue.multiply(coefficient);
@@ -182,7 +164,6 @@
            } else if (DataTypeEnum.BOOLEAN.getCode().equals(dto.getDataType())) {
                result = Boolean.parseBoolean(value.toString());
            }
        } catch (Exception ex) {
            log.warn("handleData异常,PointNo=" + dto.getPointNo());
            ex.printStackTrace();
@@ -204,9 +185,7 @@
                        } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) {
                            value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo());
                        } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) {
                            if (CommonConstant.HTTP_API_ZXZK_IH.equals(item.getSourceName())) {
                                value = httpCollectorForZxzk.getTagValue(item.getSourceId(), item.getTagNo());
                            }
                            value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType());
                        } else {
                            log.info("没有匹配的TagNo=" + item.getTagNo());
                        }