You've already forked FrameTour-BE
refactor(repository): 移除冗余的用户购买状态查询逻辑
- 删除 SourceRepository 中的 getUserIsBuy 方法 - 删除 VideoRepository 中的 getUserIsBuy 方法 - 简化业务逻辑,减少重复代码 - 提高代码可维护性和清晰度
This commit is contained in:
@@ -62,38 +62,6 @@ public class SourceRepository {
|
|||||||
memberRelationRepository.clearSCacheByFace(faceId);
|
memberRelationRepository.clearSCacheByFace(faceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUserIsBuy(Long userId, int type, Long faceId) {
|
|
||||||
FaceEntity face = faceRepository.getFace(faceId);
|
|
||||||
if (face == null) {
|
|
||||||
log.info("faceId:{} is not exist", faceId);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 确认人员faceId是否有券码
|
|
||||||
List<VoucherInfo> voucherDetails = iVoucherService.getVoucherDetails(faceId, face.getScenicId());
|
|
||||||
if (voucherDetails != null && !voucherDetails.isEmpty()) {
|
|
||||||
VoucherInfo voucherInfo = voucherDetails.getFirst();
|
|
||||||
if (voucherInfo.getDiscountType().equals(VoucherDiscountType.FREE_ALL)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch (type) {
|
|
||||||
case 1:
|
|
||||||
List<SourceEntity> videoSourceList = sourceMapper.listVideoByFaceRelation(faceId);
|
|
||||||
if (videoSourceList == null || videoSourceList.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return videoSourceList.stream().filter(Objects::nonNull).anyMatch(item -> Integer.valueOf(1).equals(item.getIsBuy()));
|
|
||||||
case 2:
|
|
||||||
List<SourceEntity> imageSourceList = sourceMapper.listImageByFaceRelation(faceId);
|
|
||||||
if (imageSourceList == null || imageSourceList.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return imageSourceList.stream().filter(Objects::nonNull).anyMatch(item -> Integer.valueOf(1).equals(item.getIsBuy()));
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SourceEntity getSource(Long id) {
|
public SourceEntity getSource(Long id) {
|
||||||
return sourceMapper.getEntity(id);
|
return sourceMapper.getEntity(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,35 +107,6 @@ public class VideoRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getUserIsBuy(Long userId, Long videoId) {
|
|
||||||
MemberVideoEntity memberVideo = videoMapper.queryUserVideo(userId, videoId);
|
|
||||||
if (memberVideo == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean isBuy = Integer.valueOf(1).equals(memberVideo.getIsBuy());
|
|
||||||
if (isBuy) {
|
|
||||||
return isBuy;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 一口价
|
|
||||||
IsBuyBatchRespVO buy = priceBiz.isOnePriceBuy(userId, memberVideo.getFaceId(), memberVideo.getScenicId(), -1, null);
|
|
||||||
if (buy == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (buy.isBuy()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 确认人员faceId是否有券码
|
|
||||||
List<VoucherInfo> voucherDetails = iVoucherService.getVoucherDetails(memberVideo.getFaceId(), memberVideo.getScenicId());
|
|
||||||
if (voucherDetails != null && !voucherDetails.isEmpty()) {
|
|
||||||
VoucherInfo voucherInfo = voucherDetails.getFirst();
|
|
||||||
if (voucherInfo.getDiscountType().equals(VoucherDiscountType.FREE_ALL)) {
|
|
||||||
isBuy = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isBuy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean clearVideoCache(Long videoId) {
|
public boolean clearVideoCache(Long videoId) {
|
||||||
if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) {
|
if (redisTemplate.hasKey(String.format(VIDEO_CACHE_KEY, videoId))) {
|
||||||
VideoEntity video = getVideo(videoId);
|
VideoEntity video = getVideo(videoId);
|
||||||
|
|||||||
Reference in New Issue
Block a user