From 97d6acaf340b19d66244967b00dd2fdff410e034 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 13 六月 2024 20:49:09 +0800 Subject: [PATCH] attribute value add dateType and dateType enums --- models/attribute.go | 43 +++++++++++++++++++++++++++++++++++++++---- 1 files changed, 39 insertions(+), 4 deletions(-) diff --git a/models/attribute.go b/models/attribute.go index fde8381..19fc906 100644 --- a/models/attribute.go +++ b/models/attribute.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "gorm.io/gorm" "wms/pkg/mysqlx" @@ -10,9 +11,12 @@ // Attribute 鍔ㄦ�佸睘鎬ц〃 Attribute struct { gorm.Model - Name string `gorm:"type:varchar(100);not null;default:''" json:"name"` //灞炴�у悕绉� - DataType DataType `gorm:"type:tinyint;not null;default:0" json:"dataType"` //缁欒皝鐢ㄧ殑 1 鐗╂枡锛堜骇鍝侊級 - Value string `json:"value" gorm:"-"` //浠嶢ttributeValue鍙栧埌鐨剉alue + Name string `gorm:"type:varchar(100);not null;default:''" json:"name"` //灞炴�у悕绉� + DataType DataType `gorm:"type:tinyint;not null;default:0" json:"dataType"` //鍊肩被鍨嬶紙1瀛楃涓� 2 int 3 涓嬫媺妗� 锛� + EntityType EntityType `gorm:"type:tinyint;not null;default:0" json:"entityType"` //缁欒皝鐢ㄧ殑 1 鐗╂枡锛堜骇鍝侊級 + SelectValues []string `json:"selectValues" gorm:"-"` //dateType=3鏃剁敤 + SelectValue string `json:"-" gorm:"type:text;"` + Value string `json:"value" gorm:"-"` //浠嶢ttributeValue鍙栧埌鐨剉alue } AttributeSearch struct { @@ -27,13 +31,44 @@ type DataType int const ( - DateTypeProduct = 1 + DataTypeString = 1 //鎵嬪~瀛楃涓� + DataTypeInt = 2 //鎵嬪~鏁村瀷 + DataTypeSelect = 3 //涓嬫媺妗� +) + +type EntityType int + +const ( + EntityTypeProduct = 1 ) func (slf *Attribute) TableName() string { return "wms_attribute" } +func (slf *Attribute) BeforeCreate(tx *gorm.DB) (err error) { + if len(slf.SelectValues) != 0 { + bts, err := json.Marshal(slf.SelectValues) + if err != nil { + return err + } + slf.SelectValue = string(bts) + } + return nil +} + +func (slf *Attribute) AfterFind(tx *gorm.DB) (err error) { + if slf.SelectValue != "" { + var list []string + err = json.Unmarshal([]byte(slf.SelectValue), &list) + if err != nil { + return err + } + slf.SelectValues = list + } + return nil +} + func NewAttributeSearch() *AttributeSearch { return &AttributeSearch{Orm: mysqlx.GetDB()} } -- Gitblit v1.8.0