You've already forked FrameTour-BE
feat(printer): 优化拼图打印逻辑并调整日期格式
- 调整AppPuzzleController中recordId参数为固定值0L - 修改FaceMatchingOrchestrator中的日期格式为"yyyy.MM.dd" - 完善PrinterServiceImpl水印处理条件判断 - 新增针对sourceId为0时的拼图照片偏移处理逻辑 - 修复重复打印检查逻辑,使用resultImageUrl代替puzzleRecordId比较 - 增强异常处理和日志记录,提升系统稳定性
This commit is contained in:
@@ -165,7 +165,7 @@ public class AppPuzzleController {
|
|||||||
face.getScenicId(),
|
face.getScenicId(),
|
||||||
record.getFaceId(),
|
record.getFaceId(),
|
||||||
resultImageUrl,
|
resultImageUrl,
|
||||||
recordId
|
0L // 打印特有
|
||||||
);
|
);
|
||||||
|
|
||||||
if (memberPrintId == null) {
|
if (memberPrintId == null) {
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ public class FaceMatchingOrchestrator {
|
|||||||
baseDynamicData.put("faceId", String.valueOf(faceId));
|
baseDynamicData.put("faceId", String.valueOf(faceId));
|
||||||
baseDynamicData.put("scenicName", scenicBasic.getName());
|
baseDynamicData.put("scenicName", scenicBasic.getName());
|
||||||
baseDynamicData.put("scenicText", scenicBasic.getName());
|
baseDynamicData.put("scenicText", scenicBasic.getName());
|
||||||
baseDynamicData.put("dateStr", DateUtil.format(new Date(), "yyyy-MM-dd"));
|
baseDynamicData.put("dateStr", DateUtil.format(new Date(), "yyyy.MM.dd"));
|
||||||
|
|
||||||
// 遍历所有模板,逐个生成
|
// 遍历所有模板,逐个生成
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
|
|||||||
@@ -755,7 +755,7 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
PrinterEntity printer = printerMapper.getById(item.getPrinterId());
|
PrinterEntity printer = printerMapper.getById(item.getPrinterId());
|
||||||
// 水印处理逻辑(仅当sourceId不为空时执行)
|
// 水印处理逻辑(仅当sourceId不为空时执行)
|
||||||
String printUrl = item.getCropUrl();
|
String printUrl = item.getCropUrl();
|
||||||
if (item.getSourceId() != null) {
|
if (item.getSourceId() != null && item.getSourceId() > 0) {
|
||||||
try {
|
try {
|
||||||
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(item.getScenicId());
|
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(item.getScenicId());
|
||||||
String printWatermarkType = scenicConfig.getString("print_watermark_type");
|
String printWatermarkType = scenicConfig.getString("print_watermark_type");
|
||||||
@@ -863,6 +863,55 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取景区配置失败,使用原始照片进行打印。景区ID: {}, 照片ID: {}", item.getScenicId(), item.getId(), e);
|
log.error("获取景区配置失败,使用原始照片进行打印。景区ID: {}, 照片ID: {}", item.getScenicId(), item.getId(), e);
|
||||||
}
|
}
|
||||||
|
} else if (item.getSourceId() != null && item.getSourceId() == 0) {
|
||||||
|
// 拼图:向上移动40像素以避免打印机偏移
|
||||||
|
try {
|
||||||
|
// 生成唯一的处理标识符,避免多线程环境下的文件冲突
|
||||||
|
String processId = item.getId() + "_" + UUID.randomUUID().toString();
|
||||||
|
File originalFile = new File("puzzle_" + processId + ".png");
|
||||||
|
File shiftedFile = new File("puzzle_" + processId + "_shifted.png");
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 下载原图
|
||||||
|
HttpUtil.downloadFile(item.getCropUrl(), originalFile);
|
||||||
|
|
||||||
|
// 向上偏移40像素
|
||||||
|
ImageUtils.shiftImageUp(originalFile, shiftedFile, 40);
|
||||||
|
|
||||||
|
// 上传处理后的图片
|
||||||
|
IStorageAdapter adapter;
|
||||||
|
ScenicConfigManager scenicConfig = scenicRepository.getScenicConfigManager(item.getScenicId());
|
||||||
|
String storeType = scenicConfig.getString("store_type");
|
||||||
|
if (storeType != null) {
|
||||||
|
adapter = StorageFactory.get(storeType);
|
||||||
|
String storeConfigJson = scenicConfig.getString("store_config_json");
|
||||||
|
if (StringUtils.isNotBlank(storeConfigJson)) {
|
||||||
|
adapter.loadConfig(JacksonUtil.parseObject(storeConfigJson, Map.class));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
adapter = StorageFactory.use("assets-ext");
|
||||||
|
}
|
||||||
|
|
||||||
|
String shiftedUrl = adapter.uploadFile(null, shiftedFile, StorageConstant.PHOTO_WATERMARKED_PATH, shiftedFile.getName());
|
||||||
|
adapter.setAcl(StorageAcl.PUBLIC_READ, StorageConstant.PHOTO_WATERMARKED_PATH, shiftedFile.getName());
|
||||||
|
|
||||||
|
printUrl = shiftedUrl;
|
||||||
|
log.info("拼图照片向上偏移40像素成功,照片ID: {}, 新URL: {}", item.getId(), shiftedUrl);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("拼图照片向上偏移处理失败,使用原始照片进行打印。照片ID: {}", item.getId(), e);
|
||||||
|
} finally {
|
||||||
|
// 清理临时文件
|
||||||
|
if (originalFile != null && originalFile.exists()) {
|
||||||
|
originalFile.delete();
|
||||||
|
}
|
||||||
|
if (shiftedFile != null && shiftedFile.exists()) {
|
||||||
|
shiftedFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("拼图照片处理失败,使用原始照片进行打印。照片ID: {}", item.getId(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据数量创建多个打印任务
|
// 根据数量创建多个打印任务
|
||||||
@@ -1222,11 +1271,11 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
if (existingPhotos != null && !existingPhotos.isEmpty()) {
|
if (existingPhotos != null && !existingPhotos.isEmpty()) {
|
||||||
for (MemberPrintResp photo : existingPhotos) {
|
for (MemberPrintResp photo : existingPhotos) {
|
||||||
// 检查是否是同一个拼图记录且状态为0(未打印)
|
// 检查是否是同一个拼图记录且状态为0(未打印)
|
||||||
if (photo.getSourceId() != null && photo.getSourceId().equals(puzzleRecordId)
|
if (photo.getOrigUrl() != null && photo.getOrigUrl().equals(resultImageUrl)
|
||||||
&& photo.getStatus() != null && photo.getStatus() == 0) {
|
&& photo.getStatus() != null && photo.getStatus() == 0) {
|
||||||
log.info("拼图照片已存在于打印列表中,直接返回: memberId={}, scenicId={}, puzzleRecordId={}, memberPrintId={}",
|
log.info("拼图照片已存在于打印列表中,直接返回: memberId={}, scenicId={}, puzzleRecordId={}, memberPrintId={}",
|
||||||
memberId, scenicId, puzzleRecordId, photo.getId());
|
memberId, scenicId, puzzleRecordId, photo.getId());
|
||||||
return photo.getId().intValue();
|
return photo.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user