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 a16a6f95..4c22772b 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 @@ -460,6 +460,7 @@ public class PrinterServiceImpl implements PrinterService { // 构建价格计算请求 PriceCalculationRequest request = new PriceCalculationRequest(); request.setUserId(memberId); + request.setScenicId(scenicId); // 创建商品项列表 List productItems = new ArrayList<>(); @@ -559,7 +560,27 @@ public class PrinterServiceImpl implements PrinterService { @Override public List addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req, Long faceId) { List resultIds = new ArrayList<>(); + + // 预先查询用户在该景区的已有打印记录,用于去重 + List existingPhotos = printerMapper.listRelationByFaceId(memberId, scenicId, faceId); + Map sourceIdToMemberPrintId = new HashMap<>(); + if (existingPhotos != null) { + for (MemberPrintResp photo : existingPhotos) { + if (photo.getSourceId() != null) { + sourceIdToMemberPrintId.put(photo.getSourceId(), photo.getId()); + } + } + } + req.getIds().forEach(id -> { + // 检查该sourceId是否已经添加过 + if (sourceIdToMemberPrintId.containsKey(id)) { + Integer existingId = sourceIdToMemberPrintId.get(id); + log.info("sourceId={}已存在于打印列表中,返回已有记录: memberPrintId={}", id, existingId); + resultIds.add(existingId); + return; + } + SourceRespVO byId = sourceMapper.getById(id); if (byId == null) { resultIds.add(null); @@ -738,12 +759,30 @@ public class PrinterServiceImpl implements PrinterService { // 添加普通照片打印商品项 (sourceId > 0) if (normalCount > 0) { + 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); + if (source == null) { + return null; + } + return source.getDeviceId(); + }) + .filter(Objects::nonNull) + .distinct() + .map(String::valueOf) + .toList(); + ProductItem normalPhotoItem = new ProductItem(); normalPhotoItem.setProductType(ProductType.PHOTO_PRINT); normalPhotoItem.setProductId(scenicId.toString()); normalPhotoItem.setQuantity(Long.valueOf(normalCount).intValue()); normalPhotoItem.setPurchaseCount(1); normalPhotoItem.setScenicId(scenicId.toString()); + normalPhotoItem.setAttributeKeys(normalAttrs); productItems.add(normalPhotoItem); log.debug("创建订单-普通照片打印数量: {}", normalCount); }