You've already forked FrameTour-BE
feat(printer): 移除拼图照片自动裁剪功能
- 删除了从打印机配置获取打印尺寸的逻辑 - 移除了调用ImageUtils.smartCropAndFill进行图片裁剪的代码 - 去掉了裁剪后图片上传和临时文件清理的相关实现 - 简化了打印服务流程,直接使用原始图片URL - 保留了cropUrl字段但不再进行实际裁剪操作
This commit is contained in:
@@ -1240,54 +1240,6 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
|
||||
// 获取打印尺寸并裁剪图片
|
||||
String cropUrl = resultImageUrl; // 默认使用原图
|
||||
try {
|
||||
// 从打印机表获取尺寸
|
||||
Integer printWidth = null;
|
||||
Integer printHeight = null;
|
||||
|
||||
List<PrinterResp> printers = printerMapper.listByScenicId(scenicId);
|
||||
if (printers != null && !printers.isEmpty()) {
|
||||
PrinterResp firstPrinter = printers.get(0);
|
||||
printWidth = firstPrinter.getPreferW();
|
||||
printHeight = firstPrinter.getPreferH();
|
||||
log.debug("从打印机获取尺寸: scenicId={}, printerId={}, width={}, height={}",
|
||||
scenicId, firstPrinter.getId(), printWidth, printHeight);
|
||||
}
|
||||
|
||||
// 如果打印机没有配置或配置无效,使用默认值
|
||||
if (printWidth == null || printWidth <= 0) {
|
||||
printWidth = 1020;
|
||||
log.debug("打印机宽度未配置或无效,使用默认值: width={}", printWidth);
|
||||
}
|
||||
if (printHeight == null || printHeight <= 0) {
|
||||
printHeight = 1520;
|
||||
log.debug("打印机高度未配置或无效,使用默认值: height={}", printHeight);
|
||||
}
|
||||
|
||||
// 使用smartCropAndFill裁剪图片
|
||||
File croppedFile = ImageUtils.smartCropAndFill(resultImageUrl, printWidth, printHeight);
|
||||
|
||||
try {
|
||||
// 上传裁剪后的图片
|
||||
String[] split = croppedFile.getName().split("\\.");
|
||||
String ext = split.length > 0 ? split[split.length - 1] : "jpg";
|
||||
|
||||
cropUrl = StorageFactory.use().uploadFile(null, croppedFile, "printer", UUID.randomUUID() + "." + ext);
|
||||
|
||||
log.info("拼图照片裁剪成功: memberId={}, scenicId={}, puzzleRecordId={}, 原图={}, 裁剪后={}, 尺寸={}x{}",
|
||||
memberId, scenicId, puzzleRecordId, resultImageUrl, cropUrl, printWidth, printHeight);
|
||||
} finally {
|
||||
// 清理临时文件
|
||||
if (croppedFile != null && croppedFile.exists()) {
|
||||
croppedFile.delete();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("拼图照片裁剪失败,使用原图: memberId={}, scenicId={}, puzzleRecordId={}, url={}",
|
||||
memberId, scenicId, puzzleRecordId, resultImageUrl, e);
|
||||
// 出现异常则使用原图
|
||||
cropUrl = resultImageUrl;
|
||||
}
|
||||
|
||||
entity.setCropUrl(cropUrl);
|
||||
entity.setStatus(0);
|
||||
|
||||
Reference in New Issue
Block a user