You've already forked FrameTour-BE
feat(source): 增强source关联关系的数据一致性校验
- 在SourceMapper中新增sourceExists方法,用于校验source是否存在 - 新增filterValidSourceRelations方法,过滤无效的source引用 - 在FaceServiceImpl中增强关联关系创建逻辑,防止重复和无效数据 - 在VideoPieceGetter任务中增加source存在性校验,避免创建孤立关联- 添加详细的日志记录,便于追踪关联关系创建过程 -优化XML映射文件,支持新的校验和过滤查询逻辑
This commit is contained in:
@@ -58,6 +58,10 @@ public interface SourceMapper {
|
|||||||
|
|
||||||
List<MemberSourceEntity> filterExistingRelations(List<MemberSourceEntity> list);
|
List<MemberSourceEntity> filterExistingRelations(List<MemberSourceEntity> list);
|
||||||
|
|
||||||
|
boolean sourceExists(Long sourceId);
|
||||||
|
|
||||||
|
List<MemberSourceEntity> filterValidSourceRelations(List<MemberSourceEntity> list);
|
||||||
|
|
||||||
int updateRelation(MemberSourceEntity memberSourceEntity);
|
int updateRelation(MemberSourceEntity memberSourceEntity);
|
||||||
int freeRelations(List<Long> ids, int type);
|
int freeRelations(List<Long> ids, int type);
|
||||||
|
|
||||||
|
|||||||
@@ -343,10 +343,15 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
||||||
face.getMemberId(), sampleListIds, isNew);
|
face.getMemberId(), sampleListIds, isNew);
|
||||||
|
|
||||||
// 过滤已存在的关联关系,避免重复添加
|
// 过滤已存在的关联关系和无效的source引用,防止数据不一致
|
||||||
List<MemberSourceEntity> filteredList = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
List<MemberSourceEntity> existingFiltered = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
||||||
if (!filteredList.isEmpty()) {
|
List<MemberSourceEntity> validFiltered = sourceMapper.filterValidSourceRelations(existingFiltered);
|
||||||
sourceMapper.addRelations(filteredList);
|
if (!validFiltered.isEmpty()) {
|
||||||
|
sourceMapper.addRelations(validFiltered);
|
||||||
|
log.debug("创建关联关系: faceId={}, 原始数量={}, 过滤后数量={}",
|
||||||
|
faceId, memberSourceEntityList.size(), validFiltered.size());
|
||||||
|
} else {
|
||||||
|
log.warn("没有有效的关联关系可创建: faceId={}, 原始数量={}", faceId, memberSourceEntityList.size());
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
taskTaskService.autoCreateTaskByFaceId(faceId);
|
taskTaskService.autoCreateTaskByFaceId(faceId);
|
||||||
@@ -1118,10 +1123,15 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
||||||
face.getMemberId(), sampleListIds, false);
|
face.getMemberId(), sampleListIds, false);
|
||||||
|
|
||||||
// 过滤已存在的关联关系,避免重复添加
|
// 过滤已存在的关联关系和无效的source引用,防止数据不一致
|
||||||
List<MemberSourceEntity> filteredList = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
List<MemberSourceEntity> existingFiltered = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
||||||
if (!filteredList.isEmpty()) {
|
List<MemberSourceEntity> validFiltered = sourceMapper.filterValidSourceRelations(existingFiltered);
|
||||||
sourceMapper.addRelations(filteredList);
|
if (!validFiltered.isEmpty()) {
|
||||||
|
sourceMapper.addRelations(validFiltered);
|
||||||
|
log.debug("创建关联关系: faceId={}, 原始数量={}, 过滤后数量={}",
|
||||||
|
faceId, memberSourceEntityList.size(), validFiltered.size());
|
||||||
|
} else {
|
||||||
|
log.warn("没有有效的关联关系可创建: faceId={}, 原始数量={}", faceId, memberSourceEntityList.size());
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
taskTaskService.autoCreateTaskByFaceId(faceId);
|
taskTaskService.autoCreateTaskByFaceId(faceId);
|
||||||
|
|||||||
@@ -153,10 +153,15 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
memberSourceEntity.setIsBuy(0);
|
memberSourceEntity.setIsBuy(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 过滤已存在的关联关系,避免重复添加
|
// 过滤已存在的关联关系和无效的source引用,防止数据不一致
|
||||||
List<MemberSourceEntity> filteredList = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
List<MemberSourceEntity> existingFiltered = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
||||||
if (!filteredList.isEmpty()) {
|
List<MemberSourceEntity> validFiltered = sourceMapper.filterValidSourceRelations(existingFiltered);
|
||||||
sourceMapper.addRelations(filteredList);
|
if (!validFiltered.isEmpty()) {
|
||||||
|
sourceMapper.addRelations(validFiltered);
|
||||||
|
log.debug("创建关联关系: faceId={}, 原始数量={}, 过滤后数量={}",
|
||||||
|
faceId, memberSourceEntityList.size(), validFiltered.size());
|
||||||
|
} else {
|
||||||
|
log.warn("没有有效的关联关系可创建: faceId={}, 原始数量={}", faceId, memberSourceEntityList.size());
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
VideoPieceGetter.Task task = new VideoPieceGetter.Task();
|
VideoPieceGetter.Task task = new VideoPieceGetter.Task();
|
||||||
|
|||||||
@@ -355,7 +355,13 @@ public class VideoPieceGetter {
|
|||||||
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
||||||
});
|
});
|
||||||
if (!anyMatch) {
|
if (!anyMatch) {
|
||||||
sourceMapper.addRelation(videoSource);
|
// 验证source是否存在,防止创建孤立的关联关系
|
||||||
|
if (sourceMapper.sourceExists(videoSource.getSourceId())) {
|
||||||
|
sourceMapper.addRelation(videoSource);
|
||||||
|
} else {
|
||||||
|
log.warn("尝试创建关联关系但source不存在: sourceId={}, faceId={}, memberId={}",
|
||||||
|
videoSource.getSourceId(), videoSource.getFaceId(), videoSource.getMemberId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(task.faceId);
|
memberRelationRepository.clearSCacheByFace(task.faceId);
|
||||||
}
|
}
|
||||||
@@ -395,7 +401,13 @@ public class VideoPieceGetter {
|
|||||||
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
||||||
});
|
});
|
||||||
if (!anyMatch) {
|
if (!anyMatch) {
|
||||||
sourceMapper.addRelation(videoSource);
|
// 验证source是否存在,防止创建孤立的关联关系
|
||||||
|
if (sourceMapper.sourceExists(videoSource.getSourceId())) {
|
||||||
|
sourceMapper.addRelation(videoSource);
|
||||||
|
} else {
|
||||||
|
log.warn("尝试创建关联关系但source不存在: sourceId={}, faceId={}, memberId={}",
|
||||||
|
videoSource.getSourceId(), videoSource.getFaceId(), videoSource.getMemberId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(task.faceId);
|
memberRelationRepository.clearSCacheByFace(task.faceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,40 @@
|
|||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="sourceExists" resultType="boolean">
|
||||||
|
SELECT COUNT(1) > 0 FROM source WHERE id = #{sourceId}
|
||||||
|
</select>
|
||||||
|
<select id="filterValidSourceRelations" resultType="com.ycwl.basic.model.pc.source.entity.MemberSourceEntity">
|
||||||
|
<if test="list != null and list.size() > 0">
|
||||||
|
SELECT
|
||||||
|
r.memberId as memberId,
|
||||||
|
r.sourceId as sourceId,
|
||||||
|
r.type as type,
|
||||||
|
r.faceId as faceId,
|
||||||
|
r.scenicId as scenicId,
|
||||||
|
r.isBuy as isBuy,
|
||||||
|
r.orderId as orderId,
|
||||||
|
r.isFree as isFree,
|
||||||
|
r.id as id
|
||||||
|
FROM (
|
||||||
|
<foreach collection="list" item="item" separator="UNION ALL ">
|
||||||
|
SELECT
|
||||||
|
#{item.memberId} as memberId,
|
||||||
|
#{item.sourceId} as sourceId,
|
||||||
|
#{item.type} as type,
|
||||||
|
#{item.faceId} as faceId,
|
||||||
|
#{item.scenicId} as scenicId,
|
||||||
|
#{item.isBuy} as isBuy,
|
||||||
|
#{item.orderId} as orderId,
|
||||||
|
#{item.isFree} as isFree,
|
||||||
|
#{item.id} as id
|
||||||
|
</foreach>
|
||||||
|
) r
|
||||||
|
WHERE EXISTS (
|
||||||
|
SELECT 1 FROM source s WHERE s.id = r.sourceId
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
<insert id="addSourceWatermark">
|
<insert id="addSourceWatermark">
|
||||||
insert source_watermark(source_id, face_id, watermark_type, watermark_url)
|
insert source_watermark(source_id, face_id, watermark_type, watermark_url)
|
||||||
values (#{sourceId}, #{faceId}, #{type}, #{url})
|
values (#{sourceId}, #{faceId}, #{type}, #{url})
|
||||||
|
|||||||
Reference in New Issue
Block a user