You've already forked FrameTour-BE
refactor(task): 重构任务参数处理逻辑
- 新增 filterTaskParams 方法,用于过滤模板所需的源数据 - 新增 getTaskParams 方法,用于获取任务参数并进行预处理 - 优化了视频源和图片源的处理逻辑,提高了代码可读性和可维护性 - 重构了任务回调中的源数据处理流程,使用新方法替代原有逻辑
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.crypto.digest.MD5;
|
||||
import com.ycwl.basic.integration.common.manager.DeviceConfigManager;
|
||||
import com.ycwl.basic.integration.common.manager.RenderWorkerConfigManager;
|
||||
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||
import com.ycwl.basic.repository.SourceRepository;
|
||||
import com.ycwl.basic.utils.JacksonUtil;
|
||||
import com.ycwl.basic.biz.OrderBiz;
|
||||
import com.ycwl.basic.biz.TaskStatusBiz;
|
||||
@@ -126,6 +127,8 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
private VideoReUploader videoReUploader;
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
@Autowired
|
||||
private SourceRepository sourceRepository;
|
||||
|
||||
private RenderWorkerEntity getWorker(@NonNull WorkerAuthReqVo req) {
|
||||
String accessKey = req.getAccessKey();
|
||||
@@ -348,58 +351,15 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
}
|
||||
}
|
||||
|
||||
List<SourceEntity> videoSourceList = sourceMapper.listVideoByScenicFaceRelation(face.getScenicId(), faceId);
|
||||
Map<String, List<SourceEntity>> sourcesMap = videoSourceList.stream()
|
||||
.peek(item -> item.setUrl(item.getVideoUrl()))
|
||||
.filter(item -> item.getDeviceId() != null) // 添加对 deviceId 为 null 的检查
|
||||
.filter(item -> {
|
||||
DeviceEntity device = deviceRepository.getDevice(item.getDeviceId());
|
||||
if (device == null) {
|
||||
log.info("task callback: deviceId:{} is not exist", item.getDeviceId());
|
||||
return false;
|
||||
}
|
||||
return Integer.valueOf(1).equals(device.getStatus());
|
||||
})
|
||||
.collect(Collectors.groupingBy(item -> item.getDeviceId().toString()));
|
||||
if (sourcesMap.isEmpty()) {
|
||||
// 主动禁止没有视频源视频生成
|
||||
log.info("task callback: 没有视频源,templateId: {}", templateId);
|
||||
Map<String, List<SourceEntity>> allTaskParams = sourceRepository.getTaskParams(faceId, templateId);
|
||||
if (allTaskParams.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(templateId);
|
||||
if (templatePlaceholder.stream().distinct().count() == templatePlaceholder.size()) {
|
||||
sourcesMap.forEach((key, value) -> {
|
||||
// 每个value只保留第一个
|
||||
value.removeIf(item -> !value.getFirst().equals(item));
|
||||
});
|
||||
}
|
||||
|
||||
// 处理以P开头的templatePlaceHolder,添加type=2的source
|
||||
boolean hasPPlaceholder = templatePlaceholder.stream().anyMatch(placeholder -> placeholder.startsWith("P"));
|
||||
if (hasPPlaceholder) {
|
||||
List<SourceEntity> imageSourceList = sourceMapper.listImageSourcesByFaceId(faceId);
|
||||
if (!imageSourceList.isEmpty()) {
|
||||
// 将图片source按设备ID分组并添加到sourcesMap中
|
||||
Map<String, List<SourceEntity>> imageSourceMap = imageSourceList.stream()
|
||||
.peek(item -> item.setUrl(item.getUrl())) // 图片使用url字段
|
||||
.filter(item -> item.getDeviceId() != null)
|
||||
.filter(item -> {
|
||||
DeviceEntity device = deviceRepository.getDevice(item.getDeviceId());
|
||||
if (device == null) {
|
||||
return false;
|
||||
}
|
||||
return Integer.valueOf(1).equals(device.getStatus());
|
||||
})
|
||||
.collect(Collectors.groupingBy(item -> Strings.concat("P", item.getDeviceId().toString())));
|
||||
|
||||
// 合并到现有的sourcesMap中
|
||||
imageSourceMap.forEach((key, value) -> {
|
||||
sourcesMap.merge(key, value, (existing, replacement) -> {
|
||||
existing.addAll(replacement);
|
||||
return existing;
|
||||
});
|
||||
});
|
||||
}
|
||||
Map<String, List<SourceEntity>> sourcesMap = templateBiz.filterTaskParams(templateId, allTaskParams);
|
||||
if (sourcesMap.isEmpty()) {
|
||||
log.info("task callback: 筛选后无有效源数据,templateId: {}", templateId);
|
||||
return;
|
||||
}
|
||||
TaskReqQuery taskReqQuery = new TaskReqQuery();
|
||||
taskReqQuery.setFaceId(faceId);
|
||||
|
Reference in New Issue
Block a user