mirror of
https://github.com/certd/certd.git
synced 2026-05-16 05:07:32 +08:00
feat: 首页全新改版
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { In, MoreThan, Repository } from 'typeorm';
|
||||
import { BaseService, PageReq } from '@certd/lib-server';
|
||||
import { HistoryEntity } from '../entity/history.js';
|
||||
import { PipelineEntity } from '../entity/pipeline.js';
|
||||
@@ -9,7 +9,7 @@ import { HistoryLogService } from './history-log-service.js';
|
||||
import { FileItem, Pipeline, RunnableCollection } from '@certd/pipeline';
|
||||
import { FileStore } from '@certd/pipeline';
|
||||
import { logger } from '@certd/pipeline';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
/**
|
||||
* 证书申请
|
||||
*/
|
||||
@@ -174,4 +174,21 @@ export class HistoryService extends BaseService<HistoryEntity> {
|
||||
logger.error('删除文件失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
async dayCount(param: { days: number; userId: any }) {
|
||||
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点
|
||||
userId: param.userId,
|
||||
createTime: MoreThan(todayEnd.add(-param.days, 'day').toDate()),
|
||||
})
|
||||
.groupBy('date')
|
||||
.getRawMany();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,18 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
|
||||
async page(pageReq: PageReq<PipelineEntity>) {
|
||||
const result = await super.page(pageReq);
|
||||
await this.fillLastVars(result.records);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async fillLastVars(records: PipelineEntity[]) {
|
||||
const pipelineIds: number[] = [];
|
||||
const recordMap = {};
|
||||
for (const record of result.records) {
|
||||
for (const record of records) {
|
||||
pipelineIds.push(record.id);
|
||||
recordMap[record.id] = record;
|
||||
record.title = record.title + '';
|
||||
}
|
||||
if (pipelineIds?.length > 0) {
|
||||
const vars = await this.storageService.findPipelineVars(pipelineIds);
|
||||
@@ -87,8 +94,6 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async registerTriggerById(pipelineId) {
|
||||
@@ -467,4 +472,48 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
logEntity.logs = JSON.stringify(history.logs);
|
||||
await this.historyLogService.addOrUpdate(logEntity);
|
||||
}
|
||||
|
||||
async count(param: { userId: any }) {
|
||||
const count = await this.repository.count({
|
||||
where: {
|
||||
userId: param.userId,
|
||||
},
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
async statusCount(param: { userId: any }) {
|
||||
const statusCount = await this.repository
|
||||
.createQueryBuilder()
|
||||
.select('status')
|
||||
.addSelect('count(1)', 'count')
|
||||
.where({
|
||||
userId: param.userId,
|
||||
})
|
||||
.groupBy('status')
|
||||
.getRawMany();
|
||||
return statusCount;
|
||||
}
|
||||
|
||||
async latestExpiringList({ userId }: any) {
|
||||
let list = await this.repository.find({
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
status: true,
|
||||
},
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
});
|
||||
await this.fillLastVars(list);
|
||||
list = list.filter(item => {
|
||||
return item.lastVars?.certExpiresTime != null;
|
||||
});
|
||||
list = list.sort((a, b) => {
|
||||
return a.lastVars.certExpiresTime - b.lastVars.certExpiresTime;
|
||||
});
|
||||
|
||||
return list.slice(0, 5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user