fix(reporting-service): 修复授权事件区域名称显示 undefined
不同授权事件使用不同的字段名: - province 事件:provinceCode/provinceName - city 事件:cityCode/cityName - community 事件:communityName - 通用:regionCode/regionName 现在正确处理所有变体,避免显示 "undefined undefined 完成授权" 🤖 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
1676e82cc6
commit
347e5ce3de
|
|
@ -54,12 +54,19 @@ interface AuthorizationRoleEvent {
|
||||||
payload: {
|
payload: {
|
||||||
authorizationId?: string;
|
authorizationId?: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
accountSequence: string;
|
accountSequence?: string;
|
||||||
roleType: string;
|
roleType?: string;
|
||||||
regionCode: string;
|
// 不同事件类型使用不同的字段名
|
||||||
regionName: string;
|
regionCode?: string;
|
||||||
|
regionName?: string;
|
||||||
|
provinceCode?: string;
|
||||||
|
provinceName?: string;
|
||||||
|
cityCode?: string;
|
||||||
|
cityName?: string;
|
||||||
|
communityName?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
authorizedAt?: string;
|
authorizedAt?: string;
|
||||||
|
authorizedBy?: string | null;
|
||||||
};
|
};
|
||||||
_outbox?: OutboxMeta;
|
_outbox?: OutboxMeta;
|
||||||
}
|
}
|
||||||
|
|
@ -223,23 +230,38 @@ export class ActivityEventConsumerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据事件类型决定是否记录活动
|
// 根据事件类型决定是否记录活动
|
||||||
if (eventType.includes('authorized') || eventType.includes('Authorized')) {
|
if (eventType.includes('authorized') || eventType.includes('Authorized') || eventType.includes('granted')) {
|
||||||
const roleTypeLabel = this.getRoleTypeLabel(payload.roleType);
|
const roleTypeLabel = this.getRoleTypeLabel(payload.roleType);
|
||||||
const entityId = payload.authorizationId || message.aggregateId;
|
const entityId = payload.authorizationId || message.aggregateId;
|
||||||
|
|
||||||
|
// 从不同事件类型中提取区域信息
|
||||||
|
// - province 事件使用 provinceCode/provinceName
|
||||||
|
// - city 事件使用 cityCode/cityName
|
||||||
|
// - community 事件使用 communityName
|
||||||
|
// - 其他使用 regionCode/regionName
|
||||||
|
const regionCode =
|
||||||
|
payload.regionCode || payload.provinceCode || payload.cityCode || '';
|
||||||
|
const regionName =
|
||||||
|
payload.regionName ||
|
||||||
|
payload.provinceName ||
|
||||||
|
payload.cityName ||
|
||||||
|
payload.communityName ||
|
||||||
|
regionCode ||
|
||||||
|
'未知区域';
|
||||||
|
|
||||||
// 幂等创建活动日志(如果已存在则跳过)
|
// 幂等创建活动日志(如果已存在则跳过)
|
||||||
const created = await this.activityRepo.createIfNotExists({
|
const created = await this.activityRepo.createIfNotExists({
|
||||||
activityType: 'company_authorization' as ActivityType,
|
activityType: 'company_authorization' as ActivityType,
|
||||||
title: '授权成功',
|
title: '授权成功',
|
||||||
description: `${payload.regionName} ${roleTypeLabel} 完成授权`,
|
description: `${regionName} ${roleTypeLabel} 完成授权`,
|
||||||
icon: '🏢',
|
icon: '🏢',
|
||||||
relatedUserId: BigInt(payload.userId),
|
relatedUserId: BigInt(payload.userId),
|
||||||
relatedEntityType: 'authorization',
|
relatedEntityType: 'authorization',
|
||||||
relatedEntityId: entityId,
|
relatedEntityId: entityId,
|
||||||
metadata: {
|
metadata: {
|
||||||
roleType: payload.roleType,
|
roleType: payload.roleType,
|
||||||
regionCode: payload.regionCode,
|
regionCode: regionCode,
|
||||||
regionName: payload.regionName,
|
regionName: regionName,
|
||||||
accountSequence: payload.accountSequence,
|
accountSequence: payload.accountSequence,
|
||||||
authorizedAt: payload.authorizedAt || message.occurredAt,
|
authorizedAt: payload.authorizedAt || message.occurredAt,
|
||||||
},
|
},
|
||||||
|
|
@ -260,13 +282,13 @@ export class ActivityEventConsumerController {
|
||||||
this.realtimeStatsRepo.incrementProvinceAuth(today),
|
this.realtimeStatsRepo.incrementProvinceAuth(today),
|
||||||
this.globalStatsRepo.incrementProvinceCompany(),
|
this.globalStatsRepo.incrementProvinceCompany(),
|
||||||
]);
|
]);
|
||||||
this.logger.log(`Province company stats incremented: ${payload.regionCode}`);
|
this.logger.log(`Province company stats incremented: ${regionCode}`);
|
||||||
} else if (isCityCompany) {
|
} else if (isCityCompany) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.realtimeStatsRepo.incrementCityAuth(today),
|
this.realtimeStatsRepo.incrementCityAuth(today),
|
||||||
this.globalStatsRepo.incrementCityCompany(),
|
this.globalStatsRepo.incrementCityCompany(),
|
||||||
]);
|
]);
|
||||||
this.logger.log(`City company stats incremented: ${payload.regionCode}`);
|
this.logger.log(`City company stats incremented: ${regionCode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log(`Activity and stats recorded for authorization: ${payload.accountSequence}`);
|
this.logger.log(`Activity and stats recorded for authorization: ${payload.accountSequence}`);
|
||||||
|
|
@ -287,10 +309,21 @@ export class ActivityEventConsumerController {
|
||||||
const { payload, aggregateId } = message;
|
const { payload, aggregateId } = message;
|
||||||
const roleTypeLabel = this.getRoleTypeLabel(payload.roleType);
|
const roleTypeLabel = this.getRoleTypeLabel(payload.roleType);
|
||||||
|
|
||||||
|
// 从不同事件类型中提取区域信息
|
||||||
|
const regionCode =
|
||||||
|
payload.regionCode || payload.provinceCode || payload.cityCode || '';
|
||||||
|
const regionName =
|
||||||
|
payload.regionName ||
|
||||||
|
payload.provinceName ||
|
||||||
|
payload.cityName ||
|
||||||
|
payload.communityName ||
|
||||||
|
regionCode ||
|
||||||
|
'未知区域';
|
||||||
|
|
||||||
const created = await this.activityRepo.createIfNotExists({
|
const created = await this.activityRepo.createIfNotExists({
|
||||||
activityType: 'benefit_applied' as ActivityType,
|
activityType: 'benefit_applied' as ActivityType,
|
||||||
title: '权益激活',
|
title: '权益激活',
|
||||||
description: `${payload.regionName} ${roleTypeLabel} 激活权益`,
|
description: `${regionName} ${roleTypeLabel} 激活权益`,
|
||||||
icon: '🎁',
|
icon: '🎁',
|
||||||
relatedUserId: BigInt(payload.userId),
|
relatedUserId: BigInt(payload.userId),
|
||||||
relatedEntityType: 'benefit',
|
relatedEntityType: 'benefit',
|
||||||
|
|
@ -299,8 +332,8 @@ export class ActivityEventConsumerController {
|
||||||
authorizationId: payload.authorizationId,
|
authorizationId: payload.authorizationId,
|
||||||
accountSequence: payload.accountSequence,
|
accountSequence: payload.accountSequence,
|
||||||
roleType: payload.roleType,
|
roleType: payload.roleType,
|
||||||
regionCode: payload.regionCode,
|
regionCode: regionCode,
|
||||||
regionName: payload.regionName,
|
regionName: regionName,
|
||||||
activatedAt: message.occurredAt,
|
activatedAt: message.occurredAt,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue