This commit is contained in:
cool 2024-01-23 10:45:29 +08:00
parent df540acb09
commit 5b599c4a20
2 changed files with 6 additions and 18 deletions

View File

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

View File

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