tuqin
2026-09-24 034f720f0bbc7f253c15613c28d994d7abf401eb
src/main/java/com/ruoyi/device/service/impl/DeviceAreaServiceImpl.java
@@ -17,6 +17,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -51,8 +52,9 @@
                .collect(Collectors.toMap(DeviceArea::getId, a -> a));
        // 递归汇总每个节点的设备数量(含所有子级)
        Map<Long, Long> countMap = directCountMap.entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        // 必须从空 map 开始:每个区域的自身直挂数只在 accumulate 中累加一次,
        // 否则会与“初始即含自身直挂数”叠加,导致每个区域自身设备数被计两次(双倍)
        Map<Long, Long> countMap = new HashMap<>();
        for (DeviceArea area : all) {
            accumulate(area.getId(), directCountMap.getOrDefault(area.getId(), 0L), countMap, areaMap);
        }