Skip to content

Commit

Permalink
fix(mis): 修复平台管理页面账户消费记录搜索账户名时传参错误问题 (#1130)
Browse files Browse the repository at this point in the history
### 现状

在搜索账户的消费记录和充值记录时,如果是查询某一个账户的记录时,会传参租户和账户名在数据库里搜索,但是租户是取得查询者的租户,此时如果是在平台管理页面,租户A下的平台管理员查询租户B下的账户时,会出现查询不到该账户记录的情况。

### 改动
在传参前,先根据getAccounts获取到该账户的所属租户,进行正确的传参
  • Loading branch information
ZihanChen821 authored Feb 21, 2024
1 parent 2f687c5 commit a56ec73
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-camels-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/mis-web": patch
---

修复平台管理页面账户消费记录搜索账户名时传参错误问题
5 changes: 3 additions & 2 deletions apps/mis-web/src/pages/api/file/exportChargeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion apps/mis-web/src/pages/api/file/exportPayRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 24 additions & 5 deletions apps/mis-web/src/pages/api/finance/charges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string> {

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 }
Expand All @@ -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) {
Expand All @@ -137,7 +154,7 @@ export const buildChargesRequestTarget = (accountName: string | undefined, info:
} else {
return {
$case: "accountsOfTenant" as const,
accountsOfTenant: { tenantName: info.tenant },
accountsOfTenant: { tenantName },
};
}
} else {
Expand All @@ -149,7 +166,7 @@ export const buildChargesRequestTarget = (accountName: string | undefined, info:
} else {
return {
$case: "tenant" as const,
tenant: { tenantName: info.tenant },
tenant: { tenantName },
};
}
}
Expand All @@ -163,14 +180,16 @@ 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", {
startTime,
endTime,
type,
userIds: userIds ?? [],
target: buildChargesRequestTarget(accountName, info, searchType, isPlatformRecords),
target: buildChargesRequestTarget(accountName, tenantOfAccount, searchType, isPlatformRecords),
page,
pageSize,
}), []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -65,14 +65,16 @@ 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", {
startTime,
endTime,
type,
userIds: userIds ?? [],
target: buildChargesRequestTarget(accountName, info, searchType, isPlatformRecords),
target: buildChargesRequestTarget(accountName, tenantOfAccount, searchType, isPlatformRecords),
}), ["totalAmount", "totalCount"]);

return {
Expand Down
15 changes: 12 additions & 3 deletions apps/mis-web/src/pages/api/finance/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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"]);
Expand Down

0 comments on commit a56ec73

Please sign in to comment.