fix(pre-planting): 修复省市代码格式不一致导致授权分配失败

预种DTO接收2位省代码(如"44")和4位市代码(如"4401"),
但authorization-service需要6位标准格式(如"440000"/"440100")。
- resolveAllocations中新增padEnd(6,'0')标准化转换
- fallback系统账户生成从padStart改为padEnd(右补零)
- 正常认种不受影响(SelectProvinceCityDto直接接收6位格式)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-01 01:23:55 -08:00
parent 3be7b47678
commit b9ddda2532
2 changed files with 17 additions and 6 deletions

View File

@ -151,6 +151,17 @@ export class PrePlantingRewardService {
const allocations: RewardAllocation[] = []; const allocations: RewardAllocation[] = [];
const multiplier = portionCount; const multiplier = portionCount;
// [2026-03-01] 标准化省市代码为 6 位格式
// 预种 DTO 接收前端传入的短格式(省 2 位如 "44",市 4 位如 "4401"
// 但 authorization-service 查询和系统账户编号都需要 6 位格式("440000"/"440100")。
// 正常认种 SelectProvinceCityDto 直接接收 6 位格式,故不存在此问题。
const stdProvinceCode = provinceCode.length < 6
? provinceCode.padEnd(6, '0')
: provinceCode;
const stdCityCode = cityCode.length < 6
? cityCode.padEnd(6, '0')
: cityCode;
// ===== 4 类系统费用(硬编码,无需查询) ===== // ===== 4 类系统费用(硬编码,无需查询) =====
allocations.push({ allocations.push({
recipientAccountSequence: SYSTEM_ACCOUNTS.COST, recipientAccountSequence: SYSTEM_ACCOUNTS.COST,
@ -196,9 +207,9 @@ export class PrePlantingRewardService {
] = await Promise.all([ ] = await Promise.all([
this.referralClient.getReferralChain(accountSequence), this.referralClient.getReferralChain(accountSequence),
this.authorizationClient.getCommunityDistribution(accountSequence), this.authorizationClient.getCommunityDistribution(accountSequence),
this.authorizationClient.getProvinceAreaDistribution(provinceCode), this.authorizationClient.getProvinceAreaDistribution(stdProvinceCode),
this.authorizationClient.getProvinceTeamDistribution(accountSequence), this.authorizationClient.getProvinceTeamDistribution(accountSequence),
this.authorizationClient.getCityAreaDistribution(cityCode), this.authorizationClient.getCityAreaDistribution(stdCityCode),
this.authorizationClient.getCityTeamDistribution(accountSequence), this.authorizationClient.getCityTeamDistribution(accountSequence),
]); ]);

View File

@ -67,7 +67,7 @@ export class PrePlantingAuthorizationClient {
* [2026-02-28] * [2026-02-28]
* 1. treeCount=01 * 1. treeCount=01
* 2. { distributions: [{accountSequence, ...}] } { accountSequence } * 2. { distributions: [{accountSequence, ...}] } { accountSequence }
* 3. fallback padStart(6,'0') 7 9440000 944 * 3. fallback 使 padEnd(6,'0') 7 9440000
*/ */
async getProvinceAreaDistribution( async getProvinceAreaDistribution(
provinceCode: string, provinceCode: string,
@ -102,7 +102,7 @@ export class PrePlantingAuthorizationClient {
`Failed to get province area distribution for ${provinceCode}, fallback to system province account`, `Failed to get province area distribution for ${provinceCode}, fallback to system province account`,
); );
return { return {
recipientAccountSequence: `9${provinceCode.padStart(6, '0')}`, recipientAccountSequence: `9${provinceCode.padEnd(6, '0')}`,
isFallback: true, isFallback: true,
}; };
} }
@ -142,7 +142,7 @@ export class PrePlantingAuthorizationClient {
* [2026-02-28] * [2026-02-28]
* 1. treeCount=01 * 1. treeCount=01
* 2. { distributions: [...] } * 2. { distributions: [...] }
* 3. fallback padStart(6,'0') 7 8440100 84401 * 3. fallback 使 padEnd(6,'0') 7 8440100
*/ */
async getCityAreaDistribution( async getCityAreaDistribution(
cityCode: string, cityCode: string,
@ -176,7 +176,7 @@ export class PrePlantingAuthorizationClient {
`Failed to get city area distribution for ${cityCode}, fallback to system city account`, `Failed to get city area distribution for ${cityCode}, fallback to system city account`,
); );
return { return {
recipientAccountSequence: `8${cityCode.padStart(6, '0')}`, recipientAccountSequence: `8${cityCode.padEnd(6, '0')}`,
isFallback: true, isFallback: true,
}; };
} }