Skip to content

Commit

Permalink
fix(mis): 消费记录、充值记录搜索功能优化 (#1152)
Browse files Browse the repository at this point in the history
## 消费记录类型选择框修改
账户管理->消费记录、租户管理->账户消费记录,平台管理->账户消费记录:
1、类型改为多选
2、类型选择下拉框不隐藏文字信息
### 改进前

![1713859929246](https://github.com/PKUHPC/SCOW/assets/78541912/d4ded0f4-490d-4901-b825-17ee53b3682e)
### 改进后

![1713860086118](https://github.com/PKUHPC/SCOW/assets/78541912/0324498f-2e89-4fce-85dc-be48d573beb5)

![1713860050066](https://github.com/PKUHPC/SCOW/assets/78541912/58d553eb-f26c-4ce4-aaaa-c92ad011df44)
## 充值记录类型选择框修改
账户管理->充值记录,租户管理->账户充值记录,租户管理->租户充值记录,平台管理->充值记录:
1、增加充值类型搜索
2、类型搜索框进行trim
### 改进前

![1713860486279](https://github.com/PKUHPC/SCOW/assets/78541912/2c151376-f85e-40e8-963a-c595daa6706a)
### 改进后

![1713860541548](https://github.com/PKUHPC/SCOW/assets/78541912/67de633f-924a-46e9-af51-4fe82f5afa22)

![1713862788038](https://github.com/PKUHPC/SCOW/assets/78541912/6bf70036-9bc4-4973-beb6-e72598d44373)
## 账户搜索框修改
租户管理->账户消费记录,租户管理->账户充值记录,平台管理->账户消费记录:
1、账户搜索框改为可以输入多个
2、账户搜索框,允许直接输入内容后,不用再点击搜索结果也可以进行搜索
### 改进前

![修改前](https://github.com/PKUHPC/SCOW/assets/78541912/d19b6b22-6cb7-4de5-90d5-11a39b889343)
### 改进后

![修改后](https://github.com/PKUHPC/SCOW/assets/78541912/c371f0f7-11b1-49c2-afab-bc877de8b613)
## 其他
1、导出功能根据类型从string->string[]同步更新
2、mis、audit中测试用例随着账户名和类型可多选,string->string[],随之修改和增加
3、mis、audit中日志相关随string->string[]进行一定修改
连锁i修改,操作日志,体现单选、多选、全选,并兼容过去记录:

![微信截图_20240507114137](https://github.com/PKUHPC/SCOW/assets/78541912/ccdcb7b1-51fe-4b61-8682-3e75827738da)

---------

Co-authored-by: valign <akrddr@163.com>
  • Loading branch information
OYX-1 and cuvalign committed May 9, 2024
1 parent 86a48d8 commit a53bcad
Show file tree
Hide file tree
Showing 31 changed files with 817 additions and 313 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-candles-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/grpc-api": minor
---

充值记录和消费记录支持多选账户搜索,充值记录增加类型搜索;导出充值记录和消费记录同步增加这两个搜索条件
6 changes: 6 additions & 0 deletions .changeset/smart-actors-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/mis-server": patch
"@scow/mis-web": patch
---

充值记录和消费记录支持多选账户搜索,充值记录增加类型搜索;导出充值记录和消费记录同步增加这两个搜索条件
13 changes: 7 additions & 6 deletions apps/audit-server/src/services/operationLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "@scow/protos/build/audit/operation_log";
import { I18nObject } from "@scow/protos/build/common/i18n";
import { OperationLog, OperationResult } from "src/entities/OperationLog";
import { checkCustomEventType, filterOperationLogs,
import { addOperationLogAccountNames, checkCustomEventType, filterOperationLogs,
getTargetAccountName, toGrpcOperationLog } from "src/utils/operationLogs";
import { DEFAULT_PAGE_SIZE, paginationProps } from "src/utils/orm";

Expand Down Expand Up @@ -72,8 +72,9 @@ export const operationLogServiceServer = plugin((server) => {

const res = operationLogs.map(toGrpcOperationLog);

const addAccountNamesRes = res.map(addOperationLogAccountNames);
return [{
results: res,
results: addAccountNamesRes,
totalCount: count,
}];
},
Expand All @@ -98,19 +99,19 @@ export const operationLogServiceServer = plugin((server) => {
});

const records = operationLogs.map(toGrpcOperationLog);

if (records.length === 0) {
const addAccountNamesRecords = records.map(addOperationLogAccountNames);
if (addAccountNamesRecords.length === 0) {
break;
}

let data: RecordFormatReturnType[] = [];
// 记录传输的总数量
let writeTotal = 0;

for (const row of records) {
for (const row of addAccountNamesRecords) {
data.push(row);
writeTotal += 1;
if (data.length === 200 || writeTotal === records.length) {
if (data.length === 200 || writeTotal === addAccountNamesRecords.length) {
await new Promise(async (resolve) => {
await writeAsync({ operationLogs: data });
// 清空暂存
Expand Down
33 changes: 33 additions & 0 deletions apps/audit-server/src/utils/operationLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const getTargetAccountName = (operationEvent: OperationEvent): string | u
switch (operationEvent[operationType].target.$case) {
case "accountOfTenant" :
return operationEvent[operationType].target.accountOfTenant.accountName;
case "accountsOfTenant" :
return operationEvent[operationType].target.accountsOfTenant.accountNames;
case "accountsOfAllTenants":
return operationEvent[operationType].target.accountsOfAllTenants.accountNames;
default:
return;
}
Expand Down Expand Up @@ -146,3 +150,32 @@ export const checkCustomEventType = async (em: SqlEntityManager<MySqlDriver>, op
}

};

/**
* @param operationEvent
* @returns targetAccountName
* @description
* 如果是导出消费记录或者导出充值记录且target是accountOfTenant,返回accountName
* 如果是导出操作日志且source是account,返回accountName
*/
export const addOperationLogAccountNames = (operationLog: OperationLog): OperationLog => {
const operationType = operationLog.operationEvent?.$case;
if (operationType !== "exportChargeRecord" && operationType !== "exportPayRecord") {
return operationLog;
}
const targetObject = operationLog.operationEvent[operationType].target;
const targetCase = targetObject.$case;
const caseObject = targetObject[targetCase];
const addLogAccountNames = () => {
const logCopy = JSON.parse(JSON.stringify(operationLog));
logCopy.operationEvent[operationType].target[targetCase].accountNames = [];
return logCopy;
};
switch (targetCase) {
case "accountsOfTenant" :
case "accountsOfAllTenants":
return caseObject.accountNames ? operationLog : addLogAccountNames();
default:
return operationLog;
}
};
8 changes: 4 additions & 4 deletions apps/audit-server/tests/log/operationLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ it("create operation log with targetAccountName", async () => {
operationEvent: {
$case: "exportPayRecord" as const,
exportPayRecord: { target:{
$case: "accountOfTenant" as const,
accountOfTenant: {
accountName: "testAccount",
$case: "accountsOfTenant" as const,
accountsOfTenant: {
tenantName: "testTenant",
accountNames: [],
},
},
},
Expand Down Expand Up @@ -245,7 +245,7 @@ it("create operation log with targetAccountName", async () => {
expect(operationLogs[1].metaData?.[operationLogs[1].metaData?.$case])
.toEqual(exportPayRecordLog.operationEvent.exportPayRecord);
expect(operationLogs[1].metaData?.targetAccountName)
.toEqual(exportPayRecordLog.operationEvent.exportPayRecord.target.accountOfTenant.accountName);
.toEqual(exportPayRecordLog.operationEvent.exportPayRecord.target.accountsOfTenant.accountNames);

expect(operationLogs[2].metaData?.$case).toEqual("exportChargeRecord");
expect(operationLogs[2].metaData?.[operationLogs[2].metaData?.$case])
Expand Down
33 changes: 15 additions & 18 deletions apps/mis-server/src/services/charging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import { Tenant } from "src/entities/Tenant";
import { queryWithCache } from "src/utils/cache";
import {
getChargesSearchType,
getChargesSearchTypes,
getChargesTargetSearchParam,
getPaymentsSearchType,
getPaymentsTargetSearchParam,
} from "src/utils/chargesQuery";
import { CHARGE_TYPE_OTHERS } from "src/utils/constants";
Expand Down Expand Up @@ -158,21 +160,21 @@ export const chargingServiceServer = plugin((server) => {
*
* case tenant:返回这个租户(tenantName)的充值记录
* case allTenants: 返回该所有租户充值记录
* case accountOfTenant: 返回该这个租户(tenantName)下这个账户(accountName)的充值记录
* case accountsOfTenant: 返回这个租户(tenantName)下所有账户的充值记录
* case accountsOfTenant: 返回这个租户(tenantName)下多个账户的充值记录
*
* @returns
*/
getPaymentRecords: async ({ request, em }) => {

const { endTime, startTime, target } =
ensureNotUndefined(request, ["startTime", "endTime", "target"]);
const { endTime, startTime, target, types } =
ensureNotUndefined(request, ["startTime", "endTime", "target", "types"]);

const searchParam = getPaymentsTargetSearchParam(target);

const searchTypes = getPaymentsSearchType(types);
const records = await em.find(PayRecord, {
time: { $gte: startTime, $lte: endTime },
...searchParam,
...searchTypes,
}, { orderBy: { time: QueryOrder.DESC } });

return [{
Expand Down Expand Up @@ -405,19 +407,16 @@ export const chargingServiceServer = plugin((server) => {
* case tenant:返回这个租户(tenantName)的消费记录
* case allTenants: 返回所有租户消费记录
* case accountOfTenant: 返回这个租户(tenantName)下这个账户(accountName)的消费记录
* case accountsOfTenant: 返回这个租户(tenantName)下所有账户的消费记录
* case accountsOfAllTenants: 返回所有租户下所有账户的消费记录
* case accountsOfTenant: 返回这个租户(tenantName)下多个账户的消费记录
* case accountsOfAllTenants: 返回所有租户下多个账户的消费记录
*
* @returns
*/
getPaginatedChargeRecords: async ({ request, em }) => {
const { startTime, endTime, type, target, userIds, page, pageSize }
const { startTime, endTime, type, types, target, userIds, page, pageSize }
= ensureNotUndefined(request, ["startTime", "endTime"]);

const searchParam = getChargesTargetSearchParam(target);

const searchType = getChargesSearchType(type);

const searchType = types.length === 0 ? getChargesSearchType(type) : getChargesSearchTypes(types);
const records = await em.find(ChargeRecord, {
time: { $gte: startTime, $lte: endTime },
...searchType,
Expand Down Expand Up @@ -451,19 +450,17 @@ export const chargingServiceServer = plugin((server) => {
* case tenant:返回这个租户(tenantName)的消费记录
* case allTenants: 返回所有租户消费记录
* case accountOfTenant: 返回这个租户(tenantName)下这个账户(accountName)的消费记录
* case accountsOfTenant: 返回这个租户(tenantName)下所有账户的消费记录
* case accountsOfAllTenants: 返回所有租户下所有账户的消费记录
* case accountsOfTenant: 返回这个租户(tenantName)下多个账户的消费记录
* case accountsOfAllTenants: 返回所有租户下多个账户的消费记录
*
* @returns
*/
getChargeRecordsTotalCount: async ({ request, em }) => {
const { startTime, endTime, type, target, userIds }
const { startTime, endTime, type, types, target, userIds }
= ensureNotUndefined(request, ["startTime", "endTime"]);

const searchParam = getChargesTargetSearchParam(target);

const searchType = getChargesSearchType(type);

const searchType = types.length === 0 ? getChargesSearchType(type) : getChargesSearchTypes(types);
const { total_count, total_amount }: { total_count: number, total_amount: string }
= await em.createQueryBuilder(ChargeRecord, "c")
.select(raw("count(c.id) as total_count"))
Expand Down
16 changes: 10 additions & 6 deletions apps/mis-server/src/services/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import { UserRole, UserStatus } from "src/entities/UserAccount";
import { getAccountStateInfo } from "src/utils/accountUserState";
import {
getChargesSearchType,
getChargesSearchTypes,
getChargesTargetSearchParam,
getPaymentsSearchType,
getPaymentsTargetSearchParam,
} from "src/utils/chargesQuery";
import { mapUsersSortField } from "src/utils/queryOptions";
Expand Down Expand Up @@ -270,14 +272,14 @@ export const exportServiceServer = plugin((server) => {
startTime,
endTime,
type,
types,
target,
count,
userIds,
} = request;

const searchParam = getChargesTargetSearchParam(target);
const searchType = getChargesSearchType(type);

const searchType = types.length === 0 ? getChargesSearchType(type) : getChargesSearchTypes(types);
const query = {
time: { $gte: startTime, $lte: endTime },
...searchType,
Expand Down Expand Up @@ -346,14 +348,16 @@ export const exportServiceServer = plugin((server) => {
endTime,
target,
count,
types,
} = ensureNotUndefined(request, ["target"]);

const searchParam = getPaymentsTargetSearchParam(target);
const query = {
time: { $gte: startTime, $lte: endTime },
const searchTypes = getPaymentsSearchType(types);
const query: { time: { $gte: string; $lte: string }; [key: string]: any } = {
time: { $gte: startTime as string, $lte: endTime as string },
...searchParam,
...searchTypes,
};

// type并非仅有一个空字符串时,增加type条件
const recordFormat = (x: Loaded<PayRecord, never>) => ({
tenantName: x.tenantName,
accountName: x.accountName,
Expand Down
16 changes: 16 additions & 0 deletions apps/mis-server/src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ export function range(start = 1, end = 0, step = 1): number[] {
}
return r;
}

type ObjectTypeWithType = {
type: string;
[key: string]: any;
};

export function extractTypesFromObjects(array: ObjectTypeWithType[]): string[] {
const types = new Set<string>();
for (const item of array) {
if (item.type) {
types.add(item.type);
}
}
return Array.from(types);
}

Loading

0 comments on commit a53bcad

Please sign in to comment.