You've already forked FrameTour-BE
refactor(biz): 重构Vlog 视频价格计算逻辑
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
All checks were successful
ZhenTu-BE/pipeline/head This commit looks good
- 移除 OrderBiz 中的固定价格设置,改为调用价格计算服务 - 删除 PriceBiz 中未使用的 IOnePricePurchaseService 注入 - 优化 AppOrderV2Controller 中的产品数量设置逻辑 - 新增 VideoTaskRepository 中的 getTaskDeviceCount 方法,用于获取任务设备数量 - 调整 GoodsServiceImpl 和 OrderServiceImpl 中的相关代码,使用新的设备数量获取方法
This commit is contained in:
@@ -117,13 +117,18 @@ public class OrderBiz {
|
||||
if (template == null) {
|
||||
return priceObj;
|
||||
}
|
||||
priceObj.setPrice(template.getPrice());
|
||||
BigDecimal slashPrice = template.getSlashPrice();
|
||||
if (slashPrice == null) {
|
||||
priceObj.setSlashPrice(priceObj.getPrice());
|
||||
} else {
|
||||
priceObj.setSlashPrice(slashPrice);
|
||||
}
|
||||
PriceCalculationRequest vlogCalculationRequest = new PriceCalculationRequest();
|
||||
ProductItem vlogProductItem = new ProductItem();
|
||||
vlogProductItem.setProductType(ProductType.VLOG_VIDEO);
|
||||
vlogProductItem.setProductId(template.getId().toString());
|
||||
vlogProductItem.setQuantity(videoTaskRepository.getTaskDeviceCount(video.getTaskId()));
|
||||
vlogProductItem.setScenicId(scenic.getId().toString());
|
||||
vlogCalculationRequest.setProducts(Collections.singletonList(vlogProductItem));
|
||||
vlogCalculationRequest.setFaceId(priceObj.getFaceId());
|
||||
PriceCalculationResult vlogCalculationResult = iPriceCalculationService.calculatePrice(vlogCalculationRequest);
|
||||
priceObj.setPrice(vlogCalculationResult.getFinalAmount());
|
||||
priceObj.setSlashPrice(vlogCalculationResult.getOriginalAmount());
|
||||
priceObj.setFaceId(goodsId);
|
||||
priceObj.setScenicId(video.getScenicId());
|
||||
break;
|
||||
case 1: // source
|
||||
|
@@ -39,8 +39,6 @@ public class PriceBiz {
|
||||
private FaceRepository faceRepository;
|
||||
@Autowired
|
||||
private CouponBiz couponBiz;
|
||||
@Autowired
|
||||
private IOnePricePurchaseService onePricePurchaseService;
|
||||
|
||||
public List<GoodsListRespVO> listGoodsByScenic(Long scenicId) {
|
||||
List<GoodsListRespVO> goodsList = new ArrayList<>();
|
||||
|
@@ -96,32 +96,11 @@ public class AppOrderV2Controller {
|
||||
request.getProducts().forEach(product -> {
|
||||
switch (product.getProductType()) {
|
||||
case VLOG_VIDEO:
|
||||
AtomicInteger deviceCount = new AtomicInteger();
|
||||
List<MemberVideoEntity> videoEntities = videoMapper.listRelationByFaceAndTemplate(face.getId(), Long.valueOf(product.getProductId()));
|
||||
if (videoEntities != null && !videoEntities.isEmpty()) {
|
||||
TaskEntity task = videoTaskRepository.getTaskById(videoEntities.getFirst().getTaskId());
|
||||
if (task != null) {
|
||||
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
|
||||
if (paramJson == null) {
|
||||
deviceCount.set(1);
|
||||
} else {
|
||||
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
|
||||
paramJson.entrySet().stream()
|
||||
.filter(entry -> StringUtils.isNumeric(entry.getKey()))
|
||||
.forEach(entry -> {
|
||||
List<Object> jsonArray = JacksonUtil.parseArray(JacksonUtil.toJSONString(entry.getValue()), Object.class);
|
||||
if (jsonArray != null && !jsonArray.isEmpty()) {
|
||||
for (Object ignored : jsonArray) {
|
||||
if (templatePlaceholder.contains(entry.getKey())) {
|
||||
deviceCount.getAndIncrement();
|
||||
templatePlaceholder.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
product.setQuantity(deviceCount.get());
|
||||
}
|
||||
product.setQuantity(videoTaskRepository.getTaskDeviceCount(videoEntities.getFirst().getTaskId()));
|
||||
} else {
|
||||
product.setQuantity(1);
|
||||
}
|
||||
break;
|
||||
case RECORDING_SET:
|
||||
|
@@ -12,8 +12,11 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Component
|
||||
public class VideoTaskRepository {
|
||||
@@ -23,6 +26,8 @@ public class VideoTaskRepository {
|
||||
private TaskMapper taskMapper;
|
||||
|
||||
public static final String TASK_CACHE_KEY = "task:byId:%s";
|
||||
@Autowired
|
||||
private TemplateRepository templateRepository;
|
||||
|
||||
public TaskEntity getTaskById(Long taskId) {
|
||||
if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) {
|
||||
@@ -63,4 +68,30 @@ public class VideoTaskRepository {
|
||||
return shotTime;
|
||||
}
|
||||
|
||||
public Integer getTaskDeviceCount(Long taskId) {
|
||||
TaskEntity task = getTaskById(taskId);
|
||||
if (task == null) {
|
||||
return 1;
|
||||
}
|
||||
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
|
||||
if (paramJson == null) {
|
||||
return 1;
|
||||
}
|
||||
AtomicInteger deviceCount = new AtomicInteger();
|
||||
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
|
||||
paramJson.entrySet().stream()
|
||||
.filter(entry -> StringUtils.isNumeric(entry.getKey()))
|
||||
.forEach(entry -> {
|
||||
List<Object> jsonArray = JacksonUtil.parseArray(JacksonUtil.toJSONString(entry.getValue()), Object.class);
|
||||
if (jsonArray != null && !jsonArray.isEmpty()) {
|
||||
for (Object ignored : jsonArray) {
|
||||
if (templatePlaceholder.contains(entry.getKey())) {
|
||||
deviceCount.getAndIncrement();
|
||||
templatePlaceholder.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return deviceCount.get();
|
||||
}
|
||||
}
|
||||
|
@@ -290,28 +290,8 @@ public class GoodsServiceImpl implements GoodsService {
|
||||
if (task == null) {
|
||||
return ApiResponse.fail("该vlog不存在或已失效");
|
||||
}
|
||||
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
|
||||
AtomicInteger deviceCount = new AtomicInteger();
|
||||
goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId()));
|
||||
if (paramJson == null) {
|
||||
deviceCount.set(1);
|
||||
} else {
|
||||
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
|
||||
paramJson.entrySet().stream()
|
||||
.filter(entry -> StringUtils.isNumeric(entry.getKey()))
|
||||
.forEach(entry -> {
|
||||
List<Object> jsonArray = JacksonUtil.parseArray(JacksonUtil.toJSONString(entry.getValue()), Object.class);
|
||||
if (jsonArray != null && !jsonArray.isEmpty()) {
|
||||
for (Object ignored : jsonArray) {
|
||||
if (templatePlaceholder.contains(entry.getKey())) {
|
||||
deviceCount.getAndIncrement();
|
||||
templatePlaceholder.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
goodsDetailVO.setLensNum(deviceCount.get());
|
||||
goodsDetailVO.setLensNum(videoTaskRepository.getTaskDeviceCount(task.getId()));
|
||||
CouponRecordQueryResp couponRecord = couponBiz.queryUserCouponRecord(task.getScenicId(), userId, task.getFaceId(), task.getTemplateId().toString());
|
||||
if (couponRecord != null) {
|
||||
if (couponRecord.isUsable()) {
|
||||
|
@@ -298,19 +298,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
goods.setUrl(videoMapperById.getVideoUrl());
|
||||
goods.setGoodsType(0);
|
||||
goods.setTemplateCoverUrl(template.getCoverUrl());
|
||||
long deviceCount;
|
||||
if (task.getTaskParams() == null) {
|
||||
deviceCount = 1;
|
||||
} else {
|
||||
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
|
||||
List<String> templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
|
||||
deviceCount = paramJson.keySet().stream()
|
||||
.filter(StringUtils::isNumeric)
|
||||
.filter(templatePlaceholder::contains)
|
||||
.count();
|
||||
}
|
||||
goods.setCreateTime(videoTaskRepository.getTaskShotDate(task.getId()));
|
||||
goods.setParts(Math.toIntExact(deviceCount));
|
||||
goods.setParts(videoTaskRepository.getTaskDeviceCount(task.getId()));
|
||||
goodsList.add(goods);
|
||||
item.setShootingTime(videoTaskRepository.getTaskShotDate(videoMapperById.getTaskId()));
|
||||
item.setVideoUrl(videoMapperById.getVideoUrl());
|
||||
|
Reference in New Issue
Block a user