dengzedong
2025-01-18 3c511d4ef08ffece38891435a9d16ee38319345b
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java
@@ -43,7 +43,7 @@
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos) {
    public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos,List<String> listGood,List<String> listBad) {
        List<InfluxPointValuePOJO> result = new ArrayList<>();
        try {
            log.info("累计点处理开始");
@@ -52,7 +52,7 @@
            }
            dtos.forEach(dto -> {
                try {
                    Object value = singleCompute(dto, collectTime);
                    Object value = singleCompute(dto, collectTime,listGood,listBad);
                    InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value);
                    pojo.setTimestamp(collectTime.toInstant());
                    result.add(pojo);
@@ -89,10 +89,16 @@
        return data;
    }
    private Object singleCompute(DaPointDTO dto, Date collectTime) {
        return singleCompute(dto,collectTime,null,null);
    }
    private Object singleCompute(DaPointDTO dto, Date collectTime,List<String> listGood,List<String> listBad) {
        ApiPointDTO pointDTO = dataPointApi.getInfoByNo(dto.getMomentPoint());
        if (pointDTO == null) {
            if (listBad != null) {
                listBad.add(dto.getPointNo());
            }
            return CommonConstant.BAD_VALUE;
        }
        Calendar calendar = Calendar.getInstance();
@@ -108,12 +114,18 @@
        List<ApiPointValueDTO> dataList = dataPointApi.queryPointHistoryValue(queryDto);
        if (CollectionUtils.isEmpty(dataList)) {
            if (listGood != null) {
                listGood.add(dto.getPointNo());
            }
            return BigDecimal.ZERO;
        } else if (dataList.size() < dto.getLength()) {
            // 补全数据
            dataList = completionData(dto.getLength(), dataList, startTime, endTime, pointDTO);
        }
        double total = dataList.stream().mapToDouble(ApiPointValueDTO::getV).sum();
        if (listGood != null) {
            listGood.add(dto.getPointNo());
        }
        return new BigDecimal(total).divide(new BigDecimal(dto.getDivisor()), 2, BigDecimal.ROUND_HALF_UP);
    }
@@ -169,6 +181,6 @@
                return item.getValue();
            }
        }
        return null;
        return 0.0;
    }
}