You've already forked FrameTour-BE
feat(source): 添加过滤已存在关联关系功能
- 在SourceMapper中新增filterExistingRelations方法 - 修改FaceServiceImpl中的关联关系保存逻辑 - 修改TaskFaceServiceImpl中的关联关系保存逻辑 - 修改VideoPieceGetter中的关联关系检查逻辑 - 在SourceMapper.xml中添加filterExistingRelations的SQL实现
This commit is contained in:
@@ -56,6 +56,8 @@ public interface SourceMapper {
|
|||||||
|
|
||||||
int addRelations(List<MemberSourceEntity> list);
|
int addRelations(List<MemberSourceEntity> list);
|
||||||
|
|
||||||
|
List<MemberSourceEntity> filterExistingRelations(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,8 +343,11 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
||||||
face.getMemberId(), sampleListIds, isNew);
|
face.getMemberId(), sampleListIds, isNew);
|
||||||
|
|
||||||
// 保存关联关系并创建任务
|
// 过滤已存在的关联关系,避免重复添加
|
||||||
sourceMapper.addRelations(memberSourceEntityList);
|
List<MemberSourceEntity> filteredList = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
||||||
|
if (!filteredList.isEmpty()) {
|
||||||
|
sourceMapper.addRelations(filteredList);
|
||||||
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
taskTaskService.autoCreateTaskByFaceId(faceId);
|
taskTaskService.autoCreateTaskByFaceId(faceId);
|
||||||
|
|
||||||
@@ -1115,7 +1118,11 @@ public class FaceServiceImpl implements FaceService {
|
|||||||
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
handleVideoRecreation(scenicConfig, memberSourceEntityList, faceId,
|
||||||
face.getMemberId(), sampleListIds, false);
|
face.getMemberId(), sampleListIds, false);
|
||||||
|
|
||||||
sourceMapper.addRelations(memberSourceEntityList);
|
// 过滤已存在的关联关系,避免重复添加
|
||||||
|
List<MemberSourceEntity> filteredList = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
||||||
|
if (!filteredList.isEmpty()) {
|
||||||
|
sourceMapper.addRelations(filteredList);
|
||||||
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
taskTaskService.autoCreateTaskByFaceId(faceId);
|
taskTaskService.autoCreateTaskByFaceId(faceId);
|
||||||
|
|
||||||
|
@@ -153,7 +153,11 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
|||||||
memberSourceEntity.setIsBuy(0);
|
memberSourceEntity.setIsBuy(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceMapper.addRelations(memberSourceEntityList);
|
// 过滤已存在的关联关系,避免重复添加
|
||||||
|
List<MemberSourceEntity> filteredList = sourceMapper.filterExistingRelations(memberSourceEntityList);
|
||||||
|
if (!filteredList.isEmpty()) {
|
||||||
|
sourceMapper.addRelations(filteredList);
|
||||||
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
VideoPieceGetter.Task task = new VideoPieceGetter.Task();
|
VideoPieceGetter.Task task = new VideoPieceGetter.Task();
|
||||||
task.faceId = faceEntity.getId();
|
task.faceId = faceEntity.getId();
|
||||||
|
@@ -334,6 +334,7 @@ public class VideoPieceGetter {
|
|||||||
sourceEntity.setDeviceId(deviceId);
|
sourceEntity.setDeviceId(deviceId);
|
||||||
sourceEntity.setType(1);
|
sourceEntity.setType(1);
|
||||||
if (task.memberId != null && task.faceId != null) {
|
if (task.memberId != null && task.faceId != null) {
|
||||||
|
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(task.faceId, 1);
|
||||||
MemberSourceEntity videoSource = new MemberSourceEntity();
|
MemberSourceEntity videoSource = new MemberSourceEntity();
|
||||||
videoSource.setMemberId(task.getMemberId());
|
videoSource.setMemberId(task.getMemberId());
|
||||||
videoSource.setType(1);
|
videoSource.setType(1);
|
||||||
@@ -348,7 +349,14 @@ public class VideoPieceGetter {
|
|||||||
} else {
|
} else {
|
||||||
videoSource.setIsBuy(0);
|
videoSource.setIsBuy(0);
|
||||||
}
|
}
|
||||||
sourceMapper.addRelation(videoSource);
|
boolean anyMatch = memberSourceEntities.stream().anyMatch(memberSourceEntity -> {
|
||||||
|
return memberSourceEntity.getSourceId().equals(videoSource.getSourceId())
|
||||||
|
&& memberSourceEntity.getType().equals(videoSource.getType())
|
||||||
|
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
||||||
|
});
|
||||||
|
if (!anyMatch) {
|
||||||
|
sourceMapper.addRelation(videoSource);
|
||||||
|
}
|
||||||
memberRelationRepository.clearSCacheByFace(task.faceId);
|
memberRelationRepository.clearSCacheByFace(task.faceId);
|
||||||
}
|
}
|
||||||
sourceMapper.add(sourceEntity);
|
sourceMapper.add(sourceEntity);
|
||||||
@@ -364,27 +372,32 @@ public class VideoPieceGetter {
|
|||||||
} else {
|
} else {
|
||||||
// 有原视频
|
// 有原视频
|
||||||
if (task.memberId != null && task.faceId != null) {
|
if (task.memberId != null && task.faceId != null) {
|
||||||
int count = sourceMapper.hasRelationTo(task.getMemberId(), source.getId(), 1);
|
List<MemberSourceEntity> memberSourceEntities = memberRelationRepository.listSourceByFaceRelation(task.faceId, 1);
|
||||||
if (count <= 0) {
|
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), deviceV2.getScenicId(), 1, task.getFaceId());
|
||||||
// 没有关联
|
MemberSourceEntity videoSource = new MemberSourceEntity();
|
||||||
IsBuyRespVO isBuy = orderBiz.isBuy(task.getMemberId(), deviceV2.getScenicId(), 1, task.getFaceId());
|
videoSource.setId(SnowFlakeUtil.getLongId());
|
||||||
MemberSourceEntity videoSource = new MemberSourceEntity();
|
videoSource.setScenicId(deviceV2.getScenicId());
|
||||||
videoSource.setId(SnowFlakeUtil.getLongId());
|
videoSource.setFaceId(task.getFaceId());
|
||||||
videoSource.setScenicId(deviceV2.getScenicId());
|
videoSource.setMemberId(task.getMemberId());
|
||||||
videoSource.setFaceId(task.getFaceId());
|
videoSource.setType(1);
|
||||||
videoSource.setMemberId(task.getMemberId());
|
if (isBuy.isBuy()) { // 如果用户买过
|
||||||
videoSource.setType(1);
|
videoSource.setIsBuy(1);
|
||||||
if (isBuy.isBuy()) { // 如果用户买过
|
} else if (isBuy.isFree()) { // 全免费逻辑
|
||||||
videoSource.setIsBuy(1);
|
videoSource.setIsBuy(1);
|
||||||
} else if (isBuy.isFree()) { // 全免费逻辑
|
} else {
|
||||||
videoSource.setIsBuy(1);
|
videoSource.setIsBuy(0);
|
||||||
} else {
|
|
||||||
videoSource.setIsBuy(0);
|
|
||||||
}
|
|
||||||
videoSource.setSourceId(source.getId());
|
|
||||||
sourceMapper.addRelation(videoSource);
|
|
||||||
memberRelationRepository.clearSCacheByFace(task.faceId);
|
|
||||||
}
|
}
|
||||||
|
videoSource.setSourceId(source.getId());
|
||||||
|
// 没有关联
|
||||||
|
boolean anyMatch = memberSourceEntities.stream().anyMatch(memberSourceEntity -> {
|
||||||
|
return memberSourceEntity.getSourceId().equals(videoSource.getSourceId())
|
||||||
|
&& memberSourceEntity.getType().equals(videoSource.getType())
|
||||||
|
&& memberSourceEntity.getFaceId().equals(videoSource.getFaceId());
|
||||||
|
});
|
||||||
|
if (!anyMatch) {
|
||||||
|
sourceMapper.addRelation(videoSource);
|
||||||
|
}
|
||||||
|
memberRelationRepository.clearSCacheByFace(task.faceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@@ -16,6 +16,41 @@
|
|||||||
(#{item.scenicId}, #{item.faceId}, #{item.memberId}, #{item.sourceId}, #{item.isBuy}, #{item.type}, #{item.orderId}, #{item.isFree})
|
(#{item.scenicId}, #{item.faceId}, #{item.memberId}, #{item.sourceId}, #{item.isBuy}, #{item.type}, #{item.orderId}, #{item.isFree})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
<select id="filterExistingRelations" 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 NOT EXISTS (
|
||||||
|
SELECT 1 FROM member_source ms
|
||||||
|
WHERE ms.member_id = r.memberId
|
||||||
|
AND ms.source_id = r.sourceId
|
||||||
|
AND ms.type = r.type
|
||||||
|
AND ms.face_id = r.faceId
|
||||||
|
)
|
||||||
|
</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