You've already forked FrameTour-BE
refactor(order): 重构订单购买逻辑并优化接口参数
- 调整 isBuy 方法参数顺序,增加 faceId 参数支持 - 删除冗余的购买检查方法和旧版 isBuy 重载方法 - 简化购买状态判断逻辑,移除重复代码 - 更新视频查看权限服务中的购买检查调用 - 修改人脸服务中景区 ID 类型为 Long - 调整打印机服务中人脸查询方法参数类型 - 统一订单业务类中方法签名和调用方式 - 移除订单请求模型中无用字段注释 - 增加人脸 ID 列表字段支持批量查询 - 优化任务服务中购买状态检查逻辑
This commit is contained in:
@@ -4,11 +4,13 @@ import com.ycwl.basic.biz.OrderBiz;
|
||||
import com.ycwl.basic.integration.common.manager.ScenicConfigManager;
|
||||
import com.ycwl.basic.model.mobile.order.IsBuyRespVO;
|
||||
import com.ycwl.basic.model.mobile.video.dto.VideoViewPermissionDTO;
|
||||
import com.ycwl.basic.model.pc.task.entity.TaskEntity;
|
||||
import com.ycwl.basic.model.pc.video.entity.UserVideoViewEntity;
|
||||
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.repository.UserVideoViewRepository;
|
||||
import com.ycwl.basic.repository.VideoRepository;
|
||||
import com.ycwl.basic.repository.VideoTaskRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -28,6 +30,7 @@ public class VideoViewPermissionService {
|
||||
private final VideoRepository videoRepository;
|
||||
private final ScenicRepository scenicRepository;
|
||||
private final OrderBiz orderBiz;
|
||||
private final VideoTaskRepository videoTaskRepository;
|
||||
|
||||
/**
|
||||
* 检查并记录用户查看视频
|
||||
@@ -50,9 +53,10 @@ public class VideoViewPermissionService {
|
||||
log.warn("视频缺少景区信息: videoId={}", videoId);
|
||||
return createErrorPermission("视频信息不完整");
|
||||
}
|
||||
TaskEntity taskById = videoTaskRepository.getTaskById(video.getTaskId());
|
||||
|
||||
// 检查用户是否已购买
|
||||
IsBuyRespVO buy = orderBiz.isBuy(userId, scenicId, 0, videoId);
|
||||
IsBuyRespVO buy = orderBiz.isBuy(scenicId, userId, taskById.getFaceId(), 0, videoId);
|
||||
if (buy != null && (buy.isBuy() || buy.isFree())) {
|
||||
// 已购买,不限制查看
|
||||
log.debug("用户已购买视频,无查看限制: userId={}, videoId={}", userId, videoId);
|
||||
@@ -119,9 +123,10 @@ public class VideoViewPermissionService {
|
||||
if (scenicId == null) {
|
||||
return createErrorPermission("视频信息不完整");
|
||||
}
|
||||
TaskEntity taskById = videoTaskRepository.getTaskById(video.getTaskId());
|
||||
|
||||
// 检查用户是否已购买
|
||||
IsBuyRespVO buy = orderBiz.isBuy(userId, scenicId, 0, videoId);
|
||||
IsBuyRespVO buy = orderBiz.isBuy(scenicId, userId, taskById.getFaceId(), 0, videoId);
|
||||
if (buy != null && (buy.isBuy() || buy.isFree())) {
|
||||
// 已购买,不限制查看
|
||||
log.debug("用户已购买视频,无查看限制: userId={}, videoId={}", userId, videoId);
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface FaceService {
|
||||
|
||||
FaceRecognizeResp faceUpload(MultipartFile file, Long scenicId, Long userId, String scene);
|
||||
|
||||
List<FaceRespVO> listByUser(Long userId, String scenicId);
|
||||
List<FaceRespVO> listByUser(Long userId, Long scenicId);
|
||||
SearchFaceRespVo matchFaceId(Long faceId);
|
||||
|
||||
SearchFaceRespVo matchFaceId(Long faceId, boolean isNew);
|
||||
|
||||
@@ -319,7 +319,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FaceRespVO> listByUser(Long userId, String scenicId) {
|
||||
public List<FaceRespVO> listByUser(Long userId, Long scenicId) {
|
||||
return faceMapper.listByScenicAndUserId(scenicId, userId);
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
sourceVideoContent.setGroup("直出原片");
|
||||
sourceImageContent.setGroup("直出原片");
|
||||
if (!scenicConfigFacade.isDisableSourceImage(face.getScenicId())) {
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, face.getScenicId(), SourceType.IMAGE.getCode(), faceId);
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(face.getScenicId(), userId, faceId, SourceType.IMAGE.getCode(), faceId);
|
||||
sourceImageContent.setSourceType(isBuyRespVO.getGoodsType());
|
||||
sourceImageContent.setContentId(isBuyRespVO.getGoodsId());
|
||||
if (isBuyRespVO.isBuy()) {
|
||||
@@ -538,7 +538,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
contentList.add(sourceImageContent);
|
||||
}
|
||||
if (!scenicConfigFacade.isDisableSourceVideo(face.getScenicId())) {
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(userId, face.getScenicId(), SourceType.VIDEO.getCode(), faceId);
|
||||
IsBuyRespVO isBuyRespVO = orderBiz.isBuy(face.getScenicId(), userId, faceId, SourceType.VIDEO.getCode(), faceId);
|
||||
sourceVideoContent.setSourceType(isBuyRespVO.getGoodsType());
|
||||
sourceVideoContent.setContentId(isBuyRespVO.getGoodsId());
|
||||
if (isBuyRespVO.isBuy()) {
|
||||
|
||||
@@ -696,10 +696,6 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
// 使用synchronized确保同一用户对同一商品的订单创建操作串行化
|
||||
synchronized (orderKey.intern()) {
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(userId, createOrderReqVO.getScenicId(), createOrderReqVO.getGoodsType(), createOrderReqVO.getGoodsId());
|
||||
if (isBuy.isBuy()) {
|
||||
return ApiResponse.fail("您已购买此内容,无需重复购买!");
|
||||
}
|
||||
// 看看有没有之前购买的订单
|
||||
OrderEntity order = orderMapper.getUserOrderItem(userId, createOrderReqVO.getScenicId(), 0, null, createOrderReqVO.getGoodsType(), createOrderReqVO.getGoodsId());
|
||||
boolean haveOldOrder = false;
|
||||
@@ -727,8 +723,14 @@ public class OrderServiceImpl implements OrderService {
|
||||
order.setPrice(priceObj.getPrice());
|
||||
// 判断是否是本人数据
|
||||
FaceEntity goodsFace = faceRepository.getFace(priceObj.getFaceId());
|
||||
if (goodsFace != null && !goodsFace.getMemberId().equals(userId)) {
|
||||
return ApiResponse.fail("您无权购买此内容!");
|
||||
if (goodsFace != null) {
|
||||
if (!goodsFace.getMemberId().equals(userId)) {
|
||||
return ApiResponse.fail("您无权购买此内容!");
|
||||
}
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(createOrderReqVO.getScenicId(), userId, goodsFace.getId(), createOrderReqVO.getGoodsType(), createOrderReqVO.getGoodsId());
|
||||
if (isBuy.isBuy()) {
|
||||
return ApiResponse.fail("您已购买此内容,无需重复购买!");
|
||||
}
|
||||
}
|
||||
// promo code
|
||||
order.setPayPrice(priceObj.getPrice());
|
||||
@@ -940,7 +942,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
default -> 0L;
|
||||
};
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(userId, face.getScenicId(), type, goodsId);
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(face.getScenicId(), userId, face.getId(), type, goodsId);
|
||||
if (isBuy.isBuy()) {
|
||||
throw new BaseException("您已购买此内容,无需重复购买!");
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class BuyStatusProcessor {
|
||||
}
|
||||
|
||||
// 获取用户购买状态
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(memberId, scenicId,
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(scenicId, memberId, faceId,
|
||||
memberSourceEntityList.getFirst().getType(),
|
||||
faceId);
|
||||
|
||||
|
||||
@@ -972,7 +972,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
Long faceId = null;
|
||||
|
||||
// 查询该用户在该景区的所有人脸记录
|
||||
List<FaceRespVO> userFaces = faceMapper.listByScenicAndUserId(scenicId.toString(), userId);
|
||||
List<FaceRespVO> userFaces = faceMapper.listByScenicAndUserId(scenicId, userId);
|
||||
|
||||
// 查找是否存在相同URL的记录
|
||||
for (FaceRespVO faceResp : userFaces) {
|
||||
|
||||
@@ -151,7 +151,7 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
||||
return memberSourceEntity;
|
||||
}).collect(Collectors.toList());
|
||||
if (!memberSourceEntityList.isEmpty()) {
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(face.getMemberId(), face.getScenicId(), memberSourceEntityList.getFirst().getType(), faceEntity.getId());
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(face.getScenicId(), face.getMemberId(), faceEntity.getId(), memberSourceEntityList.getFirst().getType(), faceEntity.getId());
|
||||
for (MemberSourceEntity memberSourceEntity : memberSourceEntityList) {
|
||||
if (isBuy.isBuy()) { // 如果用户买过
|
||||
memberSourceEntity.setIsBuy(1);
|
||||
|
||||
@@ -442,7 +442,7 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
memberVideoEntity.setTaskId(list.getFirst().getId());
|
||||
VideoEntity video = videoMapper.findByTaskId(list.getFirst().getId());
|
||||
if (video != null) {
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(face.getMemberId(), list.getFirst().getScenicId(), 0, video.getId());
|
||||
IsBuyRespVO isBuy = orderBiz.isBuy(list.getFirst().getScenicId(), face.getMemberId(), face.getId(), 0, video.getId());
|
||||
if (isBuy.isBuy()) {
|
||||
memberVideoEntity.setIsBuy(1);
|
||||
memberVideoEntity.setOrderId(isBuy.getOrderId());
|
||||
@@ -516,7 +516,7 @@ public class TaskTaskServiceImpl implements TaskService {
|
||||
int isBuy = 0;
|
||||
FaceEntity face = faceRepository.getFace(task.getFaceId());
|
||||
if (face != null) {
|
||||
IsBuyRespVO priceObj = orderBiz.isBuy(face.getMemberId(), task.getScenicId(), 0, video.getId());
|
||||
IsBuyRespVO priceObj = orderBiz.isBuy(task.getScenicId(), face.getMemberId(), face.getId(), 0, video.getId());
|
||||
if (priceObj.isBuy()) {
|
||||
isBuy = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user