From 8f8fe39b73107452aed40d55690c556d818834d8 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Tue, 7 Nov 2023 20:58:51 +0800 Subject: [PATCH] bugfix --- .../CoalWashingDailyAnalysisEntity.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/entity/CoalWashingDailyAnalysisEntity.java b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/entity/CoalWashingDailyAnalysisEntity.java index efe897fe..be66f04f 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/entity/CoalWashingDailyAnalysisEntity.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/entity/CoalWashingDailyAnalysisEntity.java @@ -100,8 +100,6 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity { inputItems.sort( Comparator.comparing(x -> ObjectUtils.defaultIfNull(x.getTime(), LocalTime.MIN))); - - for (int i = 0; i < inputItems.size(); i++) { CoalWashingDailyAnalysisItemVo coalWashingDailyAnalysisItemVo = inputItems.get(i); if (StringUtils.equals(type, "2") && i == inputItems.size() - 1) { @@ -115,7 +113,8 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity { Double prevNumber = ObjectUtils.defaultIfNull(initTotalNumber, 0.0); // 总的权重 - Double totalWeight = 0.0; + Double totalWeight1 = 0.0; + Double totalWeight2 = 0.0; // 大堆平均之和 Double avgSum1 = 0.0; Double avgSum2 = 0.0; @@ -126,12 +125,20 @@ public class CoalWashingDailyAnalysisEntity extends OrgCommonEntity { inputItem.getTotalNumber() == null ? 1 : Double.max(1, inputItem.getTotalNumber() - prevNumber); - totalWeight += currWeight; - avgSum1 += ObjectUtils.defaultIfNull(inputItem.getAvgDdp1(), 0.0) * currWeight; - avgSum2 += ObjectUtils.defaultIfNull(inputItem.getAvgDdp2(), 0.0) * currWeight; - inputItem.setRollingAvgDdp1(avgSum1 / totalWeight); - inputItem.setRollingAvgDdp2(avgSum2 / totalWeight); + if (inputItem.getAvgDdp1() != null) { + totalWeight1 += currWeight; + + avgSum1 += ObjectUtils.defaultIfNull(inputItem.getAvgDdp1(), 0.0) * currWeight; + + inputItem.setRollingAvgDdp1(avgSum1 / totalWeight1); + } + + if (inputItem.getAvgDdp2() != null) { + totalWeight2 += currWeight; + avgSum2 += ObjectUtils.defaultIfNull(inputItem.getAvgDdp2(), 0.0) * currWeight; + inputItem.setRollingAvgDdp2(avgSum2 / totalWeight2); + } } for (int i = 0; i < inputItems.size(); i++) {