feat: 完善后台导入日志权限与备份恢复
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
-- Extend job types for import preview and backup/restore tasks.
|
||||
ALTER TABLE `job`
|
||||
MODIFY `type` ENUM('GEN_CODE','IMPORT_OUTBOUND','IMPORT_OUTBOUND_PREVIEW','WATERMARK','ONCHAIN','BACKUP','RESTORE') NOT NULL;
|
||||
|
||||
-- Trace codes now support multiple outbound photos while keeping the old single-photo field for compatibility.
|
||||
ALTER TABLE `trace_code`
|
||||
ADD COLUMN `out_images` JSON NULL;
|
||||
|
||||
CREATE TABLE `operation_log` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`user_id` INTEGER NULL,
|
||||
`username` VARCHAR(191) NULL,
|
||||
`role` ENUM('SUPER_ADMIN','OPERATOR','AUDITOR','VIEWER') NULL,
|
||||
`module` VARCHAR(191) NOT NULL,
|
||||
`action` VARCHAR(191) NOT NULL,
|
||||
`method` VARCHAR(20) NOT NULL,
|
||||
`path` VARCHAR(512) NOT NULL,
|
||||
`target_id` VARCHAR(191) NULL,
|
||||
`status` VARCHAR(32) NOT NULL,
|
||||
`message` TEXT NULL,
|
||||
`ip` VARCHAR(191) NULL,
|
||||
`user_agent` TEXT NULL,
|
||||
`duration_ms` INTEGER NULL,
|
||||
`request_summary` JSON NULL,
|
||||
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
CREATE INDEX `operation_log_user_id_idx` ON `operation_log`(`user_id`);
|
||||
CREATE INDEX `operation_log_module_idx` ON `operation_log`(`module`);
|
||||
CREATE INDEX `operation_log_action_idx` ON `operation_log`(`action`);
|
||||
CREATE INDEX `operation_log_status_idx` ON `operation_log`(`status`);
|
||||
CREATE INDEX `operation_log_created_at_idx` ON `operation_log`(`created_at`);
|
||||
ALTER TABLE `operation_log`
|
||||
ADD CONSTRAINT `operation_log_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `sys_user`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
CREATE TABLE `outbound_import_session` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`status` ENUM('PARSING','READY','IMPORTING','IMPORTED','FAILED','EXPIRED') NOT NULL DEFAULT 'PARSING',
|
||||
`file_name` VARCHAR(191) NOT NULL,
|
||||
`file_key` VARCHAR(512) NULL,
|
||||
`total` INTEGER NOT NULL DEFAULT 0,
|
||||
`valid_count` INTEGER NOT NULL DEFAULT 0,
|
||||
`invalid_count` INTEGER NOT NULL DEFAULT 0,
|
||||
`error` TEXT NULL,
|
||||
`committed_at` DATETIME(3) NULL,
|
||||
`expires_at` DATETIME(3) NOT NULL,
|
||||
`created_by` INTEGER NULL,
|
||||
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updated_at` DATETIME(3) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
CREATE INDEX `outbound_import_session_status_idx` ON `outbound_import_session`(`status`);
|
||||
CREATE INDEX `outbound_import_session_created_by_idx` ON `outbound_import_session`(`created_by`);
|
||||
CREATE INDEX `outbound_import_session_expires_at_idx` ON `outbound_import_session`(`expires_at`);
|
||||
ALTER TABLE `outbound_import_session`
|
||||
ADD CONSTRAINT `outbound_import_session_created_by_fkey` FOREIGN KEY (`created_by`) REFERENCES `sys_user`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
CREATE TABLE `outbound_import_row` (
|
||||
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||
`session_id` VARCHAR(191) NOT NULL,
|
||||
`row_no` INTEGER NOT NULL,
|
||||
`status` ENUM('VALID','INVALID','IMPORTED','FAILED') NOT NULL DEFAULT 'INVALID',
|
||||
`short_code` VARCHAR(191) NULL,
|
||||
`batch_no` VARCHAR(191) NULL,
|
||||
`out_time` DATETIME(3) NULL,
|
||||
`out_image_paths` JSON NULL,
|
||||
`out_image_keys` JSON NULL,
|
||||
`tx_hash` VARCHAR(255) NULL,
|
||||
`onchain_at` DATETIME(3) NULL,
|
||||
`block_height` BIGINT NULL,
|
||||
`remark` VARCHAR(255) NULL,
|
||||
`reason` TEXT NULL,
|
||||
`preview` JSON NULL,
|
||||
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
CREATE INDEX `outbound_import_row_session_id_idx` ON `outbound_import_row`(`session_id`);
|
||||
CREATE INDEX `outbound_import_row_status_idx` ON `outbound_import_row`(`status`);
|
||||
CREATE INDEX `outbound_import_row_short_code_idx` ON `outbound_import_row`(`short_code`);
|
||||
ALTER TABLE `outbound_import_row`
|
||||
ADD CONSTRAINT `outbound_import_row_session_id_fkey` FOREIGN KEY (`session_id`) REFERENCES `outbound_import_session`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
CREATE TABLE `backup_record` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`file_name` VARCHAR(191) NOT NULL,
|
||||
`file_path` VARCHAR(1024) NOT NULL,
|
||||
`size` BIGINT NOT NULL DEFAULT 0,
|
||||
`status` ENUM('PENDING','PROCESSING','SUCCESS','FAILED') NOT NULL DEFAULT 'PENDING',
|
||||
`mode` VARCHAR(32) NOT NULL DEFAULT 'BACKUP',
|
||||
`manifest` JSON NULL,
|
||||
`error` TEXT NULL,
|
||||
`created_by` INTEGER NULL,
|
||||
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updated_at` DATETIME(3) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
CREATE INDEX `backup_record_status_idx` ON `backup_record`(`status`);
|
||||
CREATE INDEX `backup_record_mode_idx` ON `backup_record`(`mode`);
|
||||
CREATE INDEX `backup_record_created_by_idx` ON `backup_record`(`created_by`);
|
||||
CREATE INDEX `backup_record_created_at_idx` ON `backup_record`(`created_at`);
|
||||
ALTER TABLE `backup_record`
|
||||
ADD CONSTRAINT `backup_record_created_by_fkey` FOREIGN KEY (`created_by`) REFERENCES `sys_user`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -91,8 +91,11 @@ enum QueryResult {
|
||||
enum JobType {
|
||||
GEN_CODE
|
||||
IMPORT_OUTBOUND
|
||||
IMPORT_OUTBOUND_PREVIEW
|
||||
WATERMARK
|
||||
ONCHAIN
|
||||
BACKUP
|
||||
RESTORE
|
||||
}
|
||||
|
||||
enum JobStatus {
|
||||
@@ -103,6 +106,29 @@ enum JobStatus {
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum OutboundImportSessionStatus {
|
||||
PARSING
|
||||
READY
|
||||
IMPORTING
|
||||
IMPORTED
|
||||
FAILED
|
||||
EXPIRED
|
||||
}
|
||||
|
||||
enum OutboundImportRowStatus {
|
||||
VALID
|
||||
INVALID
|
||||
IMPORTED
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum BackupStatus {
|
||||
PENDING
|
||||
PROCESSING
|
||||
SUCCESS
|
||||
FAILED
|
||||
}
|
||||
|
||||
model SysUser {
|
||||
id Int @id @default(autoincrement())
|
||||
username String @unique
|
||||
@@ -115,6 +141,9 @@ model SysUser {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
artworks Artwork[]
|
||||
operationLogs OperationLog[]
|
||||
outboundImportSessions OutboundImportSession[]
|
||||
backupRecords BackupRecord[]
|
||||
|
||||
@@map("sys_user")
|
||||
}
|
||||
@@ -251,6 +280,7 @@ model TraceCode {
|
||||
groupId Int? @map("group_id")
|
||||
outTime DateTime? @map("out_time")
|
||||
outImage String? @map("out_image")
|
||||
outImages Json? @map("out_images")
|
||||
remark String?
|
||||
status TraceCodeStatus @default(INACTIVE)
|
||||
queryCount Int @default(0) @map("query_count")
|
||||
@@ -336,6 +366,106 @@ model Job {
|
||||
@@map("job")
|
||||
}
|
||||
|
||||
model OperationLog {
|
||||
id BigInt @id @default(autoincrement())
|
||||
userId Int? @map("user_id")
|
||||
username String?
|
||||
role RoleType?
|
||||
module String
|
||||
action String
|
||||
method String
|
||||
path String
|
||||
targetId String? @map("target_id")
|
||||
status String
|
||||
message String? @db.Text
|
||||
ip String?
|
||||
userAgent String? @db.Text @map("user_agent")
|
||||
durationMs Int? @map("duration_ms")
|
||||
requestSummary Json? @map("request_summary")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
user SysUser? @relation(fields: [userId], references: [id])
|
||||
|
||||
@@index([userId])
|
||||
@@index([module])
|
||||
@@index([action])
|
||||
@@index([status])
|
||||
@@index([createdAt])
|
||||
@@map("operation_log")
|
||||
}
|
||||
|
||||
model OutboundImportSession {
|
||||
id String @id @default(cuid())
|
||||
status OutboundImportSessionStatus @default(PARSING)
|
||||
fileName String @map("file_name")
|
||||
fileKey String? @map("file_key")
|
||||
total Int @default(0)
|
||||
validCount Int @default(0) @map("valid_count")
|
||||
invalidCount Int @default(0) @map("invalid_count")
|
||||
error String? @db.Text
|
||||
committedAt DateTime? @map("committed_at")
|
||||
expiresAt DateTime @map("expires_at")
|
||||
createdBy Int? @map("created_by")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
creator SysUser? @relation(fields: [createdBy], references: [id])
|
||||
rows OutboundImportRow[]
|
||||
|
||||
@@index([status])
|
||||
@@index([createdBy])
|
||||
@@index([expiresAt])
|
||||
@@map("outbound_import_session")
|
||||
}
|
||||
|
||||
model OutboundImportRow {
|
||||
id BigInt @id @default(autoincrement())
|
||||
sessionId String @map("session_id")
|
||||
rowNo Int @map("row_no")
|
||||
status OutboundImportRowStatus @default(INVALID)
|
||||
shortCode String? @map("short_code")
|
||||
batchNo String? @map("batch_no")
|
||||
outTime DateTime? @map("out_time")
|
||||
outImagePaths Json? @map("out_image_paths")
|
||||
outImageKeys Json? @map("out_image_keys")
|
||||
txHash String? @map("tx_hash")
|
||||
onchainAt DateTime? @map("onchain_at")
|
||||
blockHeight BigInt? @map("block_height")
|
||||
remark String?
|
||||
reason String? @db.Text
|
||||
preview Json?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
session OutboundImportSession @relation(fields: [sessionId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([sessionId])
|
||||
@@index([status])
|
||||
@@index([shortCode])
|
||||
@@map("outbound_import_row")
|
||||
}
|
||||
|
||||
model BackupRecord {
|
||||
id String @id @default(cuid())
|
||||
fileName String @map("file_name")
|
||||
filePath String @map("file_path")
|
||||
size BigInt @default(0)
|
||||
status BackupStatus @default(PENDING)
|
||||
mode String @default("BACKUP")
|
||||
manifest Json?
|
||||
error String? @db.Text
|
||||
createdBy Int? @map("created_by")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
creator SysUser? @relation(fields: [createdBy], references: [id])
|
||||
|
||||
@@index([status])
|
||||
@@index([mode])
|
||||
@@index([createdBy])
|
||||
@@index([createdAt])
|
||||
@@map("backup_record")
|
||||
}
|
||||
|
||||
model SystemSetting {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique
|
||||
|
||||
Reference in New Issue
Block a user