feat(gao): point redemption in product stock list and detail

This commit is contained in:
Timi
2026-11-18 16:41:03 +08:00
parent 0166a5585b
commit ca87a273bc
3 changed files with 31 additions and 3 deletions
@@ -21,6 +21,9 @@ public interface GaoPointRedemptionMapper extends BaseMapper<GaoPointRedemption,
/// 按门店和 ID 查询兑换单 /// 按门店和 ID 查询兑换单
GaoPointRedemption selectByStoreIdAndId(@Param("storeId") String storeId, @Param("id") String id); GaoPointRedemption selectByStoreIdAndId(@Param("storeId") String storeId, @Param("id") String id);
/// 按 ID 列表查询兑换单
List<GaoPointRedemption> selectByIdList(@Param("idList") List<String> idList);
/// 锁定兑换单 /// 锁定兑换单
GaoPointRedemption selectForUpdate(@Param("id") String id); GaoPointRedemption selectForUpdate(@Param("id") String id);
@@ -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.common.service.AttachmentService;
import com.imyeyu.api.modules.gao.entity.GaoCustomer; import com.imyeyu.api.modules.gao.entity.GaoCustomer;
import com.imyeyu.api.modules.gao.entity.GaoOrderFulfillment; 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.entity.GaoProductStockRecord;
import com.imyeyu.api.modules.gao.mapper.GaoOrderFulfillmentMapper; 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.mapper.GaoProductStockRecordMapper;
import com.imyeyu.api.modules.gao.service.GaoCustomerService; import com.imyeyu.api.modules.gao.service.GaoCustomerService;
import com.imyeyu.api.modules.gao.service.GaoProductStockRecordService; import com.imyeyu.api.modules.gao.service.GaoProductStockRecordService;
@@ -36,6 +38,7 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService
private final GaoProductStockRecordMapper mapper; private final GaoProductStockRecordMapper mapper;
private final GaoOrderFulfillmentMapper orderFulfillmentMapper; private final GaoOrderFulfillmentMapper orderFulfillmentMapper;
private final GaoPointRedemptionMapper pointRedemptionMapper;
private final AttachmentService attachmentService; private final AttachmentService attachmentService;
private final GaoCustomerService customerService; private final GaoCustomerService customerService;
private final UserService userService; private final UserService userService;
@@ -158,8 +161,16 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService
Map<String, GaoOrderFulfillment> fulfillmentMap = fulfillmentIdList.isEmpty() Map<String, GaoOrderFulfillment> fulfillmentMap = fulfillmentIdList.isEmpty()
? Map.of() : orderFulfillmentMapper.selectByIdList(fulfillmentIdList).stream() ? Map.of() : orderFulfillmentMapper.selectByIdList(fulfillmentIdList).stream()
.collect(Collectors.toMap(GaoOrderFulfillment::getId, item -> item)); .collect(Collectors.toMap(GaoOrderFulfillment::getId, item -> item));
List<String> 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<String, GaoPointRedemption> redemptionMap = redemptionIdList.isEmpty()
? Map.of() : pointRedemptionMapper.selectByIdList(redemptionIdList).stream()
.collect(Collectors.toMap(GaoPointRedemption::getId, item -> item));
List<String> customerIdList = recordList.stream() List<String> customerIdList = recordList.stream()
.map(record -> getCustomerId(record, fulfillmentMap)) .map(record -> getCustomerId(record, fulfillmentMap, redemptionMap))
.filter(value -> value != null && !value.isBlank()) .filter(value -> value != null && !value.isBlank())
.distinct() .distinct()
.toList(); .toList();
@@ -173,7 +184,7 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService
operator.setAttachmentList(userAvatarMap.getOrDefault(operator.getId(), List.of())); operator.setAttachmentList(userAvatarMap.getOrDefault(operator.getId(), List.of()));
} }
record.setOperator(operator); record.setOperator(operator);
String customerId = getCustomerId(record, fulfillmentMap); String customerId = getCustomerId(record, fulfillmentMap, redemptionMap);
if (TimiJava.isEmpty(customerId)) { if (TimiJava.isEmpty(customerId)) {
continue; continue;
} }
@@ -185,7 +196,16 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService
} }
} }
private String getCustomerId(GaoProductStockRecord record, Map<String, GaoOrderFulfillment> fulfillmentMap) { private String getCustomerId(GaoProductStockRecord record, Map<String, GaoOrderFulfillment> fulfillmentMap,
Map<String, GaoPointRedemption> 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) { if (record.getBizType() != GaoProductStockRecord.BizType.ORDER_FULFILLMENT) {
return null; return null;
} }
@@ -11,6 +11,11 @@
WHERE `store_id` = #{storeId} AND `id` = #{id} AND `deleted_at` IS NULL WHERE `store_id` = #{storeId} AND `id` = #{id} AND `deleted_at` IS NULL
LIMIT 1 LIMIT 1
</select> </select>
<select id="selectByIdList" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
SELECT * FROM `gao_point_redemption`
WHERE `deleted_at` IS NULL AND `id` IN
<foreach collection="idList" item="id" open="(" separator="," close=")">#{id}</foreach>
</select>
<select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption"> <select id="selectForUpdate" resultType="com.imyeyu.api.modules.gao.entity.GaoPointRedemption">
SELECT * FROM `gao_point_redemption` SELECT * FROM `gao_point_redemption`
WHERE `id` = #{id} AND `deleted_at` IS NULL WHERE `id` = #{id} AND `deleted_at` IS NULL