数采 全部类型都考虑 单位转换 handle,getCurrent
| | |
| | | |
| | | public static final String PV = "point_value:"; |
| | | |
| | | public static final long offset = 60 * 2L; |
| | | public static final long offset = 3L; |
| | | |
| | | /** |
| | | * 采集 |
| | |
| | | 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())); |
| | |
| | | private ConstantHandle constantHandle; |
| | | |
| | | @Resource |
| | | private CumulateHandle cumulateHandle; |
| | | |
| | | @Resource |
| | | private ExtremalHandle extremalHandle; |
| | | |
| | | @Resource |
| | | private JavaScriptHandler javaScriptHandler; |
| | | |
| | | @Autowired |
| | |
| | | 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); |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | 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()); |
| | | }); |
| | |
| | | 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; |
| | |
| | | @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("累计点处理开始"); |
| | |
| | | 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(); |
| | |
| | | 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()); |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @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("极值点处理开始"); |
| | |
| | | } |
| | | 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(); |
| | |
| | | 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); |
| | | }); |
| | |
| | | public Map<String, Object> getCurrent(List<String> pointNos) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | List<DaPointDTO> pointMeasureList = daPointService.getMeasurePoint(pointNos); |
| | | pointMeasureList.forEach( |
| | | item -> { |
| | | for (DaPointDTO item : pointMeasureList) { |
| | | try { |
| | | Object value = CommonConstant.BAD_VALUE; |
| | | boolean hasKey = redisTemplate.hasKey(PointCollector.PV + item.getPointNo()); |
| | | if (hasKey) { |
| | | if (hasKey && !StrUtils.isNumeric(value.toString())) { |
| | | value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); |
| | | } |
| | | if(hasKey && StrUtils.isNumeric(value.toString()) && |
| | | new BigDecimal(value.toString()).compareTo(CommonConstant.BAD_VALUE) != 0 ) { |
| | | 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())) { |
| | |
| | | } |
| | | log.info("TagNo=" + item.getTagNo() + ",value=" + value.toString()); |
| | | if (!PointDataTypeEnum.BOOLEAN.getCode().equals(item.getDataType())) { |
| | | BigDecimal decValue = new BigDecimal(value.toString()); |
| | | 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())) { |
| | |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | ); |
| | | return data; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | Calendar startCal = unit.calculate(endTime, length); |
| | | Calendar startCal = unit.calculate(endTime, length-1); |
| | | return startCal.getTime(); |
| | | } |
| | | } |
| | |
| | | t1.point_type, |
| | | t1.store_type, |
| | | t1.data_type, |
| | | t1.unittransfactor, |
| | | t1.minfreqid |
| | | FROM t_da_point t1 |
| | | <where> |