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(); }