53 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package entities
 | ||
| 
 | ||
| import (
 | ||
| 	"time"
 | ||
| 
 | ||
| 	"github.com/google/uuid"
 | ||
| 	"gorm.io/gorm"
 | ||
| )
 | ||
| 
 | ||
| // ProductParameter 产品参数配置实体
 | ||
| type ProductParameter struct {
 | ||
| 	ID          string         `gorm:"primaryKey;type:varchar(36)" comment:"参数配置ID"`
 | ||
| 	ProductID   string         `gorm:"type:varchar(36);not null;index" comment:"产品ID"`
 | ||
| 	Name        string         `gorm:"type:varchar(100);not null" comment:"参数名称"`
 | ||
| 	Field       string         `gorm:"type:varchar(50);not null" comment:"参数字段名"`
 | ||
| 	Type        string         `gorm:"type:varchar(20);not null;default:'string'" comment:"参数类型"`
 | ||
| 	Required    bool           `gorm:"default:true" comment:"是否必填"`
 | ||
| 	Description string         `gorm:"type:text" comment:"参数描述"`
 | ||
| 	Example     string         `gorm:"type:varchar(200)" comment:"参数示例"`
 | ||
| 	Validation  string         `gorm:"type:text" comment:"验证规则"`
 | ||
| 	SortOrder   int            `gorm:"default:0" comment:"排序"`
 | ||
| 	
 | ||
| 	// 关联关系
 | ||
| 	Product *Product `gorm:"foreignKey:ProductID" comment:"产品"`
 | ||
| 	
 | ||
| 	CreatedAt time.Time      `gorm:"autoCreateTime" comment:"创建时间"`
 | ||
| 	UpdatedAt time.Time      `gorm:"autoUpdateTime" comment:"更新时间"`
 | ||
| 	DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
 | ||
| }
 | ||
| 
 | ||
| // BeforeCreate GORM钩子:创建前自动生成UUID
 | ||
| func (pp *ProductParameter) BeforeCreate(tx *gorm.DB) error {
 | ||
| 	if pp.ID == "" {
 | ||
| 		pp.ID = uuid.New().String()
 | ||
| 	}
 | ||
| 	return nil
 | ||
| }
 | ||
| 
 | ||
| // IsValid 检查参数配置是否有效
 | ||
| func (pp *ProductParameter) IsValid() bool {
 | ||
| 	return pp.DeletedAt.Time.IsZero()
 | ||
| }
 | ||
| 
 | ||
| // GetValidationRules 获取验证规则
 | ||
| func (pp *ProductParameter) GetValidationRules() map[string]interface{} {
 | ||
| 	if pp.Validation == "" {
 | ||
| 		return nil
 | ||
| 	}
 | ||
| 	
 | ||
| 	// 这里可以解析JSON格式的验证规则
 | ||
| 	// 暂时返回空map,后续可以扩展
 | ||
| 	return make(map[string]interface{})
 | ||
| }  |