feat: 1:文件访问分oss和s3 2:去掉定时任务去同步每天的数据
This commit is contained in:
+443
-160
@@ -714,7 +714,7 @@ public class OrderController {
|
||||
.toList();
|
||||
String aiVideoUrl = null;
|
||||
if (!aiVideoFiles.isEmpty()) {
|
||||
aiVideoUrl = fileCenterService.getViewUrlByPath(aiVideoFiles.get(0).getFilePath()).replace(cdnOssUrl, cdnUrl);
|
||||
aiVideoUrl = fileCenterService.getFileViewUrl(aiVideoFiles.get(0).getFileId());
|
||||
}
|
||||
orderFileMap.put("aiVideo", aiVideoUrl);
|
||||
|
||||
@@ -727,11 +727,11 @@ public class OrderController {
|
||||
fileMap.put("style", fileStyle);
|
||||
for (OrderFile orderFile : imgFiles){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
imgMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
String url = fileCenterService.getFileViewUrl(orderFile.getFileId());
|
||||
imgMap.put("url", url);
|
||||
imgMap.put("contentType", orderFile.getFileType());
|
||||
imgMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("path",orderFile.getFilePath());
|
||||
fileMap.put("fileId",orderFile.getFileId());
|
||||
imgMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
imgList.add(imgMap);
|
||||
}
|
||||
@@ -745,8 +745,8 @@ public class OrderController {
|
||||
for (int i = 0; i < videoFiles.size(); i++){
|
||||
OrderFile orderFile = videoFiles.get(i);
|
||||
Map<String,String> videoMap = new HashMap<>();
|
||||
String url = fileCenterService.getViewUrlByPath(orderFile.getFilePath());
|
||||
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||
String url = fileCenterService.getFileViewUrl(orderFile.getFileId());
|
||||
videoMap.put("url", url);
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
|
||||
@@ -866,160 +866,163 @@ public class OrderController {
|
||||
/**
|
||||
* 新版:查询用户订单详情列表(含视频/图片/一键成片)- 性能优化版本
|
||||
*/
|
||||
@Operation(summary = "新版-查询用户订单详情列表(含视频/图片/一键成片)")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/user/v2")
|
||||
public PageResult<Map> listInfoByUserV2(@RequestParam Map<String, Object> params) {
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
params.put("userId", user.getId());
|
||||
List<Integer> orderStatusList = List.of(OrderStatus.COMPLETE.getId(), OrderStatus.UPLOADING.getId(), OrderStatus.UPLOADED.getId());
|
||||
params.put("orderStatusList", orderStatusList);
|
||||
|
||||
PageResult<Order> result = orderService.findListByUser(params);
|
||||
if (result.getCount() > 0){
|
||||
List<Map> page = new ArrayList<>();
|
||||
|
||||
// 批量获取所有订单号
|
||||
List<String> orderNos = result.getData().stream()
|
||||
.map(Order::getOrderNo)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 批量获取所有文件信息
|
||||
Map<String, List<OrderFile>> orderFilesMap = orderFileService.getOrderFilesByOrderNos(orderNos);
|
||||
|
||||
// 批量获取所有景区信息
|
||||
Set<Long> tourismIds = result.getData().stream()
|
||||
.map(Order::getTourismId)
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, Tourism> tourismMap = tourismService.getTourismsByIds(tourismIds);
|
||||
|
||||
// 批量获取所有二维码信息
|
||||
List<String> codeIds = result.getData().stream()
|
||||
.map(Order::getCodeId)
|
||||
.collect(Collectors.toList());
|
||||
List<QrCode> qrCodes = qrCodeService.getByCodeIds(codeIds);
|
||||
Map<String, QrCode> qrCodeMap = qrCodes.stream()
|
||||
.collect(Collectors.toMap(QrCode::getCodeId, qrCode -> qrCode));
|
||||
|
||||
// 预计算所有文件路径的URL,避免重复调用
|
||||
Set<String> allFilePaths = new HashSet<>();
|
||||
orderFilesMap.values().forEach(files ->
|
||||
files.forEach(file -> allFilePaths.add(file.getFilePath())));
|
||||
|
||||
Map<String, String> fileUrlMap = new HashMap<>();
|
||||
Map<String, String> fileStyleUrlMap = new HashMap<>();
|
||||
|
||||
// 批量获取文件URL
|
||||
for (String filePath : allFilePaths) {
|
||||
String url = fileCenterService.getViewUrlByPath(filePath);
|
||||
fileUrlMap.put(filePath, url.replace(cdnOssUrl, cdnUrl));
|
||||
}
|
||||
|
||||
// 预计算样式URL(仅对图片文件)
|
||||
for (List<OrderFile> files : orderFilesMap.values()) {
|
||||
for (OrderFile file : files) {
|
||||
if ("image/jpeg".equals(file.getFileType()) || "image/jpg".equals(file.getFileType()) || "image/png".equals(file.getFileType())) {
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("path", file.getFilePath());
|
||||
styleParams.put("style", fileStyle);
|
||||
String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
fileStyleUrlMap.put(file.getFilePath(), styleUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Order order : result.getData()){
|
||||
Map<String,Object> orderFileMap = new HashMap<>();
|
||||
orderFileMap.put("time", sdf.format(order.getCreateTime()));
|
||||
|
||||
// 从缓存获取景区信息
|
||||
Tourism tourism = tourismMap.get(order.getTourismId());
|
||||
orderFileMap.put("addr", tourism != null ? tourism.getTourismAddress() : "");
|
||||
orderFileMap.put("orderNo", order.getOrderNo());
|
||||
orderFileMap.put("orderStatus", order.getOrderStatus());
|
||||
|
||||
// 从缓存获取二维码信息
|
||||
QrCode qrCode = qrCodeMap.get(order.getCodeId());
|
||||
Integer showVideoEditOnly = qrCode != null ? qrCode.getShowVideoEditOnly() : 1; // 默认值为1
|
||||
orderFileMap.put("showVideoEditOnly", showVideoEditOnly);
|
||||
|
||||
// 从缓存获取文件列表
|
||||
List<OrderFile> allFiles = orderFilesMap.getOrDefault(order.getOrderNo(), new ArrayList<>());
|
||||
|
||||
// aiVideo - 使用缓存URL(始终返回)
|
||||
List<OrderFile> aiVideoFiles = allFiles.stream()
|
||||
.filter(f -> "ai_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
String aiVideoUrl = null;
|
||||
if (!aiVideoFiles.isEmpty()) {
|
||||
aiVideoUrl = fileUrlMap.get(aiVideoFiles.get(0).getFilePath());
|
||||
}
|
||||
orderFileMap.put("aiVideo", aiVideoUrl);
|
||||
|
||||
// 根据showVideoEditOnly属性决定是否返回图片和视频素材
|
||||
if (showVideoEditOnly == null || showVideoEditOnly == 1) {
|
||||
// 只显示一键成片,不返回图片和视频素材
|
||||
orderFileMap.put("imgList", new ArrayList<>());
|
||||
orderFileMap.put("videoList", new ArrayList<>());
|
||||
} else {
|
||||
// 显示所有功能,返回图片和视频素材
|
||||
|
||||
// 图片素材 - 使用缓存URL
|
||||
List<OrderFile> imgFiles = allFiles.stream()
|
||||
.filter(f -> "image/jpeg".equals(f.getFileType()))
|
||||
.toList();
|
||||
List<Map<String,String>> imgList = new ArrayList<>();
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
fileMap.put("style", fileStyle);
|
||||
for (OrderFile orderFile : imgFiles){
|
||||
Map<String,String> imgMap = new HashMap<>();
|
||||
imgMap.put("url", fileUrlMap.get(orderFile.getFilePath()));
|
||||
imgMap.put("contentType", orderFile.getFileType());
|
||||
imgMap.put("path", orderFile.getFilePath());
|
||||
fileMap.put("path", orderFile.getFilePath());
|
||||
String viewUrl = fileCenterService.getViewUrlByPathStyle(fileMap);
|
||||
imgMap.put("viewUrl", viewUrl);
|
||||
imgList.add(imgMap);
|
||||
}
|
||||
orderFileMap.put("imgList", imgList);
|
||||
|
||||
// 视频素材 - 使用缓存URL
|
||||
List<OrderFile> videoFiles = allFiles.stream()
|
||||
.filter(f -> "raw_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
List<Map<String,String>> videoList = new ArrayList<>();
|
||||
for (int i = 0; i < videoFiles.size(); i++){
|
||||
OrderFile orderFile = videoFiles.get(i);
|
||||
Map<String,String> videoMap = new HashMap<>();
|
||||
videoMap.put("url", fileUrlMap.get(orderFile.getFilePath()));
|
||||
videoMap.put("contentType", orderFile.getFileType());
|
||||
videoMap.put("path", orderFile.getFilePath());
|
||||
|
||||
// 为视频生成缩略图URL - 使用对应的图片作为缩略图
|
||||
String thumbnailUrl = null;
|
||||
if (!imgList.isEmpty() && i < imgList.size()) {
|
||||
// 使用对应索引的图片作为缩略图
|
||||
thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
} else if (!imgList.isEmpty()) {
|
||||
// 如果视频数量超过图片数量,使用第一张图片作为缩略图
|
||||
thumbnailUrl = imgList.get(0).get("viewUrl");
|
||||
}
|
||||
videoMap.put("viewUrl", thumbnailUrl);
|
||||
|
||||
videoList.add(videoMap);
|
||||
}
|
||||
orderFileMap.put("videoList", videoList);
|
||||
}
|
||||
|
||||
page.add(orderFileMap);
|
||||
}
|
||||
return PageResult.<Map>builder().data(page).resp_code(0).count(result.getCount()).build();
|
||||
}
|
||||
return new PageResult<>();
|
||||
}
|
||||
// @Operation(summary = "新版-查询用户订单详情列表(含视频/图片/一键成片)")
|
||||
// @Parameters({
|
||||
// @Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
// @Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
// })
|
||||
// @GetMapping("/user/v2")
|
||||
// public PageResult<Map> listInfoByUserV2(@RequestParam Map<String, Object> params) {
|
||||
// LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
// params.put("userId", user.getId());
|
||||
// List<Integer> orderStatusList = List.of(OrderStatus.COMPLETE.getId(), OrderStatus.UPLOADING.getId(), OrderStatus.UPLOADED.getId());
|
||||
// params.put("orderStatusList", orderStatusList);
|
||||
//
|
||||
// PageResult<Order> result = orderService.findListByUser(params);
|
||||
// if (result.getCount() > 0){
|
||||
// List<Map> page = new ArrayList<>();
|
||||
//
|
||||
// // 批量获取所有订单号
|
||||
// List<String> orderNos = result.getData().stream()
|
||||
// .map(Order::getOrderNo)
|
||||
// .collect(Collectors.toList());
|
||||
//
|
||||
// // 批量获取所有文件信息
|
||||
// Map<String, List<OrderFile>> orderFilesMap = orderFileService.getOrderFilesByOrderNos(orderNos);
|
||||
//
|
||||
// // 批量获取所有景区信息
|
||||
// Set<Long> tourismIds = result.getData().stream()
|
||||
// .map(Order::getTourismId)
|
||||
// .collect(Collectors.toSet());
|
||||
// Map<Long, Tourism> tourismMap = tourismService.getTourismsByIds(tourismIds);
|
||||
//
|
||||
// // 批量获取所有二维码信息
|
||||
// List<String> codeIds = result.getData().stream()
|
||||
// .map(Order::getCodeId)
|
||||
// .collect(Collectors.toList());
|
||||
// List<QrCode> qrCodes = qrCodeService.getByCodeIds(codeIds);
|
||||
// Map<String, QrCode> qrCodeMap = qrCodes.stream()
|
||||
// .collect(Collectors.toMap(QrCode::getCodeId, qrCode -> qrCode));
|
||||
//
|
||||
// // 预计算所有文件路径的URL,避免重复调用
|
||||
// /* Set<String> allFilePaths = new HashSet<>();
|
||||
// orderFilesMap.values().forEach(files ->
|
||||
// files.forEach(file -> allFilePaths.add(file.getFilePath())));*/
|
||||
// Set<String> allFileIds = new HashSet<>();
|
||||
// orderFilesMap.values().forEach(files ->
|
||||
// files.forEach(file -> allFileIds.add(file.getFilePath())));
|
||||
//
|
||||
// Map<String, String> fileUrlMap = new HashMap<>();
|
||||
// Map<String, String> fileStyleUrlMap = new HashMap<>();
|
||||
//
|
||||
// // 批量获取文件URL
|
||||
// for (String fileId : allFileIds) {
|
||||
// String url = fileCenterService.getFileViewUrl(fileId);
|
||||
// fileUrlMap.put(fileId, url.replace(cdnOssUrl, cdnUrl));
|
||||
// }
|
||||
//
|
||||
// // 预计算样式URL(仅对图片文件)
|
||||
// for (List<OrderFile> files : orderFilesMap.values()) {
|
||||
// for (OrderFile file : files) {
|
||||
// if ("image/jpeg".equals(file.getFileType()) || "image/jpg".equals(file.getFileType()) || "image/png".equals(file.getFileType())) {
|
||||
// Map<String, String> styleParams = new HashMap<>();
|
||||
// styleParams.put("fileId", file.getFileId());
|
||||
// styleParams.put("style", fileStyle);
|
||||
// String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
// fileStyleUrlMap.put(file.getFilePath(), styleUrl);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for(Order order : result.getData()){
|
||||
// Map<String,Object> orderFileMap = new HashMap<>();
|
||||
// orderFileMap.put("time", sdf.format(order.getCreateTime()));
|
||||
//
|
||||
// // 从缓存获取景区信息
|
||||
// Tourism tourism = tourismMap.get(order.getTourismId());
|
||||
// orderFileMap.put("addr", tourism != null ? tourism.getTourismAddress() : "");
|
||||
// orderFileMap.put("orderNo", order.getOrderNo());
|
||||
// orderFileMap.put("orderStatus", order.getOrderStatus());
|
||||
//
|
||||
// // 从缓存获取二维码信息
|
||||
// QrCode qrCode = qrCodeMap.get(order.getCodeId());
|
||||
// Integer showVideoEditOnly = qrCode != null ? qrCode.getShowVideoEditOnly() : 1; // 默认值为1
|
||||
// orderFileMap.put("showVideoEditOnly", showVideoEditOnly);
|
||||
//
|
||||
// // 从缓存获取文件列表
|
||||
// List<OrderFile> allFiles = orderFilesMap.getOrDefault(order.getOrderNo(), new ArrayList<>());
|
||||
//
|
||||
// // aiVideo - 使用缓存URL(始终返回)
|
||||
// List<OrderFile> aiVideoFiles = allFiles.stream()
|
||||
// .filter(f -> "ai_video".equals(f.getFileTag()))
|
||||
// .toList();
|
||||
// String aiVideoUrl = null;
|
||||
// if (!aiVideoFiles.isEmpty()) {
|
||||
// aiVideoUrl = fileUrlMap.get(aiVideoFiles.get(0).getFileId());
|
||||
// }
|
||||
// orderFileMap.put("aiVideo", aiVideoUrl);
|
||||
//
|
||||
// // 根据showVideoEditOnly属性决定是否返回图片和视频素材
|
||||
// if (showVideoEditOnly == null || showVideoEditOnly == 1) {
|
||||
// // 只显示一键成片,不返回图片和视频素材
|
||||
// orderFileMap.put("imgList", new ArrayList<>());
|
||||
// orderFileMap.put("videoList", new ArrayList<>());
|
||||
// } else {
|
||||
// // 显示所有功能,返回图片和视频素材
|
||||
//
|
||||
// // 图片素材 - 使用缓存URL
|
||||
// List<OrderFile> imgFiles = allFiles.stream()
|
||||
// .filter(f -> "image/jpeg".equals(f.getFileType()))
|
||||
// .toList();
|
||||
// List<Map<String,String>> imgList = new ArrayList<>();
|
||||
// Map<String, String> fileMap = new HashMap<>();
|
||||
// fileMap.put("style", fileStyle);
|
||||
// for (OrderFile orderFile : imgFiles){
|
||||
// Map<String,String> imgMap = new HashMap<>();
|
||||
// imgMap.put("url", fileUrlMap.get(orderFile.getFileId()));
|
||||
// imgMap.put("contentType", orderFile.getFileType());
|
||||
// imgMap.put("path", orderFile.getFilePath());
|
||||
// fileMap.put("fileId", orderFile.getFileId());
|
||||
// String viewUrl = fileCenterService.getViewUrlByPathStyle(fileMap);
|
||||
// imgMap.put("viewUrl", viewUrl);
|
||||
// imgList.add(imgMap);
|
||||
// }
|
||||
// orderFileMap.put("imgList", imgList);
|
||||
//
|
||||
// // 视频素材 - 使用缓存URL
|
||||
// List<OrderFile> videoFiles = allFiles.stream()
|
||||
// .filter(f -> "raw_video".equals(f.getFileTag()))
|
||||
// .toList();
|
||||
// List<Map<String,String>> videoList = new ArrayList<>();
|
||||
// for (int i = 0; i < videoFiles.size(); i++){
|
||||
// OrderFile orderFile = videoFiles.get(i);
|
||||
// Map<String,String> videoMap = new HashMap<>();
|
||||
// videoMap.put("url", fileUrlMap.get(orderFile.getFileId()));
|
||||
// videoMap.put("contentType", orderFile.getFileType());
|
||||
// videoMap.put("path", orderFile.getFilePath());
|
||||
//
|
||||
// // 为视频生成缩略图URL - 使用对应的图片作为缩略图
|
||||
// String thumbnailUrl = null;
|
||||
// if (!imgList.isEmpty() && i < imgList.size()) {
|
||||
// // 使用对应索引的图片作为缩略图
|
||||
// thumbnailUrl = imgList.get(i).get("viewUrl");
|
||||
// } else if (!imgList.isEmpty()) {
|
||||
// // 如果视频数量超过图片数量,使用第一张图片作为缩略图
|
||||
// thumbnailUrl = imgList.get(0).get("viewUrl");
|
||||
// }
|
||||
// videoMap.put("viewUrl", thumbnailUrl);
|
||||
//
|
||||
// videoList.add(videoMap);
|
||||
// }
|
||||
// orderFileMap.put("videoList", videoList);
|
||||
// }
|
||||
//
|
||||
// page.add(orderFileMap);
|
||||
// }
|
||||
// return PageResult.<Map>builder().data(page).resp_code(0).count(result.getCount()).build();
|
||||
// }
|
||||
// return new PageResult<>();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 新版:查询用户图片订单详情列表
|
||||
@@ -1079,6 +1082,286 @@ public class OrderController {
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化版:查询用户订单详情列表(含视频/图片/一键成片)
|
||||
* 重构版本,提高代码可读性和维护性
|
||||
*/
|
||||
@Operation(summary = "优化版-查询用户订单详情列表(含视频/图片/一键成片)")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/user/v2")
|
||||
public PageResult<Map> listInfoByUserV3(@RequestParam Map<String, Object> params) {
|
||||
// 1. 准备查询参数
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
params.put("userId", user.getId());
|
||||
params.put("orderStatusList", getCompletedOrderStatuses());
|
||||
|
||||
// 2. 查询订单数据
|
||||
PageResult<Order> orderResult = orderService.findListByUser(params);
|
||||
if (orderResult.getCount() == 0) {
|
||||
return new PageResult<>();
|
||||
}
|
||||
|
||||
// 3. 批量加载所需数据
|
||||
BatchLoadedData batchData = batchLoadOrderRelatedData(orderResult.getData());
|
||||
|
||||
// 4. 构建返回结果
|
||||
List<Map> resultList = buildOrderDetailList(orderResult.getData(), batchData);
|
||||
|
||||
return PageResult.<Map>builder()
|
||||
.data(resultList)
|
||||
.resp_code(0)
|
||||
.count(orderResult.getCount())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量加载订单相关数据的内部类
|
||||
*/
|
||||
private static class BatchLoadedData {
|
||||
Map<String, List<OrderFile>> orderFilesMap;
|
||||
Map<Long, Tourism> tourismMap;
|
||||
Map<String, QrCode> qrCodeMap;
|
||||
Map<String, String> fileUrlMap;
|
||||
Map<String, String> fileStyleUrlMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已完成的订单状态列表
|
||||
*/
|
||||
private List<Integer> getCompletedOrderStatuses() {
|
||||
return List.of(
|
||||
OrderStatus.COMPLETE.getId(),
|
||||
OrderStatus.UPLOADING.getId(),
|
||||
OrderStatus.UPLOADED.getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量加载订单相关的所有数据
|
||||
*/
|
||||
private BatchLoadedData batchLoadOrderRelatedData(List<Order> orders) {
|
||||
BatchLoadedData data = new BatchLoadedData();
|
||||
|
||||
// 1. 提取所有ID
|
||||
List<String> orderNos = orders.stream()
|
||||
.map(Order::getOrderNo)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Set<Long> tourismIds = orders.stream()
|
||||
.map(Order::getTourismId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<String> codeIds = orders.stream()
|
||||
.map(Order::getCodeId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 批量查询数据
|
||||
data.orderFilesMap = orderFileService.getOrderFilesByOrderNos(orderNos);
|
||||
data.tourismMap = tourismService.getTourismsByIds(tourismIds);
|
||||
data.qrCodeMap = qrCodeService.getByCodeIds(codeIds).stream()
|
||||
.collect(Collectors.toMap(QrCode::getCodeId, qrCode -> qrCode));
|
||||
|
||||
// 3. 批量处理文件URL
|
||||
loadFileUrls(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量加载文件URL和样式URL
|
||||
*/
|
||||
private void loadFileUrls(BatchLoadedData data) {
|
||||
Set<String> allFileIds = new HashSet<>();
|
||||
data.orderFilesMap.values().forEach(files ->
|
||||
files.forEach(file -> allFileIds.add(file.getFileId()))
|
||||
);
|
||||
|
||||
data.fileUrlMap = new HashMap<>();
|
||||
data.fileStyleUrlMap = new HashMap<>();
|
||||
|
||||
// 批量获取文件URL
|
||||
for (String fileId : allFileIds) {
|
||||
String url = fileCenterService.getFileViewUrl(fileId);
|
||||
if(url!=null && !url.isEmpty()){
|
||||
data.fileUrlMap.put(fileId, url);
|
||||
}
|
||||
}
|
||||
|
||||
// 为图片文件生成样式URL
|
||||
for (List<OrderFile> files : data.orderFilesMap.values()) {
|
||||
for (OrderFile file : files) {
|
||||
if (isImageFile(file.getFileType())) {
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("fileId", file.getFileId());
|
||||
styleParams.put("style", fileStyle);
|
||||
String styleUrl = fileCenterService.getViewUrlByPathStyle(styleParams);
|
||||
data.fileStyleUrlMap.put(file.getFileId(), styleUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建订单详情列表
|
||||
*/
|
||||
private List<Map> buildOrderDetailList(List<Order> orders, BatchLoadedData batchData) {
|
||||
List<Map> resultList = new ArrayList<>();
|
||||
|
||||
for (Order order : orders) {
|
||||
Map<String, Object> orderDetail = buildSingleOrderDetail(order, batchData);
|
||||
resultList.add(orderDetail);
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建单个订单的详情
|
||||
*/
|
||||
private Map<String, Object> buildSingleOrderDetail(Order order, BatchLoadedData batchData) {
|
||||
Map<String, Object> detail = new HashMap<>();
|
||||
|
||||
// 1. 基本信息
|
||||
detail.put("time", sdf.format(order.getCreateTime()));
|
||||
detail.put("orderNo", order.getOrderNo());
|
||||
detail.put("orderStatus", order.getOrderStatus());
|
||||
|
||||
// 2. 景区信息
|
||||
Tourism tourism = batchData.tourismMap.get(order.getTourismId());
|
||||
detail.put("addr", tourism != null ? tourism.getTourismAddress() : "");
|
||||
|
||||
// 3. 二维码配置
|
||||
QrCode qrCode = batchData.qrCodeMap.get(order.getCodeId());
|
||||
Integer showVideoEditOnly = qrCode != null ? qrCode.getShowVideoEditOnly() : 1;
|
||||
detail.put("showVideoEditOnly", showVideoEditOnly);
|
||||
|
||||
// 4. 文件信息
|
||||
List<OrderFile> orderFiles = batchData.orderFilesMap.getOrDefault(order.getOrderNo(), new ArrayList<>());
|
||||
|
||||
// 5. 处理AI视频
|
||||
String aiVideoUrl = extractAiVideoUrl(orderFiles, batchData.fileUrlMap);
|
||||
detail.put("aiVideo", aiVideoUrl);
|
||||
|
||||
// 6. 根据配置决定是否返回素材
|
||||
if (shouldShowMediaFiles(showVideoEditOnly)) {
|
||||
detail.put("imgList", buildImageList(orderFiles, batchData));
|
||||
detail.put("videoList", buildVideoList(orderFiles, batchData, detail));
|
||||
} else {
|
||||
detail.put("imgList", new ArrayList<>());
|
||||
detail.put("videoList", new ArrayList<>());
|
||||
}
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取AI视频URL
|
||||
*/
|
||||
private String extractAiVideoUrl(List<OrderFile> files, Map<String, String> fileUrlMap) {
|
||||
return files.stream()
|
||||
.filter(f -> "ai_video".equals(f.getFileTag()))
|
||||
.findFirst()
|
||||
.map(f -> fileUrlMap.get(f.getFileId()))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否应该显示媒体文件
|
||||
*/
|
||||
private boolean shouldShowMediaFiles(Integer showVideoEditOnly) {
|
||||
return showVideoEditOnly != null && showVideoEditOnly != 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建图片列表
|
||||
*/
|
||||
private List<Map<String, String>> buildImageList(List<OrderFile> files, BatchLoadedData batchData) {
|
||||
List<Map<String, String>> imageList = new ArrayList<>();
|
||||
|
||||
List<OrderFile> imageFiles = files.stream()
|
||||
.filter(f -> "image/jpeg".equals(f.getFileType()))
|
||||
.toList();
|
||||
|
||||
for (OrderFile file : imageFiles) {
|
||||
Map<String, String> imageInfo = new HashMap<>();
|
||||
imageInfo.put("url", batchData.fileUrlMap.get(file.getFileId()));
|
||||
imageInfo.put("contentType", file.getFileType());
|
||||
imageInfo.put("path", file.getFilePath());
|
||||
|
||||
// 生成样式URL
|
||||
Map<String, String> styleParams = new HashMap<>();
|
||||
styleParams.put("fileId", file.getFileId());
|
||||
styleParams.put("style", fileStyle);
|
||||
imageInfo.put("viewUrl", fileCenterService.getViewUrlByPathStyle(styleParams));
|
||||
|
||||
imageList.add(imageInfo);
|
||||
}
|
||||
|
||||
return imageList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建视频列表
|
||||
*/
|
||||
private List<Map<String, String>> buildVideoList(List<OrderFile> files,
|
||||
BatchLoadedData batchData,
|
||||
Map<String, Object> orderDetail) {
|
||||
List<Map<String, String>> videoList = new ArrayList<>();
|
||||
|
||||
List<OrderFile> videoFiles = files.stream()
|
||||
.filter(f -> "raw_video".equals(f.getFileTag()))
|
||||
.toList();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, String>> imgList = (List<Map<String, String>>) orderDetail.get("imgList");
|
||||
|
||||
for (int i = 0; i < videoFiles.size(); i++) {
|
||||
OrderFile file = videoFiles.get(i);
|
||||
Map<String, String> videoInfo = new HashMap<>();
|
||||
|
||||
videoInfo.put("url", batchData.fileUrlMap.get(file.getFileId()));
|
||||
videoInfo.put("contentType", file.getFileType());
|
||||
videoInfo.put("path", file.getFilePath());
|
||||
|
||||
// 设置视频缩略图
|
||||
String thumbnailUrl = getVideoThumbnail(imgList, i);
|
||||
videoInfo.put("viewUrl", thumbnailUrl);
|
||||
|
||||
videoList.add(videoInfo);
|
||||
}
|
||||
|
||||
return videoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取视频缩略图URL
|
||||
*/
|
||||
private String getVideoThumbnail(List<Map<String, String>> imgList, int videoIndex) {
|
||||
if (imgList == null || imgList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 优先使用对应索引的图片
|
||||
if (videoIndex < imgList.size()) {
|
||||
return imgList.get(videoIndex).get("viewUrl");
|
||||
}
|
||||
|
||||
// 否则使用第一张图片
|
||||
return imgList.get(0).get("viewUrl");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为图片文件
|
||||
*/
|
||||
private boolean isImageFile(String fileType) {
|
||||
return "image/jpeg".equals(fileType)
|
||||
|| "image/jpg".equals(fileType)
|
||||
|| "image/png".equals(fileType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新版:查询用户视频订单详情列表
|
||||
*/
|
||||
|
||||
+2
-2
@@ -105,8 +105,8 @@ public class OrderFileController {
|
||||
fileMap.put("style", fileStyle);
|
||||
if (pageResult.getResp_code() == 0){
|
||||
for (OrderFile orderFile: pageResult.getData()){
|
||||
orderFile.setViewUrl(fileCenterService.getViewUrlByPath(orderFile.getFilePath()));
|
||||
fileMap.put("path", orderFile.getFilePath());
|
||||
orderFile.setViewUrl(fileCenterService.getFileViewUrl(orderFile.getFileId()));
|
||||
fileMap.put("fileId", orderFile.getFileId());
|
||||
orderFile.setZipViewUrl(fileCenterService.getViewUrlByPathStyle(fileMap));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
server:
|
||||
port: 7002
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: order-center
|
||||
|
||||
Reference in New Issue
Block a user