From 45a526194b33ddb4c7e668d7582e7481d0ca1fca Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期四, 27 七月 2023 10:09:25 +0800 Subject: [PATCH] fix --- api/v1/client.go | 4 ++-- service/client.go | 8 ++++---- model/client.go | 13 ++++++++----- api/v1/followRecord.go | 11 +++++------ docs/swagger.yaml | 2 +- docs/docs.go | 2 +- docs/swagger.json | 2 +- model/followRecord.go | 10 +++++++++- 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/api/v1/client.go b/api/v1/client.go index b691940..ad91842 100644 --- a/api/v1/client.go +++ b/api/v1/client.go @@ -192,7 +192,7 @@ return } - clients, errCode := clientService.GetClientList(params.Page, params.PageSize, params.Keyword) + clients, total, errCode := clientService.GetClientList(params.Page, params.PageSize, params.Keyword) if errCode != ecode.OK { ctx.Fail(errCode) return @@ -200,6 +200,6 @@ ctx.OkWithDetailed(response.ClientResponse{ List: clients, - Count: len(clients), + Count: int(total), }) } diff --git a/api/v1/followRecord.go b/api/v1/followRecord.go index cc09505..698073a 100644 --- a/api/v1/followRecord.go +++ b/api/v1/followRecord.go @@ -43,7 +43,6 @@ ctx.Ok() } - // Delete // // @Tags FollowRecord @@ -200,12 +199,12 @@ // List // // @Tags FollowRecord -// @Summary 璺熻繘璁板綍鍒楄〃 +// @Summary 鍥炶璁板綍鍒楄〃 // @Produce application/json -// @Param object body request.GetFollowRecordList true "鍙傛暟" -// @Success 200 {object} contextx.Response{data=response.FollowRecordResponse} +// @Param object body request.GetFollowRecordList true "鍙傛暟" +// @Success 200 {object} contextx.Response{data=response.FollowRecordResponse} // @Router /api/followRecord/list [post] -func (con *FollowRecordApi) List(c *gin.Context) { +func (fr *FollowRecordApi) List(c *gin.Context) { var params request.GetFollowRecordList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { @@ -219,7 +218,7 @@ } ctx.OkWithDetailed(response.FollowRecordResponse{ - List: followRecords, + List: followRecords, Count: len(followRecords), }) } diff --git a/docs/docs.go b/docs/docs.go index 2630dba..5793111 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2108,7 +2108,7 @@ "tags": [ "FollowRecord" ], - "summary": "璺熻繘璁板綍鍒楄〃", + "summary": "鍥炶璁板綍鍒楄〃", "parameters": [ { "description": "鍙傛暟", diff --git a/docs/swagger.json b/docs/swagger.json index 51dfff1..33a070f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2096,7 +2096,7 @@ "tags": [ "FollowRecord" ], - "summary": "璺熻繘璁板綍鍒楄〃", + "summary": "鍥炶璁板綍鍒楄〃", "parameters": [ { "description": "鍙傛暟", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index ddcb2a1..38e6140 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -5366,7 +5366,7 @@ data: $ref: '#/definitions/response.FollowRecordResponse' type: object - summary: 璺熻繘璁板綍鍒楄〃 + summary: 鍥炶璁板綍鍒楄〃 tags: - FollowRecord /api/followRecord/update: diff --git a/model/client.go b/model/client.go index 3df4638..2dc0889 100644 --- a/model/client.go +++ b/model/client.go @@ -35,12 +35,11 @@ ClientSearch struct { Client - Orm *gorm.DB + Orm *gorm.DB Keyword string OrderBy string PageNum int PageSize int - } ) @@ -110,15 +109,19 @@ return record, err } -func (slf *ClientSearch) Find() ([]*Client, error) { +func (slf *ClientSearch) Find() ([]*Client, int64, error) { var db = slf.build() var records = make([]*Client, 0) if slf.PageNum > 0 && slf.PageSize > 0 { db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) } + var total int64 + if err := db.Count(&total).Error; err != nil { + return records, total, err + } err := db.Preload("ClientStatus").Preload("ClientType").Preload("ClientOrigin").Preload("ClientLevel").Preload("FollowRecord").Preload("EnterpriseNature").Preload("RegisteredCapital").Preload("Industry").Preload("EnterpriseScale").Preload("Contacts").Preload("Country").Preload("Province").Preload("City").Preload("Region").Find(&records).Error - return records, err + return records, total, err } func (slf *ClientSearch) UpdateByMap(data map[string]interface{}) error { @@ -139,4 +142,4 @@ func (slf *ClientSearch) SetOrder(order string) *ClientSearch { slf.OrderBy = order return slf -} \ No newline at end of file +} diff --git a/model/followRecord.go b/model/followRecord.go index c8205b5..fdadb48 100644 --- a/model/followRecord.go +++ b/model/followRecord.go @@ -52,6 +52,9 @@ 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 { @@ -110,8 +113,13 @@ } func (slf *FollowRecordSearch) Find() ([]*FollowRecord, error) { + var db = slf.build() var records = make([]*FollowRecord, 0) - err := slf.build().Preload("Client").Preload("Contact").Find(&records).Error + 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, err } diff --git a/service/client.go b/service/client.go index 2c9a1cd..9c2a431 100644 --- a/service/client.go +++ b/service/client.go @@ -56,11 +56,11 @@ return ecode.OK } -func (ClientService) GetClientList(page, pageSize int, keyword string) ([]*model.Client, int) { +func (ClientService) GetClientList(page, pageSize int, keyword string) ([]*model.Client, int64, int) { // get contact list - contacts, err := model.NewClientSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).Find() + contacts, total, err := model.NewClientSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).Find() if err != nil { - return nil, ecode.ClientListErr + return nil, 0, ecode.ClientListErr } - return contacts, ecode.OK + return contacts, total, ecode.OK } -- Gitblit v1.8.0