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) {
|
if (template == null) {
|
||||||
return priceObj;
|
return priceObj;
|
||||||
}
|
}
|
||||||
priceObj.setPrice(template.getPrice());
|
PriceCalculationRequest vlogCalculationRequest = new PriceCalculationRequest();
|
||||||
BigDecimal slashPrice = template.getSlashPrice();
|
ProductItem vlogProductItem = new ProductItem();
|
||||||
if (slashPrice == null) {
|
vlogProductItem.setProductType(ProductType.VLOG_VIDEO);
|
||||||
priceObj.setSlashPrice(priceObj.getPrice());
|
vlogProductItem.setProductId(template.getId().toString());
|
||||||
} else {
|
vlogProductItem.setQuantity(videoTaskRepository.getTaskDeviceCount(video.getTaskId()));
|
||||||
priceObj.setSlashPrice(slashPrice);
|
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());
|
priceObj.setScenicId(video.getScenicId());
|
||||||
break;
|
break;
|
||||||
case 1: // source
|
case 1: // source
|
||||||
|
@@ -39,8 +39,6 @@ public class PriceBiz {
|
|||||||
private FaceRepository faceRepository;
|
private FaceRepository faceRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CouponBiz couponBiz;
|
private CouponBiz couponBiz;
|
||||||
@Autowired
|
|
||||||
private IOnePricePurchaseService onePricePurchaseService;
|
|
||||||
|
|
||||||
public List<GoodsListRespVO> listGoodsByScenic(Long scenicId) {
|
public List<GoodsListRespVO> listGoodsByScenic(Long scenicId) {
|
||||||
List<GoodsListRespVO> goodsList = new ArrayList<>();
|
List<GoodsListRespVO> goodsList = new ArrayList<>();
|
||||||
|
@@ -96,32 +96,11 @@ public class AppOrderV2Controller {
|
|||||||
request.getProducts().forEach(product -> {
|
request.getProducts().forEach(product -> {
|
||||||
switch (product.getProductType()) {
|
switch (product.getProductType()) {
|
||||||
case VLOG_VIDEO:
|
case VLOG_VIDEO:
|
||||||
AtomicInteger deviceCount = new AtomicInteger();
|
|
||||||
List<MemberVideoEntity> videoEntities = videoMapper.listRelationByFaceAndTemplate(face.getId(), Long.valueOf(product.getProductId()));
|
List<MemberVideoEntity> videoEntities = videoMapper.listRelationByFaceAndTemplate(face.getId(), Long.valueOf(product.getProductId()));
|
||||||
if (videoEntities != null && !videoEntities.isEmpty()) {
|
if (videoEntities != null && !videoEntities.isEmpty()) {
|
||||||
TaskEntity task = videoTaskRepository.getTaskById(videoEntities.getFirst().getTaskId());
|
product.setQuantity(videoTaskRepository.getTaskDeviceCount(videoEntities.getFirst().getTaskId()));
|
||||||
if (task != null) {
|
} else {
|
||||||
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
|
product.setQuantity(1);
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RECORDING_SET:
|
case RECORDING_SET:
|
||||||
|
@@ -12,8 +12,11 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class VideoTaskRepository {
|
public class VideoTaskRepository {
|
||||||
@@ -23,6 +26,8 @@ public class VideoTaskRepository {
|
|||||||
private TaskMapper taskMapper;
|
private TaskMapper taskMapper;
|
||||||
|
|
||||||
public static final String TASK_CACHE_KEY = "task:byId:%s";
|
public static final String TASK_CACHE_KEY = "task:byId:%s";
|
||||||
|
@Autowired
|
||||||
|
private TemplateRepository templateRepository;
|
||||||
|
|
||||||
public TaskEntity getTaskById(Long taskId) {
|
public TaskEntity getTaskById(Long taskId) {
|
||||||
if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) {
|
if (redisTemplate.hasKey(String.format(TASK_CACHE_KEY, taskId))) {
|
||||||
@@ -63,4 +68,30 @@ public class VideoTaskRepository {
|
|||||||
return shotTime;
|
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) {
|
if (task == null) {
|
||||||
return ApiResponse.fail("该vlog不存在或已失效");
|
return ApiResponse.fail("该vlog不存在或已失效");
|
||||||
}
|
}
|
||||||
Map<String, Object> paramJson = JacksonUtil.parseObject(task.getTaskParams(), Map.class);
|
|
||||||
AtomicInteger deviceCount = new AtomicInteger();
|
|
||||||
goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId()));
|
goodsDetailVO.setShotTime(taskTaskService.getTaskShotDate(task.getId()));
|
||||||
if (paramJson == null) {
|
goodsDetailVO.setLensNum(videoTaskRepository.getTaskDeviceCount(task.getId()));
|
||||||
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());
|
|
||||||
CouponRecordQueryResp couponRecord = couponBiz.queryUserCouponRecord(task.getScenicId(), userId, task.getFaceId(), task.getTemplateId().toString());
|
CouponRecordQueryResp couponRecord = couponBiz.queryUserCouponRecord(task.getScenicId(), userId, task.getFaceId(), task.getTemplateId().toString());
|
||||||
if (couponRecord != null) {
|
if (couponRecord != null) {
|
||||||
if (couponRecord.isUsable()) {
|
if (couponRecord.isUsable()) {
|
||||||
|
@@ -298,19 +298,8 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
goods.setUrl(videoMapperById.getVideoUrl());
|
goods.setUrl(videoMapperById.getVideoUrl());
|
||||||
goods.setGoodsType(0);
|
goods.setGoodsType(0);
|
||||||
goods.setTemplateCoverUrl(template.getCoverUrl());
|
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.setCreateTime(videoTaskRepository.getTaskShotDate(task.getId()));
|
||||||
goods.setParts(Math.toIntExact(deviceCount));
|
goods.setParts(videoTaskRepository.getTaskDeviceCount(task.getId()));
|
||||||
goodsList.add(goods);
|
goodsList.add(goods);
|
||||||
item.setShootingTime(videoTaskRepository.getTaskShotDate(videoMapperById.getTaskId()));
|
item.setShootingTime(videoTaskRepository.getTaskShotDate(videoMapperById.getTaskId()));
|
||||||
item.setVideoUrl(videoMapperById.getVideoUrl());
|
item.setVideoUrl(videoMapperById.getVideoUrl());
|
||||||
|
Reference in New Issue
Block a user