diff --git a/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java b/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java index c1e5c102..8bcb07d9 100644 --- a/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java +++ b/src/main/java/com/ycwl/basic/task/VideoPieceGetter.java @@ -189,33 +189,45 @@ public class VideoPieceGetter { } } isFirst.set(false); + // 处理关联设备:如果当前设备是某个主设备的配对设备,也处理主设备 if (pairDeviceMap.containsValue(faceSample.getDeviceId())) { - // 有关联设备! - // 找到对应的deviceId pairDeviceMap.entrySet().stream() .filter(entry -> entry.getValue().equals(faceSample.getDeviceId())) .map(Map.Entry::getKey).forEach(pairDeviceId -> { log.info("找到同景区关联设备:{} -> {}", pairDeviceId, faceSample.getDeviceId()); if (pairDeviceId != null) { doCut(pairDeviceId, faceSample.getId(), faceSample.getCreateAt(), task); - AtomicInteger count = currentUnFinPlaceholder.get(faceSample.getDeviceId().toString()); - if (count != null && count.decrementAndGet() <= 0) { - currentUnFinPlaceholder.remove(faceSample.getDeviceId().toString()); + // 让主设备的计数器 -1 + AtomicInteger pairCount = currentUnFinPlaceholder.get(pairDeviceId.toString()); + if (pairCount != null && pairCount.decrementAndGet() <= 0) { + currentUnFinPlaceholder.remove(pairDeviceId.toString()); + log.info("设备 {} 的placeholder已满足", pairDeviceId); } } }); } + + // 处理当前设备 doCut(faceSample.getDeviceId(), faceSample.getId(), faceSample.getCreateAt(), task); AtomicInteger count = currentUnFinPlaceholder.get(faceSample.getDeviceId().toString()); if (count != null && count.decrementAndGet() <= 0) { currentUnFinPlaceholder.remove(faceSample.getDeviceId().toString()); + log.info("设备 {} 的placeholder已满足", faceSample.getDeviceId()); } + + // 如果有templateId,检查是否所有placeholder都已满足 if (templatePlaceholder != null) { - long distinctDeviceCount = templatePlaceholder.stream().distinct().count(); - log.info("当前进度:!{}/{}", currentUnFinPlaceholder.size(), distinctDeviceCount); + int totalPlaceholderCount = templatePlaceholder.size(); + int remainingCount = currentUnFinPlaceholder.values().stream() + .mapToInt(AtomicInteger::get) + .sum(); + log.info("当前进度:已完成 {}/{},剩余 {} 个placeholder未满足", + totalPlaceholderCount - remainingCount, totalPlaceholderCount, remainingCount); + if (currentUnFinPlaceholder.isEmpty()) { if (!invoke.get()) { invoke.set(true); + log.info("所有placeholder已满足,提前调用callback"); task.getCallback().onInvoke(); } }