fix(reporting-service): 兼容 referral-service 的认种事件格式
- planting.order.paid 事件现在由 referral-service 发送
- 消息格式为 { eventName, data: {...} },与原 planting-service 格式不同
- 添加兼容逻辑,同时支持两种格式
- 修复今日认种统计为0的问题
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c7c793f128
commit
84aa8181a9
|
|
@ -65,15 +65,31 @@ interface AuthorizationRoleEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 认种订单支付事件 (planting-service)
|
* 认种订单支付事件 (referral-service 或 planting-service)
|
||||||
* Topic: planting.order.paid
|
* Topic: planting.order.paid
|
||||||
* 注意:planting-service 发送的消息是直接数据,不包含 payload 包装
|
* [2026-01-07] 更新:兼容两种消息格式
|
||||||
* [2026-01-05] 更新:移除 userId 依赖,改用 accountSequence
|
* - referral-service 发送: { eventName, data: {...} }
|
||||||
|
* - planting-service 发送: { orderId, treeCount, ... } (直接数据)
|
||||||
*/
|
*/
|
||||||
interface PlantingOrderPaidEvent {
|
interface PlantingOrderPaidEvent {
|
||||||
|
// referral-service 格式
|
||||||
|
eventName?: string;
|
||||||
|
data?: PlantingOrderPaidData;
|
||||||
|
// planting-service 直接格式
|
||||||
|
orderId?: string;
|
||||||
|
userId?: string;
|
||||||
|
accountSequence?: string;
|
||||||
|
treeCount?: number;
|
||||||
|
provinceCode?: string;
|
||||||
|
cityCode?: string;
|
||||||
|
totalAmount?: string;
|
||||||
|
paidAt?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlantingOrderPaidData {
|
||||||
orderId: string;
|
orderId: string;
|
||||||
userId?: string; // 可能为空,不依赖此字段
|
userId?: string;
|
||||||
accountSequence?: string; // 用户账户序列号
|
accountSequence?: string;
|
||||||
treeCount: number;
|
treeCount: number;
|
||||||
provinceCode?: string;
|
provinceCode?: string;
|
||||||
cityCode?: string;
|
cityCode?: string;
|
||||||
|
|
@ -243,18 +259,28 @@ export class ActivityEventConsumerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监听认种订单支付成功事件 (planting-service)
|
* 监听认种订单支付成功事件 (referral-service 或 planting-service)
|
||||||
* Topic: planting.order.paid
|
* Topic: planting.order.paid
|
||||||
* 注意:planting-service 发送的消息是直接数据,不包含 payload 包装
|
* [2026-01-07] 更新:兼容两种消息格式
|
||||||
* [2026-01-05] 更新:移除 relatedUserId,改用 accountSequence 存入 metadata
|
* - referral-service: { eventName, data: {...} }
|
||||||
|
* - planting-service: { orderId, treeCount, ... }
|
||||||
*/
|
*/
|
||||||
@MessagePattern('planting.order.paid')
|
@MessagePattern('planting.order.paid')
|
||||||
async handlePlantingOrderPaid(@Payload() message: PlantingOrderPaidEvent) {
|
async handlePlantingOrderPaid(@Payload() message: PlantingOrderPaidEvent) {
|
||||||
this.logger.log(`Received planting.order.paid event`);
|
this.logger.log(`Received planting.order.paid event: ${JSON.stringify(message).substring(0, 200)}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// planting-service 直接发送数据,不包装在 payload 中
|
// [2026-01-07] 兼容两种格式:referral-service 的 data 包装格式和 planting-service 的直接格式
|
||||||
const data = message;
|
const data: PlantingOrderPaidData = message.data || {
|
||||||
|
orderId: message.orderId || '',
|
||||||
|
userId: message.userId,
|
||||||
|
accountSequence: message.accountSequence,
|
||||||
|
treeCount: message.treeCount || 0,
|
||||||
|
provinceCode: message.provinceCode,
|
||||||
|
cityCode: message.cityCode,
|
||||||
|
totalAmount: message.totalAmount,
|
||||||
|
paidAt: message.paidAt || new Date().toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
// 记录活动日志 - 不依赖 userId,使用 accountSequence
|
// 记录活动日志 - 不依赖 userId,使用 accountSequence
|
||||||
await this.activityRepo.create({
|
await this.activityRepo.create({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue