97 lines
4.4 KiB
Go
97 lines
4.4 KiB
Go
package entity
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// SystemParam 系统参数实体
|
|
// 用于存储系统运行所需的各种配置参数,支持多种数据类型和分组管理
|
|
type SystemParam struct {
|
|
// ID 主键,使用 UUID v4 保证全局唯一性,避免自增 ID 带来的信息泄露风险
|
|
ID string `json:"id" gorm:"column:id;type:varchar(36);primaryKey;not null;comment:主键"`
|
|
|
|
// ParamKey 参数键名,全局唯一,用于标识和访问参数值
|
|
// 命名规范:小写字母 + 下划线,如:site_name, max_upload_size
|
|
ParamKey string `json:"param_key" gorm:"column:param_key;type:varchar(100);uniqueIndex;not null;comment:参数键"`
|
|
|
|
// ParamValue 参数值,存储实际配置内容
|
|
// 根据 ParamType 不同,可能是字符串、数字、布尔值或 JSON 数组
|
|
ParamValue string `json:"param_value" gorm:"column:param_value;type:varchar(1000);not null;comment:参数值"`
|
|
|
|
// ParamType 参数类型,决定参数的校验规则和展示方式
|
|
// 可选值:text(文本), number(数字), boolean(布尔), select(下拉选择)
|
|
ParamType string `json:"param_type" gorm:"column:param_type;type:varchar(20);not null;default:'text';comment:类型:text,number,boolean,select"`
|
|
|
|
// ParamGroup 参数分组,用于对参数进行逻辑分组管理
|
|
// 常见分组:basic(基础), security(安全), business(业务), system(系统)
|
|
ParamGroup string `json:"param_group" gorm:"column:param_group;type:varchar(50);not null;default:'default';comment:分组"`
|
|
|
|
// ParamDesc 参数描述,说明该参数的用途、取值范围、默认值等信息
|
|
// 建议包含:参数说明、可选值说明、修改影响等
|
|
ParamDesc string `json:"param_desc" gorm:"column:param_desc;type:varchar(500);comment:描述"`
|
|
|
|
// CreatorID 创建人 ID,记录创建该参数的用户标识
|
|
// 用于审计追踪,定位参数创建者
|
|
CreatorID string `json:"creator_id" gorm:"column:creator_id;type:varchar(36);not null;default:'';comment:创建人 ID"`
|
|
|
|
// CreateTime 创建时间,记录参数创建的时间点
|
|
// 使用指针类型,可以区分"未设置"和"已设置"状态
|
|
// 数据库层面使用 CURRENT_TIMESTAMP 自动填充
|
|
CreateTime *time.Time `json:"create_time" gorm:"column:create_time;type:datetime;default:current_timestamp;comment:创建时间"`
|
|
|
|
// LastUpdaterID 最后更新人 ID,记录最后一次修改该参数的用户标识
|
|
// 用于审计追踪,定位参数修改者
|
|
LastUpdaterID string `json:"last_updater_id" gorm:"column:last_updater_id;type:varchar(36);not null;default:'';comment:最后更新人 ID"`
|
|
|
|
// UpdateTime 最后更新时间,记录参数最后一次修改的时间点
|
|
// 使用指针类型,可以区分"未设置"和"已设置"状态
|
|
// 数据库层面使用 ON UPDATE CURRENT_TIMESTAMP 自动更新
|
|
UpdateTime *time.Time `json:"update_time" gorm:"column:update_time;type:datetime;default:current_timestamp;on update current_timestamp;comment:最后更新时间"`
|
|
}
|
|
|
|
// TableName 指定表名为 system_param
|
|
// 遵循数据库命名规范:小写字母 + 下划线,复数形式
|
|
func (SystemParam) TableName() string {
|
|
return "system_param"
|
|
}
|
|
|
|
// ParamType 参数类型常量
|
|
// 定义系统支持的参数类型,用于前端展示和后端校验
|
|
type ParamType string
|
|
|
|
const (
|
|
// ParamTypeText 文本类型,适用于字符串值
|
|
ParamTypeText ParamType = "text"
|
|
// ParamTypeNumber 数字类型,适用于整数值
|
|
ParamTypeNumber ParamType = "number"
|
|
// ParamTypeBoolean 布尔类型,适用于 true/false 值
|
|
ParamTypeBoolean ParamType = "boolean"
|
|
// ParamTypeSelect 下拉选择类型,适用于预定义选项值
|
|
ParamTypeSelect ParamType = "select"
|
|
)
|
|
|
|
// ParamGroup 参数分组常量
|
|
// 定义系统参数的逻辑分组,便于分类管理和权限控制
|
|
type ParamGroup string
|
|
|
|
const (
|
|
// GroupBasic 基础配置分组,包含系统基本信息
|
|
// 如:站点名称、Logo、联系方式等
|
|
GroupBasic ParamGroup = "basic"
|
|
|
|
// GroupSecurity 安全配置分组,包含安全相关参数
|
|
// 如:密码策略、登录限制、Token 有效期等
|
|
GroupSecurity ParamGroup = "security"
|
|
|
|
// GroupBusiness 业务配置分组,包含业务逻辑相关参数
|
|
// 如:订单配置、支付参数、业务开关等
|
|
GroupBusiness ParamGroup = "business"
|
|
|
|
// GroupSystem 系统配置分组,包含系统运行参数
|
|
// 如:缓存配置、日志级别、性能参数等
|
|
GroupSystem ParamGroup = "system"
|
|
|
|
// GroupDefault 默认分组,未明确分组的参数归入此类
|
|
GroupDefault ParamGroup = "default"
|
|
)
|