fix(一键成片):功能逻辑优化
This commit is contained in:
+128
-25
@@ -1,17 +1,25 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.RequestParamsEntity;
|
||||
import com.central.order.model.SourceDTO;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.model.*;
|
||||
import com.central.order.service.IOrderFileService;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -22,36 +30,131 @@ import java.util.List;
|
||||
@RestController
|
||||
@Tag(name = "剪辑管理")
|
||||
@RequestMapping("/auto/cut")
|
||||
@RequiredArgsConstructor
|
||||
public class AutoCutVideoController {
|
||||
|
||||
@Value("${videos.edit-config.url}")
|
||||
private String url;
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
private final RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private IOrderService orderService;
|
||||
@Autowired
|
||||
private IOrderFileService orderFileService;
|
||||
@Autowired
|
||||
private ITourismFileService tourismFileService;
|
||||
@Autowired
|
||||
private FileCenterService fileCenterService;
|
||||
|
||||
@Operation(summary = "根据订单号生成视频")
|
||||
@GetMapping("/generate/{orderNo}")
|
||||
public Result generateVideo(@PathVariable String orderNo) {
|
||||
try {
|
||||
// 1. 获取订单信息
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
public Result sendPostRequest() {
|
||||
// 构造请求参数
|
||||
List<String> textList = List.of("测试测试");
|
||||
List<String> videoList = List.of("https://lsy010.oss-cn-beijing.aliyuncs.com/1.mp4");
|
||||
List<String> audioList = Arrays.asList(
|
||||
"https://lsy010.oss-cn-beijing.aliyuncs.com/%E5%B7%B1%E4%BA%A5%E6%9D%82%E8%AF%97.wav",
|
||||
"https://lsy010.oss-cn-beijing.aliyuncs.com/%E6%B8%94%E6%AD%8C%E5%AD%90.wav",
|
||||
"https://lsy010.oss-cn-beijing.aliyuncs.com/%E7%A4%BA%E5%84%BF.wav",
|
||||
"https://lsy010.oss-cn-beijing.aliyuncs.com/%E7%A8%9A%E5%AD%90%E5%BC%84%E5%86%B0.wav"
|
||||
);
|
||||
List<String> imageList = Arrays.asList("https://lsy010.oss-cn-beijing.aliyuncs.com/63bedec88986d.png");
|
||||
// 2. 获取订单相关文件
|
||||
List<OrderFile> orderFiles = orderFileService.getOrderFileByOrderNo(orderNo);
|
||||
|
||||
SourceDTO sourceDTO = new SourceDTO(textList, videoList, audioList, imageList);
|
||||
RequestParamsEntity requestParams = new RequestParamsEntity(
|
||||
"68c9ba9a92934623acdb6e84b4174f43",
|
||||
"112233444",
|
||||
"222222",
|
||||
sourceDTO
|
||||
);
|
||||
// 3. 获取景区素材
|
||||
List<TourismFile> tourismFiles = tourismFileService.getByTourismId(order.getTourismId());
|
||||
|
||||
// 发送POST请求
|
||||
return Result.succeed(restTemplate.postForObject(url, requestParams, Object.class));
|
||||
// 4. 构建素材列表
|
||||
SourceDTO sourceDTO = buildSourceDTO(orderFiles, tourismFiles);
|
||||
|
||||
// 5. 构建请求参数
|
||||
RequestParamsEntity requestParams = buildRequestParams(order, sourceDTO);
|
||||
|
||||
// 6. 调用一键成片接口
|
||||
Object response = restTemplate.postForObject(url, requestParams, Object.class);
|
||||
|
||||
log.info("一键成片请求成功: orderNo={}, response={}", orderNo, response);
|
||||
return Result.succeed(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("一键成片请求失败: orderNo={}", orderNo, e);
|
||||
return Result.failed("生成视频失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建素材数据
|
||||
*/
|
||||
private SourceDTO buildSourceDTO(List<OrderFile> orderFiles, List<TourismFile> tourismFiles) {
|
||||
// 1. 初始化列表
|
||||
List<String> textList = new ArrayList<>();
|
||||
List<String> videoList = new ArrayList<>();
|
||||
List<String> audioList = new ArrayList<>();
|
||||
List<String> imageList = new ArrayList<>();
|
||||
|
||||
// 2. 处理订单文件
|
||||
if (!orderFiles.isEmpty()) {
|
||||
for (OrderFile file : orderFiles) {
|
||||
String fileUrl = fileCenterService.getViewUrlByPath(file.getFilePath());
|
||||
|
||||
// 根据文件类型分类
|
||||
switch (getFileType(file.getFileType())) {
|
||||
case "video":
|
||||
videoList.add(fileUrl);
|
||||
break;
|
||||
case "audio":
|
||||
audioList.add(fileUrl);
|
||||
break;
|
||||
case "image":
|
||||
imageList.add(fileUrl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 处理景区素材
|
||||
if (!tourismFiles.isEmpty()) {
|
||||
for (TourismFile file : tourismFiles) {
|
||||
String fileUrl = fileCenterService.getViewUrlByPath(file.getImageUrl());
|
||||
imageList.add(fileUrl);
|
||||
|
||||
// 如果有景区描述,添加到文本列表
|
||||
if (StringUtils.hasText(file.getDescription())) {
|
||||
textList.add(file.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 构建返回对象
|
||||
return new SourceDTO(textList, videoList, audioList, imageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建请求参数
|
||||
*/
|
||||
private RequestParamsEntity buildRequestParams(Order order, SourceDTO sourceDTO) {
|
||||
return RequestParamsEntity.builder()
|
||||
.appId("68c9ba9a92934623acdb6e84b4174f43") // 从配置文件获取
|
||||
.taskId(order.getOrderNo()) // 使用订单号作为任务ID
|
||||
.callbackUrl("your-callback-url") // 从配置文件获取
|
||||
.source(sourceDTO)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件类型
|
||||
*/
|
||||
private String getFileType(String mimeType) {
|
||||
if (mimeType == null) {
|
||||
return "other";
|
||||
}
|
||||
|
||||
if (mimeType.startsWith("video/")) {
|
||||
return "video";
|
||||
} else if (mimeType.startsWith("audio/")) {
|
||||
return "audio";
|
||||
} else if (mimeType.startsWith("image/")) {
|
||||
return "image";
|
||||
}
|
||||
|
||||
return "other";
|
||||
}
|
||||
}
|
||||
|
||||
+25
-7
@@ -1,21 +1,39 @@
|
||||
package com.central.order.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 一键成片请求参数实体类
|
||||
* @author lsl
|
||||
*
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RequestParamsEntity {
|
||||
|
||||
private String templateId;
|
||||
private String orderSn;
|
||||
private String userId;
|
||||
private SourceDTO sourceDTO;
|
||||
@Schema(description = "应用ID")
|
||||
@NotBlank(message = "应用ID不能为空")
|
||||
private String appId;
|
||||
|
||||
@Schema(description = "任务ID")
|
||||
@NotBlank(message = "任务ID不能为空")
|
||||
private String taskId;
|
||||
|
||||
@Schema(description = "回调地址")
|
||||
@NotBlank(message = "回调地址不能为空")
|
||||
private String callbackUrl;
|
||||
|
||||
@Schema(description = "素材来源")
|
||||
@NotNull(message = "素材来源不能为空")
|
||||
private SourceDTO source;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,10 @@ package com.central.order.model;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.Data;
|
||||
import lombok.Builder;
|
||||
import lombok.NoArgsConstructor;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,13 +16,20 @@ import java.util.List;
|
||||
*
|
||||
*/
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SourceDTO {
|
||||
@Schema(description = "文本列表")
|
||||
private List<String> textList;
|
||||
|
||||
@Schema(description = "视频列表")
|
||||
private List<String> videoList;
|
||||
|
||||
@Schema(description = "音频列表")
|
||||
private List<String> audioList;
|
||||
|
||||
@Schema(description = "图片列表")
|
||||
private List<String> imageList;
|
||||
|
||||
}
|
||||
|
||||
@@ -75,4 +75,6 @@ file:
|
||||
# password: ${zlt.datasource.password}
|
||||
videos:
|
||||
edit-config:
|
||||
url: https://www.lieflat.cn/api/editTask/editTaskSubmit
|
||||
url: ${EDIT_SERVICE_URL:http://example.com/api/edit}
|
||||
app-id: ${EDIT_APP_ID:your-app-id}
|
||||
callback-url: ${EDIT_CALLBACK_URL:http://your-domain/api/callback}
|
||||
|
||||
Reference in New Issue
Block a user