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("更新采集状态"); 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("|", "||"); 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); } } }