初始化
This commit is contained in:
22
server/model/department.go
Normal file
22
server/model/department.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Department 部门/组织架构模型
|
||||
// 使用物化路径实现树形结构
|
||||
type Department struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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=顶级
|
||||
Path string `json:"path" gorm:"size:1024;not null"` // 物化路径
|
||||
LeaderID uint64 `json:"leader_id" gorm:"default:0"` // 部门负责人用户ID
|
||||
SortOrder int `json:"sort_order" gorm:"default:0"` // 排序
|
||||
Status int8 `json:"status" gorm:"default:1"` // 1=启用 0=禁用
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (Department) TableName() string {
|
||||
return "fs_department"
|
||||
}
|
||||
59
server/model/file.go
Normal file
59
server/model/file.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// File 文件模型
|
||||
type File struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"`
|
||||
OwnerID uint64 `json:"owner_id" gorm:"index;not null"`
|
||||
Size int64 `json:"size" gorm:"default:0"`
|
||||
MD5 string `json:"md5" gorm:"size:32;index"`
|
||||
SHA256 string `json:"sha256" gorm:"size:64"`
|
||||
StorageKey string `json:"storage_key" gorm:"size:512;not null"`
|
||||
StoragePolicyID uint64 `json:"storage_policy_id" gorm:"index;default:1"`
|
||||
MimeType string `json:"mime_type" gorm:"size:128"`
|
||||
IsFavorite int8 `json:"is_favorite" gorm:"default:0"`
|
||||
Status int8 `json:"status" gorm:"default:1"`
|
||||
DownloadCount int `json:"download_count" gorm:"default:0"`
|
||||
Version int `json:"version" gorm:"default:1"` // 乐观锁版本号
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (File) TableName() string {
|
||||
return "fs_file"
|
||||
}
|
||||
|
||||
// FileAssociation 业务文件关联模型
|
||||
// 用于兼容 OA 系统的文件关联
|
||||
type FileAssociation struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (FileAssociation) TableName() string {
|
||||
return "fs_file_association"
|
||||
}
|
||||
|
||||
// FilePermission 文件权限模型
|
||||
type FilePermission struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
FileID uint64 `json:"file_id" gorm:"not null"`
|
||||
UserID uint64 `json:"user_id" gorm:"default:0"`
|
||||
RoleID uint64 `json:"role_id" gorm:"default:0"`
|
||||
PermLevel string `json:"perm_level" gorm:"size:16;default:read"`
|
||||
GrantBy uint64 `json:"grant_by" gorm:"not null"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (FilePermission) TableName() string {
|
||||
return "fs_file_permission"
|
||||
}
|
||||
23
server/model/folder.go
Normal file
23
server/model/folder.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Folder 文件夹模型
|
||||
// 使用物化路径(materialized path)实现树形结构
|
||||
// 例如: /0/1/5/ 表示根目录下ID=1的文件夹中的ID=5的文件夹
|
||||
type Folder struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
Name string `json:"name" gorm:"size:256;not null"`
|
||||
ParentID uint64 `json:"parent_id" gorm:"index;default:0"` // 0=根目录
|
||||
OwnerID uint64 `json:"owner_id" gorm:"index;not null"`
|
||||
Path string `json:"path" gorm:"size:1024;not null"` // 物化路径
|
||||
Status int8 `json:"status" gorm:"default:1"` // 1=正常 0=回收站
|
||||
Version int `json:"version" gorm:"default:1"` // 乐观锁版本号
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (Folder) TableName() string {
|
||||
return "fs_folder"
|
||||
}
|
||||
59
server/model/role.go
Normal file
59
server/model/role.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Role 角色模型
|
||||
// RBAC核心: 用户 -> 角色 -> 权限
|
||||
type Role struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"` // 角色描述
|
||||
IsSystem int8 `json:"is_system" gorm:"default:0"` // 是否系统内置角色(不可删除)
|
||||
Status int8 `json:"status" gorm:"default:1"` // 1=启用 0=禁用
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Permissions []Permission `json:"permissions,omitempty" gorm:"many2many:fs_role_permission;"`
|
||||
}
|
||||
|
||||
func (Role) TableName() string {
|
||||
return "fs_role"
|
||||
}
|
||||
|
||||
// Permission 权限模型
|
||||
// 定义系统中所有可控制的操作权限
|
||||
type Permission struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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
|
||||
Action string `json:"action" gorm:"size:32;not null"` // 操作类型: create, read, update, delete, manage
|
||||
Description string `json:"description" gorm:"size:256"`
|
||||
}
|
||||
|
||||
func (Permission) TableName() string {
|
||||
return "fs_permission"
|
||||
}
|
||||
|
||||
// RolePermission 角色-权限关联表
|
||||
type RolePermission struct {
|
||||
RoleID uint64 `json:"role_id" gorm:"primaryKey"`
|
||||
PermissionID uint64 `json:"permission_id" gorm:"primaryKey"`
|
||||
}
|
||||
|
||||
func (RolePermission) TableName() string {
|
||||
return "fs_role_permission"
|
||||
}
|
||||
|
||||
// UserRole 用户-角色关联表
|
||||
// 一个用户可以有多个角色, 权限取并集
|
||||
type UserRole struct {
|
||||
UserID uint64 `json:"user_id" gorm:"primaryKey"`
|
||||
RoleID uint64 `json:"role_id" gorm:"primaryKey"`
|
||||
}
|
||||
|
||||
func (UserRole) TableName() string {
|
||||
return "fs_user_role"
|
||||
}
|
||||
23
server/model/share.go
Normal file
23
server/model/share.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Share 文件分享模型
|
||||
type Share struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"`
|
||||
Password string `json:"password,omitempty" gorm:"size:64"`
|
||||
ExpireAt *time.Time `json:"expire_at"`
|
||||
MaxDownload int `json:"max_download"`
|
||||
DownloadCount int `json:"download_count"`
|
||||
AllowPreview int8 `json:"allow_preview"` // 1=允许预览 0=禁止预览
|
||||
AllowDownload int8 `json:"allow_download"` // 1=允许下载 0=禁止下载
|
||||
Status int8 `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (Share) TableName() string {
|
||||
return "fs_share"
|
||||
}
|
||||
97
server/model/sso.go
Normal file
97
server/model/sso.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SSOProvider SSO提供商配置
|
||||
// 支持 OAuth2.0 / CAS / LDAP / OIDC 等协议
|
||||
type SSOProvider struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"` // 协议配置
|
||||
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=禁用
|
||||
SortOrder int `json:"sort_order" gorm:"default:0"` // 排序
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (SSOProvider) TableName() string {
|
||||
return "fs_sso_provider"
|
||||
}
|
||||
|
||||
// SSOConfig SSO协议配置
|
||||
// 不同协议使用不同的配置字段
|
||||
type SSOConfig struct {
|
||||
// OAuth2.0 / OIDC 通用配置
|
||||
ClientID string `json:"client_id,omitempty"`
|
||||
ClientSecret string `json:"client_secret,omitempty"`
|
||||
AuthURL string `json:"auth_url,omitempty"` // 授权端点
|
||||
TokenURL string `json:"token_url,omitempty"` // Token端点
|
||||
UserInfoURL string `json:"user_info_url,omitempty"` // 用户信息端点
|
||||
RedirectURI string `json:"redirect_uri,omitempty"` // 回调地址
|
||||
Scopes string `json:"scopes,omitempty"` // 授权范围
|
||||
ResponseType string `json:"response_type,omitempty"` // response_type
|
||||
|
||||
// OIDC 特有
|
||||
IssuerURL string `json:"issuer_url,omitempty"` // Issuer URL
|
||||
|
||||
// CAS 特有
|
||||
CasServerURL string `json:"cas_server_url,omitempty"` // CAS服务器地址
|
||||
|
||||
// LDAP 特有
|
||||
LDAPServer string `json:"ldap_server,omitempty"` // LDAP服务器地址
|
||||
LDAPPort int `json:"ldap_port,omitempty"` // LDAP端口
|
||||
LDAPBaseDN string `json:"ldap_base_dn,omitempty"` // Base DN
|
||||
LDAPBindUser string `json:"ldap_bind_user,omitempty"` // 绑定用户
|
||||
LDAPBindPass string `json:"ldap_bind_pass,omitempty"` // 绑定密码
|
||||
LDAPFilter string `json:"ldap_filter,omitempty"` // 用户过滤器
|
||||
|
||||
// 字段映射 (从SSO用户信息到本地用户的字段映射)
|
||||
MappingUsername string `json:"mapping_username,omitempty"` // 用户名字段映射
|
||||
MappingEmail string `json:"mapping_email,omitempty"` // 邮箱字段映射
|
||||
MappingNickname string `json:"mapping_nickname,omitempty"` // 昵称字段映射
|
||||
}
|
||||
|
||||
// Value 实现 driver.Valuer
|
||||
func (c SSOConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(c)
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner
|
||||
func (c *SSOConfig) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("SSOConfig.Scan: 无法将 %T 转换为 []byte", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, c)
|
||||
}
|
||||
|
||||
// SSOSession SSO会话记录
|
||||
// 记录SSO登录的来源和关联信息
|
||||
type SSOSession struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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
|
||||
AccessToken string `json:"-" gorm:"size:1024"` // SSO Access Token
|
||||
RefreshToken string `json:"-" gorm:"size:1024"` // SSO Refresh Token
|
||||
ExpiresAt time.Time `json:"expires_at"` // Token过期时间
|
||||
LastLoginAt time.Time `json:"last_login_at"` // 最近登录时间
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (SSOSession) TableName() string {
|
||||
return "fs_sso_session"
|
||||
}
|
||||
64
server/model/storage_policy.go
Normal file
64
server/model/storage_policy.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StoragePolicy 存储策略模型
|
||||
type StoragePolicy struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"`
|
||||
Status int8 `json:"status" gorm:"default:1"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (StoragePolicy) TableName() string {
|
||||
return "fs_storage_policy"
|
||||
}
|
||||
|
||||
// PolicyConfig 存储策略配置
|
||||
type PolicyConfig struct {
|
||||
// 本地存储配置
|
||||
BasePath string `json:"base_path,omitempty"`
|
||||
|
||||
// MinIO/S3/OSS 配置
|
||||
Endpoint string `json:"endpoint,omitempty"`
|
||||
Bucket string `json:"bucket,omitempty"`
|
||||
AccessKey string `json:"access_key,omitempty"`
|
||||
SecretKey string `json:"secret_key,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
UseSSL bool `json:"use_ssl,omitempty"`
|
||||
|
||||
// 访问模式配置
|
||||
AccessMode string `json:"access_mode,omitempty"` // proxy=中转模式, presigned=预签名直连, 默认proxy
|
||||
// Nginx代理MinIO的地址(预签名模式下, 替换MinIO内部地址为Nginx公网地址)
|
||||
NginxEndpoint string `json:"nginx_endpoint,omitempty"` // 如 http://files.example.com
|
||||
// 中转模式下是否启用X-Sendfile
|
||||
UseXSendfile bool `json:"use_x_sendfile,omitempty"`
|
||||
// X-Sendfile对应的Nginx内部路径
|
||||
XSendfilePath string `json:"x_sendfile_path,omitempty"` // 如 /minio-files
|
||||
}
|
||||
|
||||
// Value 实现 driver.Valuer 接口, 用于写入数据库
|
||||
func (c PolicyConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(c)
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner 接口, 用于从数据库读取
|
||||
func (c *PolicyConfig) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("PolicyConfig.Scan: 无法将 %T 转换为 []byte", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, c)
|
||||
}
|
||||
28
server/model/user.go
Normal file
28
server/model/user.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Package model 定义数据模型
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// User 用户模型
|
||||
// 对应数据库表: fs_user
|
||||
type User struct {
|
||||
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
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"`
|
||||
Nickname string `json:"nickname" gorm:"size:64"`
|
||||
Avatar string `json:"avatar" gorm:"size:512"`
|
||||
Role string `json:"role" gorm:"size:32;default:user"`
|
||||
Status int8 `json:"status" gorm:"default:1"`
|
||||
DeptID uint64 `json:"dept_id" gorm:"index;default:0"`
|
||||
StorageQuota int64 `json:"storage_quota" gorm:"default:10737418240"`
|
||||
UsedStorage int64 `json:"used_storage" gorm:"default:0"`
|
||||
MustChangePwd int8 `json:"must_change_pwd" gorm:"default:0"` // 1=首次登录必须改密码
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (User) TableName() string {
|
||||
return "fs_user"
|
||||
}
|
||||
Reference in New Issue
Block a user