From e32658fc5edbef008f1dc571705ac55fd516b2a1 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 1 Mar 2026 02:22:01 -0800 Subject: [PATCH] =?UTF-8?q?fix(pre-planting):=20=E4=BF=AE=E5=A4=8D=20autho?= =?UTF-8?q?rization-service=20=E5=93=8D=E5=BA=94=E5=8C=85=E8=A3=85?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authorization-service 全局 TransformInterceptor 将响应包装为 { success, data: T, timestamp },预种客户端需读取 response.data.data 而非 response.data。此前因解析失败静默 fallback 到系统账户。 Co-Authored-By: Claude Opus 4.6 --- .../pre-planting-authorization.client.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts b/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts index ef6a566d..4536c3f3 100644 --- a/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts +++ b/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts @@ -19,6 +19,16 @@ interface AreaDistributionItem { isSystemAccount: boolean; } +/** + * authorization-service 全局 TransformInterceptor 包装格式 + * 所有响应都被包装为 { success: boolean, data: T, timestamp: string } + */ +interface WrappedResponse { + success: boolean; + data: T; + timestamp: string; +} + @Injectable() export class PrePlantingAuthorizationClient { private readonly logger = new Logger(PrePlantingAuthorizationClient.name); @@ -41,13 +51,13 @@ export class PrePlantingAuthorizationClient { ): Promise { try { const response = await firstValueFrom( - this.httpService.get<{ accountSequence: string }>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/community-reward-distribution`, { params: { accountSequence } }, ), ); return { - recipientAccountSequence: response.data.accountSequence, + recipientAccountSequence: response.data.data.accountSequence, isFallback: false, }; } catch (error) { @@ -66,7 +76,7 @@ export class PrePlantingAuthorizationClient { * * [2026-02-28] 修复: * 1. 传 treeCount=0(预种阶段不计入省公司月度考核,等合成1棵树后再累计) - * 2. 正确解析 { distributions: [{accountSequence, ...}] } 返回格式(之前错误地期望 { accountSequence }) + * 2. 正确解析 { success, data: { distributions: [...] } } 包装格式 * 3. fallback 路径使用 padEnd(6,'0') 右补零,确保生成 7 位标准格式(如 9440000) */ async getProvinceAreaDistribution( @@ -74,13 +84,13 @@ export class PrePlantingAuthorizationClient { ): Promise { try { const response = await firstValueFrom( - this.httpService.get<{ distributions: AreaDistributionItem[] }>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/province-area-reward-distribution`, { params: { provinceCode, treeCount: 0 } }, ), ); - const distributions = response.data.distributions; + const distributions = response.data.data.distributions; if (!distributions || distributions.length === 0) { throw new Error('Empty distributions returned'); } @@ -116,13 +126,13 @@ export class PrePlantingAuthorizationClient { ): Promise { try { const response = await firstValueFrom( - this.httpService.get<{ accountSequence: string }>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/province-team-reward-distribution`, { params: { accountSequence } }, ), ); return { - recipientAccountSequence: response.data.accountSequence, + recipientAccountSequence: response.data.data.accountSequence, isFallback: false, }; } catch (error) { @@ -139,9 +149,9 @@ export class PrePlantingAuthorizationClient { /** * 市区域权益分配对象 * - * [2026-02-28] 修复:与省区域同样的三个问题 + * [2026-02-28] 修复:与省区域同样的处理 * 1. 传 treeCount=0(预种阶段不计入市公司月度考核,等合成1棵树后再累计) - * 2. 正确解析 { distributions: [...] } 返回格式 + * 2. 正确解析 { success, data: { distributions: [...] } } 包装格式 * 3. fallback 路径使用 padEnd(6,'0') 右补零,确保生成 7 位标准格式(如 8440100) */ async getCityAreaDistribution( @@ -149,13 +159,13 @@ export class PrePlantingAuthorizationClient { ): Promise { try { const response = await firstValueFrom( - this.httpService.get<{ distributions: AreaDistributionItem[] }>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/city-area-reward-distribution`, { params: { cityCode, treeCount: 0 } }, ), ); - const distributions = response.data.distributions; + const distributions = response.data.data.distributions; if (!distributions || distributions.length === 0) { throw new Error('Empty distributions returned'); } @@ -190,13 +200,13 @@ export class PrePlantingAuthorizationClient { ): Promise { try { const response = await firstValueFrom( - this.httpService.get<{ accountSequence: string }>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/city-team-reward-distribution`, { params: { accountSequence } }, ), ); return { - recipientAccountSequence: response.data.accountSequence, + recipientAccountSequence: response.data.data.accountSequence, isFallback: false, }; } catch (error) {