From 991a8b10e33a1a21bfd9ae20fe082b57f08966a4 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 30 Dec 2025 17:49:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(printer):=20=E8=A7=A3=E5=86=B3=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=B1=BB=E5=9E=8B=E8=AE=BE=E7=BD=AE=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加source为空时的图片类型判断逻辑 - 当source为空时将图片类型设置为PUZZLE - 保持原有source不为空时的IPC类型设置逻辑 - 确保PHONE类型的设置逻辑不受影响 --- .../printer/impl/PrinterServiceImpl.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java b/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java index 4ec52000..10351136 100644 --- a/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java @@ -400,17 +400,20 @@ public class PrinterServiceImpl implements PrinterService { obj.setGoodsType(3); // 按照 sourceId 分类照片 - // sourceId > 0: 普通照片打印 (PHOTO_PRINT) + // sourceId > 0 且 source 表存在: 普通照片打印 (PHOTO_PRINT) + // sourceId > 0 且 source 表不存在: 拼图打印 (PUZZLE),归类为特效照片价格 // sourceId == null: 手机照片打印 (PHOTO_PRINT_MU) // sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX) long normalCount = 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(); List normalAttrs = userPhotoList.stream() .filter(item -> Objects.nonNull(item.getQuantity()) && item.getSourceId() != null && item.getSourceId() > 0) + .filter(item -> sourceMapper.getById(item.getSourceId()) != null) .map(MemberPrintResp::getSourceId) .map(id -> { SourceEntity source = sourceRepository.getSource(id); @@ -436,7 +439,15 @@ public class PrinterServiceImpl implements PrinterService { .mapToInt(MemberPrintResp::getQuantity) .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) { // 如果没有照片,返回零价格 @@ -479,15 +490,15 @@ public class PrinterServiceImpl implements PrinterService { } // 添加特效照片打印商品项 (sourceId == 0) - if (effectCount > 0) { + if (effectCount > 0 || puzzleCount > 0) { ProductItem effectPhotoItem = new ProductItem(); effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX); effectPhotoItem.setProductId(scenicId.toString()); - effectPhotoItem.setQuantity(Long.valueOf(effectCount).intValue()); + effectPhotoItem.setQuantity(Long.valueOf(effectCount + puzzleCount).intValue()); effectPhotoItem.setPurchaseCount(1); effectPhotoItem.setScenicId(scenicId.toString()); productItems.add(effectPhotoItem); - log.debug("特效照片打印数量: {}", effectCount); + log.debug("特效照片打印数量: {}", effectCount + puzzleCount); } request.setProducts(productItems); @@ -660,12 +671,14 @@ public class PrinterServiceImpl implements PrinterService { List userPhotoList = getUserPhotoList(memberId, scenicId, faceId); // 按照 sourceId 分类照片 - // sourceId > 0: 普通照片打印 (PHOTO_PRINT) + // sourceId > 0 且 source 表存在: 普通照片打印 (PHOTO_PRINT) + // sourceId > 0 且 source 表不存在: 拼图打印 (PUZZLE),归类为特效照片价格 // sourceId == null: 手机照片打印 (PHOTO_PRINT_MU) // sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX) long normalCount = 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(); @@ -681,7 +694,14 @@ public class PrinterServiceImpl implements PrinterService { .mapToInt(MemberPrintResp::getQuantity) .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) { throw new BaseException("没有可打印的照片"); @@ -741,15 +761,15 @@ public class PrinterServiceImpl implements PrinterService { } // 添加特效照片打印商品项 (sourceId == 0) - if (effectCount > 0) { + if (effectCount > 0 || puzzleCount > 0) { ProductItem effectPhotoItem = new ProductItem(); effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX); effectPhotoItem.setProductId(scenicId.toString()); - effectPhotoItem.setQuantity(Long.valueOf(effectCount).intValue()); + effectPhotoItem.setQuantity(Long.valueOf(effectCount + puzzleCount).intValue()); effectPhotoItem.setPurchaseCount(1); effectPhotoItem.setScenicId(scenicId.toString()); productItems.add(effectPhotoItem); - log.debug("创建订单-特效照片打印数量: {}", effectCount); + log.debug("创建订单-特效照片打印数量: {}", effectCount + puzzleCount); } request.setProducts(productItems);