perf: 证书仓库页面增加到期状态查询条件

This commit is contained in:
xiaojunnuo
2026-01-29 00:38:33 +08:00
parent c408687af7
commit 58c3d7087b
11 changed files with 73 additions and 9 deletions
@@ -1,11 +1,12 @@
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from "@midwayjs/core";
import { CommonException, Constants, CrudController } from "@certd/lib-server";
import { CommonException, Constants, CrudController, SysSettingsService } from "@certd/lib-server";
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
import { CertInfoService } from "../../../modules/monitor/index.js";
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
import { SelectQueryBuilder } from "typeorm";
import { logger } from "@certd/basic";
import fs from "fs";
import dayjs from "dayjs";
/**
*/
@@ -19,6 +20,9 @@ export class CertInfoController extends CrudController<CertInfoService> {
@Inject()
pipelineService: PipelineService;
@Inject()
sysSettingService: SysSettingsService;
getService(): CertInfoService {
return this.service;
}
@@ -29,6 +33,12 @@ export class CertInfoController extends CrudController<CertInfoService> {
body.query.userId = this.getUserId();
const domains = body.query?.domains;
delete body.query.domains;
const expiresLeft = body.query?.expiresLeft;
delete body.query.expiresLeft;
const sysSetting = await this.sysSettingService.getPublicSettings();
const DEFAULT_WILL_EXPIRE_DAYS = sysSetting?.defaultWillExpireDays || sysSetting?.defaultCertRenewDays || 15;
const res = await this.service.page({
query: body.query,
page: body.page,
@@ -37,6 +47,16 @@ export class CertInfoController extends CrudController<CertInfoService> {
if (domains) {
bq.andWhere('domains like :domains', { domains: `%${domains}%` });
}
if (expiresLeft) {
const willExpire = dayjs().add(DEFAULT_WILL_EXPIRE_DAYS, 'day').valueOf();
if (expiresLeft === "expired") {
bq.andWhere('expires_time < :now', { now: Date.now() });
} else if (expiresLeft === "expiring") {
bq.andWhere('expires_time <= :willExpire and expires_time > :now', { willExpire, now: Date.now() });
} else if (expiresLeft === "noExpired") {
bq.andWhere('expires_time > :willExpire', { willExpire });
}
}
}
});