模板支持相同机位

This commit is contained in:
2025-04-30 18:29:14 +08:00
parent c45dffa0a0
commit 00f38c949c
6 changed files with 77 additions and 76 deletions

View File

@ -33,7 +33,6 @@ public class TemplateRepository {
return template.getChildren().stream() return template.getChildren().stream()
.filter(item -> item.getIsPlaceholder() == 1) .filter(item -> item.getIsPlaceholder() == 1)
.map(TemplateRespVO::getSourceUrl) .map(TemplateRespVO::getSourceUrl)
.distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -55,6 +55,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -268,18 +269,22 @@ public class GoodsServiceImpl implements GoodsService {
} }
TaskEntity task = videoTaskRepository.getTaskById(videoRespVO.getTaskId()); TaskEntity task = videoTaskRepository.getTaskById(videoRespVO.getTaskId());
JSONObject paramJson = JSON.parseObject(task.getTaskParams()); JSONObject paramJson = JSON.parseObject(task.getTaskParams());
long deviceCount; AtomicInteger deviceCount = new AtomicInteger();
goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId())); goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId()));
if (paramJson == null) { if (paramJson == null) {
deviceCount = 1; deviceCount.set(1);
} else { } else {
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId()); List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
deviceCount = paramJson.keySet().stream() paramJson.entrySet().stream()
.filter(StringUtils::isNumeric) .filter(entry -> StringUtils.isNumeric(entry.getKey()))
.filter(templatePlaceholder::contains) .forEach(entry -> {
.count(); if (templatePlaceholder.contains(entry.getKey())) {
deviceCount.getAndIncrement();
templatePlaceholder.remove(entry.getKey());
} }
goodsDetailVO.setLensNum((int) deviceCount); });
}
goodsDetailVO.setLensNum(deviceCount.get());
return ApiResponse.success(goodsDetailVO); return ApiResponse.success(goodsDetailVO);
} }

View File

@ -132,6 +132,7 @@ public class SourceServiceImpl implements SourceService {
// 下载切片 // 下载切片
VideoPieceGetter.Task task = new VideoPieceGetter.Task(); VideoPieceGetter.Task task = new VideoPieceGetter.Task();
task.faceSampleIds = Collections.singletonList(source.getFaceSampleId()); task.faceSampleIds = Collections.singletonList(source.getFaceSampleId());
task.force = true;
VideoPieceGetter.addTask(task); VideoPieceGetter.addTask(task);
} }
return ApiResponse.success("任务已下发"); return ApiResponse.success("任务已下发");

View File

@ -274,10 +274,15 @@ public class TaskTaskServiceImpl implements TaskService {
log.info("task callback: 没有视频源"); log.info("task callback: 没有视频源");
return; return;
} }
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(templateId);
if (templatePlaceholder.stream().distinct().count() == templatePlaceholder.size()) {
sourcesMap.forEach((key, value) -> { sourcesMap.forEach((key, value) -> {
// 每个value只保留第一个 // 每个value只保留第一个
value.removeIf(item -> !value.get(0).equals(item)); value.removeIf(item -> !value.get(0).equals(item));
}); });
} else {
log.info("task callback: 模板占位符有重复templateId: {}", templateId);
}
TaskReqQuery taskReqQuery = new TaskReqQuery(); TaskReqQuery taskReqQuery = new TaskReqQuery();
taskReqQuery.setFaceId(faceId); taskReqQuery.setFaceId(faceId);
taskReqQuery.setTemplateId(templateId); taskReqQuery.setTemplateId(templateId);
@ -469,10 +474,15 @@ public class TaskTaskServiceImpl implements TaskService {
log.info("task callback: 没有视频源templateId: {}", templateId); log.info("task callback: 没有视频源templateId: {}", templateId);
return; return;
} }
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(templateId);
if (templatePlaceholder.stream().distinct().count() == templatePlaceholder.size()) {
sourcesMap.forEach((key, value) -> { sourcesMap.forEach((key, value) -> {
// 每个value只保留第一个 // 每个value只保留第一个
value.removeIf(item -> !value.get(0).equals(item)); value.removeIf(item -> !value.get(0).equals(item));
}); });
} else {
log.info("task callback: 模板占位符有重复templateId: {}", templateId);
}
TaskReqQuery taskReqQuery = new TaskReqQuery(); TaskReqQuery taskReqQuery = new TaskReqQuery();
taskReqQuery.setFaceId(faceId); taskReqQuery.setFaceId(faceId);
taskReqQuery.setTemplateId(templateId); taskReqQuery.setTemplateId(templateId);

View File

@ -75,6 +75,7 @@ public class VideoPieceGetter {
public Long memberId; public Long memberId;
public Long faceId; public Long faceId;
public Long templateId; public Long templateId;
public boolean force;
public static interface Callback { public static interface Callback {
void onInvoke(); void onInvoke();
@ -170,6 +171,7 @@ public class VideoPieceGetter {
} catch (InterruptedException ignore) { } catch (InterruptedException ignore) {
} }
} }
isFirst.set(false);
if (pairDeviceMap.containsValue(faceSample.getDeviceId())) { if (pairDeviceMap.containsValue(faceSample.getDeviceId())) {
// 有关联设备! // 有关联设备!
// 找到对应的deviceId // 找到对应的deviceId
@ -179,40 +181,18 @@ public class VideoPieceGetter {
log.info("找到同景区关联设备:{} -> {}", pairDeviceId, faceSample.getDeviceId()); log.info("找到同景区关联设备:{} -> {}", pairDeviceId, faceSample.getDeviceId());
if (pairDeviceId != null) { if (pairDeviceId != null) {
executor.execute(() -> { executor.execute(() -> {
boolean result = doCut(pairDeviceId, faceSample.getId(), faceSample.getCreateAt(), task); doCut(pairDeviceId, faceSample.getId(), faceSample.getCreateAt(), task);
if (templatePlaceholder != null) {
if (templatePlaceholder.contains(faceSample.getDeviceId().toString())) {
if (currentUnFinPlaceholder.contains(faceSample.getDeviceId().toString())) {
if (result) {
currentUnFinPlaceholder.remove(faceSample.getDeviceId().toString()); currentUnFinPlaceholder.remove(faceSample.getDeviceId().toString());
}
}
}
log.info("当前进度:!{}/{}", currentUnFinPlaceholder.size(), collection.size());
if (currentUnFinPlaceholder.size() <= 0) {
if (!invoke.get()) {
invoke.set(true);
task.getCallback().onInvoke();
}
}
}
}); });
} }
}); });
} }
isFirst.set(false);
executor.execute(() -> { executor.execute(() -> {
boolean result = doCut(faceSample.getDeviceId(), faceSample.getId(), faceSample.getCreateAt(), task); doCut(faceSample.getDeviceId(), faceSample.getId(), faceSample.getCreateAt(), task);
if (templatePlaceholder != null) {
if (templatePlaceholder.contains(faceSample.getDeviceId().toString())) {
if (currentUnFinPlaceholder.contains(faceSample.getDeviceId().toString())) {
if (result) {
currentUnFinPlaceholder.remove(faceSample.getDeviceId().toString()); currentUnFinPlaceholder.remove(faceSample.getDeviceId().toString());
} if (templatePlaceholder != null) {
} log.info("当前进度:!{}/{}", currentUnFinPlaceholder.size(), templatePlaceholder.size());
} if (currentUnFinPlaceholder.isEmpty()) {
log.info("当前进度:!{}/{}", currentUnFinPlaceholder.size(), collection.size());
if (currentUnFinPlaceholder.size() <= 0) {
if (!invoke.get()) { if (!invoke.get()) {
invoke.set(true); invoke.set(true);
task.getCallback().onInvoke(); task.getCallback().onInvoke();
@ -250,7 +230,7 @@ public class VideoPieceGetter {
SourceEntity source = sourceMapper.querySameVideo(faceSampleId, device.getId()); SourceEntity source = sourceMapper.querySameVideo(faceSampleId, device.getId());
if (source == null) { if (source == null || task.force) {
BigDecimal cutPre = BigDecimal.valueOf(5L); BigDecimal cutPre = BigDecimal.valueOf(5L);
BigDecimal cutPost = BigDecimal.valueOf(4L); BigDecimal cutPost = BigDecimal.valueOf(4L);
if (config != null) { if (config != null) {
@ -299,6 +279,7 @@ public class VideoPieceGetter {
// 上传成功后删除文件 // 上传成功后删除文件
outFile.delete(); outFile.delete();
} }
if (source == null) {
SourceEntity imgSource = sourceMapper.findBySampleId(faceSampleId); SourceEntity imgSource = sourceMapper.findBySampleId(faceSampleId);
SourceEntity sourceEntity = new SourceEntity(); SourceEntity sourceEntity = new SourceEntity();
sourceEntity.setId(SnowFlakeUtil.getLongId()); sourceEntity.setId(SnowFlakeUtil.getLongId());
@ -330,7 +311,12 @@ public class VideoPieceGetter {
sourceMapper.addRelation(videoSource); sourceMapper.addRelation(videoSource);
} }
sourceMapper.add(sourceEntity); sourceMapper.add(sourceEntity);
videoReUploader.addTask(sourceEntity.getVideoUrl(), sourceEntity.getId()); videoReUploader.addTask(url, sourceEntity.getId());
} else {
source.setVideoUrl(url);
sourceMapper.update(source);
videoReUploader.addTask(url, source.getId());
}
} else { } else {
// 有原视频 // 有原视频
if (task.memberId != null && task.faceId != null) { if (task.memberId != null && task.faceId != null) {

View File

@ -84,7 +84,7 @@ public class VideoTaskGenerator {
query.setStartTime(DateUtil.beginOfDay(new Date())); query.setStartTime(DateUtil.beginOfDay(new Date()));
query.setEndTime(DateUtil.endOfDay(new Date())); query.setEndTime(DateUtil.endOfDay(new Date()));
List<FaceRespVO> list = faceMapper.list(query); List<FaceRespVO> list = faceMapper.list(query);
list.stream().parallel().forEach(face -> { list.forEach(face -> {
faceService.matchFaceId(face.getId(), false); faceService.matchFaceId(face.getId(), false);
if (Integer.valueOf(3).equals(scenicConfig.getBookRoutine())) { if (Integer.valueOf(3).equals(scenicConfig.getBookRoutine())) {
// 全部生成 // 全部生成