| | |
| | | // AttributeValue 属性值和对象 |
| | | AttributeValue struct { |
| | | gorm.Model |
| | | EntityID string `gorm:"primaryKey"` |
| | | AttributeID uint `gorm:"primaryKey"` |
| | | Value string `json:"value"` |
| | | EntityID string `gorm:"uniqueIndex:entity_id_attr_id;type:varchar(100);not null;default:''" json:"entityID"` |
| | | AttributeID uint `gorm:"uniqueIndex:entity_id_attr_id;type:int;not null;default:0" json:"attributeID"` |
| | | Value string `gorm:"type:varchar(255);not null;default:''" json:"value"` |
| | | } |
| | | |
| | | AttributeValueSearch struct { |
| | | AttributeValue |
| | | Ids []string |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | |
| | | slf.ID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *AttributeValueSearch) SetEntityID(entityId string) *AttributeValueSearch { |
| | | slf.EntityID = entityId |
| | | return slf |
| | | } |
| | | func (slf *AttributeValueSearch) SetEntityIDs(entityId []string) *AttributeValueSearch { |
| | | slf.Ids = entityId |
| | | return slf |
| | | } |
| | | func (slf *AttributeValueSearch) SetAttributeID(attributeId uint) *AttributeValueSearch { |
| | | slf.AttributeID = attributeId |
| | | return slf |
| | | } |
| | | func (slf *AttributeValueSearch) SetValue(value string) *AttributeValueSearch { |
| | | slf.Value = value |
| | | return slf |
| | | } |
| | | func (slf *AttributeValueSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | if slf.EntityID != "" { |
| | | db = db.Where("entity_id = ?", slf.EntityID) |
| | | } |
| | | if slf.AttributeID != 0 { |
| | | db = db.Where("attribute_id = ?", slf.AttributeID) |
| | | } |
| | | if slf.Value != "" { |
| | | db = db.Where("value like ?", "%"+slf.Value+"%") |
| | | } |
| | | if len(slf.Ids) > 0 { |
| | | db = db.Where("entity_id in ?", slf.Ids) |
| | | } |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |