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); } /**