mirror of
https://github.com/certd/certd.git
synced 2026-05-17 05:37:30 +08:00
perf: 管理控制台数据统计
This commit is contained in:
@@ -175,17 +175,21 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
async dayCount(param: { days: number; userId: any }) {
|
||||
async countPerDay(param: { days: number; userId?: any }) {
|
||||
const todayEnd = dayjs().endOf('day');
|
||||
const where: any = {
|
||||
// 0点
|
||||
// userId: param.userId,
|
||||
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
|
||||
};
|
||||
if (param.userId > 0) {
|
||||
where.userId = param.userId;
|
||||
}
|
||||
const result = await this.getRepository()
|
||||
.createQueryBuilder('main')
|
||||
.select('date(main.createTime) AS date') // 将UNIX时间戳转换为日期
|
||||
.addSelect('COUNT(*) AS count')
|
||||
.where({
|
||||
// 0点
|
||||
userId: param.userId,
|
||||
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
|
||||
})
|
||||
.where(where)
|
||||
.groupBy('date')
|
||||
.getRawMany();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum, sleep } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { In, MoreThan, Repository } from 'typeorm';
|
||||
import { BaseService, NeedVIPException, PageReq, SysPublicSettings, SysSettingsService } from '@certd/lib-server';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
import { PipelineDetail } from '../entity/vo/pipeline-detail.js';
|
||||
@@ -19,6 +19,7 @@ import { AccessGetter } from './access-getter.js';
|
||||
import { CnameRecordService } from '../../cname/service/cname-record-service.js';
|
||||
import { CnameProxyService } from './cname-proxy-service.js';
|
||||
import { PluginConfigGetter } from '../../plugin/service/plugin-config-getter.js';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const runningTasks: Map<string | number, Executor> = new Map();
|
||||
const freeCount = 10;
|
||||
@@ -473,7 +474,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
await this.historyLogService.addOrUpdate(logEntity);
|
||||
}
|
||||
|
||||
async count(param: { userId: any }) {
|
||||
async count(param: { userId?: any }) {
|
||||
const count = await this.repository.count({
|
||||
where: {
|
||||
userId: param.userId,
|
||||
@@ -482,7 +483,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
return count;
|
||||
}
|
||||
|
||||
async statusCount(param: { userId: any }) {
|
||||
async statusCount(param: { userId?: any } = {}) {
|
||||
const statusCount = await this.repository
|
||||
.createQueryBuilder()
|
||||
.select('status')
|
||||
@@ -516,4 +517,20 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
|
||||
return list.slice(0, 5);
|
||||
}
|
||||
|
||||
async createCountPerDay(param: { days: number } = { days: 7 }) {
|
||||
const todayEnd = dayjs().endOf('day');
|
||||
const result = await this.getRepository()
|
||||
.createQueryBuilder('main')
|
||||
.select('date(main.createTime) AS date') // 将UNIX时间戳转换为日期
|
||||
.addSelect('COUNT(*) AS count')
|
||||
.where({
|
||||
// 0点
|
||||
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
|
||||
})
|
||||
.groupBy('date')
|
||||
.getRawMany();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { MoreThan, Repository } from 'typeorm';
|
||||
import { UserEntity } from '../entity/user.js';
|
||||
import * as _ from 'lodash-es';
|
||||
import md5 from 'md5';
|
||||
@@ -15,6 +15,7 @@ import bcrypt from 'bcryptjs';
|
||||
import { SysSettingsService } from '@certd/lib-server';
|
||||
import { SysInstallInfo } from '@certd/lib-server';
|
||||
import { RandomUtil } from '../../../../utils/random.js';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
@@ -245,4 +246,29 @@ export class UserService extends BaseService<UserEntity> {
|
||||
status,
|
||||
});
|
||||
}
|
||||
|
||||
async count(param: { userId?: any } = {}) {
|
||||
const count = await this.repository.count({
|
||||
where: {
|
||||
id: param.userId,
|
||||
},
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
async registerCountPerDay(param: { days: number } = { days: 7 }) {
|
||||
const todayEnd = dayjs().endOf('day');
|
||||
const result = await this.getRepository()
|
||||
.createQueryBuilder('main')
|
||||
.select('date(main.createTime) AS date') // 将UNIX时间戳转换为日期
|
||||
.addSelect('COUNT(*) AS count')
|
||||
.where({
|
||||
// 0点
|
||||
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
|
||||
})
|
||||
.groupBy('date')
|
||||
.getRawMany();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user