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) {