From c7d54da49f781bf17729ac30bf7ab574b8505600 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 14 Dec 2025 06:48:58 -0800 Subject: [PATCH] =?UTF-8?q?fix(reward):=20=E4=BF=AE=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8=20authorization-service=20=E6=97=B6=E4=BC=A0=E9=80=92?= =?UTF-8?q?=20userId=20=E8=80=8C=E9=9D=9E=20accountSequence=20=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - IAuthorizationServiceClient 接口参数类型从 userId: bigint 改为 accountSequence: string - authorization-service.client.ts 调用时使用正确的 accountSequence 格式 - calculateCommunityRight/calculateProvinceTeamRight/calculateCityTeamRight 方法增加 sourceAccountSequence 参数 此修复确保 reward-service 调用 authorization-service 时传递正确的用户标识格式(如 D25121400006), 而不是数字形式的 userId(如 7),使 authorization-service 能正确查找社区授权记录。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../services/reward-calculation.service.ts | 30 ++++++---- .../authorization-service.client.ts | 60 +++++++++---------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/backend/services/reward-service/src/domain/services/reward-calculation.service.ts b/backend/services/reward-service/src/domain/services/reward-calculation.service.ts index ee38b19c..f2d6632e 100644 --- a/backend/services/reward-service/src/domain/services/reward-calculation.service.ts +++ b/backend/services/reward-service/src/domain/services/reward-calculation.service.ts @@ -30,13 +30,13 @@ export interface AreaRewardDistribution { } export interface IAuthorizationServiceClient { - findNearestAuthorizedProvince(userId: bigint, provinceCode: string): Promise; - findNearestAuthorizedCity(userId: bigint, cityCode: string): Promise; - findNearestCommunity(userId: bigint): Promise; - getCommunityRewardDistribution(userId: bigint, treeCount: number): Promise; - getProvinceTeamRewardDistribution(userId: bigint, provinceCode: string, treeCount: number): Promise; + findNearestAuthorizedProvince(accountSequence: string, provinceCode: string): Promise; + findNearestAuthorizedCity(accountSequence: string, cityCode: string): Promise; + findNearestCommunity(accountSequence: string): Promise; + getCommunityRewardDistribution(accountSequence: string, treeCount: number): Promise; + getProvinceTeamRewardDistribution(accountSequence: string, provinceCode: string, treeCount: number): Promise; getProvinceAreaRewardDistribution(provinceCode: string, treeCount: number): Promise; - getCityTeamRewardDistribution(userId: bigint, cityCode: string, treeCount: number): Promise; + getCityTeamRewardDistribution(accountSequence: string, cityCode: string, treeCount: number): Promise; getCityAreaRewardDistribution(cityCode: string, treeCount: number): Promise; } @@ -145,6 +145,7 @@ export class RewardCalculationService { const provinceTeamRewards = await this.calculateProvinceTeamRight( params.sourceOrderNo, params.sourceUserId, + params.sourceAccountSequence!, params.provinceCode, params.treeCount, ); @@ -163,6 +164,7 @@ export class RewardCalculationService { const cityTeamRewards = await this.calculateCityTeamRight( params.sourceOrderNo, params.sourceUserId, + params.sourceAccountSequence!, params.cityCode, params.treeCount, ); @@ -181,6 +183,7 @@ export class RewardCalculationService { const communityRewards = await this.calculateCommunityRight( params.sourceOrderNo, params.sourceUserId, + params.sourceAccountSequence!, params.treeCount, ); rewards.push(...communityRewards); @@ -393,18 +396,19 @@ export class RewardCalculationService { private async calculateProvinceTeamRight( sourceOrderNo: string, sourceUserId: bigint, + sourceAccountSequence: string, provinceCode: string, treeCount: number, ): Promise { this.logger.debug( - `[calculateProvinceTeamRight] userId=${sourceUserId}, province=${provinceCode}, treeCount=${treeCount}`, + `[calculateProvinceTeamRight] accountSequence=${sourceAccountSequence}, province=${provinceCode}, treeCount=${treeCount}`, ); const { usdt, hashpowerPercent } = RIGHT_AMOUNTS[RightType.PROVINCE_TEAM_RIGHT]; // 调用 authorization-service 获取省团队权益分配方案 const distribution = await this.authorizationService.getProvinceTeamRewardDistribution( - sourceUserId, + sourceAccountSequence, provinceCode, treeCount, ); @@ -504,18 +508,19 @@ export class RewardCalculationService { private async calculateCityTeamRight( sourceOrderNo: string, sourceUserId: bigint, + sourceAccountSequence: string, cityCode: string, treeCount: number, ): Promise { this.logger.debug( - `[calculateCityTeamRight] userId=${sourceUserId}, city=${cityCode}, treeCount=${treeCount}`, + `[calculateCityTeamRight] accountSequence=${sourceAccountSequence}, city=${cityCode}, treeCount=${treeCount}`, ); const { usdt, hashpowerPercent } = RIGHT_AMOUNTS[RightType.CITY_TEAM_RIGHT]; // 调用 authorization-service 获取市团队权益分配方案 const distribution = await this.authorizationService.getCityTeamRewardDistribution( - sourceUserId, + sourceAccountSequence, cityCode, treeCount, ); @@ -617,17 +622,18 @@ export class RewardCalculationService { private async calculateCommunityRight( sourceOrderNo: string, sourceUserId: bigint, + sourceAccountSequence: string, treeCount: number, ): Promise { this.logger.debug( - `[calculateCommunityRight] userId=${sourceUserId}, treeCount=${treeCount}`, + `[calculateCommunityRight] accountSequence=${sourceAccountSequence}, treeCount=${treeCount}`, ); const { usdt, hashpowerPercent } = RIGHT_AMOUNTS[RightType.COMMUNITY_RIGHT]; // 调用 authorization-service 获取社区权益分配方案 const distribution = await this.authorizationService.getCommunityRewardDistribution( - sourceUserId, + sourceAccountSequence, treeCount, ); diff --git a/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts b/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts index eb030feb..53d36813 100644 --- a/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts +++ b/backend/services/reward-service/src/infrastructure/external/authorization-service/authorization-service.client.ts @@ -39,71 +39,69 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { this.baseUrl = this.configService.get('AUTHORIZATION_SERVICE_URL', 'http://localhost:3006'); } - async findNearestAuthorizedProvince(userId: bigint, provinceCode: string): Promise { + async findNearestAuthorizedProvince(accountSequence: string, provinceCode: string): Promise { try { const response = await fetch( - `${this.baseUrl}/api/v1/authorization/nearest-province?accountSequence=${userId}&provinceCode=${provinceCode}`, + `${this.baseUrl}/api/v1/authorization/nearest-province?accountSequence=${accountSequence}&provinceCode=${provinceCode}`, ); if (!response.ok) { - this.logger.warn(`No authorized province found for user ${userId}, province ${provinceCode}`); + this.logger.warn(`No authorized province found for accountSequence ${accountSequence}, province ${provinceCode}`); return null; } // authorization-service 返回格式: { success, data: { accountSequence }, timestamp } const result: AuthorizationServiceResponse = await response.json(); - const accountSeq = result.data?.accountSequence; - return accountSeq ? BigInt(accountSeq) : null; + return result.data?.accountSequence || null; } catch (error) { this.logger.error(`Error finding nearest authorized province:`, error); return null; } } - async findNearestAuthorizedCity(userId: bigint, cityCode: string): Promise { + async findNearestAuthorizedCity(accountSequence: string, cityCode: string): Promise { try { const response = await fetch( - `${this.baseUrl}/api/v1/authorization/nearest-city?accountSequence=${userId}&cityCode=${cityCode}`, + `${this.baseUrl}/api/v1/authorization/nearest-city?accountSequence=${accountSequence}&cityCode=${cityCode}`, ); if (!response.ok) { - this.logger.warn(`No authorized city found for user ${userId}, city ${cityCode}`); + this.logger.warn(`No authorized city found for accountSequence ${accountSequence}, city ${cityCode}`); return null; } // authorization-service 返回格式: { success, data: { accountSequence }, timestamp } const result: AuthorizationServiceResponse = await response.json(); - const accountSeq = result.data?.accountSequence; - return accountSeq ? BigInt(accountSeq) : null; + return result.data?.accountSequence || null; } catch (error) { this.logger.error(`Error finding nearest authorized city:`, error); return null; } } - async findNearestCommunity(userId: bigint): Promise { + async findNearestCommunity(accountSequence: string): Promise { try { const response = await fetch( - `${this.baseUrl}/api/v1/authorization/nearest-community?accountSequence=${userId}`, + `${this.baseUrl}/api/v1/authorization/nearest-community?accountSequence=${accountSequence}`, ); if (!response.ok) { - this.logger.warn(`No community found for user ${userId}`); + this.logger.warn(`No community found for accountSequence ${accountSequence}`); return null; } // authorization-service 返回格式: { success, data: { accountSequence }, timestamp } const result: AuthorizationServiceResponse = await response.json(); - const accountSeq = result.data?.accountSequence; - this.logger.debug(`findNearestCommunity for userId=${userId}: result=${accountSeq}`); - return accountSeq ? BigInt(accountSeq) : null; + const resultAccountSeq = result.data?.accountSequence; + this.logger.debug(`findNearestCommunity for accountSequence=${accountSequence}: result=${resultAccountSeq}`); + return resultAccountSeq || null; } catch (error) { this.logger.error(`Error finding nearest community:`, error); return null; } } - async getCommunityRewardDistribution(userId: bigint, treeCount: number): Promise { + async getCommunityRewardDistribution(accountSequence: string, treeCount: number): Promise { const HEADQUARTERS_ACCOUNT_SEQUENCE = 'S0000000001'; const defaultDistribution: RewardDistribution = { distributions: [ @@ -117,11 +115,11 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { try { const response = await fetch( - `${this.baseUrl}/api/v1/authorization/community-reward-distribution?accountSequence=${userId}&treeCount=${treeCount}`, + `${this.baseUrl}/api/v1/authorization/community-reward-distribution?accountSequence=${accountSequence}&treeCount=${treeCount}`, ); if (!response.ok) { - this.logger.warn(`Failed to get community reward distribution for user ${userId}, treeCount ${treeCount}`); + this.logger.warn(`Failed to get community reward distribution for accountSequence ${accountSequence}, treeCount ${treeCount}`); return defaultDistribution; } @@ -129,12 +127,12 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { const result: AuthorizationServiceResponse = await response.json(); if (!result.data?.distributions || result.data.distributions.length === 0) { - this.logger.warn(`Empty distributions returned for user ${userId}`); + this.logger.warn(`Empty distributions returned for accountSequence ${accountSequence}`); return defaultDistribution; } this.logger.debug( - `getCommunityRewardDistribution for userId=${userId}, treeCount=${treeCount}: ` + + `getCommunityRewardDistribution for accountSequence=${accountSequence}, treeCount=${treeCount}: ` + `distributions=${JSON.stringify(result.data.distributions)}`, ); @@ -145,7 +143,7 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { } } - async getProvinceTeamRewardDistribution(userId: bigint, provinceCode: string, treeCount: number): Promise { + async getProvinceTeamRewardDistribution(accountSequence: string, provinceCode: string, treeCount: number): Promise { const HEADQUARTERS_ACCOUNT_SEQUENCE = 'S0000000001'; const defaultDistribution: RewardDistribution = { distributions: [ @@ -159,23 +157,23 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { try { const response = await fetch( - `${this.baseUrl}/api/v1/authorization/province-team-reward-distribution?accountSequence=${userId}&provinceCode=${provinceCode}&treeCount=${treeCount}`, + `${this.baseUrl}/api/v1/authorization/province-team-reward-distribution?accountSequence=${accountSequence}&provinceCode=${provinceCode}&treeCount=${treeCount}`, ); if (!response.ok) { - this.logger.warn(`Failed to get province team reward distribution for user ${userId}, province ${provinceCode}`); + this.logger.warn(`Failed to get province team reward distribution for accountSequence ${accountSequence}, province ${provinceCode}`); return defaultDistribution; } const result: AuthorizationServiceResponse = await response.json(); if (!result.data?.distributions || result.data.distributions.length === 0) { - this.logger.warn(`Empty province team distributions returned for user ${userId}`); + this.logger.warn(`Empty province team distributions returned for accountSequence ${accountSequence}`); return defaultDistribution; } this.logger.debug( - `getProvinceTeamRewardDistribution for userId=${userId}, provinceCode=${provinceCode}, treeCount=${treeCount}: ` + + `getProvinceTeamRewardDistribution for accountSequence=${accountSequence}, provinceCode=${provinceCode}, treeCount=${treeCount}: ` + `distributions=${JSON.stringify(result.data.distributions)}`, ); @@ -229,7 +227,7 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { } } - async getCityTeamRewardDistribution(userId: bigint, cityCode: string, treeCount: number): Promise { + async getCityTeamRewardDistribution(accountSequence: string, cityCode: string, treeCount: number): Promise { const HEADQUARTERS_ACCOUNT_SEQUENCE = 'S0000000001'; const defaultDistribution: RewardDistribution = { distributions: [ @@ -243,23 +241,23 @@ export class AuthorizationServiceClient implements IAuthorizationServiceClient { try { const response = await fetch( - `${this.baseUrl}/api/v1/authorization/city-team-reward-distribution?accountSequence=${userId}&cityCode=${cityCode}&treeCount=${treeCount}`, + `${this.baseUrl}/api/v1/authorization/city-team-reward-distribution?accountSequence=${accountSequence}&cityCode=${cityCode}&treeCount=${treeCount}`, ); if (!response.ok) { - this.logger.warn(`Failed to get city team reward distribution for user ${userId}, city ${cityCode}`); + this.logger.warn(`Failed to get city team reward distribution for accountSequence ${accountSequence}, city ${cityCode}`); return defaultDistribution; } const result: AuthorizationServiceResponse = await response.json(); if (!result.data?.distributions || result.data.distributions.length === 0) { - this.logger.warn(`Empty city team distributions returned for user ${userId}`); + this.logger.warn(`Empty city team distributions returned for accountSequence ${accountSequence}`); return defaultDistribution; } this.logger.debug( - `getCityTeamRewardDistribution for userId=${userId}, cityCode=${cityCode}, treeCount=${treeCount}: ` + + `getCityTeamRewardDistribution for accountSequence=${accountSequence}, cityCode=${cityCode}, treeCount=${treeCount}: ` + `distributions=${JSON.stringify(result.data.distributions)}`, );