From f33ce8e7a78d83666085e9e839d3f3e4b48cba59 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 1 Oct 2025 21:22:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(video):=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=88=87=E7=89=87=E4=BB=BB=E5=8A=A1=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加对配对设备的处理,确保主设备也能正确执行切片任务 - 调整计数器逻辑,使主设备和配对设备的未完成占位符计数一致 - 增强日志记录,明确标识设备占位符满足情况 - 改进进度计算方式,更准确地反映任务完成状态- 在所有占位符满足时提前调用回调函数,提升任务执行效率 --- .../com/ycwl/basic/task/VideoPieceGetter.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) 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(); } }