fix(订单素材管理): 素材上传成功后,达到二维码素材要求数量后,通知用户已经上传完成。解决之前通过设备执行状态完成来触发通知和一键成片逻辑的bug。新增判断二维码是否开启一键成片的功能的逻辑,之前是没有检查会全部触发一键成片

This commit is contained in:
2025-07-14 00:53:06 +08:00
parent a333a1a663
commit d3ad03c159
@@ -7,6 +7,7 @@ import com.central.order.enums.OrderStatus;
import com.central.order.feign.FileCenterService; import com.central.order.feign.FileCenterService;
import com.central.order.feign.UserCenterService; import com.central.order.feign.UserCenterService;
import com.central.order.model.*; import com.central.order.model.*;
import com.central.order.model.EditTask;
import com.central.order.service.*; import com.central.order.service.*;
import com.central.order.util.DateUtils; import com.central.order.util.DateUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@@ -167,44 +168,44 @@ public class OrderFileController {
log.warn("参数为空,orderFile: {}", orderFile); log.warn("参数为空,orderFile: {}", orderFile);
return Result.failed(orderFile,"参数为空"); return Result.failed(orderFile,"参数为空");
} }
// 校验订单是否存在 // 校验订单是否存在
Order order = orderService.getOrderByNumber(orderFile.getOrderNo()); Order order = orderService.getOrderByNumber(orderFile.getOrderNo());
if (order == null) { if (order == null) {
log.warn("订单不存在,订单号: {}", orderFile.getOrderNo()); log.warn("订单不存在,订单号: {}", orderFile.getOrderNo());
return Result.failed(orderFile,"订单不存在"); return Result.failed(orderFile,"订单不存在");
} }
// 校验文件路径是否为空 // 校验文件路径是否为空
if (orderFile.getFilePath() == null || orderFile.getFilePath().trim().isEmpty()) { if (orderFile.getFilePath() == null || orderFile.getFilePath().trim().isEmpty()) {
log.warn("素材路径为空,订单号: {}", orderFile.getOrderNo()); log.warn("素材路径为空,订单号: {}", orderFile.getOrderNo());
return Result.failed(orderFile,"素材路径为空"); return Result.failed(orderFile,"素材路径为空");
} }
// 先校验记录是否已经存在 // 先校验记录是否已经存在
OrderFile existingOrderFile = orderFileService.getOrderFileByFilePath(orderFile.getFilePath()); OrderFile existingOrderFile = orderFileService.getOrderFileByFilePath(orderFile.getFilePath());
if (existingOrderFile != null) { if (existingOrderFile != null) {
log.info("记录已存在,不再重复创建,订单号: {}, 文件路径: {}", orderFile.getOrderNo(), orderFile.getFilePath()); log.info("记录已存在,不再重复创建,订单号: {}, 文件路径: {}", orderFile.getOrderNo(), orderFile.getFilePath());
return Result.succeed(existingOrderFile, "记录已存在,无需重复创建"); return Result.succeed(existingOrderFile, "记录已存在,无需重复创建");
} }
// 设置订单相关信息 // 设置订单相关信息
orderFile.setOrderNo(order.getOrderNo()); orderFile.setOrderNo(order.getOrderNo());
orderFile.setUserId(order.getUserId()); orderFile.setUserId(order.getUserId());
// 创建文件信息 // 创建文件信息
FileInfo fileInfo = fileCenterService.creatFileInfo(orderFile.getFilePath()); FileInfo fileInfo = fileCenterService.creatFileInfo(orderFile.getFilePath());
if (fileInfo == null) { if (fileInfo == null) {
log.warn("文件信息创建失败,filePath: {}", orderFile.getFilePath()); log.warn("文件信息创建失败,filePath: {}", orderFile.getFilePath());
return Result.failed(orderFile,"文件信息创建失败"); return Result.failed(orderFile,"文件信息创建失败");
} }
// 设置文件相关信息 // 设置文件相关信息
orderFile.setFileId(fileInfo.getId()); orderFile.setFileId(fileInfo.getId());
orderFile.setFilePath(fileInfo.getPath()); orderFile.setFilePath(fileInfo.getPath());
orderFile.setFileType(fileInfo.getContentType()); orderFile.setFileType(fileInfo.getContentType());
orderFile.setTourismId(order.getTourismId()); orderFile.setTourismId(order.getTourismId());
// 保存记录 // 保存记录
boolean saved = orderFileService.save(orderFile); boolean saved = orderFileService.save(orderFile);
if (saved) { if (saved) {
@@ -257,27 +258,46 @@ public class OrderFileController {
//发送用户素材上传成功通知 //发送用户素材上传成功通知
sendMessageForResouresUploaded(order,tourism); sendMessageForResouresUploaded(order,tourism);
//触发一键成片 // 检查是否开启一键成片功能
// 1. 创建新任务 if (isVideoEditEnabled(qrCode)) {
EditTask task = editTaskService.createTask(order.getOrderNo(), order.getUserId()); log.info("二维码已开启一键成片功能,开始触发一键成片: orderNo={}, codeId={}",
order.getOrderNo(), order.getCodeId());
// 2. 获取素材文件 //触发一键成片
List<OrderFile> orderFiles = orderFileService.getOrderFileByOrderNo(order.getOrderNo()); // 1. 创建新任务
EditTask task = editTaskService.createTask(order.getOrderNo(), order.getUserId());
// 3. 提交编辑任务 // 2. 获取素材文件
String jobId = videoEditService.submitEditTask(order.getOrderNo(), orderFiles); List<OrderFile> orderFiles = orderFileService.getOrderFileByOrderNo(order.getOrderNo());
log.info("提交一键成片任务成功: orderNo={}, jobId={}, totalMediaFiles={}",
order.getOrderNo(), jobId, orderFiles.size()); // 3. 提交编辑任务
// 4. 更新任务信息 String jobId = videoEditService.submitEditTask(order.getOrderNo(), orderFiles);
task.setJobId(jobId); log.info("提交一键成片任务成功: orderNo={}, jobId={}, totalMediaFiles={}",
task.setStatus(EditTaskStatus.PROCESSING); order.getOrderNo(), jobId, orderFiles.size());
editTaskService.saveOrUpdateTask(task); // 4. 更新任务信息
task.setJobId(jobId);
task.setStatus(EditTaskStatus.PROCESSING);
editTaskService.saveOrUpdateTask(task);
} else {
log.info("二维码未开启一键成片功能,跳过一键成片: orderNo={}, codeId={}, enableVideoEdit={}",
order.getOrderNo(), order.getCodeId(), qrCode.getEnableVideoEdit());
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("检查素材数量异常,订单号: {}", order.getOrderNo(), e); log.error("检查素材数量异常,订单号: {}", order.getOrderNo(), e);
} }
} }
/**
* 检查是否开启一键成片功能
*/
private boolean isVideoEditEnabled(QrCode qrCode) {
return qrCode != null
&& qrCode.getEnableVideoEdit() != null
&& qrCode.getEnableVideoEdit() == 1
&& qrCode.getTemplateId() != null; // 确保有模板ID
}
/** /**
* 素材上传完成小程序通知 * 素材上传完成小程序通知
* @param order * @param order
@@ -324,21 +344,21 @@ public class OrderFileController {
if (filePath == null || filePath.trim().isEmpty()) { if (filePath == null || filePath.trim().isEmpty()) {
return Result.failed("文件路径不能为空"); return Result.failed("文件路径不能为空");
} }
OrderFile orderFile = orderFileService.getOrderFileByFilePath(filePath); OrderFile orderFile = orderFileService.getOrderFileByFilePath(filePath);
if (orderFile == null) { if (orderFile == null) {
return Result.failed("未找到对应的订单文件记录"); return Result.failed("未找到对应的订单文件记录");
} }
// 设置文件查看URL // 设置文件查看URL
orderFile.setViewUrl(fileCenterService.getViewUrlByPath(orderFile.getFilePath())); orderFile.setViewUrl(fileCenterService.getViewUrlByPath(orderFile.getFilePath()));
// 设置压缩文件查看URL // 设置压缩文件查看URL
Map<String, String> fileMap = new HashMap<>(); Map<String, String> fileMap = new HashMap<>();
fileMap.put("style", fileStyle); fileMap.put("style", fileStyle);
fileMap.put("path", orderFile.getFilePath()); fileMap.put("path", orderFile.getFilePath());
orderFile.setZipViewUrl(fileCenterService.getViewUrlByPathStyle(fileMap)); orderFile.setZipViewUrl(fileCenterService.getViewUrlByPathStyle(fileMap));
return Result.succeed(orderFile, "记录已存在"); return Result.succeed(orderFile, "记录已存在");
} catch (Exception e) { } catch (Exception e) {
log.error("根据文件路径查询订单文件记录失败: filePath={}", filePath, e); log.error("根据文件路径查询订单文件记录失败: filePath={}", filePath, e);
@@ -353,10 +373,10 @@ public class OrderFileController {
if (filePath == null || filePath.trim().isEmpty()) { if (filePath == null || filePath.trim().isEmpty()) {
return Result.failed("文件路径不能为空"); return Result.failed("文件路径不能为空");
} }
OrderFile orderFile = orderFileService.getOrderFileByFilePath(filePath); OrderFile orderFile = orderFileService.getOrderFileByFilePath(filePath);
boolean exists = orderFile != null; boolean exists = orderFile != null;
if (exists) { if (exists) {
return Result.succeed(true, "记录已存在"); return Result.succeed(true, "记录已存在");
} else { } else {