| | |
| | | |
| | | DictSearch struct { |
| | | Dict |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | DictTypes []constvar.DictType |
| | | } |
| | | ) |
| | | |
| | | func (slf *Dict) TableName() string { |
| | | return "dict" |
| | | return "silk_dict" |
| | | } |
| | | |
| | | func NewDictSearch() *DictSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetKeyword(keyword string) *DictSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetDictType(dt *constvar.DictType) *DictSearch { |
| | | slf.DictType = dt |
| | | return slf |
| | | } |
| | | |
| | | func (slf *DictSearch) SetDictTypes(dts []constvar.DictType) *DictSearch { |
| | | slf.DictTypes = dts |
| | | return slf |
| | | } |
| | | |
| | |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if slf.Keyword != "" { |
| | | kw := "%" + slf.Keyword + "%" |
| | | db = db.Where("name like ? or number like ?", kw, kw) |
| | | } |
| | | |
| | | if len(slf.DictTypes) > 0 { |
| | | db = db.Where("dict_type in (?)", slf.DictTypes) |
| | | } |
| | | |
| | | return db |
| | |
| | | records = make([]*Dict, 0) |
| | | db = slf.build() |
| | | ) |
| | | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |