From f45e4cb8045fe60f96f467dc4ea1e2ae57445712 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 03 七月 2024 23:13:40 +0800 Subject: [PATCH] 默认位置parent_id为视图位置id --- models/attribute_value.go | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) diff --git a/models/attribute_value.go b/models/attribute_value.go index f6bca8b..fc6e42a 100644 --- a/models/attribute_value.go +++ b/models/attribute_value.go @@ -17,6 +17,7 @@ AttributeValueSearch struct { AttributeValue + Ids []string Order string PageNum int PageSize int @@ -51,14 +52,40 @@ 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) } -- Gitblit v1.8.0