feat(pipeline): 增强人脸匹配流水线的健壮性

- 在BuildSourceRelationStage中增加sampleListIds空值检查与降级处理
- 在PersistRelationsStage中增加memberSourceList空值检查与提前跳过逻辑
- 为BuildSourceRelationStage、DeleteOldRelationsStage和PersistRelationsStage添加完整的单元测试覆盖
- 实现异常情况下的优雅降级与错误日志记录
- 完善上下文状态管理与阶段跳过机制
This commit is contained in:
2025-12-03 18:49:03 +08:00
parent b165840176
commit 8c08c8947e
5 changed files with 705 additions and 0 deletions

View File

@@ -67,6 +67,23 @@ public class BuildSourceRelationStage extends AbstractFaceMatchingStage<FaceMatc
List<Long> sampleListIds = context.getSampleListIds();
Long faceId = context.getFaceId();
// 防御性检查:sampleListIds为空
if (sampleListIds == null || sampleListIds.isEmpty()) {
// 尝试从searchResult中获取
if (context.getSearchResult() != null) {
sampleListIds = context.getSearchResult().getSampleListIds();
if (sampleListIds != null && !sampleListIds.isEmpty()) {
context.setSampleListIds(sampleListIds);
} else {
log.debug("sampleListIds为空,跳过源文件关联,faceId={}", faceId);
return StageResult.skipped("sampleListIds为空");
}
} else {
log.debug("sampleListIds为空,跳过源文件关联,faceId={}", faceId);
return StageResult.skipped("sampleListIds为空");
}
}
try {
// 处理源文件关联
List<MemberSourceEntity> memberSourceEntityList =

View File

@@ -60,6 +60,12 @@ public class PersistRelationsStage extends AbstractFaceMatchingStage<FaceMatchin
List<MemberSourceEntity> memberSourceEntityList = context.getMemberSourceList();
Long faceId = context.getFaceId();
// 防御性检查:memberSourceList为空
if (memberSourceEntityList == null || memberSourceEntityList.isEmpty()) {
log.debug("memberSourceList为空,跳过持久化,faceId={}", faceId);
return StageResult.skipped("memberSourceList为空");
}
try {
// 1. 过滤已存在的关联关系
List<MemberSourceEntity> existingFiltered = sourceMapper.filterExistingRelations(memberSourceEntityList);