fix(dingdansu)

This commit is contained in:
2025-07-09 21:14:03 +08:00
parent 3a0f1de469
commit 9b164a94c2
4 changed files with 107 additions and 15 deletions
@@ -151,27 +151,45 @@ 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()) {
log.warn("素材路径为空,订单号: {}", orderFile.getOrderNo());
return Result.failed(orderFile,"素材路径为空");
}
// 先校验记录是否已经存在
OrderFile existingOrderFile = orderFileService.getOrderFileByFilePath(orderFile.getFilePath());
if (existingOrderFile != null) {
log.info("记录已存在,不再重复创建,订单号: {}, 文件路径: {}", orderFile.getOrderNo(), orderFile.getFilePath());
return Result.succeed(existingOrderFile, "记录已存在,无需重复创建");
}
// 设置订单相关信息
orderFile.setOrderNo(order.getOrderNo()); orderFile.setOrderNo(order.getOrderNo());
orderFile.setUserId(order.getUserId()); orderFile.setUserId(order.getUserId());
if (orderFile.getFilePath() != null) {
// 创建文件信息
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());
} else {
log.warn("素材路径为空,订单号: {}", orderFile.getOrderNo()); // 保存记录
return Result.failed(orderFile,"素材路径为空");
}
boolean saved = orderFileService.save(orderFile); boolean saved = orderFileService.save(orderFile);
if (saved) { if (saved) {
// 机库上报订单素材,更新订单状态为素材上传中,如果订单为设备执行中则更新,否则说明状态已更新 // 机库上报订单素材,更新订单状态为素材上传中,如果订单为设备执行中则更新,否则说明状态已更新
@@ -181,7 +199,7 @@ public class OrderFileController {
orderService.updateOrder(order); orderService.updateOrder(order);
} }
log.info("素材记录创建成功,订单号: {}, 文件ID: {}", orderFile.getOrderNo(), orderFile.getFileId()); log.info("素材记录创建成功,订单号: {}, 文件ID: {}", orderFile.getOrderNo(), orderFile.getFileId());
return Result.succeed(orderFile, "更新成功"); return Result.succeed(orderFile, "创建成功");
} else { } else {
log.error("素材记录保存失败,订单号: {}", orderFile.getOrderNo()); log.error("素材记录保存失败,订单号: {}", orderFile.getOrderNo());
return Result.failed(orderFile,"素材记录保存失败"); return Result.failed(orderFile,"素材记录保存失败");
@@ -203,4 +221,55 @@ public class OrderFileController {
} }
@Operation(summary = "根据文件路径查询订单文件记录是否存在")
@GetMapping("/path/{filePath}")
public Result<OrderFile> getOrderFileByFilePath(@PathVariable("filePath") String filePath) {
try {
if (filePath == null || filePath.trim().isEmpty()) {
return Result.failed("文件路径不能为空");
}
OrderFile orderFile = orderFileService.getOrderFileByFilePath(filePath);
if (orderFile == null) {
return Result.failed("未找到对应的订单文件记录");
}
// 设置文件查看URL
orderFile.setViewUrl(fileCenterService.getViewUrlByPath(orderFile.getFilePath()));
// 设置压缩文件查看URL
Map<String, String> fileMap = new HashMap<>();
fileMap.put("style", fileStyle);
fileMap.put("path", orderFile.getFilePath());
orderFile.setZipViewUrl(fileCenterService.getViewUrlByPathStyle(fileMap));
return Result.succeed(orderFile, "记录已存在");
} catch (Exception e) {
log.error("根据文件路径查询订单文件记录失败: filePath={}", filePath, e);
return Result.failed("查询失败: " + e.getMessage());
}
}
@Operation(summary = "检查文件路径对应的订单文件记录是否存在")
@GetMapping("/exists/{filePath}")
public Result<Boolean> checkOrderFileExists(@PathVariable("filePath") String filePath) {
try {
if (filePath == null || filePath.trim().isEmpty()) {
return Result.failed("文件路径不能为空");
}
OrderFile orderFile = orderFileService.getOrderFileByFilePath(filePath);
boolean exists = orderFile != null;
if (exists) {
return Result.succeed(true, "记录已存在");
} else {
return Result.succeed(false, "记录不存在");
}
} catch (Exception e) {
log.error("检查文件路径对应的订单文件记录是否存在失败: filePath={}", filePath, e);
return Result.failed("检查失败: " + e.getMessage());
}
}
} }
@@ -84,5 +84,12 @@ public interface IOrderFileService extends ISuperService<OrderFile> {
* 获取订单图片文件 * 获取订单图片文件
*/ */
List<OrderFile> getOrderImageFiles(String orderNo); List<OrderFile> getOrderImageFiles(String orderNo);
/**
* 根据文件路径查询订单文件资源
* @param filePath 文件路径
* @return 订单文件资源
*/
OrderFile getOrderFileByFilePath(String filePath);
} }
@@ -103,4 +103,19 @@ public class OrderFileServiceImpl extends SuperServiceImpl<OrderFileMapper, Orde
.orderByAsc("create_time")); .orderByAsc("create_time"));
} }
@Override
public OrderFile getOrderFileByFilePath(String filePath) {
try {
log.debug("根据文件路径查询订单文件: filePath={}", filePath);
return baseMapper.selectOne(
new QueryWrapper<OrderFile>()
.eq("file_path", filePath)
.last("LIMIT 1")
);
} catch (Exception e) {
log.error("根据文件路径查询订单文件失败: filePath={}", filePath, e);
return null;
}
}
} }
@@ -153,7 +153,8 @@ zlt:
/api-device/token/query, /api-device/token/query,
/api-order/user/temp, /api-order/user/temp,
/api-file/file/expires, /api-file/file/expires,
/api-order/refund/auto /api-order/refund/auto,
/api-order/files/exists/**
auth: auth:
urlPermission: urlPermission:
#是否开启url级别权限 #是否开启url级别权限