yinbentan
2024-07-08 f4508a84236a4aff1c7b5bfa17a14a8ff95728ba
models/attribute.go
@@ -25,6 +25,8 @@
      PageNum  int
      PageSize int
      Orm      *gorm.DB
      Keyword  string
      IDs      []uint
   }
)
@@ -103,9 +105,16 @@
   slf.ID = id
   return slf
}
func (slf *AttributeSearch) SetIDs(ids []uint) *AttributeSearch {
   slf.IDs = ids
   return slf
}
func (slf *AttributeSearch) SetName(name string) *AttributeSearch {
   slf.Name = name
   return slf
}
func (slf *AttributeSearch) SetEntityType(entityType EntityType) *AttributeSearch {
   slf.EntityType = entityType
   return slf
}
@@ -115,14 +124,22 @@
   if slf.ID != 0 {
      db = db.Where("id = ?", slf.ID)
   }
   if len(slf.IDs) != 0 {
      db = db.Where("id in ?", slf.IDs)
   }
   if slf.Order != "" {
      db = db.Order(slf.Order)
   }
   if slf.EntityType != 0 {
      db = db.Where("entity_type = ?", slf.EntityType)
   }
   if slf.Name != "" {
      db = db.Where("name = ?", slf.Name)
   }
   if slf.Keyword != "" {
      db = db.Where("id like ? or data_type like ? ", fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword))
   }
   return db
}