| | |
| | | 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; |
| | |
| | | .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); |
| | | } |