fix(pre-planting): 修复 authorization-service 响应包装格式解析
authorization-service 全局 TransformInterceptor 将响应包装为
{ success, data: T, timestamp },预种客户端需读取 response.data.data
而非 response.data。此前因解析失败静默 fallback 到系统账户。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a15a4a97b1
commit
e32658fc5e
|
|
@ -19,6 +19,16 @@ interface AreaDistributionItem {
|
|||
isSystemAccount: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* authorization-service 全局 TransformInterceptor 包装格式
|
||||
* 所有响应都被包装为 { success: boolean, data: T, timestamp: string }
|
||||
*/
|
||||
interface WrappedResponse<T> {
|
||||
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<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ accountSequence: string }>(
|
||||
this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
|
||||
`${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<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ distributions: AreaDistributionItem[] }>(
|
||||
this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
|
||||
`${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<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ accountSequence: string }>(
|
||||
this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
|
||||
`${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<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ distributions: AreaDistributionItem[] }>(
|
||||
this.httpService.get<WrappedResponse<{ distributions: AreaDistributionItem[] }>>(
|
||||
`${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<RewardDistributionResult> {
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.httpService.get<{ accountSequence: string }>(
|
||||
this.httpService.get<WrappedResponse<{ accountSequence: string }>>(
|
||||
`${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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue