| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 测量点处理 |
| | |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | } else { |
| | | data.put(item.getPointNo(), value); |
| | | } |
| | | |
| | | if (!hasKey) { |
| | | // 存入缓存 |
| | | toRedis(value, item); |
| | | } |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | |
| | | ); |
| | | 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); |
| | | } |
| | | } |
| | | } |