feat(puzzle): 新增拼图功能模块

- 新增AppPuzzleController控制器,提供拼图相关接口
- 实现根据faceId查询拼图数量和记录列表功能
- 实现根据recordId查询拼图详情和下载拼图资源功能
- 实现拼图价格计算和导入打印列表功能
- 在FaceServiceImpl中集成拼图记录展示逻辑
- 在OrderServiceImpl中新增PHOTO_LOG产品类型处理
- 在PrinterService中实现从拼图添加到打印列表的功能
- 完善拼图记录转换为内容页面VO的逻辑处理
This commit is contained in:
2025-11-20 23:11:04 +08:00
parent d458f918ed
commit 9123a1f6db
5 changed files with 390 additions and 1 deletions

View File

@@ -1209,4 +1209,104 @@ public class PrinterServiceImpl implements PrinterService {
return selectedPrinter;
}
@Override
public Integer addUserPhotoFromPuzzle(Long memberId, Long scenicId, Long faceId, String resultImageUrl, Long puzzleRecordId) {
if (resultImageUrl == null || resultImageUrl.isEmpty()) {
log.error("拼图图片URL为空: memberId={}, scenicId={}, puzzleRecordId={}", memberId, scenicId, puzzleRecordId);
return null;
}
// 检查是否已经存在未打印的记录(status=0),避免重复导入
List<MemberPrintResp> existingPhotos = printerMapper.listRelationByFaceId(memberId, scenicId, faceId);
if (existingPhotos != null && !existingPhotos.isEmpty()) {
for (MemberPrintResp photo : existingPhotos) {
// 检查是否是同一个拼图记录且状态为0(未打印)
if (photo.getSourceId() != null && photo.getSourceId().equals(puzzleRecordId)
&& photo.getStatus() != null && photo.getStatus() == 0) {
log.info("拼图照片已存在于打印列表中,直接返回: memberId={}, scenicId={}, puzzleRecordId={}, memberPrintId={}",
memberId, scenicId, puzzleRecordId, photo.getId());
return photo.getId().intValue();
}
}
}
MemberPrintEntity entity = new MemberPrintEntity();
entity.setMemberId(memberId);
entity.setScenicId(scenicId);
entity.setFaceId(faceId);
entity.setSourceId(puzzleRecordId); // 使用拼图记录ID作为sourceId
entity.setOrigUrl(resultImageUrl);
// 获取打印尺寸并裁剪图片
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 = resultImageUrl.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);
try {
int rows = printerMapper.addUserPhoto(entity);
if (rows > 0 && entity.getId() != null) {
log.info("拼图照片添加到打印列表成功: memberId={}, scenicId={}, puzzleRecordId={}, memberPrintId={}",
memberId, scenicId, puzzleRecordId, entity.getId());
return entity.getId();
} else {
log.error("拼图照片添加到打印列表失败: memberId={}, scenicId={}, puzzleRecordId={}",
memberId, scenicId, puzzleRecordId);
return null;
}
} catch (Exception e) {
log.error("拼图照片添加到打印列表异常: memberId={}, scenicId={}, puzzleRecordId={}",
memberId, scenicId, puzzleRecordId, e);
return null;
}
}
}