From aa0382e44311f9f7e62a688c8fcaa9c69a512e0f Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期二, 24 十二月 2024 15:15:10 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/string/StrUtils.java | 10 ++++++++++ iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java | 25 +++++++++++++++++++++---- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java | 12 +++++++----- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java | 10 +++++++++- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/string/StrUtils.java b/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/string/StrUtils.java index 84c37ab..31e2c4c 100644 --- a/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/string/StrUtils.java +++ b/iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/string/StrUtils.java @@ -77,4 +77,14 @@ .collect(Collectors.joining("\n")); } + /** + * 判断字符串是不是数字 + * + * @param str + * @return + */ + public static boolean isNumeric(String str) { + return str.matches("-?\\d+(\\.\\d+)?"); + } + } diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java index c7475c9..f263bd2 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java @@ -29,7 +29,9 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; +import java.time.Duration; import java.util.*; +import java.util.concurrent.TimeUnit; /** * @author PanZhibao @@ -73,9 +75,9 @@ @Autowired private RedisTemplate<String, Object> redisTemplate; - public static final String PV = "PV_"; + public static final String PV = "point_value:"; - public static final int offset = 60 * 3; + public static final long offset = 60 * 3L; /** * 采集 @@ -111,13 +113,13 @@ for (InfluxPointValuePOJO pointValue : pointValues) { if (pointValue instanceof InfluxPointValueSimPOJO) { InfluxPointValueSimPOJO simPOJO = (InfluxPointValueSimPOJO) pointValue; - redisTemplate.opsForValue().set(PV + simPOJO.getPoint(), simPOJO.getValue(), offset); + redisTemplate.opsForValue().set(PV + simPOJO.getPoint(), simPOJO.getValue().doubleValue(), offset, TimeUnit.SECONDS); } else if (pointValue instanceof InfluxPointValueDigPOJO) { InfluxPointValueDigPOJO digPOJO = (InfluxPointValueDigPOJO) pointValue; - redisTemplate.opsForValue().set(PV + digPOJO.getPoint(), digPOJO.getValue(), offset); + redisTemplate.opsForValue().set(PV + digPOJO.getPoint(), digPOJO.getValue().intValue(), offset, TimeUnit.SECONDS); } else if (pointValue instanceof InfluxPointValueBoolPOJO) { InfluxPointValueBoolPOJO boolPOJO = (InfluxPointValueBoolPOJO) pointValue; - redisTemplate.opsForValue().set(PV + boolPOJO.getPoint(), boolPOJO.getValue(), offset); + redisTemplate.opsForValue().set(PV + boolPOJO.getPoint(), boolPOJO.getValue().booleanValue(), offset, TimeUnit.SECONDS); } } log.info("更新采集状态"); diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java index 699ea60..f140509 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java @@ -1,5 +1,6 @@ package com.iailab.module.data.point.collection.handler; +import com.iailab.framework.common.util.string.StrUtils; import com.iailab.module.data.common.enums.CommonConstant; import com.iailab.module.data.common.enums.DataTypeEnum; import com.iailab.module.data.common.enums.JsErrorCode; @@ -143,7 +144,14 @@ pointNos.add(s); dataMap.putAll(measureHandle.getCurrent(pointNos)); dataMap.putAll(constantHandle.getCurrent(pointNos)); - expression = expression.replace(s, dataMap.get(s).toString()); + String valueStr = dataMap.get(s).toString(); + if (StrUtils.isNumeric(valueStr) && new BigDecimal(valueStr).compareTo(CommonConstant.BAD_VALUE) == 0) { + log.info("BAD_VALUE:" + s); + } + if (StrUtils.isNumeric(valueStr) && new BigDecimal(valueStr).compareTo(BigDecimal.ZERO) < 0) { + valueStr = "(" + valueStr + ")"; + } + expression = expression.replace(s, valueStr); } expression = expression.replace("&", "&&"); expression = expression.replace("|", "||"); 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 bd0a697..482c718 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 @@ -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); + } + } } -- Gitblit v1.9.3