fix(printer): 解决图片类型设置逻辑问题

- 添加source为空时的图片类型判断逻辑
- 当source为空时将图片类型设置为PUZZLE
- 保持原有source不为空时的IPC类型设置逻辑
- 确保PHONE类型的设置逻辑不受影响
This commit is contained in:
2025-12-30 17:49:39 +08:00
parent ab1e8cf7ef
commit 991a8b10e3

View File

@@ -400,17 +400,20 @@ public class PrinterServiceImpl implements PrinterService {
obj.setGoodsType(3); obj.setGoodsType(3);
// 按照 sourceId 分类照片 // 按照 sourceId 分类照片
// sourceId > 0: 普通照片打印 (PHOTO_PRINT) // sourceId > 0 且 source 表存在: 普通照片打印 (PHOTO_PRINT)
// sourceId > 0 且 source 表不存在: 拼图打印 (PUZZLE),归类为特效照片价格
// sourceId == null: 手机照片打印 (PHOTO_PRINT_MU) // sourceId == null: 手机照片打印 (PHOTO_PRINT_MU)
// sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX) // sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX)
long normalCount = userPhotoList.stream() long normalCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity()) .filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0) && item.getSourceId() != null && item.getSourceId() > 0)
.filter(item -> sourceMapper.getById(item.getSourceId()) != null)
.mapToInt(MemberPrintResp::getQuantity) .mapToInt(MemberPrintResp::getQuantity)
.sum(); .sum();
List<String> normalAttrs = userPhotoList.stream() List<String> normalAttrs = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity()) .filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0) && item.getSourceId() != null && item.getSourceId() > 0)
.filter(item -> sourceMapper.getById(item.getSourceId()) != null)
.map(MemberPrintResp::getSourceId) .map(MemberPrintResp::getSourceId)
.map(id -> { .map(id -> {
SourceEntity source = sourceRepository.getSource(id); SourceEntity source = sourceRepository.getSource(id);
@@ -436,7 +439,15 @@ public class PrinterServiceImpl implements PrinterService {
.mapToInt(MemberPrintResp::getQuantity) .mapToInt(MemberPrintResp::getQuantity)
.sum(); .sum();
long totalCount = normalCount + mobileCount + effectCount; // 拼图:sourceId > 0 但 source 表中不存在(即来自 puzzle_generation_record 表)
long puzzleCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0)
.filter(item -> sourceMapper.getById(item.getSourceId()) == null)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long totalCount = normalCount + mobileCount + effectCount + puzzleCount;
if (totalCount == 0) { if (totalCount == 0) {
// 如果没有照片,返回零价格 // 如果没有照片,返回零价格
@@ -479,15 +490,15 @@ public class PrinterServiceImpl implements PrinterService {
} }
// 添加特效照片打印商品项 (sourceId == 0) // 添加特效照片打印商品项 (sourceId == 0)
if (effectCount > 0) { if (effectCount > 0 || puzzleCount > 0) {
ProductItem effectPhotoItem = new ProductItem(); ProductItem effectPhotoItem = new ProductItem();
effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX); effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX);
effectPhotoItem.setProductId(scenicId.toString()); effectPhotoItem.setProductId(scenicId.toString());
effectPhotoItem.setQuantity(Long.valueOf(effectCount).intValue()); effectPhotoItem.setQuantity(Long.valueOf(effectCount + puzzleCount).intValue());
effectPhotoItem.setPurchaseCount(1); effectPhotoItem.setPurchaseCount(1);
effectPhotoItem.setScenicId(scenicId.toString()); effectPhotoItem.setScenicId(scenicId.toString());
productItems.add(effectPhotoItem); productItems.add(effectPhotoItem);
log.debug("特效照片打印数量: {}", effectCount); log.debug("特效照片打印数量: {}", effectCount + puzzleCount);
} }
request.setProducts(productItems); request.setProducts(productItems);
@@ -660,12 +671,14 @@ public class PrinterServiceImpl implements PrinterService {
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId); List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId);
// 按照 sourceId 分类照片 // 按照 sourceId 分类照片
// sourceId > 0: 普通照片打印 (PHOTO_PRINT) // sourceId > 0 且 source 表存在: 普通照片打印 (PHOTO_PRINT)
// sourceId > 0 且 source 表不存在: 拼图打印 (PUZZLE),归类为特效照片价格
// sourceId == null: 手机照片打印 (PHOTO_PRINT_MU) // sourceId == null: 手机照片打印 (PHOTO_PRINT_MU)
// sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX) // sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX)
long normalCount = userPhotoList.stream() long normalCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity()) .filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0) && item.getSourceId() != null && item.getSourceId() > 0)
.filter(item -> sourceMapper.getById(item.getSourceId()) != null)
.mapToInt(MemberPrintResp::getQuantity) .mapToInt(MemberPrintResp::getQuantity)
.sum(); .sum();
@@ -681,7 +694,14 @@ public class PrinterServiceImpl implements PrinterService {
.mapToInt(MemberPrintResp::getQuantity) .mapToInt(MemberPrintResp::getQuantity)
.sum(); .sum();
long totalCount = normalCount + mobileCount + effectCount; // 拼图:sourceId > 0 但 source 表中不存在(即来自 puzzle_generation_record 表)
long puzzleCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0)
.filter(item -> sourceMapper.getById(item.getSourceId()) == null)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long totalCount = normalCount + mobileCount + effectCount + puzzleCount;
if (totalCount == 0) { if (totalCount == 0) {
throw new BaseException("没有可打印的照片"); throw new BaseException("没有可打印的照片");
@@ -741,15 +761,15 @@ public class PrinterServiceImpl implements PrinterService {
} }
// 添加特效照片打印商品项 (sourceId == 0) // 添加特效照片打印商品项 (sourceId == 0)
if (effectCount > 0) { if (effectCount > 0 || puzzleCount > 0) {
ProductItem effectPhotoItem = new ProductItem(); ProductItem effectPhotoItem = new ProductItem();
effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX); effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX);
effectPhotoItem.setProductId(scenicId.toString()); effectPhotoItem.setProductId(scenicId.toString());
effectPhotoItem.setQuantity(Long.valueOf(effectCount).intValue()); effectPhotoItem.setQuantity(Long.valueOf(effectCount + puzzleCount).intValue());
effectPhotoItem.setPurchaseCount(1); effectPhotoItem.setPurchaseCount(1);
effectPhotoItem.setScenicId(scenicId.toString()); effectPhotoItem.setScenicId(scenicId.toString());
productItems.add(effectPhotoItem); productItems.add(effectPhotoItem);
log.debug("创建订单-特效照片打印数量: {}", effectCount); log.debug("创建订单-特效照片打印数量: {}", effectCount + puzzleCount);
} }
request.setProducts(productItems); request.setProducts(productItems);