chore: 首页数据统计项目显示

This commit is contained in:
xiaojunnuo
2026-02-27 00:14:53 +08:00
parent 787f6ef528
commit b2c421600c
8 changed files with 72 additions and 22 deletions
@@ -46,14 +46,15 @@ export class StatisticController extends BaseController {
@Post('/count', { summary: Constants.per.authOnly })
public async count() {
const pipelineCount = await this.pipelineService.count({ userId: this.getUserId() });
const pipelineStatusCount = await this.pipelineService.statusCount({ userId: this.getUserId() });
const pipelineEnableCount = await this.pipelineService.enableCount({ userId: this.getUserId() });
const {userId,projectId} = await this.getProjectUserIdRead();
const pipelineCount = await this.pipelineService.count({ userId,projectId });
const pipelineStatusCount = await this.pipelineService.statusCount({ userId,projectId });
const pipelineEnableCount = await this.pipelineService.enableCount({ userId,projectId });
const historyCount = await this.historyService.countPerDay({ userId: this.getUserId(), days: 7 });
const expiringList = await this.pipelineService.latestExpiringList({ userId: this.getUserId(), count: 5 });
const historyCount = await this.historyService.countPerDay({ userId,projectId, days: 7 });
const expiringList = await this.pipelineService.latestExpiringList({ userId,projectId, count: 5 });
const certCount = await this.certInfoService.count({ userId: this.getUserId() });
const certCount = await this.certInfoService.count({ userId,projectId });
const count: UserStatisticCount = {
pipelineCount,
@@ -191,11 +191,12 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
});
}
async count({ userId }: { userId: number }) {
async count({ userId,projectId }: { userId: number,projectId?:number }) {
const total = await this.repository.count({
where: {
userId,
expiresTime: Not(IsNull()),
projectId,
},
});
@@ -203,6 +204,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
where: {
userId,
expiresTime: LessThan(new Date().getTime()),
projectId,
},
});
@@ -210,6 +212,7 @@ export class CertInfoService extends BaseService<CertInfoEntity> {
where: {
userId,
expiresTime: Between(new Date().getTime(), new Date().getTime() + 15 * 24 * 60 * 60 * 1000),
projectId,
},
});
@@ -183,7 +183,7 @@ export class HistoryService extends BaseService<HistoryEntity> {
}
}
async countPerDay(param: { days: number; userId?: any }) {
async countPerDay(param: { days: number; userId?: any,projectId?:number }) {
const todayEnd = dayjs().endOf('day');
const where: any = {
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
@@ -191,6 +191,9 @@ export class HistoryService extends BaseService<HistoryEntity> {
if (param.userId > 0) {
where.userId = param.userId;
}
if (param.projectId > 0) {
where.projectId = param.projectId;
}
const result = await this.getRepository()
.createQueryBuilder('main')
.select(`${this.dbAdapter.date('main.createTime')} AS date`) // 将UNIX时间戳转换为日期
@@ -824,35 +824,39 @@ export class PipelineService extends BaseService<PipelineEntity> {
await this.historyLogService.addOrUpdate(logEntity);
}
async count(param: { userId?: any }) {
async count(param: { userId?: any,projectId?:number }) {
const count = await this.repository.count({
where: {
userId: param.userId
userId: param.userId,
projectId: param.projectId,
isTemplate: false
}
});
return count;
}
async statusCount(param: { userId?: any } = {}) {
async statusCount(param: { userId?: any,projectId?:number } = {}) {
const statusCount = await this.repository
.createQueryBuilder()
.select("status")
.addSelect("count(1)", "count")
.where({
userId: param.userId
userId: param.userId,
projectId: param.projectId
})
.groupBy("status")
.getRawMany();
return statusCount;
}
async enableCount(param: { userId?: any } = {}) {
async enableCount(param: { userId?: any,projectId?:number } = {}) {
const statusCount = await this.repository
.createQueryBuilder()
.select("disabled")
.addSelect("count(1)", "count")
.where({
userId: param.userId
userId: param.userId,
projectId: param.projectId
})
.groupBy("disabled")
.getRawMany();
@@ -866,7 +870,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
return result;
}
async latestExpiringList({ userId }: any) {
async latestExpiringList({ userId,projectId }: any) {
let list = await this.repository.find({
select: {
id: true,
@@ -875,7 +879,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
},
where: {
userId,
disabled: false
disabled: false,
projectId
}
});
await this.fillLastVars(list);