| | |
| | | |
| | | FollowRecordSearch struct { |
| | | FollowRecord |
| | | Orm *gorm.DB |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | func (slf *FollowRecordSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&FollowRecord{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Keyword != "" { |
| | | db = db.Where("topic LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) Find() ([]*FollowRecord, error) { |
| | | func (slf *FollowRecordSearch) FindAll() ([]*FollowRecord, int64, error) { |
| | | var db = slf.build() |
| | | var records = make([]*FollowRecord, 0) |
| | | err := slf.build().Preload("Client").Preload("Contact").Find(&records).Error |
| | | return records, err |
| | | var total int64 |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, err |
| | | } |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Preload("Client").Preload("Contact").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) Count() (int64, error) { |
| | |
| | | slf.ClientId = clientId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) SetKeyword(keyword string) *FollowRecordSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) SetPage(page, size int) *FollowRecordSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) SetOrder(order string) *FollowRecordSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |