fix(一键成片):功能逻辑优化
This commit is contained in:
+128
-25
@@ -1,17 +1,25 @@
|
|||||||
package com.central.order.controller;
|
package com.central.order.controller;
|
||||||
|
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.order.model.RequestParamsEntity;
|
import com.central.order.feign.FileCenterService;
|
||||||
import com.central.order.model.SourceDTO;
|
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 io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,36 +30,131 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@Tag(name = "剪辑管理")
|
@Tag(name = "剪辑管理")
|
||||||
@RequestMapping("/auto/cut")
|
@RequestMapping("/auto/cut")
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class AutoCutVideoController {
|
public class AutoCutVideoController {
|
||||||
|
|
||||||
@Value("${videos.edit-config.url}")
|
@Value("${videos.edit-config.url}")
|
||||||
private String 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()
|
// 2. 获取订单相关文件
|
||||||
public Result sendPostRequest() {
|
List<OrderFile> orderFiles = orderFileService.getOrderFileByOrderNo(orderNo);
|
||||||
// 构造请求参数
|
|
||||||
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");
|
|
||||||
|
|
||||||
SourceDTO sourceDTO = new SourceDTO(textList, videoList, audioList, imageList);
|
// 3. 获取景区素材
|
||||||
RequestParamsEntity requestParams = new RequestParamsEntity(
|
List<TourismFile> tourismFiles = tourismFileService.getByTourismId(order.getTourismId());
|
||||||
"68c9ba9a92934623acdb6e84b4174f43",
|
|
||||||
"112233444",
|
|
||||||
"222222",
|
|
||||||
sourceDTO
|
|
||||||
);
|
|
||||||
|
|
||||||
// 发送POST请求
|
// 4. 构建素材列表
|
||||||
return Result.succeed(restTemplate.postForObject(url, requestParams, Object.class));
|
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;
|
package com.central.order.model;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
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
|
* @author lsl
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Data
|
||||||
@Getter
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class RequestParamsEntity {
|
public class RequestParamsEntity {
|
||||||
|
|
||||||
private String templateId;
|
@Schema(description = "应用ID")
|
||||||
private String orderSn;
|
@NotBlank(message = "应用ID不能为空")
|
||||||
private String userId;
|
private String appId;
|
||||||
private SourceDTO sourceDTO;
|
|
||||||
|
@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.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -12,13 +16,20 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Setter
|
@Data
|
||||||
@Getter
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SourceDTO {
|
public class SourceDTO {
|
||||||
|
@Schema(description = "文本列表")
|
||||||
private List<String> textList;
|
private List<String> textList;
|
||||||
private List<String> videoList;
|
|
||||||
private List<String> audioList;
|
|
||||||
private List<String> imageList;
|
|
||||||
|
|
||||||
|
@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}
|
# password: ${zlt.datasource.password}
|
||||||
videos:
|
videos:
|
||||||
edit-config:
|
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