refactor(biz): 重构Vlog 视频价格计算逻辑
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:
2025-09-08 10:11:19 +08:00
parent d9a2da49bb
commit 29637bc5e5
6 changed files with 48 additions and 66 deletions

View File

@@ -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();
}
}