feat: 完成 PRD 差距与修复,新增审核流与日志清理功能,支持出库信息与动态字段,优化 C 端用户体验
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { Cron, CronExpression } from '@nestjs/schedule';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
|
||||
// 查询日志保留周期清理:每天凌晨执行,删除超过保留天数的日志。
|
||||
// 保留天数取系统设置 logRetentionDays(后台可配置),<=0 表示长期保留、不清理。
|
||||
@Injectable()
|
||||
export class LogRetentionService {
|
||||
private readonly logger = new Logger(LogRetentionService.name);
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly settings: SettingsService,
|
||||
) {}
|
||||
|
||||
@Cron(CronExpression.EVERY_DAY_AT_3AM)
|
||||
async cleanup(): Promise<void> {
|
||||
const days = await this.resolveRetentionDays();
|
||||
if (!days || days <= 0) {
|
||||
this.logger.log('日志保留周期为长期保留,跳过清理');
|
||||
return;
|
||||
}
|
||||
const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000);
|
||||
const { count } = await this.prisma.queryLog.deleteMany({
|
||||
where: { queriedAt: { lt: cutoff } },
|
||||
});
|
||||
this.logger.log(`查询日志清理完成:删除 ${count} 条(保留 ${days} 天,截止 ${cutoff.toISOString()})`);
|
||||
}
|
||||
|
||||
private async resolveRetentionDays(): Promise<number> {
|
||||
const raw = await this.settings.get('logRetentionDays');
|
||||
const n = Number(raw);
|
||||
if (raw !== null && !Number.isNaN(n)) return n;
|
||||
return 365;
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,21 @@ import { buildPage } from '../common/utils/pagination.util';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
class QueryLogQueryDto extends PaginationDto {
|
||||
@ApiPropertyOptional({ description: '关键词(短码)' })
|
||||
@ApiPropertyOptional({ description: '关键词(短码 / 追溯码 / SKU / 档案编号)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
keyword?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'SKU' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
sku?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '批次编号' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
batchNo?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: '查询结果', enum: QueryResult })
|
||||
@IsOptional()
|
||||
@IsEnum(QueryResult)
|
||||
@@ -39,7 +49,16 @@ export class QueryLogController {
|
||||
@ApiOperation({ summary: '查询日志列表' })
|
||||
async list(@Query() query: QueryLogQueryDto) {
|
||||
const where: Prisma.QueryLogWhereInput = {};
|
||||
if (query.keyword) where.shortCode = { contains: query.keyword };
|
||||
if (query.keyword) {
|
||||
where.OR = [
|
||||
{ shortCode: { contains: query.keyword } },
|
||||
{ code: { contains: query.keyword } },
|
||||
{ sku: { contains: query.keyword } },
|
||||
{ archiveNo: { contains: query.keyword } },
|
||||
];
|
||||
}
|
||||
if (query.sku) where.sku = { contains: query.sku };
|
||||
if (query.batchNo) where.batchNo = { contains: query.batchNo };
|
||||
if (query.result) where.queryResult = query.result;
|
||||
if (query.startTime || query.endTime) {
|
||||
where.queriedAt = {};
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { QueryLogController } from './query-log.controller';
|
||||
import { LogRetentionService } from './log-retention.service';
|
||||
|
||||
@Module({
|
||||
controllers: [QueryLogController],
|
||||
providers: [LogRetentionService],
|
||||
})
|
||||
export class QueryLogModule {}
|
||||
|
||||
Reference in New Issue
Block a user