提交
This commit is contained in:
@@ -4,7 +4,7 @@ import "time"
|
||||
|
||||
// App 开放平台应用
|
||||
type App struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
AppID string `json:"app_id" gorm:"uniqueIndex;size:64;not null"`
|
||||
AppSecret string `json:"-" gorm:"size:128;not null"`
|
||||
AppName string `json:"app_name" gorm:"size:128;not null"`
|
||||
@@ -20,7 +20,7 @@ func (App) TableName() string {
|
||||
// AppUser 应用授权用户
|
||||
// 只有绑定的用户才能通过该应用进行SSO登录
|
||||
type AppUser struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
AppID uint64 `json:"app_id" gorm:"index;not null"` // 应用ID
|
||||
UserID uint64 `json:"user_id" gorm:"index;not null"` // 用户ID
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
@@ -4,11 +4,11 @@ import "time"
|
||||
|
||||
// BackupPolicy 备份策略
|
||||
type BackupPolicy struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"size:128;not null"` // 策略名称
|
||||
BackupType string `json:"backup_type" gorm:"size:32;not null"` // full=全量, incremental=增量
|
||||
TargetType string `json:"target_type" gorm:"size:32;not null"` // local=本地, minio=MinIO
|
||||
TargetConfig string `json:"target_config" gorm:"type:json"` // 目标配置JSON
|
||||
TargetConfig string `json:"target_config" gorm:"type:text"` // 目标配置JSON
|
||||
IncludeDB int8 `json:"include_db" gorm:"default:1"` // 是否备份数据库
|
||||
IncludeFiles int8 `json:"include_files" gorm:"default:1"` // 是否备份文件
|
||||
CronExpr string `json:"cron_expr" gorm:"size:64"` // cron表达式
|
||||
@@ -26,7 +26,7 @@ func (BackupPolicy) TableName() string {
|
||||
|
||||
// BackupLog 备份执行日志
|
||||
type BackupLog struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
PolicyID uint64 `json:"policy_id" gorm:"index;not null"`
|
||||
PolicyName string `json:"policy_name" gorm:"size:128"`
|
||||
BackupType string `json:"backup_type" gorm:"size:32"`
|
||||
|
||||
@@ -5,7 +5,7 @@ import "time"
|
||||
// Department 部门/组织架构模型
|
||||
// 使用物化路径实现树形结构
|
||||
type Department struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"size:128;not null"` // 部门名称
|
||||
Code string `json:"code" gorm:"uniqueIndex;size:64"` // 部门编码
|
||||
ParentID uint64 `json:"parent_id" gorm:"index;default:0"` // 上级部门ID, 0=顶级
|
||||
|
||||
@@ -5,6 +5,7 @@ import "time"
|
||||
// File 文件模型
|
||||
type File struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
BizID string `json:"biz_id" gorm:"index;size:128"` // 业务ID
|
||||
Name string `json:"name" gorm:"size:256;not null"`
|
||||
Extension string `json:"extension" gorm:"size:32"`
|
||||
FolderID uint64 `json:"folder_id" gorm:"index;not null"`
|
||||
@@ -31,7 +32,7 @@ func (File) TableName() string {
|
||||
// FileAssociation 业务文件关联模型
|
||||
// 用于兼容 OA 系统的文件关联
|
||||
type FileAssociation struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
BizID string `json:"biz_id" gorm:"size:128;index;not null"`
|
||||
BizType string `json:"biz_type" gorm:"size:64;index;not null"`
|
||||
FileID uint64 `json:"file_id" gorm:"not null"`
|
||||
@@ -45,7 +46,7 @@ func (FileAssociation) TableName() string {
|
||||
|
||||
// FilePermission 文件权限模型
|
||||
type FilePermission struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
FileID uint64 `json:"file_id" gorm:"not null"`
|
||||
UserID uint64 `json:"user_id" gorm:"default:0"`
|
||||
RoleID uint64 `json:"role_id" gorm:"default:0"`
|
||||
|
||||
@@ -5,7 +5,7 @@ import "time"
|
||||
// OperationLog 操作日志
|
||||
// 记录用户的关键操作行为
|
||||
type OperationLog struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
UserID uint64 `json:"user_id" gorm:"index;default:0"` // 操作人
|
||||
Username string `json:"username" gorm:"size:64"` // 操作人用户名
|
||||
Action string `json:"action" gorm:"size:32;index;not null"` // 操作类型: login/upload/download/delete/share...
|
||||
|
||||
@@ -5,7 +5,7 @@ import "time"
|
||||
// Role 角色模型
|
||||
// RBAC核心: 用户 -> 角色 -> 权限
|
||||
type Role struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"uniqueIndex;size:64;not null"` // 角色标识: admin/editor/viewer
|
||||
DisplayName string `json:"display_name" gorm:"size:64;not null"` // 显示名称: 管理员/编辑者/查看者
|
||||
Description string `json:"description" gorm:"size:256"` // 角色描述
|
||||
@@ -25,7 +25,7 @@ func (Role) TableName() string {
|
||||
// Permission 权限模型
|
||||
// 定义系统中所有可控制的操作权限
|
||||
type Permission struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Code string `json:"code" gorm:"uniqueIndex;size:64;not null"` // 权限标识: file:upload, file:delete, user:manage
|
||||
Name string `json:"name" gorm:"size:64;not null"` // 显示名称: 上传文件, 删除文件, 用户管理
|
||||
Resource string `json:"resource" gorm:"size:32;not null"` // 资源类型: file, folder, share, user, system
|
||||
|
||||
@@ -4,7 +4,7 @@ import "time"
|
||||
|
||||
// Share 文件分享模型
|
||||
type Share struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
FileID uint64 `json:"file_id" gorm:"not null"`
|
||||
OwnerID uint64 `json:"owner_id" gorm:"not null"`
|
||||
ShareCode string `json:"share_code" gorm:"uniqueIndex;size:32;not null"`
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
// SSOProvider SSO提供商配置
|
||||
// 支持 OAuth2.0 / CAS / LDAP / OIDC 等协议
|
||||
type SSOProvider struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"size:64;not null"` // 提供商名称: 企业微信/钉钉/飞书
|
||||
Type string `json:"type" gorm:"size:32;not null"` // 协议类型: oauth2/cas/oidc/ldap
|
||||
DisplayName string `json:"display_name" gorm:"size:64;not null"` // 登录页显示名称
|
||||
Icon string `json:"icon" gorm:"size:512"` // 图标URL
|
||||
Config SSOConfig `json:"config" gorm:"type:json"` // 协议配置
|
||||
Config SSOConfig `json:"config" gorm:"type:text"` // 协议配置
|
||||
AutoCreate int8 `json:"auto_create" gorm:"default:1"` // 自动创建用户: 1=是 0=否
|
||||
DefaultRole string `json:"default_role" gorm:"size:32;default:viewer"` // 自动创建时的默认角色
|
||||
Status int8 `json:"status" gorm:"default:1"` // 1=启用 0=禁用
|
||||
@@ -63,7 +63,11 @@ type SSOConfig struct {
|
||||
|
||||
// Value 实现 driver.Valuer
|
||||
func (c SSOConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(c)
|
||||
b, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner
|
||||
@@ -71,8 +75,13 @@ func (c *SSOConfig) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
var bytes []byte
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
bytes = v
|
||||
case string:
|
||||
bytes = []byte(v)
|
||||
default:
|
||||
return fmt.Errorf("SSOConfig.Scan: 无法将 %T 转换为 []byte", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, c)
|
||||
@@ -81,7 +90,7 @@ func (c *SSOConfig) Scan(value interface{}) error {
|
||||
// SSOSession SSO会话记录
|
||||
// 记录SSO登录的来源和关联信息
|
||||
type SSOSession struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
UserID uint64 `json:"user_id" gorm:"index;not null"` // 关联的本地用户ID
|
||||
ProviderID uint64 `json:"provider_id" gorm:"not null"` // SSO提供商ID
|
||||
ExternalID string `json:"external_id" gorm:"size:256;not null"` // 外部系统用户ID
|
||||
|
||||
@@ -6,7 +6,7 @@ import "time"
|
||||
// 支持: 用户专属 > 角色 > 系统默认
|
||||
// 同一用户可通过多个角色获得多个存储策略, 按优先级调度
|
||||
type StorageAssignment struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
PolicyID uint64 `json:"policy_id" gorm:"index;not null"` // 存储策略ID
|
||||
|
||||
// 分配目标
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
|
||||
// StoragePolicy 存储策略模型
|
||||
type StoragePolicy struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" gorm:"size:64;not null"`
|
||||
Type string `json:"type" gorm:"size:32;not null"` // local/minio/s3/oss
|
||||
PolicyType string `json:"policy_type" gorm:"size:32;default:hot"` // hot/cold/public/slave
|
||||
Config PolicyConfig `json:"config" gorm:"type:json"`
|
||||
Config PolicyConfig `json:"config" gorm:"type:text"`
|
||||
Status int8 `json:"status" gorm:"default:1"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
@@ -48,16 +48,26 @@ type PolicyConfig struct {
|
||||
|
||||
// Value 实现 driver.Valuer 接口, 用于写入数据库
|
||||
func (c PolicyConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(c)
|
||||
b, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner 接口, 用于从数据库读取
|
||||
// MySQL 返回 []byte, PostgreSQL/SQL Server 返回 string
|
||||
func (c *PolicyConfig) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
var bytes []byte
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
bytes = v
|
||||
case string:
|
||||
bytes = []byte(v)
|
||||
default:
|
||||
return fmt.Errorf("PolicyConfig.Scan: 无法将 %T 转换为 []byte", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, c)
|
||||
|
||||
@@ -6,7 +6,7 @@ import "time"
|
||||
// User 用户模型
|
||||
// 对应数据库表: fs_user
|
||||
type User struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||
Username string `json:"username" gorm:"uniqueIndex;size:64;not null"`
|
||||
Password string `json:"-" gorm:"size:256;not null"` // json:"-" 防止密码泄露
|
||||
Email string `json:"email" gorm:"size:128"`
|
||||
|
||||
Reference in New Issue
Block a user