fix(pre-planting): 修复省/市区域权益分配的三个 bug
问题:
1. 省/市区域 API 调用缺少必需的 treeCount 参数,导致 authorization-service
报错,每次都走 fallback 路径
2. fallback 路径没有对省/市代码做 padStart(6,'0') 补位,
生成了错误的账户ID(如 944 而非 9440000,84401 而非 8440100)
3. API 返回格式解析错误:authorization-service 返回
{ distributions: [{accountSequence, ...}] },但预种客户端错误地期望
{ accountSequence: string },导致取到 undefined
修复:
- getProvinceAreaDistribution / getCityAreaDistribution 新增 portionCount 参数
- 正确解析 distributions 数组,优先取非系统账户(省/市公司)
- fallback 中使用 padStart(6,'0') 确保 7 位标准账户 ID 格式
- resolveAllocations 调用时传入 portionCount
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6a659ca718
commit
1c71cda2ec
|
|
@ -196,9 +196,9 @@ export class PrePlantingRewardService {
|
|||
] = await Promise.all([
|
||||
this.referralClient.getReferralChain(accountSequence),
|
||||
this.authorizationClient.getCommunityDistribution(accountSequence),
|
||||
this.authorizationClient.getProvinceAreaDistribution(provinceCode),
|
||||
this.authorizationClient.getProvinceAreaDistribution(provinceCode, portionCount),
|
||||
this.authorizationClient.getProvinceTeamDistribution(accountSequence),
|
||||
this.authorizationClient.getCityAreaDistribution(cityCode),
|
||||
this.authorizationClient.getCityAreaDistribution(cityCode, portionCount),
|
||||
this.authorizationClient.getCityTeamDistribution(accountSequence),
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,16 @@ export interface RewardDistributionResult {
|
|||
isFallback: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* authorization-service 省/市区域 API 返回的 distributions 数组项
|
||||
*/
|
||||
interface AreaDistributionItem {
|
||||
accountSequence: string;
|
||||
treeCount: number;
|
||||
reason: string;
|
||||
isSystemAccount: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class PrePlantingAuthorizationClient {
|
||||
private readonly logger = new Logger(PrePlantingAuthorizationClient.name);
|
||||
|
|
@ -53,19 +63,39 @@ export class PrePlantingAuthorizationClient {
|
|||
|
||||
/**
|
||||
* 省区域权益分配对象
|
||||
*
|
||||
* [2026-02-28] 修复:
|
||||
* 1. 传 treeCount 参数(authorization-service 必需,用于省公司月度考核累计)
|
||||
* 2. 正确解析 { distributions: [{accountSequence, ...}] } 返回格式(之前错误地期望 { accountSequence })
|
||||
* 3. fallback 路径添加 padStart(6,'0'),确保生成 7 位标准格式(如 9440000 而非 944)
|
||||
*/
|
||||
async getProvinceAreaDistribution(
|
||||
provinceCode: string,
|
||||
portionCount: number = 1,
|
||||
): Promise<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ accountSequence: string }>(
|
||||
this.httpService.get<{ distributions: AreaDistributionItem[] }>(
|
||||
`${this.baseUrl}/internal/authorization/province-area-reward-distribution`,
|
||||
{ params: { provinceCode } },
|
||||
{ params: { provinceCode, treeCount: portionCount } },
|
||||
),
|
||||
);
|
||||
|
||||
const distributions = response.data.distributions;
|
||||
if (!distributions || distributions.length === 0) {
|
||||
throw new Error('Empty distributions returned');
|
||||
}
|
||||
|
||||
// 预种不拆分金额,取第一个分配对象的 accountSequence
|
||||
// 如果跨考核达标点有多个 distribution,优先取非系统账户(即省公司)
|
||||
const target = distributions.find(d => !d.isSystemAccount) || distributions[0];
|
||||
|
||||
this.logger.debug(
|
||||
`Province area distribution for ${provinceCode}: ${target.accountSequence} (${target.reason})`,
|
||||
);
|
||||
|
||||
return {
|
||||
recipientAccountSequence: response.data.accountSequence,
|
||||
recipientAccountSequence: target.accountSequence,
|
||||
isFallback: false,
|
||||
};
|
||||
} catch (error) {
|
||||
|
|
@ -73,7 +103,7 @@ export class PrePlantingAuthorizationClient {
|
|||
`Failed to get province area distribution for ${provinceCode}, fallback to system province account`,
|
||||
);
|
||||
return {
|
||||
recipientAccountSequence: `9${provinceCode}`,
|
||||
recipientAccountSequence: `9${provinceCode.padStart(6, '0')}`,
|
||||
isFallback: true,
|
||||
};
|
||||
}
|
||||
|
|
@ -109,19 +139,38 @@ export class PrePlantingAuthorizationClient {
|
|||
|
||||
/**
|
||||
* 市区域权益分配对象
|
||||
*
|
||||
* [2026-02-28] 修复:与省区域同样的三个问题
|
||||
* 1. 传 treeCount 参数
|
||||
* 2. 正确解析 { distributions: [...] } 返回格式
|
||||
* 3. fallback 路径添加 padStart(6,'0'),确保生成 7 位标准格式(如 8440100 而非 84401)
|
||||
*/
|
||||
async getCityAreaDistribution(
|
||||
cityCode: string,
|
||||
portionCount: number = 1,
|
||||
): Promise<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ accountSequence: string }>(
|
||||
this.httpService.get<{ distributions: AreaDistributionItem[] }>(
|
||||
`${this.baseUrl}/internal/authorization/city-area-reward-distribution`,
|
||||
{ params: { cityCode } },
|
||||
{ params: { cityCode, treeCount: portionCount } },
|
||||
),
|
||||
);
|
||||
|
||||
const distributions = response.data.distributions;
|
||||
if (!distributions || distributions.length === 0) {
|
||||
throw new Error('Empty distributions returned');
|
||||
}
|
||||
|
||||
// 预种不拆分金额,取第一个分配对象的 accountSequence
|
||||
const target = distributions.find(d => !d.isSystemAccount) || distributions[0];
|
||||
|
||||
this.logger.debug(
|
||||
`City area distribution for ${cityCode}: ${target.accountSequence} (${target.reason})`,
|
||||
);
|
||||
|
||||
return {
|
||||
recipientAccountSequence: response.data.accountSequence,
|
||||
recipientAccountSequence: target.accountSequence,
|
||||
isFallback: false,
|
||||
};
|
||||
} catch (error) {
|
||||
|
|
@ -129,7 +178,7 @@ export class PrePlantingAuthorizationClient {
|
|||
`Failed to get city area distribution for ${cityCode}, fallback to system city account`,
|
||||
);
|
||||
return {
|
||||
recipientAccountSequence: `8${cityCode}`,
|
||||
recipientAccountSequence: `8${cityCode.padStart(6, '0')}`,
|
||||
isFallback: true,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue