perf: 管理控制台数据统计

This commit is contained in:
xiaojunnuo
2024-10-31 16:19:35 +08:00
parent 63ec5b5519
commit babd5897ae
14 changed files with 265 additions and 74 deletions

View File

@@ -1,4 +1,4 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController, Constants } from '@certd/lib-server';
import { UserService } from '../../modules/sys/authority/service/user-service.js';
import { RoleService } from '../../modules/sys/authority/service/role-service.js';
@@ -12,7 +12,7 @@ export type ChartItem = {
export type UserStatisticCount = {
pipelineCount?: number;
pipelineStatusCount?: ChartItem[];
runningCount: ChartItem[];
historyCountPerDay: ChartItem[];
expiringList: any[];
};
/**
@@ -33,36 +33,15 @@ export class StatisticController extends BaseController {
@Post('/count', { summary: Constants.per.authOnly })
public async count() {
const pipelineCount = await this.pipelineService.count({ userId: this.getUserId() });
let pipelineStatusCount = await this.pipelineService.statusCount({ userId: this.getUserId() });
pipelineStatusCount = pipelineStatusCount.map(item => {
return {
name: item.status,
value: item.count,
};
});
const historyCount = await this.historyService.dayCount({ userId: this.getUserId(), days: 7 });
const runningCount = historyCount.map(item => {
return {
name: item.date,
value: item.count,
};
});
const pipelineStatusCount = await this.pipelineService.statusCount({ userId: this.getUserId() });
const historyCount = await this.historyService.countPerDay({ userId: this.getUserId(), days: 7 });
const expiringList = await this.pipelineService.latestExpiringList({ userId: this.getUserId(), count: 5 });
const count: UserStatisticCount = {
pipelineCount,
pipelineStatusCount,
runningCount,
historyCountPerDay: historyCount,
expiringList,
};
return this.ok(count);
}
@Post('/changePassword', { summary: Constants.per.authOnly })
public async changePassword(@Body(ALL) body: any) {
const userId = this.getUserId();
await this.userService.changePassword(userId, body);
return this.ok({});
}
}