diff --git a/backend/internal/models/auth.go b/backend/internal/models/auth.go index e48ae28..47b912d 100644 --- a/backend/internal/models/auth.go +++ b/backend/internal/models/auth.go @@ -9,60 +9,60 @@ import ( // LoginRequest 登录请求结构 type LoginRequest struct { - Username string `json:"username" binding:"required"` - Password string `json:"password" binding:"required"` + Username string `json:"username" binding:"required"` // 用户名 + Password string `json:"password" binding:"required"` // 密码 } // LoginResponse 登录响应结构 type LoginResponse struct { - Code string `json:"code"` - Message string `json:"message"` - Data interface{} `json:"data,omitempty"` + Code string `json:"code"` // 响应代码 + Message string `json:"message"` // 响应消息 + Data interface{} `json:"data,omitempty"` // 响应数据 } // LoginData 登录成功返回的数据 type LoginData struct { - Token string `json:"token"` - ExpiresIn int `json:"expires_in"` - UserInfo UserInfo `json:"user_info"` + Token string `json:"token"` // JWT令牌 + ExpiresIn int `json:"expires_in"` // 过期时间(秒) + UserInfo UserInfo `json:"user_info"` // 用户信息 } // UserInfo 用户信息 type UserInfo struct { - Username string `json:"username"` - Role string `json:"role"` + Username string `json:"username"` // 用户名 + Role string `json:"role"` // 角色 } // AuthorizationCode 授权码模型 type AuthorizationCode struct { - ID string `gorm:"type:varchar(36);primaryKey" json:"id"` - Code string `gorm:"type:varchar(100);uniqueIndex;not null" json:"code"` - CustomerID string `gorm:"type:varchar(36);not null;index" json:"customer_id"` - CustomerName string `gorm:"-" json:"customer_name,omitempty"` - CustomerNameDisplay string `gorm:"-" json:"customer_name_display,omitempty"` - CreatedBy string `gorm:"type:varchar(36);not null" json:"created_by"` - SoftwareID *string `gorm:"type:varchar(50)" json:"software_id"` - Description *string `gorm:"type:text" json:"description"` - StartDate time.Time `gorm:"type:datetime(3);not null" json:"start_date"` - EndDate time.Time `gorm:"type:datetime(3);not null" json:"end_date"` - DeploymentType string `gorm:"type:varchar(20);not null;default:'standalone'" json:"deployment_type"` - DeploymentTypeDisplay string `gorm:"-" json:"deployment_type_display,omitempty"` - EncryptionType *string `gorm:"type:varchar(20);default:'standard'" json:"encryption_type"` - EncryptionTypeDisplay string `gorm:"-" json:"encryption_type_display,omitempty"` - SoftwareVersion *string `gorm:"type:varchar(50)" json:"software_version"` - MaxActivations int `gorm:"not null;default:1" json:"max_activations"` - CurrentActivations int `gorm:"-" json:"current_activations,omitempty"` - IsLocked bool `gorm:"not null;default:false" json:"is_locked"` - LockReason *string `gorm:"type:text" json:"lock_reason"` - LockedAt *time.Time `gorm:"type:datetime(3)" json:"locked_at"` - LockedBy *string `gorm:"type:varchar(36)" json:"locked_by"` - FeatureConfig JSON `gorm:"type:json" json:"feature_config" swaggertype:"object"` - UsageLimits JSON `gorm:"type:json" json:"usage_limits" swaggertype:"object"` - CustomParameters JSON `gorm:"type:json" json:"custom_parameters" swaggertype:"object"` - Status string `gorm:"-" json:"status,omitempty"` - StatusDisplay string `gorm:"-" json:"status_display,omitempty"` - CreatedAt time.Time `gorm:"type:datetime(3);not null" json:"created_at"` - UpdatedAt time.Time `gorm:"type:datetime(3);not null" json:"updated_at"` + ID string `gorm:"type:varchar(36);primaryKey" json:"id"` // 授权码ID + Code string `gorm:"type:varchar(100);uniqueIndex;not null" json:"code"` // 授权码 + CustomerID string `gorm:"type:varchar(36);not null;index" json:"customer_id"` // 客户ID + CustomerName string `gorm:"-" json:"customer_name,omitempty"` // 客户名称 + CustomerNameDisplay string `gorm:"-" json:"customer_name_display,omitempty"` // 客户名称显示(多语言) + CreatedBy string `gorm:"type:varchar(36);not null" json:"created_by"` // 创建人ID + SoftwareID *string `gorm:"type:varchar(50)" json:"software_id"` // 软件ID + Description *string `gorm:"type:text" json:"description"` // 描述 + StartDate time.Time `gorm:"type:datetime(3);not null" json:"start_date"` // 生效日期 + EndDate time.Time `gorm:"type:datetime(3);not null" json:"end_date"` // 失效日期 + DeploymentType string `gorm:"type:varchar(20);not null;default:'standalone'" json:"deployment_type"` // 部署类型:standalone/cloud/hybrid + DeploymentTypeDisplay string `gorm:"-" json:"deployment_type_display,omitempty"` // 部署类型显示(多语言) + EncryptionType *string `gorm:"type:varchar(20);default:'standard'" json:"encryption_type"` // 加密类型:standard/advanced + EncryptionTypeDisplay string `gorm:"-" json:"encryption_type_display,omitempty"` // 加密类型显示(多语言) + SoftwareVersion *string `gorm:"type:varchar(50)" json:"software_version"` // 软件版本 + MaxActivations int `gorm:"not null;default:1" json:"max_activations"` // 最大激活次数 + CurrentActivations int `gorm:"-" json:"current_activations,omitempty"` // 当前激活次数 + IsLocked bool `gorm:"not null;default:false" json:"is_locked"` // 是否锁定 + LockReason *string `gorm:"type:text" json:"lock_reason"` // 锁定原因 + LockedAt *time.Time `gorm:"type:datetime(3)" json:"locked_at"` // 锁定时间 + LockedBy *string `gorm:"type:varchar(36)" json:"locked_by"` // 锁定人ID + FeatureConfig JSON `gorm:"type:json" json:"feature_config" swaggertype:"object"` // 功能配置(JSON对象) + UsageLimits JSON `gorm:"type:json" json:"usage_limits" swaggertype:"object"` // 使用限制(JSON对象) + CustomParameters JSON `gorm:"type:json" json:"custom_parameters" swaggertype:"object"` // 自定义参数(JSON对象) + Status string `gorm:"-" json:"status,omitempty"` // 状态:normal/locked/expired + StatusDisplay string `gorm:"-" json:"status_display,omitempty"` // 状态显示(多语言) + CreatedAt time.Time `gorm:"type:datetime(3);not null" json:"created_at"` // 创建时间 + UpdatedAt time.Time `gorm:"type:datetime(3);not null" json:"updated_at"` // 更新时间 } // TableName 指定表名 @@ -75,7 +75,7 @@ func (a *AuthorizationCode) BeforeCreate(tx *gorm.DB) error { if a.ID == "" { a.ID = uuid.New().String() } - + now := time.Now() if a.CreatedAt.IsZero() { a.CreatedAt = now @@ -94,105 +94,105 @@ func (a *AuthorizationCode) BeforeUpdate(tx *gorm.DB) error { // AuthorizationCodeCreateRequest 创建授权码请求结构 type AuthorizationCodeCreateRequest struct { - CustomerID string `json:"customer_id" binding:"required"` - SoftwareID *string `json:"software_id" binding:"omitempty"` - Description *string `json:"description" binding:"omitempty,max=1000"` - ValidityDays int `json:"validity_days" binding:"required,min=1,max=36500"` - DeploymentType string `json:"deployment_type" binding:"required,oneof=standalone cloud hybrid"` - EncryptionType *string `json:"encryption_type" binding:"omitempty,oneof=standard advanced"` - SoftwareVersion *string `json:"software_version" binding:"omitempty"` - MaxActivations int `json:"max_activations" binding:"required,min=1"` - FeatureConfig interface{} `json:"feature_config" binding:"omitempty"` - UsageLimits interface{} `json:"usage_limits" binding:"omitempty"` - CustomParameters interface{} `json:"custom_parameters" binding:"omitempty"` + CustomerID string `json:"customer_id" binding:"required"` // 客户ID + SoftwareID *string `json:"software_id" binding:"omitempty"` // 软件ID + Description *string `json:"description" binding:"omitempty,max=1000"` // 描述 + ValidityDays int `json:"validity_days" binding:"required,min=1,max=36500"` // 有效天数(1-36500天) + DeploymentType string `json:"deployment_type" binding:"required,oneof=standalone cloud hybrid"` // 部署类型:standalone/cloud/hybrid + EncryptionType *string `json:"encryption_type" binding:"omitempty,oneof=standard advanced"` // 加密类型:standard/advanced + SoftwareVersion *string `json:"software_version" binding:"omitempty"` // 软件版本 + MaxActivations int `json:"max_activations" binding:"required,min=1"` // 最大激活次数 + FeatureConfig interface{} `json:"feature_config" binding:"omitempty"` // 功能配置(JSON对象) + UsageLimits interface{} `json:"usage_limits" binding:"omitempty"` // 使用限制(JSON对象) + CustomParameters interface{} `json:"custom_parameters" binding:"omitempty"` // 自定义参数(JSON对象) } // AuthorizationCodeCreateResponse 创建授权码响应结构 type AuthorizationCodeCreateResponse struct { - ID string `json:"id"` - Code string `json:"code"` + ID string `json:"id"` // 授权码ID + Code string `json:"code"` // 授权码 } // AuthorizationCodeListRequest 授权码列表查询请求结构 type AuthorizationCodeListRequest struct { - Page int `form:"page" binding:"omitempty,min=1"` // 页码,默认1 - PageSize int `form:"page_size" binding:"omitempty,min=1,max=100"` // 每页条数,默认20,最大100 - CustomerID string `form:"customer_id" binding:"omitempty"` // 客户ID筛选 - Status string `form:"status" binding:"omitempty,oneof=normal locked expired"` // 状态筛选 - StartDate string `form:"start_date" binding:"omitempty"` // 创建开始时间 - EndDate string `form:"end_date" binding:"omitempty"` // 创建结束时间 - Sort string `form:"sort" binding:"omitempty,oneof=created_at updated_at code"` // 排序字段,默认created_at - Order string `form:"order" binding:"omitempty,oneof=asc desc"` // 排序方向,默认desc + Page int `form:"page" binding:"omitempty,min=1"` // 页码,默认1 + PageSize int `form:"page_size" binding:"omitempty,min=1,max=100"` // 每页条数,默认20,最大100 + CustomerID string `form:"customer_id" binding:"omitempty"` // 客户ID筛选 + Status string `form:"status" binding:"omitempty,oneof=normal locked expired"` // 状态筛选 + StartDate string `form:"start_date" binding:"omitempty"` // 创建开始时间 + EndDate string `form:"end_date" binding:"omitempty"` // 创建结束时间 + Sort string `form:"sort" binding:"omitempty,oneof=created_at updated_at code"` // 排序字段,默认created_at + Order string `form:"order" binding:"omitempty,oneof=asc desc"` // 排序方向,默认desc } // AuthorizationCodeListItem 授权码列表项结构 type AuthorizationCodeListItem struct { - ID string `json:"id"` - Code string `json:"code"` - CustomerID string `json:"customer_id"` - CustomerName string `json:"customer_name"` - CustomerNameDisplay string `json:"customer_name_display,omitempty"` - Status string `json:"status"` - StatusDisplay string `json:"status_display,omitempty"` - StartDate string `json:"start_date"` - EndDate string `json:"end_date"` - MaxActivations int `json:"max_activations"` - CurrentActivations int `json:"current_activations"` - DeploymentType string `json:"deployment_type"` - DeploymentTypeDisplay string `json:"deployment_type_display,omitempty"` - IsLocked bool `json:"is_locked"` - Description *string `json:"description"` - CreatedAt string `json:"created_at"` + ID string `json:"id"` // 授权码ID + Code string `json:"code"` // 授权码 + CustomerID string `json:"customer_id"` // 客户ID + CustomerName string `json:"customer_name"` // 客户名称 + CustomerNameDisplay string `json:"customer_name_display,omitempty"` // 客户名称显示(多语言) + Status string `json:"status"` // 状态:normal/locked/expired + StatusDisplay string `json:"status_display,omitempty"` // 状态显示(多语言) + StartDate string `json:"start_date"` // 生效日期 + EndDate string `json:"end_date"` // 失效日期 + MaxActivations int `json:"max_activations"` // 最大激活次数 + CurrentActivations int `json:"current_activations"` // 当前激活次数 + DeploymentType string `json:"deployment_type"` // 部署类型:standalone/cloud/hybrid + DeploymentTypeDisplay string `json:"deployment_type_display,omitempty"` // 部署类型显示(多语言) + IsLocked bool `json:"is_locked"` // 是否锁定 + Description *string `json:"description"` // 描述 + CreatedAt string `json:"created_at"` // 创建时间 } // AuthorizationCodeListResponse 授权码列表响应结构 type AuthorizationCodeListResponse struct { - List []AuthorizationCodeListItem `json:"list"` - Total int64 `json:"total"` - Page int `json:"page"` - PageSize int `json:"page_size"` - TotalPages int `json:"total_pages"` + List []AuthorizationCodeListItem `json:"list"` // 授权码列表 + Total int64 `json:"total"` // 总记录数 + Page int `json:"page"` // 当前页码 + PageSize int `json:"page_size"` // 每页条数 + TotalPages int `json:"total_pages"` // 总页数 } // AuthorizationCodeUpdateRequest 更新授权码请求结构 type AuthorizationCodeUpdateRequest struct { - SoftwareID *string `json:"software_id" binding:"omitempty"` - Description *string `json:"description" binding:"omitempty,max=1000"` - ValidityDays *int `json:"validity_days" binding:"omitempty,min=1,max=36500"` - DeploymentType *string `json:"deployment_type" binding:"omitempty,oneof=standalone cloud hybrid"` - EncryptionType *string `json:"encryption_type" binding:"omitempty,oneof=standard advanced"` - SoftwareVersion *string `json:"software_version" binding:"omitempty"` - MaxActivations *int `json:"max_activations" binding:"omitempty,min=1"` - FeatureConfig interface{} `json:"feature_config" binding:"omitempty"` - UsageLimits interface{} `json:"usage_limits" binding:"omitempty"` - CustomParameters interface{} `json:"custom_parameters" binding:"omitempty"` - ChangeType string `json:"change_type" binding:"required,oneof=renewal upgrade limit_change feature_toggle lock unlock other"` - Reason *string `json:"reason" binding:"omitempty,max=500"` + SoftwareID *string `json:"software_id" binding:"omitempty"` // 软件ID + Description *string `json:"description" binding:"omitempty,max=1000"` // 描述 + ValidityDays *int `json:"validity_days" binding:"omitempty,min=1,max=36500"` // 有效天数 + DeploymentType *string `json:"deployment_type" binding:"omitempty,oneof=standalone cloud hybrid"` // 部署类型:standalone/cloud/hybrid + EncryptionType *string `json:"encryption_type" binding:"omitempty,oneof=standard advanced"` // 加密类型:standard/advanced + SoftwareVersion *string `json:"software_version" binding:"omitempty"` // 软件版本 + MaxActivations *int `json:"max_activations" binding:"omitempty,min=1"` // 最大激活次数 + FeatureConfig interface{} `json:"feature_config" binding:"omitempty"` // 功能配置 + UsageLimits interface{} `json:"usage_limits" binding:"omitempty"` // 使用限制 + CustomParameters interface{} `json:"custom_parameters" binding:"omitempty"` // 自定义参数 + ChangeType string `json:"change_type" binding:"required,oneof=renewal upgrade limit_change feature_toggle lock unlock other"` // 变更类型:renewal/upgrade/limit_change/feature_toggle/lock/unlock/other + Reason *string `json:"reason" binding:"omitempty,max=500"` // 变更原因 } // AuthorizationCodeLockRequest 锁定/解锁授权码请求结构 type AuthorizationCodeLockRequest struct { - IsLocked bool `json:"is_locked" binding:""` // true-锁定,false-解锁 - LockReason *string `json:"lock_reason" binding:"omitempty,max=500"` // 锁定原因 - Reason *string `json:"reason" binding:"omitempty,max=500"` // 变更原因(记录到变更历史) + IsLocked bool `json:"is_locked" binding:""` // true-锁定,false-解锁 + LockReason *string `json:"lock_reason" binding:"omitempty,max=500"` // 锁定原因 + Reason *string `json:"reason" binding:"omitempty,max=500"` // 变更原因(记录到变更历史) } // AuthorizationChange 授权变更历史模型 type AuthorizationChange struct { - ID string `gorm:"type:varchar(36);primaryKey" json:"id"` - AuthorizationCodeID string `gorm:"type:varchar(36);not null;index" json:"authorization_code_id"` - ChangeType string `gorm:"type:varchar(30);not null;index" json:"change_type"` - ChangeTypeDisplay string `gorm:"-" json:"change_type_display,omitempty"` - OldConfig JSON `gorm:"type:json" json:"old_config,omitempty" swaggertype:"object"` - NewConfig JSON `gorm:"type:json" json:"new_config,omitempty" swaggertype:"object"` - OperatorID string `gorm:"type:varchar(36);not null;index" json:"operator_id"` - OperatorName string `gorm:"-" json:"operator_name,omitempty"` - Reason *string `gorm:"type:text" json:"reason"` - CreatedAt time.Time `gorm:"type:datetime(3);not null;index" json:"created_at"` + ID string `gorm:"type:varchar(36);primaryKey" json:"id"` // 变更记录ID + AuthorizationCodeID string `gorm:"type:varchar(36);not null;index" json:"authorization_code_id"` // 授权码ID + ChangeType string `gorm:"type:varchar(30);not null;index" json:"change_type"` // 变更类型 + ChangeTypeDisplay string `gorm:"-" json:"change_type_display,omitempty"` // 变更类型显示(多语言) + OldConfig JSON `gorm:"type:json" json:"old_config,omitempty" swaggertype:"object"` // 变更前配置(JSON对象) + NewConfig JSON `gorm:"type:json" json:"new_config,omitempty" swaggertype:"object"` // 变更后配置(JSON对象) + OperatorID string `gorm:"type:varchar(36);not null;index" json:"operator_id"` // 操作人ID + OperatorName string `gorm:"-" json:"operator_name,omitempty"` // 操作人名称 + Reason *string `gorm:"type:text" json:"reason"` // 变更原因 + CreatedAt time.Time `gorm:"type:datetime(3);not null;index" json:"created_at"` // 创建时间 // 关联字段 - AuthorizationCode *AuthorizationCode `gorm:"foreignKey:AuthorizationCodeID" json:"authorization_code,omitempty"` - Operator *User `gorm:"foreignKey:OperatorID" json:"operator,omitempty"` + AuthorizationCode *AuthorizationCode `gorm:"foreignKey:AuthorizationCodeID" json:"authorization_code,omitempty"` // 关联的授权码 + Operator *User `gorm:"foreignKey:OperatorID" json:"operator,omitempty"` // 关联的操作人 } // TableName 指定表名 @@ -205,7 +205,7 @@ func (a *AuthorizationChange) BeforeCreate(tx *gorm.DB) error { if a.ID == "" { a.ID = uuid.New().String() } - + if a.CreatedAt.IsZero() { a.CreatedAt = time.Now() } @@ -214,32 +214,32 @@ func (a *AuthorizationChange) BeforeCreate(tx *gorm.DB) error { // AuthorizationChangeListRequest 授权变更历史列表查询请求结构 type AuthorizationChangeListRequest struct { - Page int `form:"page" binding:"omitempty,min=1"` // 页码,默认1 - PageSize int `form:"page_size" binding:"omitempty,min=1,max=100"` // 每页条数,默认20,最大100 - ChangeType string `form:"change_type" binding:"omitempty"` // 变更类型筛选 - OperatorID string `form:"operator_id" binding:"omitempty"` // 操作人筛选 - StartDate string `form:"start_date" binding:"omitempty"` // 开始时间 - EndDate string `form:"end_date" binding:"omitempty"` // 结束时间 + Page int `form:"page" binding:"omitempty,min=1"` // 页码,默认1 + PageSize int `form:"page_size" binding:"omitempty,min=1,max=100"` // 每页条数,默认20,最大100 + ChangeType string `form:"change_type" binding:"omitempty"` // 变更类型筛选 + OperatorID string `form:"operator_id" binding:"omitempty"` // 操作人筛选 + StartDate string `form:"start_date" binding:"omitempty"` // 开始时间 + EndDate string `form:"end_date" binding:"omitempty"` // 结束时间 Sort string `form:"sort" binding:"omitempty,oneof=created_at change_type"` // 排序字段,默认created_at - Order string `form:"order" binding:"omitempty,oneof=asc desc"` // 排序方向,默认desc + Order string `form:"order" binding:"omitempty,oneof=asc desc"` // 排序方向,默认desc } // AuthorizationChangeListItem 授权变更历史列表项结构 type AuthorizationChangeListItem struct { - ID string `json:"id"` - ChangeType string `json:"change_type"` - ChangeTypeDisplay string `json:"change_type_display,omitempty"` - OperatorID string `json:"operator_id"` - OperatorName string `json:"operator_name,omitempty"` - Reason *string `json:"reason"` - CreatedAt string `json:"created_at"` + ID string `json:"id"` // 变更记录ID + ChangeType string `json:"change_type"` // 变更类型 + ChangeTypeDisplay string `json:"change_type_display,omitempty"` // 变更类型显示(多语言) + OperatorID string `json:"operator_id"` // 操作人ID + OperatorName string `json:"operator_name,omitempty"` // 操作人名称 + Reason *string `json:"reason"` // 变更原因 + CreatedAt string `json:"created_at"` // 创建时间 } // AuthorizationChangeListResponse 授权变更历史列表响应结构 type AuthorizationChangeListResponse struct { - List []AuthorizationChangeListItem `json:"list"` - Total int64 `json:"total"` - Page int `json:"page"` - PageSize int `json:"page_size"` - TotalPages int `json:"total_pages"` -} \ No newline at end of file + List []AuthorizationChangeListItem `json:"list"` // 变更历史列表 + Total int64 `json:"total"` // 总记录数 + Page int `json:"page"` // 当前页码 + PageSize int `json:"page_size"` // 每页条数 + TotalPages int `json:"total_pages"` // 总页数 +}