File was renamed from model/serviceContracts.go |
| | |
| | | |
| | | ServiceContractSearch struct { |
| | | ServiceContract |
| | | Orm *gorm.DB |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | func (slf *ServiceContractSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&ServiceContract{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, error) { |
| | | func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, int64, error) { |
| | | var db = slf.build() |
| | | var records = make([]*ServiceContract, 0) |
| | | 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) |
| | | } |
| | | |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Preload("Products").Find(&records).Error |
| | | return records, err |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetKeyword(keyword string) *ServiceContractSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetPage(page, size int) *ServiceContractSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetOrder(order string) *ServiceContractSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |