fix(pre-planting): 补充社区/省团队/市团队 API 缺失的 treeCount 参数

三个接口调用时未传 treeCount,导致 authorization-service 收到
Number(undefined)=NaN,addMonthlyTrees(NaN) 使字段变为 NaN,
Prisma upsert 报 PrismaClientValidationError。

修复:全部传 treeCount=0(预种不计入月度考核),
省团队补充 provinceCode,市团队补充 cityCode,
同时修正社区/团队接口返回格式为 distributions 数组。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-01 02:30:35 -08:00
parent e32658fc5e
commit 1157760d4d
2 changed files with 55 additions and 11 deletions

View File

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

View File

@ -45,19 +45,33 @@ export class PrePlantingAuthorizationClient {
/**
*
*
* treeCount=0 addMonthlyTrees(NaN) Prisma
*/
async getCommunityDistribution(
accountSequence: string,
): Promise<RewardDistributionResult> {
try {
const response = await firstValueFrom(
this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
`${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<RewardDistributionResult> {
try {
const response = await firstValueFrom(
this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
`${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<RewardDistributionResult> {
try {
const response = await firstValueFrom(
this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
`${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) {