From 66ace2593527c7e9123f3ec60b60fe37d6ca7ff0 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 5 Jan 2026 00:05:56 -0800 Subject: [PATCH] fix(reporting): remove userId dependency in planting.order.paid handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change userId to optional in PlantingOrderPaidEvent interface - Add accountSequence field for user identification - Remove relatedUserId from activity creation (was causing BigInt error) - Store accountSequence in metadata instead Fixes: TypeError: Cannot convert undefined to a BigInt 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../kafka/activity-event-consumer.controller.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/services/reporting-service/src/infrastructure/kafka/activity-event-consumer.controller.ts b/backend/services/reporting-service/src/infrastructure/kafka/activity-event-consumer.controller.ts index a90afc62..53dc58b9 100644 --- a/backend/services/reporting-service/src/infrastructure/kafka/activity-event-consumer.controller.ts +++ b/backend/services/reporting-service/src/infrastructure/kafka/activity-event-consumer.controller.ts @@ -68,10 +68,12 @@ interface AuthorizationRoleEvent { * 认种订单支付事件 (planting-service) * Topic: planting.order.paid * 注意:planting-service 发送的消息是直接数据,不包含 payload 包装 + * [2026-01-05] 更新:移除 userId 依赖,改用 accountSequence */ interface PlantingOrderPaidEvent { orderId: string; - userId: string; + userId?: string; // 可能为空,不依赖此字段 + accountSequence?: string; // 用户账户序列号 treeCount: number; provinceCode?: string; cityCode?: string; @@ -244,6 +246,7 @@ export class ActivityEventConsumerController { * 监听认种订单支付成功事件 (planting-service) * Topic: planting.order.paid * 注意:planting-service 发送的消息是直接数据,不包含 payload 包装 + * [2026-01-05] 更新:移除 relatedUserId,改用 accountSequence 存入 metadata */ @MessagePattern('planting.order.paid') async handlePlantingOrderPaid(@Payload() message: PlantingOrderPaidEvent) { @@ -253,17 +256,18 @@ export class ActivityEventConsumerController { // planting-service 直接发送数据,不包装在 payload 中 const data = message; - // 记录活动日志 + // 记录活动日志 - 不依赖 userId,使用 accountSequence await this.activityRepo.create({ activityType: 'planting_order' as ActivityType, title: '认种订单', description: `用户认种了 ${data.treeCount} 棵榴莲树`, icon: '🌳', - relatedUserId: BigInt(data.userId), + // 不设置 relatedUserId,因为 userId 可能为空 relatedEntityType: 'order', relatedEntityId: data.orderId, metadata: { orderId: data.orderId, + accountSequence: data.accountSequence, treeCount: data.treeCount, totalAmount: data.totalAmount, provinceCode: data.provinceCode,