diff --git a/.changeset/moody-camels-cheer.md b/.changeset/moody-camels-cheer.md new file mode 100644 index 0000000000..afdb1c495f --- /dev/null +++ b/.changeset/moody-camels-cheer.md @@ -0,0 +1,5 @@ +--- +"@scow/mis-web": patch +--- + +修复平台管理页面账户消费记录搜索账户名时传参错误问题 diff --git a/apps/mis-web/src/pages/api/file/exportChargeRecord.ts b/apps/mis-web/src/pages/api/file/exportChargeRecord.ts index 0fe785afe1..02a410d27c 100644 --- a/apps/mis-web/src/pages/api/file/exportChargeRecord.ts +++ b/apps/mis-web/src/pages/api/file/exportChargeRecord.ts @@ -20,7 +20,7 @@ import { getT, prefix } from "src/i18n"; import { OperationResult, OperationType } from "src/models/operationLog"; import { SearchType } from "src/models/User"; import { MAX_EXPORT_COUNT } from "src/pageComponents/file/apis"; -import { buildChargesRequestTarget, getUserInfoForCharges } from "src/pages/api/finance/charges"; +import { buildChargesRequestTarget, getTenantOfAccount, getUserInfoForCharges } from "src/pages/api/finance/charges"; import { callLog } from "src/server/operationLog"; import { getClient } from "src/utils/client"; import { publicConfig } from "src/utils/config"; @@ -63,8 +63,9 @@ export default route(ExportChargeRecordSchema, async (req, res) => { if (!info) { return; } + const tenantOfAccount = await getTenantOfAccount(accountName, info); - const target = buildChargesRequestTarget(accountName, info, searchType, isPlatformRecords); + const target = buildChargesRequestTarget(accountName, tenantOfAccount, searchType, isPlatformRecords); const logInfo = { operatorUserId: info.identityId, diff --git a/apps/mis-web/src/pages/api/file/exportPayRecord.ts b/apps/mis-web/src/pages/api/file/exportPayRecord.ts index f26b4ef952..c114e3b967 100644 --- a/apps/mis-web/src/pages/api/file/exportPayRecord.ts +++ b/apps/mis-web/src/pages/api/file/exportPayRecord.ts @@ -31,6 +31,7 @@ import { route } from "src/utils/route"; import { getContentType, parseIp } from "src/utils/server"; import { pipeline } from "stream"; +import { getTenantOfAccount } from "../finance/charges"; import { getPaymentRecordTarget } from "../finance/payments"; export const ExportPayRecordSchema = typeboxRouteSchema({ @@ -79,7 +80,11 @@ export default route(ExportPayRecordSchema, async (req, res) => { if (!user) { return; } - const target = getPaymentRecordTarget(searchType, user, targetName); + const tenantOfAccount = searchType === SearchType.account + ? await getTenantOfAccount(targetName, user) + : user.tenantId; + + const target = getPaymentRecordTarget(searchType, user, tenantOfAccount, targetName); const logInfo = { operatorUserId: user.identityId, diff --git a/apps/mis-web/src/pages/api/finance/charges.ts b/apps/mis-web/src/pages/api/finance/charges.ts index a722ee6012..a86df068ad 100644 --- a/apps/mis-web/src/pages/api/finance/charges.ts +++ b/apps/mis-web/src/pages/api/finance/charges.ts @@ -13,6 +13,7 @@ import { typeboxRoute, typeboxRouteSchema } from "@ddadaal/next-typed-api-routes-runtime"; import { asyncClientCall } from "@ddadaal/tsgrpc-client"; import { moneyToNumber } from "@scow/lib-decimal"; +import { AccountServiceClient } from "@scow/protos/build/server/account"; import { AccountOfTenantTarget, AccountsOfAllTenantsTarget, AccountsOfTenantTarget, AllTenantsTarget, ChargingServiceClient, TenantTarget } from "@scow/protos/build/server/charging"; import { UserServiceClient } from "@scow/protos/build/server/user"; @@ -113,7 +114,23 @@ export async function getUserInfoForCharges(accountName: string | undefined, req } } -export const buildChargesRequestTarget = (accountName: string | undefined, info: UserInfo, +export async function getTenantOfAccount(accountName: string | undefined, info: UserInfo): Promise { + + if (accountName) { + const client = getClient(AccountServiceClient); + + const { results } = await asyncClientCall(client, "getAccounts", { + accountName, + }); + if (results.length !== 0) { + return results[0].tenantName; + } + } + + return info.tenant; +} + +export const buildChargesRequestTarget = (accountName: string | undefined, tenantName: string, searchType: SearchType | undefined, isPlatformRecords: boolean | undefined): ( { $case: "accountOfTenant"; accountOfTenant: AccountOfTenantTarget } | { $case: "accountsOfTenant"; accountsOfTenant: AccountsOfTenantTarget } @@ -125,7 +142,7 @@ export const buildChargesRequestTarget = (accountName: string | undefined, info: if (accountName) { return { $case: "accountOfTenant" as const, - accountOfTenant: { tenantName: info.tenant, accountName: accountName }, + accountOfTenant: { accountName, tenantName }, }; } else { if (searchType === SearchType.ACCOUNT) { @@ -137,7 +154,7 @@ export const buildChargesRequestTarget = (accountName: string | undefined, info: } else { return { $case: "accountsOfTenant" as const, - accountsOfTenant: { tenantName: info.tenant }, + accountsOfTenant: { tenantName }, }; } } else { @@ -149,7 +166,7 @@ export const buildChargesRequestTarget = (accountName: string | undefined, info: } else { return { $case: "tenant" as const, - tenant: { tenantName: info.tenant }, + tenant: { tenantName }, }; } } @@ -163,6 +180,8 @@ export default typeboxRoute(GetChargesSchema, async (req, res) => { const info = await getUserInfoForCharges(accountName, req, res); if (!info) return; + const tenantOfAccount = await getTenantOfAccount(accountName, info); + const client = getClient(ChargingServiceClient); const reply = ensureNotUndefined(await asyncClientCall(client, "getPaginatedChargeRecords", { @@ -170,7 +189,7 @@ export default typeboxRoute(GetChargesSchema, async (req, res) => { endTime, type, userIds: userIds ?? [], - target: buildChargesRequestTarget(accountName, info, searchType, isPlatformRecords), + target: buildChargesRequestTarget(accountName, tenantOfAccount, searchType, isPlatformRecords), page, pageSize, }), []); diff --git a/apps/mis-web/src/pages/api/finance/getChargeRecordsTotalCount.ts b/apps/mis-web/src/pages/api/finance/getChargeRecordsTotalCount.ts index 5ab9700467..82814b5aef 100644 --- a/apps/mis-web/src/pages/api/finance/getChargeRecordsTotalCount.ts +++ b/apps/mis-web/src/pages/api/finance/getChargeRecordsTotalCount.ts @@ -19,7 +19,7 @@ import { SearchType } from "src/models/User"; import { ensureNotUndefined } from "src/utils/checkNull"; import { getClient } from "src/utils/client"; -import { buildChargesRequestTarget, getUserInfoForCharges } from "./charges"; +import { buildChargesRequestTarget, getTenantOfAccount, getUserInfoForCharges } from "./charges"; export const GetChargeRecordsTotalCountSchema = typeboxRouteSchema({ @@ -65,6 +65,8 @@ export default typeboxRoute(GetChargeRecordsTotalCountSchema, async (req, res) = const info = await getUserInfoForCharges(accountName, req, res); if (!info) return; + const tenantOfAccount = await getTenantOfAccount(accountName, info); + const client = getClient(ChargingServiceClient); const reply = ensureNotUndefined(await asyncClientCall(client, "getChargeRecordsTotalCount", { @@ -72,7 +74,7 @@ export default typeboxRoute(GetChargeRecordsTotalCountSchema, async (req, res) = endTime, type, userIds: userIds ?? [], - target: buildChargesRequestTarget(accountName, info, searchType, isPlatformRecords), + target: buildChargesRequestTarget(accountName, tenantOfAccount, searchType, isPlatformRecords), }), ["totalAmount", "totalCount"]); return { diff --git a/apps/mis-web/src/pages/api/finance/payments.ts b/apps/mis-web/src/pages/api/finance/payments.ts index a71b22be26..805e3c1a93 100644 --- a/apps/mis-web/src/pages/api/finance/payments.ts +++ b/apps/mis-web/src/pages/api/finance/payments.ts @@ -21,6 +21,8 @@ import { SearchType } from "src/pageComponents/common/PaymentTable"; import { ensureNotUndefined } from "src/utils/checkNull"; import { getClient } from "src/utils/client"; +import { getTenantOfAccount } from "./charges"; + export const PaymentInfo = Type.Object({ index: Type.Number(), accountName: Type.Optional(Type.String()), @@ -61,7 +63,12 @@ export const GetPaymentsSchema = typeboxRouteSchema({ }, }); -export const getPaymentRecordTarget = (searchType: SearchType, user: UserInfo, targetName: string | undefined) => { +export const getPaymentRecordTarget = ( + searchType: SearchType, + user: UserInfo, + tenantOfAccount: string, + targetName: string | undefined, +) => { switch (searchType) { case SearchType.tenant: return targetName @@ -73,7 +80,7 @@ export const getPaymentRecordTarget = (searchType: SearchType, user: UserInfo, t return { $case:"accountOfTenant" as const, accountOfTenant:{ tenantName:user.tenant, accountName:targetName! } }; case SearchType.account: return targetName - ? { $case:"accountOfTenant" as const, accountOfTenant:{ tenantName:user.tenant, accountName:targetName! } } + ? { $case:"accountOfTenant" as const, accountOfTenant:{ tenantName:tenantOfAccount, accountName:targetName! } } : { $case:"accountsOfTenant" as const, accountsOfTenant:{ tenantName:user.tenant } }; default: break; @@ -104,8 +111,10 @@ export default typeboxRoute(GetPaymentsSchema, async (req, res) => { if (!user) { return; } } + const tenantOfAccount = await getTenantOfAccount(accountName, user); + const reply = ensureNotUndefined(await asyncClientCall(client, "getPaymentRecords", { - target: getPaymentRecordTarget(searchType, user, accountName), + target: getPaymentRecordTarget(searchType, user, tenantOfAccount, accountName), startTime, endTime, }), ["total"]);