package com.ruoyi.system.service.impl; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; /** 按单个接收区间检查历史序号;暂停和区间边界由调用方分组后自然排除。 */ final class IntervalIntegrityChecker { record Gap(long from, long to) { } private IntervalIntegrityChecker() { } static List gaps(Collection sequenceIds) { if (sequenceIds == null || sequenceIds.isEmpty()) return List.of(); Set unique = new LinkedHashSet<>(); sequenceIds.stream().filter(value -> value != null && value > 0).forEach(unique::add); List ordered = new ArrayList<>(unique); ordered.sort(Comparator.naturalOrder()); List result = new ArrayList<>(); for (int index = 1; index < ordered.size(); index++) { long previous = ordered.get(index - 1); long current = ordered.get(index); if (current > previous + 1) result.add(new Gap(previous + 1, current - 1)); } return List.copyOf(result); } }