dengzedong
2024-12-24 aa0382e44311f9f7e62a688c8fcaa9c69a512e0f
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -26,6 +26,7 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
 * 测量点处理
@@ -182,8 +183,9 @@
        pointMeasureList.forEach(
                item -> {
                    try {
                        boolean hasKey = redisTemplate.hasKey(PointCollector.PV + item.getPointNo());
                        Object value = CommonConstant.BAD_VALUE;
                        if (redisTemplate.hasKey(PointCollector.PV + item.getPointNo())) {
                        if (hasKey) {
                            value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo());
                        } else if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) {
                            value = opcUaCollector.getTagValue(item.getSourceId(), item.getTagNo());
@@ -193,12 +195,9 @@
                            value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo());
                        } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) {
                            value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType());
                            // 存入缓存
                            redisTemplate.opsForValue().set(PointCollector.PV + item.getPointNo(), value, PointCollector.offset);
                        } else {
                            log.info("没有匹配的TagNo=" + item.getTagNo());
                        }
                        log.info("TagNo=" + item.getTagNo() + ",value=" + value.toString());
                        if (!PointDataTypeEnum.BOOLEAN.getCode().equals(item.getDataType())) {
                            BigDecimal decValue =  new BigDecimal(value.toString());
@@ -211,6 +210,11 @@
                        } else {
                            data.put(item.getPointNo(), value);
                        }
                        if (!hasKey) {
                            // 存入缓存
                            toRedis(value, item);
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
@@ -219,4 +223,17 @@
        );
        return data;
    }
    public void toRedis(Object value, DaPointDTO point) {
        if (PointDataTypeEnum.FLOAT.getCode().equals(point.getDataType())) {
            redisTemplate.opsForValue().set(PointCollector.PV + point.getPointNo(), new BigDecimal(value.toString()).intValue(),
                    PointCollector.offset, TimeUnit.SECONDS);
        } else if (PointDataTypeEnum.INT.getCode().equals(point.getDataType())) {
            redisTemplate.opsForValue().set(PointCollector.PV + point.getPointNo(), new BigDecimal(value.toString()).doubleValue(),
                    PointCollector.offset, TimeUnit.SECONDS);
        } else if (PointDataTypeEnum.BOOLEAN.getCode().equals(point.getDataType())) {
            redisTemplate.opsForValue().set(PointCollector.PV + point.getPointNo(), Boolean.parseBoolean(value.toString()),
                    PointCollector.offset, TimeUnit.SECONDS);
        }
    }
}