工业互联网平台2.0版本后端代码
潘志宝
2025-05-22 cb7e6e88f973a9e81fd1f29dfe0b464fafafb55c
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/collection/handler/CumulateHandle.java
@@ -54,8 +54,10 @@
            }
            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())));
                    result.add(pojo);
                } catch (Exception ex) {
@@ -79,12 +81,15 @@
        }
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        pointMathList.forEach(item -> {
            Object value = CommonConstant.BAD_VALUE;
            if (redisTemplate.hasKey(PointCollector.PV + item.getPointNo())) {
                value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo());
            } else {
                value = singleCompute(item, calendar.getTime());
                Object rawValue = singleCompute(item, calendar.getTime());
                BigDecimal coefficient = item.getUnittransfactor() == null ? BigDecimal.ONE : item.getUnittransfactor();
                value = new BigDecimal(rawValue.toString()).multiply(coefficient);
            }
            data.put(item.getPointNo(), value);
        });
@@ -118,7 +123,18 @@
        queryDto.setEnd(endTime);
        queryDto.setPointNo(dto.getMomentPoint());
        log.info("queryDto=" + JSONObject.toJSONString(queryDto));
        List<ApiPointValueDTO> dataList = dataPointApi.queryPointHistoryValue(queryDto);
        List<ApiPointValueDTO> dataList = new ArrayList<>();
        List<ApiPointValueDTO> dataListTemp = dataPointApi.queryPointHistoryValue(queryDto);
        if (dto.getIsCumuNeg() != null && dto.getIsCumuNeg().equals(0)) {
            for(ApiPointValueDTO item : dataListTemp) {
                if (item.getV() > 0) {
                    dataList.add(item);
                }
            }
        } else {
            dataList = dataListTemp;
        }
        if (CollectionUtils.isEmpty(dataList)) {
            log.info("dataList is empty");
            if (listGood != null) {
@@ -127,7 +143,7 @@
            return BigDecimal.ZERO;
        } else if (dataList.size() < dto.getLength()) {
            log.info("补全数据,dataList.size()=" + dataList.size());
            dataList = completionData(dto.getLength(), dataList, startTime, endTime, pointDTO);
            dataList = completionData(dto.getLength(), dataList, startTime, endTime, momentPoint.getMinfreqid());
        }
        double total = dataList.stream().mapToDouble(ApiPointValueDTO::getV).sum();
        if (listGood != null) {
@@ -136,7 +152,7 @@
        return new BigDecimal(total).divide(new BigDecimal(dto.getDivisor()), 2, BigDecimal.ROUND_HALF_UP);
    }
    private List<ApiPointValueDTO> completionData(int length, List<ApiPointValueDTO> dataList, Date startTime, Date endTime, ApiPointDTO pointDTO) {
    private List<ApiPointValueDTO> completionData(int length, List<ApiPointValueDTO> dataList, Date startTime, Date endTime, String minfreqid) {
        if (CollectionUtils.isEmpty(dataList) || length == dataList.size()) {
            return dataList;
        } else if (length < dataList.size()) {
@@ -146,7 +162,7 @@
        List<ApiPointValueDTO> result = new ArrayList<>();
        long start = startTime.getTime();
        long end = endTime.getTime();
        long oneMin = 1000L * DataPointFreqEnum.getEumByCode(pointDTO.getMinfreqid()).getValue();
        long oneMin = 1000L * DataPointFreqEnum.getEumByCode(minfreqid).getValue();
        long mins = (end - start) / oneMin;
        //找出缺少项