30天之前的数据访问minio,30天之后的数据访问oss

This commit is contained in:
2025-10-19 11:50:02 +08:00
parent 69d784c70d
commit 785d0800ba
28 changed files with 1237 additions and 3775 deletions
@@ -105,7 +105,7 @@ public class OrderController {
@Autowired
private WxPayConfigFactory wxPayConfigFactory;
@Autowired
private OrderTenantAllocationService orderTenantAllocationService;
@@ -220,20 +220,20 @@ public class OrderController {
if (qrCode.getStatus().equals(CommonStatus.UNABLE.getId())){
return Result.failed("该二维码已过期");
}
// 智能租户分配:根据二维码ID确定租户
String determinedTenantId = orderTenantAllocationService.determineTenant(
qrCode.getCodeId(), qrCode.getTenantId());
order.setTenantId(determinedTenantId);
//设置订单所属tenantId
order.setTourismId(qrCode.getTourismId());
order.setDeviceSn(qrCode.getDeviceSn());
order.setOrderAmount(qrCode.getPrice());
// 记录订单分配日志
orderTenantAllocationService.incrementOrderCount(qrCode.getCodeId());
}else {
Assert.notNull(qrCode,"二维码不存在");
}
@@ -749,7 +749,7 @@ public class OrderController {
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
videoMap.put("contentType", orderFile.getFileType());
videoMap.put("path", orderFile.getFilePath());
// 为视频生成缩略图URL - 使用对应的图片作为缩略图
String thumbnailUrl = null;
if (!imgList.isEmpty()) {
@@ -762,7 +762,7 @@ public class OrderController {
}
}
videoMap.put("viewUrl", thumbnailUrl);
videoList.add(videoMap);
}
orderFileMap.put("videoList", videoList);
@@ -785,10 +785,10 @@ public class OrderController {
if (str == null || str.trim().isEmpty()) {
return "0.00";
}
// 获取字符串长度
int length = str.length();
// 处理长度小于2的情况
if (length == 1) {
return "0.0" + str;
@@ -866,7 +866,7 @@ public class OrderController {
/**
* 新版:查询用户订单详情列表(含视频/图片/一键成片)- 性能优化版本
*/
@Operation(summary = "新版-查询用户订单详情列表(含视频/图片/一键成片)")
/*@Operation(summary = "新版-查询用户订单详情列表(含视频/图片/一键成片)")
@Parameters({
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
@@ -881,21 +881,21 @@ public class OrderController {
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)
@@ -903,21 +903,21 @@ public class OrderController {
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 ->
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) {
@@ -930,11 +930,11 @@ public class OrderController {
}
}
}
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() : "");
@@ -966,7 +966,7 @@ public class OrderController {
orderFileMap.put("videoList", new ArrayList<>());
} else {
// 显示所有功能,返回图片和视频素材
// 图片素材 - 使用缓存URL
List<OrderFile> imgFiles = allFiles.stream()
.filter(f -> "image/jpeg".equals(f.getFileType()))
@@ -997,7 +997,7 @@ public class OrderController {
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()) {
@@ -1008,7 +1008,7 @@ public class OrderController {
thumbnailUrl = imgList.get(0).get("viewUrl");
}
videoMap.put("viewUrl", thumbnailUrl);
videoList.add(videoMap);
}
orderFileMap.put("videoList", videoList);
@@ -1019,6 +1019,286 @@ public class OrderController {
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> 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);
}
/**
@@ -1167,14 +1447,14 @@ public class OrderController {
@PostMapping("/order/{orderNo}/status/paid")
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo) {
log.info("优惠券核销成功,更新订单状态为已支付,orderNo: {}", orderNo);
try {
Order order = orderService.getOrderByNumber(orderNo);
if (order == null) {
log.error("订单不存在,orderNo: {}", orderNo);
return Result.failed("订单不存在");
}
// 检查订单当前状态
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())) {
// 更新订单状态为已支付排队中
@@ -1183,7 +1463,7 @@ public class OrderController {
order.setPayType(2); // 2表示优惠券支付
// 设置支付时间
order.setPayTime(new Date());
boolean result = orderService.updateOrder(order);
if (result) {
log.info("订单状态更新成功,orderNo: {}, 新状态: {}", orderNo, OrderStatus.PAID.getId());
@@ -1193,11 +1473,11 @@ public class OrderController {
return Result.failed("订单状态更新失败");
}
} else {
log.warn("订单状态不正确,无法更新为已支付,orderNo: {}, 当前状态: {}",
log.warn("订单状态不正确,无法更新为已支付,orderNo: {}, 当前状态: {}",
orderNo, order.getOrderStatus());
return Result.failed("订单状态不正确,无法更新为已支付");
}
} catch (Exception e) {
log.error("更新订单状态异常,orderNo: {}", orderNo, e);
return Result.failed("更新订单状态异常: " + e.getMessage());
@@ -1208,7 +1488,7 @@ public class OrderController {
@GetMapping("/order/{orderNo}")
public Result<Order> getOrderByOrderNo(@PathVariable("orderNo") String orderNo) {
log.info("根据订单号获取订单信息,orderNo: {}", orderNo);
try {
Order order = orderService.getOrderByNumber(orderNo);
if (order == null) {
@@ -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));
}
}