Files
filestoragesystem/go/internal/model/models.go
T
2026-08-23 00:48:10 +08:00

170 lines
7.7 KiB
Go

package model
import "time"
// Role 角色
type Role struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:50;uniqueIndex;not null" json:"name"`
Code string `gorm:"size:50;uniqueIndex;not null" json:"code"`
Description string `gorm:"size:255" json:"description"`
IsSystem bool `gorm:"default:false" json:"is_system"`
Status int8 `gorm:"default:1" json:"status"` // 1:启用 0:禁用
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Permission 权限
type Permission struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:50;not null" json:"name"`
Code string `gorm:"size:100;uniqueIndex;not null" json:"code"`
Module string `gorm:"size:50;not null" json:"module"`
Description string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"created_at"`
}
// User 用户
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"size:50;uniqueIndex;not null" json:"username"`
Email string `gorm:"size:100;uniqueIndex;not null" json:"email"`
PasswordHash string `gorm:"size:255;not null" json:"-"`
RoleID uint `gorm:"default:1" json:"role_id"`
Role *Role `gorm:"foreignKey:RoleID" json:"role,omitempty"`
Status int8 `gorm:"default:1" json:"status"` // 1:正常 0:禁用
StorageUsed int64 `gorm:"default:0" json:"storage_used"`
StorageLimit int64 `gorm:"default:10737418240" json:"storage_limit"`
LastLoginAt *time.Time `json:"last_login_at"`
LastLoginIP string `gorm:"size:50" json:"last_login_ip"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// APIKey API密钥
type APIKey struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
AccessKey string `gorm:"size:32;uniqueIndex;not null" json:"access_key"`
SecretKey string `gorm:"size:64;not null" json:"-"`
Name string `gorm:"size:50" json:"name"`
Status int8 `gorm:"default:1" json:"status"`
LastUsedAt *time.Time `json:"last_used_at"`
CreatedAt time.Time `json:"created_at"`
}
// Project 项目
type Project struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
Name string `gorm:"size:100;not null;uniqueIndex:idx_user_project" json:"name"`
Description string `json:"description"`
StorageUsed int64 `gorm:"default:0" json:"storage_used"`
StorageLimit int64 `gorm:"default:5368709120" json:"storage_limit"`
Status int8 `gorm:"default:1" json:"status"` // 1:正常 0:禁用
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// File 文件
type File struct {
ID uint `gorm:"primaryKey" json:"id"`
ProjectID uint `gorm:"index;not null" json:"project_id"`
UserID uint `gorm:"index;not null" json:"user_id"`
Filename string `gorm:"size:500;not null" json:"filename"` // 原始文件名(可含虚拟目录)
StoredPath string `gorm:"size:500;not null" json:"-"` // 物理存储路径
Size int64 `gorm:"not null" json:"size"`
MimeType string `gorm:"size:100" json:"mime_type"`
MD5 string `gorm:"size:32;index" json:"md5"`
StorageType int8 `gorm:"default:1" json:"storage_type"` // 1:本地存储
Visibility int8 `gorm:"default:1" json:"visibility"` // 1:私有 2:公开
DownloadCount int64 `gorm:"default:0" json:"download_count"`
Status int8 `gorm:"default:1;index" json:"status"` // 1:正常 0:已删除(回收站)
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at"`
Project *Project `gorm:"foreignKey:ProjectID" json:"project,omitempty"`
}
// TempLink 临时访问链接
type TempLink struct {
ID uint `gorm:"primaryKey" json:"id"`
FileID uint `gorm:"index;not null" json:"file_id"`
UserID uint `gorm:"not null" json:"user_id"`
Token string `gorm:"size:64;uniqueIndex;not null" json:"token"`
Password string `gorm:"size:50" json:"-"`
HasPwd bool `gorm:"-" json:"has_password"`
MaxCount int `gorm:"default:0" json:"max_count"` // 0为不限
UsedCount int `gorm:"default:0" json:"used_count"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
}
// TrafficLog 流量日志
type TrafficLog struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
ProjectID uint `json:"project_id"`
FileID uint `json:"file_id"`
Type int8 `gorm:"not null" json:"type"` // 1:上传 2:下载
Size int64 `gorm:"not null" json:"size"`
IP string `gorm:"size:50" json:"ip"`
CreatedAt time.Time `gorm:"index" json:"created_at"`
}
// Webhook Webhook回调配置
type Webhook struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
ProjectID *uint `json:"project_id"` // 为空则为用户级别
URL string `gorm:"size:500;not null" json:"url"`
Secret string `gorm:"size:64" json:"-"`
Events string `gorm:"size:255;not null" json:"events"` // 逗号分隔: file.upload,file.delete
Status int8 `gorm:"default:1" json:"status"`
LastTriggeredAt *time.Time `json:"last_triggered_at"`
CreatedAt time.Time `json:"created_at"`
}
// SystemSetting 系统设置
type SystemSetting struct {
ID uint `gorm:"primaryKey" json:"id"`
Key string `gorm:"column:key;size:100;uniqueIndex;not null" json:"key"`
Value string `json:"value"`
Description string `gorm:"size:255" json:"description"`
GroupName string `gorm:"size:50;default:general" json:"group_name"`
UpdatedAt time.Time `json:"updated_at"`
}
// OperationLog 操作日志
type OperationLog struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID *uint `gorm:"index" json:"user_id"`
Username string `gorm:"size:50" json:"username"`
Action string `gorm:"size:50;index;not null" json:"action"` // login/logout/upload/download/delete/create/update
ResourceType string `gorm:"size:50" json:"resource_type"`
ResourceID uint `json:"resource_id"`
ResourceName string `gorm:"size:255" json:"resource_name"`
IP string `gorm:"size:50" json:"ip"`
UserAgent string `gorm:"size:500" json:"user_agent"`
RequestPath string `gorm:"size:500" json:"request_path"`
RequestMethod string `gorm:"size:10" json:"request_method"`
Status int8 `gorm:"default:1" json:"status"` // 1:成功 0:失败
ErrorMessage string `json:"error_message"`
ExtraData string `json:"extra_data"`
CreatedAt time.Time `gorm:"index" json:"created_at"`
}
// SystemLog 系统日志
type SystemLog struct {
ID uint `gorm:"primaryKey" json:"id"`
Level string `gorm:"size:10;index;not null" json:"level"` // debug/info/warn/error/fatal
Module string `gorm:"size:50;index" json:"module"`
Message string `gorm:"not null" json:"message"`
StackTrace string `json:"stack_trace"`
RequestID string `gorm:"size:50" json:"request_id"`
IP string `gorm:"size:50" json:"ip"`
ExtraData string `json:"extra_data"`
CreatedAt time.Time `gorm:"index" json:"created_at"`
}