From 1157760d4daa7dc0289a5a7b371ee238920994fb Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 1 Mar 2026 02:30:35 -0800 Subject: [PATCH] =?UTF-8?q?fix(pre-planting):=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA/=E7=9C=81=E5=9B=A2=E9=98=9F/=E5=B8=82?= =?UTF-8?q?=E5=9B=A2=E9=98=9F=20API=20=E7=BC=BA=E5=A4=B1=E7=9A=84=20treeCo?= =?UTF-8?q?unt=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 三个接口调用时未传 treeCount,导致 authorization-service 收到 Number(undefined)=NaN,addMonthlyTrees(NaN) 使字段变为 NaN, Prisma upsert 报 PrismaClientValidationError。 修复:全部传 treeCount=0(预种不计入月度考核), 省团队补充 provinceCode,市团队补充 cityCode, 同时修正社区/团队接口返回格式为 distributions 数组。 Co-Authored-By: Claude Opus 4.6 --- .../services/pre-planting-reward.service.ts | 4 +- .../pre-planting-authorization.client.ts | 62 ++++++++++++++++--- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts b/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts index 92f41bce..9986e57d 100644 --- a/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts +++ b/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts @@ -208,9 +208,9 @@ export class PrePlantingRewardService { this.referralClient.getReferralChain(accountSequence), this.authorizationClient.getCommunityDistribution(accountSequence), this.authorizationClient.getProvinceAreaDistribution(stdProvinceCode), - this.authorizationClient.getProvinceTeamDistribution(accountSequence), + this.authorizationClient.getProvinceTeamDistribution(accountSequence, stdProvinceCode), this.authorizationClient.getCityAreaDistribution(stdCityCode), - this.authorizationClient.getCityTeamDistribution(accountSequence), + this.authorizationClient.getCityTeamDistribution(accountSequence, stdCityCode), ]); // 推荐奖励 (SHARE_RIGHT) 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 4536c3f3..6c4ff016 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 @@ -45,19 +45,33 @@ export class PrePlantingAuthorizationClient { /** * 社区权益分配对象 + * + * treeCount=0:预种阶段不计入社区月度考核,避免 addMonthlyTrees(NaN) 导致 Prisma 报错 */ async getCommunityDistribution( accountSequence: string, ): Promise { try { const response = await firstValueFrom( - this.httpService.get>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/community-reward-distribution`, - { params: { accountSequence } }, + { params: { accountSequence, treeCount: 0 } }, ), ); + + const distributions = response.data.data.distributions; + if (!distributions || distributions.length === 0) { + throw new Error('Empty distributions returned'); + } + + const target = distributions.find(d => !d.isSystemAccount) || distributions[0]; + + this.logger.debug( + `Community distribution for ${accountSequence}: ${target.accountSequence} (${target.reason})`, + ); + return { - recipientAccountSequence: response.data.data.accountSequence, + recipientAccountSequence: target.accountSequence, isFallback: false, }; } catch (error) { @@ -120,19 +134,34 @@ export class PrePlantingAuthorizationClient { /** * 省团队权益分配对象 + * + * treeCount=0:预种阶段不计入省团队月度考核 */ async getProvinceTeamDistribution( accountSequence: string, + provinceCode: string, ): Promise { try { const response = await firstValueFrom( - this.httpService.get>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/province-team-reward-distribution`, - { params: { accountSequence } }, + { params: { accountSequence, provinceCode, treeCount: 0 } }, ), ); + + const distributions = response.data.data.distributions; + if (!distributions || distributions.length === 0) { + throw new Error('Empty distributions returned'); + } + + const target = distributions.find(d => !d.isSystemAccount) || distributions[0]; + + this.logger.debug( + `Province team distribution for ${accountSequence}: ${target.accountSequence} (${target.reason})`, + ); + return { - recipientAccountSequence: response.data.data.accountSequence, + recipientAccountSequence: target.accountSequence, isFallback: false, }; } catch (error) { @@ -194,19 +223,34 @@ export class PrePlantingAuthorizationClient { /** * 市团队权益分配对象 + * + * treeCount=0:预种阶段不计入市团队月度考核 */ async getCityTeamDistribution( accountSequence: string, + cityCode: string, ): Promise { try { const response = await firstValueFrom( - this.httpService.get>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/city-team-reward-distribution`, - { params: { accountSequence } }, + { params: { accountSequence, cityCode, treeCount: 0 } }, ), ); + + const distributions = response.data.data.distributions; + if (!distributions || distributions.length === 0) { + throw new Error('Empty distributions returned'); + } + + const target = distributions.find(d => !d.isSystemAccount) || distributions[0]; + + this.logger.debug( + `City team distribution for ${accountSequence}: ${target.accountSequence} (${target.reason})`, + ); + return { - recipientAccountSequence: response.data.data.accountSequence, + recipientAccountSequence: target.accountSequence, isFallback: false, }; } catch (error) {