fix(reporting-service): fix planting.order.paid event message format
planting-service 发送的消息是直接数据格式,不包含 payload 包装, 修正 ActivityEventConsumerController 以适配实际消息格式。 🤖 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
229dff1a9d
commit
49cdeb4aef
|
|
@ -67,23 +67,16 @@ interface AuthorizationRoleEvent {
|
||||||
/**
|
/**
|
||||||
* 认种订单支付事件 (planting-service)
|
* 认种订单支付事件 (planting-service)
|
||||||
* Topic: planting.order.paid
|
* Topic: planting.order.paid
|
||||||
|
* 注意:planting-service 发送的消息是直接数据,不包含 payload 包装
|
||||||
*/
|
*/
|
||||||
interface PlantingOrderPaidEvent {
|
interface PlantingOrderPaidEvent {
|
||||||
eventId: string;
|
orderId: string;
|
||||||
eventType: string;
|
userId: string;
|
||||||
occurredAt: string;
|
treeCount: number;
|
||||||
aggregateId: string;
|
provinceCode?: string;
|
||||||
payload: {
|
cityCode?: string;
|
||||||
orderId: string;
|
totalAmount?: string;
|
||||||
orderNumber: string;
|
paidAt: string;
|
||||||
userId: string;
|
|
||||||
treeCount: number;
|
|
||||||
provinceCode?: string;
|
|
||||||
cityCode?: string;
|
|
||||||
totalAmount: string;
|
|
||||||
paidAt: string;
|
|
||||||
};
|
|
||||||
_outbox?: OutboxMeta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
|
|
@ -250,42 +243,44 @@ export class ActivityEventConsumerController {
|
||||||
/**
|
/**
|
||||||
* 监听认种订单支付成功事件 (planting-service)
|
* 监听认种订单支付成功事件 (planting-service)
|
||||||
* Topic: planting.order.paid
|
* Topic: planting.order.paid
|
||||||
|
* 注意:planting-service 发送的消息是直接数据,不包含 payload 包装
|
||||||
*/
|
*/
|
||||||
@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`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { payload } = message;
|
// planting-service 直接发送数据,不包装在 payload 中
|
||||||
|
const data = message;
|
||||||
|
|
||||||
// 记录活动日志
|
// 记录活动日志
|
||||||
await this.activityRepo.create({
|
await this.activityRepo.create({
|
||||||
activityType: 'planting_order' as ActivityType,
|
activityType: 'planting_order' as ActivityType,
|
||||||
title: '认种订单',
|
title: '认种订单',
|
||||||
description: `用户认种了 ${payload.treeCount} 棵榴莲树`,
|
description: `用户认种了 ${data.treeCount} 棵榴莲树`,
|
||||||
icon: '🌳',
|
icon: '🌳',
|
||||||
relatedUserId: BigInt(payload.userId),
|
relatedUserId: BigInt(data.userId),
|
||||||
relatedEntityType: 'order',
|
relatedEntityType: 'order',
|
||||||
relatedEntityId: payload.orderId,
|
relatedEntityId: data.orderId,
|
||||||
metadata: {
|
metadata: {
|
||||||
orderNumber: payload.orderNumber,
|
orderId: data.orderId,
|
||||||
treeCount: payload.treeCount,
|
treeCount: data.treeCount,
|
||||||
totalAmount: payload.totalAmount,
|
totalAmount: data.totalAmount,
|
||||||
provinceCode: payload.provinceCode,
|
provinceCode: data.provinceCode,
|
||||||
cityCode: payload.cityCode,
|
cityCode: data.cityCode,
|
||||||
paidAt: payload.paidAt,
|
paidAt: data.paidAt,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 累加统计数据
|
// 累加统计数据
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const amount = new Decimal(payload.totalAmount || '0');
|
const amount = new Decimal(data.totalAmount || '0');
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.realtimeStatsRepo.incrementPlanting(today, payload.treeCount, amount),
|
this.realtimeStatsRepo.incrementPlanting(today, data.treeCount, amount),
|
||||||
this.globalStatsRepo.incrementPlanting(payload.treeCount, amount),
|
this.globalStatsRepo.incrementPlanting(data.treeCount, amount),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.logger.log(`Activity and stats recorded for planting order: ${payload.orderId}`);
|
this.logger.log(`Activity and stats recorded for planting order: ${data.orderId}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error recording planting order activity:`, error);
|
this.logger.error(`Error recording planting order activity:`, error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue