| | |
| | | import com.iailab.module.data.channel.kio.collector.KingIOCollector; |
| | | import com.iailab.module.data.channel.modbus.collector.ModBusCollector; |
| | | import com.iailab.module.data.channel.opcua.collector.OpcUaCollector; |
| | | import com.iailab.module.data.point.collection.PointCollector; |
| | | import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils; |
| | | import com.iailab.module.data.point.common.PointDataTypeEnum; |
| | | import com.iailab.module.data.point.dto.DaPointDTO; |
| | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 测量点处理 |
| | |
| | | |
| | | @Resource |
| | | private DaPointService daPointService; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos, Map<String, Object> dataMap) { |
| | | log.info("测量点处理开始"); |
| | |
| | | pointMeasureList.forEach( |
| | | item -> { |
| | | try { |
| | | boolean hasKey = redisTemplate.hasKey(PointCollector.PV + item.getPointNo()); |
| | | Object value = CommonConstant.BAD_VALUE; |
| | | if (DataSourceType.OPCUA.getCode().equals(item.getSourceType())) { |
| | | 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()); |
| | | } else if (DataSourceType.ModBus.getCode().equals(item.getSourceType())) { |
| | | value = modBusCollector.getTagValue(item.getSourceId(), item.getTagNo()); |
| | |
| | | } else { |
| | | log.info("没有匹配的TagNo=" + item.getTagNo()); |
| | | } |
| | | log.info("没有匹配的TagNo=" + item.getTagNo()); |
| | | log.info("valueStr=" + value.toString()); |
| | | log.info("DataType=" + item.getDataType()); |
| | | 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())) { |
| | |
| | | } 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); |
| | | } |
| | | } |
| | | } |