Merge pull request 'feat: 视频剪辑推送中科低空' (#68) from feature_dzc into test
Reviewed-on: http://220.205.16.27:18081/goflytec/GoFly-platform-services/pulls/68
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
package com.central.order.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 飞拍平台回调配置
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "feipai")
|
||||||
|
public class FeipaiConfig {
|
||||||
|
/**
|
||||||
|
* 回调接口地址
|
||||||
|
*/
|
||||||
|
private String callbackUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台标识ID
|
||||||
|
*/
|
||||||
|
private String openId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许推送的景区ID列表
|
||||||
|
*/
|
||||||
|
private List<Long> tourismIds;
|
||||||
|
}
|
||||||
+141
@@ -1,5 +1,6 @@
|
|||||||
package com.central.order.controller;
|
package com.central.order.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.central.common.feign.UserService;
|
import com.central.common.feign.UserService;
|
||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
@@ -8,18 +9,29 @@ import com.central.order.constants.EditTaskStatus;
|
|||||||
import com.central.order.enums.OrderStatus;
|
import com.central.order.enums.OrderStatus;
|
||||||
import com.central.order.model.*;
|
import com.central.order.model.*;
|
||||||
import com.central.order.model.dto.CallbackDTO;
|
import com.central.order.model.dto.CallbackDTO;
|
||||||
|
import com.central.order.model.dto.VideoEditStatus;
|
||||||
import com.central.order.model.params.EditTaskQueryParams;
|
import com.central.order.model.params.EditTaskQueryParams;
|
||||||
|
import com.central.order.config.FeipaiConfig;
|
||||||
|
import com.central.order.feign.FileCenterService;
|
||||||
import com.central.order.service.*;
|
import com.central.order.service.*;
|
||||||
import com.central.order.util.DateUtils;
|
import com.central.order.util.DateUtils;
|
||||||
import com.central.order.util.StringUtils;
|
import com.central.order.util.StringUtils;
|
||||||
|
import com.central.order.util.http.Response;
|
||||||
|
import com.central.order.util.http.SimpleHttpRequest;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
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.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一键成片
|
* 一键成片
|
||||||
@@ -51,6 +63,12 @@ public class AutoCutVideoController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ITourismService tourismService;
|
private ITourismService tourismService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileCenterService fileCenterService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FeipaiConfig feipaiConfig;
|
||||||
|
|
||||||
@Operation(summary = "根据订单号生成视频")
|
@Operation(summary = "根据订单号生成视频")
|
||||||
@PostMapping("/generate")
|
@PostMapping("/generate")
|
||||||
public Result generateVideo(@RequestParam String orderNo) {
|
public Result generateVideo(@RequestParam String orderNo) {
|
||||||
@@ -124,6 +142,12 @@ public class AutoCutVideoController {
|
|||||||
|
|
||||||
// 发送通知
|
// 发送通知
|
||||||
notifyUser(task.getUserId().toString(), task.getOrderSn());
|
notifyUser(task.getUserId().toString(), task.getOrderSn());
|
||||||
|
|
||||||
|
// 异步通知飞拍平台(先判断景区是否支持)
|
||||||
|
OrderFile aiVideoFile = getAiVideoFile(task.getOrderSn());
|
||||||
|
if (aiVideoFile != null && isFeipaiTourism(aiVideoFile.getTourismId())) {
|
||||||
|
notifyFeipaiPlatform(task.getOrderSn(), aiVideoFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 4. 处理失败回调
|
// 4. 处理失败回调
|
||||||
else {
|
else {
|
||||||
@@ -201,6 +225,123 @@ public class AutoCutVideoController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订单的AI视频文件
|
||||||
|
*/
|
||||||
|
private OrderFile getAiVideoFile(String orderNo) {
|
||||||
|
List<OrderFile> orderFiles = orderFileService.getOrderFileByOrderNo(orderNo);
|
||||||
|
return orderFiles.stream()
|
||||||
|
.filter(f -> "ai_video".equals(f.getFileTag()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断景区是否支持飞拍平台推送
|
||||||
|
*/
|
||||||
|
private boolean isFeipaiTourism(Long tourismId) {
|
||||||
|
return feipaiConfig.getTourismIds() != null && feipaiConfig.getTourismIds().contains(tourismId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步通知飞拍平台剪辑视频完成
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
public void notifyFeipaiPlatform(String orderNo, OrderFile aiVideoFile) {
|
||||||
|
try {
|
||||||
|
log.info("开始通知飞拍平台,订单号: {}", orderNo);
|
||||||
|
|
||||||
|
// 1. 获取视频URL
|
||||||
|
String aiVideoUrl = fileCenterService.getViewUrlByPath(aiVideoFile.getFilePath());
|
||||||
|
if (aiVideoUrl == null || aiVideoUrl.isEmpty()) {
|
||||||
|
log.warn("获取AI视频URL失败,无法通知飞拍平台: orderNo={}, filePath={}", orderNo, aiVideoFile.getFilePath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 构建请求参数
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
requestBody.put("openId", feipaiConfig.getOpenId());
|
||||||
|
requestBody.put("orderNo", orderNo);
|
||||||
|
requestBody.put("aiVideoUrl", URLEncoder.encode(aiVideoUrl, "UTF-8"));
|
||||||
|
|
||||||
|
// 3. 发送POST请求
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonBody = objectMapper.writeValueAsString(requestBody);
|
||||||
|
|
||||||
|
SimpleHttpRequest httpRequest = new SimpleHttpRequest(feipaiConfig.getCallbackUrl());
|
||||||
|
Response response = httpRequest.requestBody(jsonBody).post();
|
||||||
|
String responseBody = new String(response.asBytes(), "UTF-8");
|
||||||
|
|
||||||
|
log.info("通知飞拍平台完成,订单号: {}, 响应内容: {}", orderNo, responseBody);
|
||||||
|
|
||||||
|
httpRequest.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("通知飞拍平台失败: orderNo={}", orderNo, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "测试飞拍平台推送")
|
||||||
|
@GetMapping("/test/notify/{orderNo}")
|
||||||
|
public Result<String> testNotifyFeipai(@PathVariable String orderNo) {
|
||||||
|
try {
|
||||||
|
log.info("测试通知飞拍平台,订单号: {}", orderNo);
|
||||||
|
|
||||||
|
// 1. 获取AI视频文件
|
||||||
|
OrderFile aiVideoFile = getAiVideoFile(orderNo);
|
||||||
|
if (aiVideoFile == null || aiVideoFile.getFilePath() == null) {
|
||||||
|
return Result.failed("未找到AI视频文件,filePath为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 校验景区ID是否允许推送
|
||||||
|
if (!isFeipaiTourism(aiVideoFile.getTourismId())) {
|
||||||
|
return Result.failed("该景区不支持飞拍平台推送,tourismId: " + aiVideoFile.getTourismId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 获取视频URL
|
||||||
|
String aiVideoUrl = fileCenterService.getViewUrlByPath(aiVideoFile.getFilePath());
|
||||||
|
if (aiVideoUrl == null || aiVideoUrl.isEmpty()) {
|
||||||
|
return Result.failed("获取AI视频URL失败,filePath: " + aiVideoFile.getFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 构建请求参数
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
requestBody.put("openId", feipaiConfig.getOpenId());
|
||||||
|
requestBody.put("orderNo", orderNo);
|
||||||
|
requestBody.put("aiVideoUrl", URLEncoder.encode(aiVideoUrl, "UTF-8"));
|
||||||
|
|
||||||
|
// 5. 发送POST请求
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonBody = objectMapper.writeValueAsString(requestBody);
|
||||||
|
|
||||||
|
log.info("推送飞拍平台请求参数: {}", jsonBody);
|
||||||
|
|
||||||
|
SimpleHttpRequest httpRequest = new SimpleHttpRequest(feipaiConfig.getCallbackUrl());
|
||||||
|
Response response = httpRequest.requestBody(jsonBody).post();
|
||||||
|
String responseBody = new String(response.asBytes(), "UTF-8");
|
||||||
|
|
||||||
|
log.info("飞拍平台响应: {}", responseBody);
|
||||||
|
httpRequest.close();
|
||||||
|
|
||||||
|
return Result.succeed(responseBody);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("测试通知飞拍平台失败: orderNo={}", orderNo, e);
|
||||||
|
return Result.failed("推送失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "测试定时任务-检查指定任务状态")
|
||||||
|
@GetMapping("/test/check/{jobId}")
|
||||||
|
public Result<String> testCheckTask(@PathVariable String jobId) {
|
||||||
|
try {
|
||||||
|
log.info("手动触发任务状态检查: jobId={}", jobId);
|
||||||
|
VideoEditStatus status = videoEditService.handleEditStatus(jobId);
|
||||||
|
return Result.succeed("任务状态: " + JSON.toJSONString(status));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("检查任务状态失败: jobId={}", jobId, e);
|
||||||
|
return Result.failed("检查失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "获取剪辑任务列表")
|
@Operation(summary = "获取剪辑任务列表")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
|
|||||||
+71
-6
@@ -5,6 +5,7 @@ import com.central.common.feign.UserService;
|
|||||||
import com.central.common.model.FileInfo;
|
import com.central.common.model.FileInfo;
|
||||||
import com.central.common.model.SysUser;
|
import com.central.common.model.SysUser;
|
||||||
import com.central.order.constants.EditTaskStatus;
|
import com.central.order.constants.EditTaskStatus;
|
||||||
|
import com.central.order.config.FeipaiConfig;
|
||||||
import com.central.order.feign.FileCenterService;
|
import com.central.order.feign.FileCenterService;
|
||||||
import com.central.order.model.EditTask;
|
import com.central.order.model.EditTask;
|
||||||
import com.central.order.model.Order;
|
import com.central.order.model.Order;
|
||||||
@@ -13,14 +14,21 @@ import com.central.order.model.Tourism;
|
|||||||
import com.central.order.model.dto.VideoEditStatus;
|
import com.central.order.model.dto.VideoEditStatus;
|
||||||
import com.central.order.service.*;
|
import com.central.order.service.*;
|
||||||
import com.central.order.util.DateUtils;
|
import com.central.order.util.DateUtils;
|
||||||
|
import com.central.order.util.http.Response;
|
||||||
|
import com.central.order.util.http.SimpleHttpRequest;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视频编辑服务实现类
|
* 视频编辑服务实现类
|
||||||
@@ -45,6 +53,8 @@ public class VideoEditServiceImpl implements IVideoEditService {
|
|||||||
private ITourismService tourismService;
|
private ITourismService tourismService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private WxMiniSubscribeService wxMiniSubscribeService;
|
private WxMiniSubscribeService wxMiniSubscribeService;
|
||||||
|
@Autowired
|
||||||
|
private FeipaiConfig feipaiConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -110,10 +120,13 @@ public class VideoEditServiceImpl implements IVideoEditService {
|
|||||||
throw new BusinessException("获取输出URL失败");
|
throw new BusinessException("获取输出URL失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 保存视频文件记录
|
// 2. 获取订单信息
|
||||||
saveOutputVideo(task.getOrderSn(), outputUrl);
|
Order order = orderService.getOrderByNumber(task.getOrderSn());
|
||||||
|
|
||||||
// 3. 更新任务状态
|
// 3. 保存视频文件记录
|
||||||
|
String filePath = saveOutputVideo(task.getOrderSn(), outputUrl, order);
|
||||||
|
|
||||||
|
// 4. 更新任务状态
|
||||||
editTaskService.updateTaskStatus(jobId, EditTaskStatus.COMPLETED, null);
|
editTaskService.updateTaskStatus(jobId, EditTaskStatus.COMPLETED, null);
|
||||||
|
|
||||||
log.info("视频编辑任务处理完成: jobId={}, orderNo={}, outputUrl={}",
|
log.info("视频编辑任务处理完成: jobId={}, orderNo={}, outputUrl={}",
|
||||||
@@ -122,6 +135,11 @@ public class VideoEditServiceImpl implements IVideoEditService {
|
|||||||
// 发送小程序通知
|
// 发送小程序通知
|
||||||
notifyUser(task.getUserId(), task.getOrderSn());
|
notifyUser(task.getUserId(), task.getOrderSn());
|
||||||
|
|
||||||
|
// 异步通知飞拍平台(先判断景区是否支持)
|
||||||
|
if (isFeipaiTourism(order.getTourismId())) {
|
||||||
|
notifyFeipaiPlatformAsync(task.getOrderSn(), filePath);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理任务成功状态失败: jobId={}", jobId, e);
|
log.error("处理任务成功状态失败: jobId={}", jobId, e);
|
||||||
throw new BusinessException("处理任务成功状态失败: " + e.getMessage());
|
throw new BusinessException("处理任务成功状态失败: " + e.getMessage());
|
||||||
@@ -143,21 +161,24 @@ public class VideoEditServiceImpl implements IVideoEditService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存输出视频信息
|
* 保存输出视频信息
|
||||||
|
* @return filePath
|
||||||
*/
|
*/
|
||||||
private void saveOutputVideo(String orderNo, String outputUrl) {
|
private String saveOutputVideo(String orderNo, String outputUrl, Order order) {
|
||||||
try {
|
try {
|
||||||
FileInfo fileInfo = fileCenterService.creatFileInfo(outputUrl);
|
FileInfo fileInfo = fileCenterService.creatFileInfo(outputUrl);
|
||||||
Order order = orderService.getOrderByNumber(orderNo);
|
String filePath = extractFilePath(outputUrl);
|
||||||
|
|
||||||
OrderFile orderFile = new OrderFile();
|
OrderFile orderFile = new OrderFile();
|
||||||
orderFile.setFileId(fileInfo.getId());
|
orderFile.setFileId(fileInfo.getId());
|
||||||
orderFile.setOrderNo(orderNo);
|
orderFile.setOrderNo(orderNo);
|
||||||
orderFile.setFileType("video/mp4");
|
orderFile.setFileType("video/mp4");
|
||||||
orderFile.setFileTag("ai_video");
|
orderFile.setFileTag("ai_video");
|
||||||
orderFile.setFilePath(extractFilePath(outputUrl));
|
orderFile.setFilePath(filePath);
|
||||||
orderFile.setUserId(order.getUserId());
|
orderFile.setUserId(order.getUserId());
|
||||||
orderFile.setTourismId(order.getTourismId());
|
orderFile.setTourismId(order.getTourismId());
|
||||||
orderFileService.save(orderFile);
|
orderFileService.save(orderFile);
|
||||||
|
|
||||||
|
return filePath;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("保存输出视频信息失败: orderNo={}, outputUrl={}", orderNo, outputUrl, e);
|
log.error("保存输出视频信息失败: orderNo={}, outputUrl={}", orderNo, outputUrl, e);
|
||||||
throw new BusinessException("保存视频信息失败: " + e.getMessage());
|
throw new BusinessException("保存视频信息失败: " + e.getMessage());
|
||||||
@@ -212,4 +233,48 @@ public class VideoEditServiceImpl implements IVideoEditService {
|
|||||||
log.error("发送一键成片完成通知失败: userId={}, message={}", userId, orderNo, e);
|
log.error("发送一键成片完成通知失败: userId={}, message={}", userId, orderNo, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断景区是否支持飞拍平台推送
|
||||||
|
*/
|
||||||
|
private boolean isFeipaiTourism(Long tourismId) {
|
||||||
|
return feipaiConfig.getTourismIds() != null && feipaiConfig.getTourismIds().contains(tourismId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步通知飞拍平台剪辑视频完成
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
public void notifyFeipaiPlatformAsync(String orderNo, String filePath) {
|
||||||
|
try {
|
||||||
|
log.info("开始通知飞拍平台,订单号: {}", orderNo);
|
||||||
|
|
||||||
|
// 1. 获取视频URL
|
||||||
|
String aiVideoUrl = fileCenterService.getViewUrlByPath(filePath);
|
||||||
|
if (aiVideoUrl == null || aiVideoUrl.isEmpty()) {
|
||||||
|
log.warn("获取AI视频URL失败,无法通知飞拍平台: orderNo={}, filePath={}", orderNo, filePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 构建请求参数
|
||||||
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
requestBody.put("openId", feipaiConfig.getOpenId());
|
||||||
|
requestBody.put("orderNo", orderNo);
|
||||||
|
requestBody.put("aiVideoUrl", URLEncoder.encode(aiVideoUrl, "UTF-8"));
|
||||||
|
|
||||||
|
// 3. 发送POST请求
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonBody = objectMapper.writeValueAsString(requestBody);
|
||||||
|
|
||||||
|
SimpleHttpRequest httpRequest = new SimpleHttpRequest(feipaiConfig.getCallbackUrl());
|
||||||
|
Response response = httpRequest.requestBody(jsonBody).post();
|
||||||
|
String responseBody = new String(response.asBytes(), "UTF-8");
|
||||||
|
|
||||||
|
log.info("通知飞拍平台完成,订单号: {}, 响应内容: {}", orderNo, responseBody);
|
||||||
|
|
||||||
|
httpRequest.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("通知飞拍平台失败: orderNo={}", orderNo, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user