You've already forked FrameTour-BE
refactor(task): 重构任务参数处理逻辑
- 新增 filterTaskParams 方法,用于过滤模板所需的源数据 - 新增 getTaskParams 方法,用于获取任务参数并进行预处理 - 优化了视频源和图片源的处理逻辑,提高了代码可读性和可维护性 - 重构了任务回调中的源数据处理流程,使用新方法替代原有逻辑
This commit is contained in:
@@ -15,7 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -121,4 +123,39 @@ public class TemplateBiz {
|
||||
return count >= minimalPlaceholderFill;
|
||||
}
|
||||
|
||||
public Map<String, List<SourceEntity>> filterTaskParams(Long templateId, Map<String, List<SourceEntity>> allTaskParams) {
|
||||
if (allTaskParams == null || allTaskParams.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
List<String> templatePlaceholders = templateRepository.getTemplatePlaceholder(templateId);
|
||||
if (templatePlaceholders == null || templatePlaceholders.isEmpty()) {
|
||||
log.info("filterTaskParams: templateId:{} has no placeholders", templateId);
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
Map<String, List<SourceEntity>> filteredParams = new HashMap<>();
|
||||
|
||||
for (String placeholder : templatePlaceholders) {
|
||||
if (placeholder.startsWith("P")) {
|
||||
// 图片源:占位符格式为 "P{deviceId}"
|
||||
String imageKey = placeholder;
|
||||
if (allTaskParams.containsKey(imageKey)) {
|
||||
filteredParams.put(imageKey, allTaskParams.get(imageKey));
|
||||
}
|
||||
} else {
|
||||
// 视频源:占位符直接对应设备ID
|
||||
String videoKey = placeholder;
|
||||
if (allTaskParams.containsKey(videoKey)) {
|
||||
filteredParams.put(videoKey, allTaskParams.get(videoKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("filterTaskParams: templateId:{}, original keys:{}, filtered keys:{}",
|
||||
templateId, allTaskParams.keySet().size(), filteredParams.keySet().size());
|
||||
|
||||
return filteredParams;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user