fix(reporting): remove userId dependency in planting.order.paid handler

- 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 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-05 00:05:56 -08:00
parent 0f3c26c6fa
commit 66ace25935
1 changed files with 7 additions and 3 deletions

View File

@ -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,