From a1450c47964293f0234522724e4742c5de99f7b2 Mon Sep 17 00:00:00 2001 From: lcj <2331845269@qq.com> Date: Mon, 29 Sep 2025 20:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PgsProgressCategoryServiceImpl.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/progress/service/impl/PgsProgressCategoryServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/progress/service/impl/PgsProgressCategoryServiceImpl.java index dc44122c..bff285fa 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/progress/service/impl/PgsProgressCategoryServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/progress/service/impl/PgsProgressCategoryServiceImpl.java @@ -779,8 +779,8 @@ public class PgsProgressCategoryServiceImpl extends ServiceImpl children = parentIdToChildrenMap.getOrDefault(progressCategory.getId(), Collections.emptyList()); + List children = parentIdToChildrenMap.getOrDefault(progressCategory.getId(), Collections.emptyList()); + if (CollUtil.isNotEmpty(children)) { // 获取父节点状态 String parentStatus = getParentStatus(children); // 累加子节点数据 @@ -1451,19 +1451,27 @@ public class PgsProgressCategoryServiceImpl extends ServiceImpl categoryList) { - BigDecimal completedTotal = BigDecimal.ZERO; - BigDecimal allTotal = BigDecimal.ZERO; + // 如果没有数据,则返回0 + if (CollUtil.isEmpty(categoryList)) { + return BigDecimal.ZERO; + } + + BigDecimal totalCompleted = BigDecimal.ZERO; + BigDecimal totalWork = BigDecimal.ZERO; + + // 遍历所有项目进度,计算总完成数和总数 for (PgsProgressCategory category : categoryList) { BigDecimal completed = category.getCompleted(); BigDecimal total = category.getTotal(); - if (PgsProgressUnitTypeEnum.NUMBER.getValue().equals(category.getUnitType())) { - completedTotal = completedTotal.add(completed); - } else if (PgsProgressUnitTypeEnum.PERCENTAGE.getValue().equals(category.getUnitType())) { - completedTotal = completedTotal.add(completed.divide(BigDecimal.valueOf(100L), 2, RoundingMode.HALF_UP).multiply(total)); + + if (PgsProgressUnitTypeEnum.PERCENTAGE.getValue().equals(category.getUnitType())) { + completed = completed.divide(BigDecimal.valueOf(100L), 4, RoundingMode.HALF_UP).multiply(total); } - allTotal = allTotal.add(total); + + totalCompleted = totalCompleted.add(completed); + totalWork = totalWork.add(total); } - return BigDecimalUtil.toPercentage(completedTotal, allTotal); + return BigDecimalUtil.toPercentage(totalCompleted, totalWork); } /**