From 5b599c4a200da07f8ace6ffdc68a8e779013bacc Mon Sep 17 00:00:00 2001 From: cool Date: Tue, 23 Jan 2024 10:45:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/base/service/sys/log.ts | 12 +++--------- src/modules/recycle/service/data.ts | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/modules/base/service/sys/log.ts b/src/modules/base/service/sys/log.ts index 5d92474..e54c0f7 100644 --- a/src/modules/base/service/sys/log.ts +++ b/src/modules/base/service/sys/log.ts @@ -1,7 +1,7 @@ import { Inject, Provide } from '@midwayjs/decorator'; import { BaseService } from '@cool-midway/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; -import { Repository } from 'typeorm'; +import { LessThan, Repository } from 'typeorm'; import * as _ from 'lodash'; import { BaseSysLogEntity } from '../../entity/sys/log'; import * as moment from 'moment'; @@ -57,14 +57,8 @@ export class BaseSysLogService extends BaseService { } const keepDay = await this.baseSysConfService.getValue('logKeep'); if (keepDay) { - const beforeDate = `${moment() - .add(-keepDay, 'days') - .format('YYYY-MM-DD')} 00:00:00`; - await this.baseSysLogEntity - .createQueryBuilder() - .delete() - .where('createTime < :createTime', { createTime: beforeDate }) - .execute(); + const beforeDate = moment().add(-keepDay, 'days').startOf('day').toDate(); + await this.baseSysLogEntity.delete({ createTime: LessThan(beforeDate) }); } else { await this.baseSysLogEntity.clear(); } diff --git a/src/modules/recycle/service/data.ts b/src/modules/recycle/service/data.ts index a5ce7b0..300ce36 100644 --- a/src/modules/recycle/service/data.ts +++ b/src/modules/recycle/service/data.ts @@ -2,7 +2,7 @@ import { RecycleDataEntity } from './../entity/data'; import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/decorator'; import { BaseService } from '@cool-midway/core'; import { InjectEntityModel, TypeORMDataSourceManager } from '@midwayjs/typeorm'; -import { Repository } from 'typeorm'; +import { LessThan, Repository } from 'typeorm'; import * as _ from 'lodash'; import * as moment from 'moment'; import { BaseSysConfService } from '../../base/service/sys/conf'; @@ -74,14 +74,8 @@ export class RecycleDataService extends BaseService { } const keepDay = await this.baseSysConfService.getValue('recycleKeep'); if (keepDay) { - const beforeDate = `${moment() - .add(-keepDay, 'days') - .format('YYYY-MM-DD')} 00:00:00`; - await this.recycleDataEntity - .createQueryBuilder('a') - .delete() - .where('a.createTime < :createTime', { createTime: beforeDate }) - .execute(); + const beforeDate = moment().add(-keepDay, 'days').startOf('day').toDate(); + await this.recycleDataEntity.delete({ createTime: LessThan(beforeDate) }); } else { await this.recycleDataEntity.clear(); }