From dac214fa72dc2974954a4d8ee934695f548ad155 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期三, 02 八月 2023 14:14:30 +0800 Subject: [PATCH] fix --- model/serviceFollowup.go | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 39 insertions(+), 9 deletions(-) diff --git a/model/serviceFollowup.go b/model/serviceFollowup.go index c534dcf..c6baa40 100644 --- a/model/serviceFollowup.go +++ b/model/serviceFollowup.go @@ -28,7 +28,13 @@ ServiceFollowupSearch struct { ServiceFollowup - Orm *gorm.DB + + Orm *gorm.DB + Keyword string + OrderBy string + PageNum int + PageSize int + } ) @@ -44,6 +50,9 @@ func (slf *ServiceFollowupSearch) build() *gorm.DB { var db = slf.Orm.Model(&ServiceFollowup{}) + if slf.Keyword != "" { + db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") + } if slf.Id != 0 { db = db.Where("id = ?", slf.Id) } @@ -73,11 +82,23 @@ return record, err } -func (slf *ServiceFollowupSearch) FindAll() ([]*ServiceFollowup, error) { +func (slf *ServiceFollowupSearch) FindAll() ([]*ServiceFollowup, int64, error) { var db = slf.build() var records = make([]*ServiceFollowup, 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("CustomerServiceSheet").Find(&records).Error - return records, err + return records, total, err } func (slf *ServiceFollowupSearch) SetId(id int) *ServiceFollowupSearch { @@ -85,10 +106,19 @@ return slf } -// 鍙婃椂鐜� 瑙e喅鐜� 婊℃剰搴� 鏈嶅姟浜哄憳鏄惁鏉ヨ繃 锛堟湇鍔″洖璁垮崟锛� -// 宸ュ崟绫诲瀷 鎶ヤ慨鏉ユ簮锛堝伐鍗曠鐞嗭級 -// 鍚堝悓绫诲瀷 鍚堝悓鐘舵�侊紙鏈嶅姟鍚堝悓锛� -// 浠樻鏂瑰紡 鏄惁寮�绁� 璐︽埛锛堥攢鍞��娆惧崟锛� -// 閫�鍏ヤ粨搴� 鐘舵�侊紙閿�鍞��璐у崟锛� -// 鎶ヤ环鍗曠姸鎬� 锛堟姤浠峰崟锛� // 鍙兘鎬� 甯佺 褰撳墠鐘舵�侊紙閿�鍞満浼氾級 + +func (slf *ServiceFollowupSearch) SetKeyword(keyword string) *ServiceFollowupSearch { + slf.Keyword = keyword + return slf +} + +func (slf *ServiceFollowupSearch) SetPage(page, size int) *ServiceFollowupSearch { + slf.PageNum, slf.PageSize = page, size + return slf +} + +func (slf *ServiceFollowupSearch) SetOrder(order string) *ServiceFollowupSearch { + slf.OrderBy = order + return slf +} \ No newline at end of file -- Gitblit v1.8.0