diff --git a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointRedemptionMapper.java b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointRedemptionMapper.java index d2c9e3f..f25f864 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointRedemptionMapper.java +++ b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoPointRedemptionMapper.java @@ -21,6 +21,9 @@ public interface GaoPointRedemptionMapper extends BaseMapper selectByIdList(@Param("idList") List idList); + /// 锁定兑换单 GaoPointRedemption selectForUpdate(@Param("id") String id); diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockRecordServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockRecordServiceImplement.java index bc55a4e..1a4ccf0 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockRecordServiceImplement.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoProductStockRecordServiceImplement.java @@ -4,8 +4,10 @@ import com.imyeyu.api.modules.common.entity.Attachment; import com.imyeyu.api.modules.common.service.AttachmentService; import com.imyeyu.api.modules.gao.entity.GaoCustomer; import com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment; +import com.imyeyu.api.modules.gao.entity.GaoPointRedemption; import com.imyeyu.api.modules.gao.entity.GaoProductStockRecord; import com.imyeyu.api.modules.gao.mapper.GaoOrderFulfillmentMapper; +import com.imyeyu.api.modules.gao.mapper.GaoPointRedemptionMapper; import com.imyeyu.api.modules.gao.mapper.GaoProductStockRecordMapper; import com.imyeyu.api.modules.gao.service.GaoCustomerService; import com.imyeyu.api.modules.gao.service.GaoProductStockRecordService; @@ -36,6 +38,7 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService private final GaoProductStockRecordMapper mapper; private final GaoOrderFulfillmentMapper orderFulfillmentMapper; + private final GaoPointRedemptionMapper pointRedemptionMapper; private final AttachmentService attachmentService; private final GaoCustomerService customerService; private final UserService userService; @@ -158,8 +161,16 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService Map fulfillmentMap = fulfillmentIdList.isEmpty() ? Map.of() : orderFulfillmentMapper.selectByIdList(fulfillmentIdList).stream() .collect(Collectors.toMap(GaoOrderFulfillment::getId, item -> item)); + List redemptionIdList = recordList.stream() + .filter(record -> record.getOperationType() == GaoProductStockRecord.OperationType.POINT_REDEMPTION_OUT + && record.getBizType() == GaoProductStockRecord.BizType.POINT_REDEMPTION) + .map(GaoProductStockRecord::getBizId) + .filter(value -> value != null && !value.isBlank()).distinct().toList(); + Map redemptionMap = redemptionIdList.isEmpty() + ? Map.of() : pointRedemptionMapper.selectByIdList(redemptionIdList).stream() + .collect(Collectors.toMap(GaoPointRedemption::getId, item -> item)); List customerIdList = recordList.stream() - .map(record -> getCustomerId(record, fulfillmentMap)) + .map(record -> getCustomerId(record, fulfillmentMap, redemptionMap)) .filter(value -> value != null && !value.isBlank()) .distinct() .toList(); @@ -173,7 +184,7 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService operator.setAttachmentList(userAvatarMap.getOrDefault(operator.getId(), List.of())); } record.setOperator(operator); - String customerId = getCustomerId(record, fulfillmentMap); + String customerId = getCustomerId(record, fulfillmentMap, redemptionMap); if (TimiJava.isEmpty(customerId)) { continue; } @@ -185,7 +196,16 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService } } - private String getCustomerId(GaoProductStockRecord record, Map fulfillmentMap) { + private String getCustomerId(GaoProductStockRecord record, Map fulfillmentMap, + Map redemptionMap) { + if (TimiJava.isEmpty(record.getBizId())) { + return null; + } + if (record.getOperationType() == GaoProductStockRecord.OperationType.POINT_REDEMPTION_OUT + && record.getBizType() == GaoProductStockRecord.BizType.POINT_REDEMPTION) { + GaoPointRedemption redemption = redemptionMap.get(record.getBizId()); + return redemption == null ? null : redemption.getCustomerId(); + } if (record.getBizType() != GaoProductStockRecord.BizType.ORDER_FULFILLMENT) { return null; } diff --git a/src/main/resources/mapper/timi-server/gao/GaoPointRedemptionMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoPointRedemptionMapper.xml index f333a99..f6dcf56 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoPointRedemptionMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoPointRedemptionMapper.xml @@ -11,6 +11,11 @@ WHERE `store_id` = #{storeId} AND `id` = #{id} AND `deleted_at` IS NULL LIMIT 1 +