| | |
| | | package models |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "wms/pkg/mysqlx" |
| | |
| | | // 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:"-"` //从AttributeValue取到的value |
| | | 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:"-"` //从AttributeValue取到的value |
| | | } |
| | | |
| | | AttributeSearch struct { |
| | |
| | | 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()} |
| | | } |