You've already forked FrameTour-BE
refactor(video):优化视频关联关系处理逻辑
- 调整source记录插入时机,确保关联关系处理前数据已存在 - 移除冗余的source存在性检查逻辑- 统一关联关系处理流程,避免重复代码 - 添加日志记录以便追踪处理过程- 优化代码结构,提高可读性和维护性
This commit is contained in:
@@ -333,6 +333,12 @@ public class VideoPieceGetter {
|
|||||||
sourceEntity.setScenicId(deviceV2.getScenicId());
|
sourceEntity.setScenicId(deviceV2.getScenicId());
|
||||||
sourceEntity.setDeviceId(deviceId);
|
sourceEntity.setDeviceId(deviceId);
|
||||||
sourceEntity.setType(1);
|
sourceEntity.setType(1);
|
||||||
|
|
||||||
|
// 先插入source记录
|
||||||
|
sourceMapper.add(sourceEntity);
|
||||||
|
videoReUploader.addTask(sourceEntity.getId());
|
||||||
|
|
||||||
|
// 然后处理关联关系
|
||||||
if (task.memberId != null && task.faceId != null) {
|
if (task.memberId != null && task.faceId != null) {
|
||||||
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(task.faceId, 1);
|
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(task.faceId, 1);
|
||||||
MemberSourceEntity videoSource = new MemberSourceEntity();
|
MemberSourceEntity videoSource = new MemberSourceEntity();
|
||||||
@@ -355,18 +361,11 @@ public class VideoPieceGetter {
|
|||||||
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
||||||
});
|
});
|
||||||
if (!anyMatch) {
|
if (!anyMatch) {
|
||||||
// 验证source是否存在,防止创建孤立的关联关系
|
// source已插入,可以直接添加关联关系
|
||||||
if (sourceMapper.sourceExists(videoSource.getSourceId())) {
|
sourceMapper.addRelation(videoSource);
|
||||||
sourceMapper.addRelation(videoSource);
|
|
||||||
} else {
|
|
||||||
log.warn("尝试创建关联关系但source不存在: sourceId={}, faceId={}, memberId={}",
|
|
||||||
videoSource.getSourceId(), videoSource.getFaceId(), videoSource.getMemberId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(task.faceId);
|
memberRelationRepository.clearSCacheByFace(task.faceId);
|
||||||
}
|
}
|
||||||
sourceMapper.add(sourceEntity);
|
|
||||||
videoReUploader.addTask(sourceEntity.getId());
|
|
||||||
} else {
|
} else {
|
||||||
source.setVideoUrl(url);
|
source.setVideoUrl(url);
|
||||||
if (StringUtils.isNotBlank(config.getString("video_crop"))) {
|
if (StringUtils.isNotBlank(config.getString("video_crop"))) {
|
||||||
@@ -376,7 +375,7 @@ public class VideoPieceGetter {
|
|||||||
videoReUploader.addTask(source.getId());
|
videoReUploader.addTask(source.getId());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 有原视频
|
// 有原视频,source已存在,可以直接添加关联关系
|
||||||
if (task.memberId != null && task.faceId != null) {
|
if (task.memberId != null && task.faceId != null) {
|
||||||
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(task.faceId, 1);
|
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(task.faceId, 1);
|
||||||
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), deviceV2.getScenicId(), 1, task.getFaceId());
|
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), deviceV2.getScenicId(), 1, task.getFaceId());
|
||||||
@@ -401,13 +400,8 @@ public class VideoPieceGetter {
|
|||||||
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
||||||
});
|
});
|
||||||
if (!anyMatch) {
|
if (!anyMatch) {
|
||||||
// 验证source是否存在,防止创建孤立的关联关系
|
// source已存在,可以直接添加关联关系
|
||||||
if (sourceMapper.sourceExists(videoSource.getSourceId())) {
|
sourceMapper.addRelation(videoSource);
|
||||||
sourceMapper.addRelation(videoSource);
|
|
||||||
} else {
|
|
||||||
log.warn("尝试创建关联关系但source不存在: sourceId={}, faceId={}, memberId={}",
|
|
||||||
videoSource.getSourceId(), videoSource.getFaceId(), videoSource.getMemberId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(task.faceId);
|
memberRelationRepository.clearSCacheByFace(task.faceId);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user