feat: 实现出库导入、区块链存证、查询日志、看板与系统设置

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-28 16:25:03 +08:00
co-authored by Cursor
parent 63c0488ff7
commit 23cbf37aa1
20 changed files with 720 additions and 6 deletions
@@ -0,0 +1,35 @@
import { Body, Controller, Get, Put } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { RoleType } from '@artveris/shared';
import { SettingsService } from './settings.service';
import { Roles } from '../common/decorators/roles.decorator';
import { Public } from '../common/decorators/public.decorator';
@ApiTags('系统设置')
@Controller('settings')
export class SettingsController {
constructor(private readonly settingsService: SettingsService) {}
@ApiBearerAuth()
@Get()
@ApiOperation({ summary: '获取全部系统设置' })
getAll() {
return this.settingsService.getAll();
}
@Public()
@Get('public')
@ApiOperation({ summary: '获取公开设置(应用名等)' })
async getPublic() {
const all = await this.settingsService.getAll();
return { appName: all.appName };
}
@ApiBearerAuth()
@Roles(RoleType.SUPER_ADMIN)
@Put()
@ApiOperation({ summary: '更新系统设置' })
update(@Body() body: Record<string, string>) {
return this.settingsService.update(body);
}
}
+11
View File
@@ -0,0 +1,11 @@
import { Global, Module } from '@nestjs/common';
import { SettingsService } from './settings.service';
import { SettingsController } from './settings.controller';
@Global()
@Module({
controllers: [SettingsController],
providers: [SettingsService],
exports: [SettingsService],
})
export class SettingsModule {}
+41
View File
@@ -0,0 +1,41 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PrismaService } from '../prisma/prisma.service';
const EDITABLE_KEYS = ['appName', 'logRetentionDays', 'watermarkText'];
@Injectable()
export class SettingsService {
constructor(
private readonly prisma: PrismaService,
private readonly config: ConfigService,
) {}
async getAll(): Promise<Record<string, string>> {
const rows = await this.prisma.systemSetting.findMany();
const map: Record<string, string> = {
appName: this.config.get<string>('appName') || '',
logRetentionDays: String(this.config.get<number>('logRetentionDays') || 365),
watermarkText: this.config.get<string>('watermarkText') || '仅供溯源核验使用',
};
for (const r of rows) map[r.key] = r.value;
return map;
}
async get(key: string): Promise<string | null> {
const row = await this.prisma.systemSetting.findUnique({ where: { key } });
return row?.value ?? null;
}
async update(values: Record<string, string>): Promise<Record<string, string>> {
for (const [key, value] of Object.entries(values)) {
if (!EDITABLE_KEYS.includes(key)) continue;
await this.prisma.systemSetting.upsert({
where: { key },
update: { value: String(value) },
create: { key, value: String(value) },
});
}
return this.getAll();
}
}