feat(repository): 处理重复templatePlaceholder时倒序sourceMap列表

- 新增逻辑用于识别重复的templatePlaceholder
- 对于重复的占位符,将其对应的sourceMap列表进行倒序排列
- 保持原有去重逻辑不变
- 添加了对占位符前缀"P"的检查逻辑
This commit is contained in:
2025-10-24 17:12:07 +08:00
parent ca2b812574
commit fb637bc7db

View File

@@ -129,6 +129,21 @@ public class SourceRepository {
sourcesMap.forEach((key, value) -> { sourcesMap.forEach((key, value) -> {
value.removeIf(item -> !value.getFirst().equals(item)); value.removeIf(item -> !value.getFirst().equals(item));
}); });
} else {
// 找出重复的templatePlaceholder,修改对应的sourceMap[key]中的list顺序为倒序
Map<String, Long> placeholderCounts = templatePlaceholder.stream()
.collect(Collectors.groupingBy(placeholder -> placeholder, Collectors.counting()));
placeholderCounts.entrySet().stream()
.filter(entry -> entry.getValue() > 1)
.map(Map.Entry::getKey)
.forEach(duplicatePlaceholder -> {
// 对于重复的占位符,找到对应的设备ID并倒序sourceMap中的列表
if (sourcesMap.containsKey(duplicatePlaceholder)) {
List<SourceEntity> sourceList = sourcesMap.get(duplicatePlaceholder);
java.util.Collections.reverse(sourceList);
}
});
} }
boolean hasPPlaceholder = templatePlaceholder.stream().anyMatch(placeholder -> placeholder.startsWith("P")); boolean hasPPlaceholder = templatePlaceholder.stream().anyMatch(placeholder -> placeholder.startsWith("P"));