iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/PointCollector.java
@@ -76,7 +76,7 @@ public static final String PV = "point_value:"; public static final long offset = 60 * 2L; public static final long offset = 3L; /** * 采集 @@ -100,17 +100,17 @@ List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(minfreq); pointValues.addAll(measureHandle.handle(collectTime, pointMeasureList, dataMap, listGood, listBad)); log.info("读取计算点"); List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq); pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap, listGood, listBad)); log.info("读取累计点"); List<DaPointDTO> pointCumulateList = daPointService.getCumulatePoint(minfreq); pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList, listGood, listBad)); pointValues.addAll(cumulateHandle.handle(collectTime, pointCumulateList, dataMap, listGood, listBad)); log.info("读取极值点"); List<DaPointDTO> pointExtremalList = daPointService.getExtremalPoint(minfreq); pointValues.addAll(extremalHandle.handle(collectTime, pointExtremalList, listGood, listBad)); pointValues.addAll(extremalHandle.handle(collectTime, pointExtremalList, dataMap, listGood, listBad)); log.info("读取计算点"); List<DaPointDTO> pointCalculateList = daPointService.getMathPoint(minfreq); pointValues.addAll(calculateHandle.handle(collectTime, pointCalculateList, dataMap, listGood, listBad)); log.info("存入时序库"); log.info("pointValueTimestamp=" + (pointValues.get(0) == null ? 0 : pointValues.get(0).getTimestamp().getNano())); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CalculateHandle.java
@@ -47,6 +47,12 @@ private ConstantHandle constantHandle; @Resource private CumulateHandle cumulateHandle; @Resource private ExtremalHandle extremalHandle; @Resource private JavaScriptHandler javaScriptHandler; @Autowired @@ -171,6 +177,8 @@ pointNos.add(s); dataMap.putAll(measureHandle.getCurrent(pointNos)); dataMap.putAll(constantHandle.getCurrent(pointNos)); dataMap.putAll(cumulateHandle.getCurrent(pointNos)); dataMap.putAll(extremalHandle.getCurrent(pointNos)); if (dataMap.get(s) == null) { log.info("计算点数据异常"); log.info("pointNo=" + dto.getPointNo() + ";dataMap.key=" + s); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ConstantHandle.java
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; /** @@ -33,9 +34,13 @@ return result; } dtos.forEach(dto -> { InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto); BigDecimal defaultValue = dto.getDefaultValue(); BigDecimal coefficient = dto.getUnittransfactor() == null ? BigDecimal.ONE : dto.getUnittransfactor(); defaultValue = defaultValue.multiply(coefficient); InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto,defaultValue); pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid()))); dataMap.put(dto.getPointNo(), dto.getDefaultValue()); dataMap.put(dto.getPointNo(), defaultValue); result.add(pojo); listGood.add(dto.getPointNo()); }); @@ -49,7 +54,8 @@ List<DaPointDTO> pointConstantList = daPointService.getConstantPoint(pointNos); if (!CollectionUtils.isEmpty(pointConstantList)) { pointConstantList.forEach(item -> { data.put(item.getPointNo(), item.getDefaultValue()); BigDecimal coefficient = item.getUnittransfactor() == null ? BigDecimal.ONE : item.getUnittransfactor(); data.put(item.getPointNo(), item.getDefaultValue().multiply(coefficient)); }); } return data; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java
@@ -45,7 +45,7 @@ @Autowired private RedisTemplate<String, Object> redisTemplate; public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, List<String> listGood, List<String> listBad) { public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap, List<String> listGood, List<String> listBad) { List<InfluxPointValuePOJO> result = new ArrayList<>(); try { log.info("累计点处理开始"); @@ -59,6 +59,7 @@ BigDecimal calValue = new BigDecimal(rawValue.toString()).multiply(coefficient); InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, calValue); pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid()))); dataMap.put(dto.getPointNo(), calValue); result.add(pojo); } catch (Exception ex) { ex.printStackTrace(); @@ -163,7 +164,7 @@ long start = startTime.getTime(); long end = endTime.getTime(); long oneMin = 1000L * DataPointFreqEnum.getEumByCode(minfreqid).getValue(); long mins = (end - start) / oneMin; long mins = ((end - start) / oneMin) + 1; //找出缺少项 Map<Long, Double> sourceDataMap = new HashMap<>(dataList.size()); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/ExtremalHandle.java
@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; /** @@ -43,7 +44,7 @@ @Autowired private RedisTemplate<String, Object> redisTemplate; public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, List<String> listGood, List<String> listBad) { public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap, List<String> listGood, List<String> listBad) { List<InfluxPointValuePOJO> result = new ArrayList<>(); try { log.info("极值点处理开始"); @@ -52,9 +53,12 @@ } dtos.forEach(dto -> { try { Object value = singleCompute(dto, collectTime, listGood, listBad); InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value); Object rawValue = singleCompute(dto, collectTime, listGood, listBad); BigDecimal coefficient = dto.getUnittransfactor() == null ? BigDecimal.ONE : dto.getUnittransfactor(); BigDecimal calValue = new BigDecimal(rawValue.toString()).multiply(coefficient); InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, calValue); pojo.setTimestamp(GenInfluxPointValueUtils.getByMin(collectTime, DataPointFreqEnum.getEumByCode(dto.getMinfreqid()))); dataMap.put(dto.getPointNo(), calValue); result.add(pojo); } catch (Exception ex) { ex.printStackTrace(); @@ -83,6 +87,8 @@ value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); } else { value = singleCompute(item, calendar.getTime(), new ArrayList<>(), new ArrayList<>()); BigDecimal coefficient = item.getUnittransfactor() == null ? BigDecimal.ONE : item.getUnittransfactor(); value = new BigDecimal(value.toString()).multiply(coefficient); } data.put(item.getPointNo(), value); }); iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -224,61 +224,61 @@ public Map<String, Object> getCurrent(List<String> pointNos) { Map<String, Object> data = new HashMap<>(); List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(pointNos); pointMeasureList.forEach( item -> { try { Object value = CommonConstant.BAD_VALUE; boolean hasKey = redisTemplate.hasKey(PointCollector.PV + item.getPointNo()); if (hasKey) { value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); } if(hasKey && StrUtils.isNumeric(value.toString()) && new BigDecimal(value.toString()).compareTo(CommonConstant.BAD_VALUE) != 0 ) { value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); } else if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) { value = opcUaCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.ModBus.getCode().equals(item.getSourceType())) { value = modBusCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) { value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()); } else if (SourceApiEnum.ASDB.getCode().equals(item.getSourceName())) { value = httpCollectorForAsdb.getTagValue(item.getSourceId(), item.getTagNo()); } else if (SourceApiEnum.ASDE.getCode().equals(item.getSourceName())) { value = httpCollectorForAsde.getTagValue(item.getSourceId(), item.getTagNo()); } else if (SourceApiEnum.ASDC.getCode().equals(item.getSourceName())) { value = httpCollectorForAsdc.getTagValue(item.getSourceId(), item.getTagNo()); } else if (SourceApiEnum.ASDY.getCode().equals(item.getSourceName())) { value = httpCollectorForAsdy.getTagValue(item.getSourceId(), item.getTagNo()); } } 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()); if (PointDataTypeEnum.FLOAT.getCode().equals(item.getDataType())) { decValue = decValue.setScale(2, BigDecimal.ROUND_HALF_UP); } else if (PointDataTypeEnum.INT.getCode().equals(item.getDataType())) { decValue = decValue.setScale(0, BigDecimal.ROUND_HALF_UP); } data.put(item.getPointNo(), decValue); } else { data.put(item.getPointNo(), value); } if (!hasKey) { // 存入缓存 toRedis(value, item); } } catch (Exception ex) { ex.printStackTrace(); for (DaPointDTO item : pointMeasureList) { try { Object value = CommonConstant.BAD_VALUE; boolean hasKey = redisTemplate.hasKey(PointCollector.PV + item.getPointNo()); if (hasKey && !StrUtils.isNumeric(value.toString())) { value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); data.put(item.getPointNo(), value); continue; } else if(hasKey && StrUtils.isNumeric(value.toString()) && new BigDecimal(value.toString()).compareTo(CommonConstant.BAD_VALUE) != 0 ) { value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); data.put(item.getPointNo(), value); continue; } else if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) { value = opcUaCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.ModBus.getCode().equals(item.getSourceType())) { value = modBusCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.KIO.getCode().equals(item.getSourceType())) { value = kingIOCollector.getTagValue(item.getSourceId(), item.getTagNo()); } else if (DataSourceType.HTTP.getCode().equals(item.getSourceType())) { if (SourceApiEnum.iHyperDB.getCode().equals(item.getSourceName())) { value = httpCollectorForIhd.getTagValue(item.getSourceId(), item.getTagNo(), item.getDimension(), item.getValueType()); } else if (SourceApiEnum.ASDB.getCode().equals(item.getSourceName())) { value = httpCollectorForAsdb.getTagValue(item.getSourceId(), item.getTagNo()); } else if (SourceApiEnum.ASDE.getCode().equals(item.getSourceName())) { value = httpCollectorForAsde.getTagValue(item.getSourceId(), item.getTagNo()); } else if (SourceApiEnum.ASDC.getCode().equals(item.getSourceName())) { value = httpCollectorForAsdc.getTagValue(item.getSourceId(), item.getTagNo()); } else if (SourceApiEnum.ASDY.getCode().equals(item.getSourceName())) { value = httpCollectorForAsdy.getTagValue(item.getSourceId(), item.getTagNo()); } } else { log.info("没有匹配的TagNo=" + item.getTagNo()); } ); log.info("TagNo=" + item.getTagNo() + ",value=" + value.toString()); if (!PointDataTypeEnum.BOOLEAN.getCode().equals(item.getDataType())) { BigDecimal coefficient = item.getUnittransfactor() == null ? BigDecimal.ONE : item.getUnittransfactor(); BigDecimal decValue = new BigDecimal(value.toString()).multiply(coefficient); if (PointDataTypeEnum.FLOAT.getCode().equals(item.getDataType())) { decValue = decValue.setScale(2, BigDecimal.ROUND_HALF_UP); } else if (PointDataTypeEnum.INT.getCode().equals(item.getDataType())) { decValue = decValue.setScale(0, BigDecimal.ROUND_HALF_UP); } data.put(item.getPointNo(), decValue); } else { data.put(item.getPointNo(), value); } if (!hasKey) { // 存入缓存 toRedis(value, item); } } catch (Exception ex) { ex.printStackTrace(); } } return data; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/common/PointCumulateUnitEnum.java
@@ -67,7 +67,7 @@ } } Calendar startCal = unit.calculate(endTime, length); Calendar startCal = unit.calculate(endTime, length-1); return startCal.getTime(); } } iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/point/DaPointDao.xml
@@ -161,6 +161,7 @@ t1.point_type, t1.store_type, t1.data_type, t1.unittransfactor, t1.minfreqid FROM t_da_point t1 <where>