mirror of
https://github.com/certd/certd.git
synced 2026-04-15 21:40:53 +08:00
perf: 管理控制台数据统计
This commit is contained in:
@@ -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({});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||
import { BaseController } from '@certd/lib-server';
|
||||
import { UserService } from '../../../modules/sys/authority/service/user-service.js';
|
||||
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
|
||||
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
|
||||
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
|
||||
|
||||
export type ChartItem = {
|
||||
name: string;
|
||||
value: number;
|
||||
};
|
||||
export type SysStatisticCount = {
|
||||
userCount: number;
|
||||
pipelineCount?: number;
|
||||
historyCountPerDay: ChartItem[];
|
||||
userRegisterCountPerDay: ChartItem[];
|
||||
pipelineCreateCountPerDay: ChartItem[];
|
||||
};
|
||||
/**
|
||||
*/
|
||||
@Provide()
|
||||
@Controller('/api/sys/statistic/')
|
||||
export class SysStatisticController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
@Inject()
|
||||
roleService: RoleService;
|
||||
|
||||
@Inject()
|
||||
pipelineService: PipelineService;
|
||||
@Inject()
|
||||
historyService: HistoryService;
|
||||
|
||||
@Post('/count', { summary: 'sys:settings:view' })
|
||||
public async count() {
|
||||
const userCount = await this.userService.count();
|
||||
const userRegisterCountPerDay = await this.userService.registerCountPerDay({ days: 7 });
|
||||
const pipelineCreateCountPerDay = await this.pipelineService.createCountPerDay({ days: 7 });
|
||||
const pipelineCount = await this.pipelineService.count({});
|
||||
const historyCountPerDay = await this.historyService.countPerDay({ days: 7 });
|
||||
|
||||
const count: SysStatisticCount = {
|
||||
userCount,
|
||||
userRegisterCountPerDay,
|
||||
pipelineCount,
|
||||
pipelineCreateCountPerDay,
|
||||
historyCountPerDay,
|
||||
};
|
||||
return this.ok(count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user