feat(printer): 添加景区ID参数并优化用户照片打印去重逻辑

- 在价格计算请求中添加景区ID参数
- 实现用户照片按sourceId去重机制,避免重复添加相同照片
- 查询用户在景区的已有打印记录用于去重判断
- 优化普通照片打印商品项,添加设备ID属性信息
- 过滤无效数据并去重后生成设备ID属性列表
This commit is contained in:
2025-12-31 23:37:00 +08:00
parent 41e90bab9c
commit 81dc2f1b86

View File

@@ -460,6 +460,7 @@ public class PrinterServiceImpl implements PrinterService {
// 构建价格计算请求
PriceCalculationRequest request = new PriceCalculationRequest();
request.setUserId(memberId);
request.setScenicId(scenicId);
// 创建商品项列表
List<ProductItem> productItems = new ArrayList<>();
@@ -559,7 +560,27 @@ public class PrinterServiceImpl implements PrinterService {
@Override
public List<Integer> addUserPhotoFromSource(Long memberId, Long scenicId, FromSourceReq req, Long faceId) {
List<Integer> resultIds = new ArrayList<>();
// 预先查询用户在该景区的已有打印记录,用于去重
List<MemberPrintResp> existingPhotos = printerMapper.listRelationByFaceId(memberId, scenicId, faceId);
Map<Long, Integer> 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<String> 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);
}