工业互联网平台2.0版本后端代码
潘志宝
2025-05-26 9881ce0814ad642646d9b76ad2caa70a0b966036
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/MeasureHandle.java
@@ -224,17 +224,18 @@
    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())) {
@@ -258,7 +259,8 @@
                        }
                        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())) {
@@ -276,9 +278,7 @@
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
        );
        return data;
    }