From 4dd4ae617e7f37817d2c795ff011d73a67dc29bf Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期五, 11 八月 2023 17:28:56 +0800 Subject: [PATCH] fix --- model/collectionProjection.go | 2 service/quotation.go | 4 +- model/quotation.go | 38 ++++++++++++------ docs/swagger.yaml | 7 ++- model/request/collectionProjection.go | 2 api/v1/quotation.go | 2 docs/docs.go | 8 ++- docs/swagger.json | 8 ++- model/request/quotation.go | 2 9 files changed, 46 insertions(+), 27 deletions(-) diff --git a/api/v1/quotation.go b/api/v1/quotation.go index b436336..724da4f 100644 --- a/api/v1/quotation.go +++ b/api/v1/quotation.go @@ -160,7 +160,7 @@ return } - quotations, total, errCode := quotationService.GetQuotationList(params.Page, params.PageSize, params.Keyword) + quotations, total, errCode := quotationService.GetQuotationList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/docs/docs.go b/docs/docs.go index d7d128f..3927227 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -14624,9 +14624,6 @@ "request.GetQuotationList": { "type": "object", "properties": { - "keyword": { - "type": "string" - }, "page": { "description": "椤电爜", "type": "integer" @@ -14634,6 +14631,11 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "searchMap": { + "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"}; {\"sale_chance_id\": 閿�鍞嚎绱d}", + "type": "object", + "additionalProperties": true } } }, diff --git a/docs/swagger.json b/docs/swagger.json index f4be661..f142c53 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -14612,9 +14612,6 @@ "request.GetQuotationList": { "type": "object", "properties": { - "keyword": { - "type": "string" - }, "page": { "description": "椤电爜", "type": "integer" @@ -14622,6 +14619,11 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "searchMap": { + "description": "鎼滅储鏉′欢: map[string]interface{}{\"name\": \"xxx\"}; {\"sale_chance_id\": 閿�鍞嚎绱d}", + "type": "object", + "additionalProperties": true } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 60d12cb..8934514 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -3178,14 +3178,17 @@ type: object request.GetQuotationList: properties: - keyword: - type: string page: description: 椤电爜 type: integer pageSize: description: 姣忛〉澶у皬 type: integer + searchMap: + additionalProperties: true + description: '鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; {"sale_chance_id": + 閿�鍞嚎绱d}' + type: object type: object request.GetSaleChanceList: properties: diff --git a/model/collectionProjection.go b/model/collectionProjection.go index de10709..6275bb2 100644 --- a/model/collectionProjection.go +++ b/model/collectionProjection.go @@ -51,7 +51,7 @@ db = db.Where(key+" = ?", v) } case int: - if key == "client_id" { + if key == "client_id" || key == "sale_chance_id" { db = db.Where(key+" = ?", v) } } diff --git a/model/quotation.go b/model/quotation.go index b97befb..f6980ec 100644 --- a/model/quotation.go +++ b/model/quotation.go @@ -29,11 +29,11 @@ QuotationSearch struct { Quotation - Orm *gorm.DB - Keyword string - OrderBy string - PageNum int - PageSize int + Orm *gorm.DB + SearchMap map[string]interface{} + OrderBy string + PageNum int + PageSize int } ) @@ -49,11 +49,23 @@ func (slf *QuotationSearch) build() *gorm.DB { var db = slf.Orm.Model(&Quotation{}) - if slf.Keyword != "" { - db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") - } if slf.Id != 0 { db = db.Where("id = ?", slf.Id) + } + + if len(slf.SearchMap) > 0 { + for key, value := range slf.SearchMap { + switch v := value.(type) { + case string: + if key == "validity_date" { + db = db.Where(key+" = ?", v) + } + case int: + if key == "client_id" || key == "sale_chance_id" { + db = db.Where(key+" = ?", v) + } + } + } } return db @@ -106,11 +118,6 @@ return db.Updates(data).Error } -func (slf *QuotationSearch) SetKeyword(keyword string) *QuotationSearch { - slf.Keyword = keyword - return slf -} - func (slf *QuotationSearch) SetPage(page, size int) *QuotationSearch { slf.PageNum, slf.PageSize = page, size return slf @@ -120,3 +127,8 @@ slf.OrderBy = order return slf } + +func (slf *QuotationSearch) SetSearchMap(searchMap map[string]interface{}) *QuotationSearch { + slf.SearchMap = searchMap + return slf +} diff --git a/model/request/collectionProjection.go b/model/request/collectionProjection.go index 579f593..5472cb0 100644 --- a/model/request/collectionProjection.go +++ b/model/request/collectionProjection.go @@ -17,5 +17,5 @@ type GetCollectionProjectionList struct { PageInfo - SearchMap map[string]interface{} + SearchMap map[string]interface{} // 鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; {"sale_chance_id": 閿�鍞満浼歩d} } diff --git a/model/request/quotation.go b/model/request/quotation.go index f996a4c..3e04989 100644 --- a/model/request/quotation.go +++ b/model/request/quotation.go @@ -26,5 +26,5 @@ type GetQuotationList struct { PageInfo - Keyword string `json:"keyword"` + SearchMap map[string]interface{} // 鎼滅储鏉′欢: map[string]interface{}{"name": "xxx"}; {"sale_chance_id": 閿�鍞嚎绱d} } diff --git a/service/quotation.go b/service/quotation.go index 3ada6cd..d1b3935 100644 --- a/service/quotation.go +++ b/service/quotation.go @@ -44,9 +44,9 @@ return ecode.OK } -func (QuotationService) GetQuotationList(page, pageSize int, keyword string) ([]*model.Quotation, int64, int) { +func (QuotationService) GetQuotationList(page, pageSize int, data map[string]interface{}) ([]*model.Quotation, int64, int) { // get contact list - contacts, total, err := model.NewQuotationSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll() + contacts, total, err := model.NewQuotationSearch().SetPage(page, pageSize).SetSearchMap(data).FindAll() if err != nil { return nil, 0, ecode.QuotationListErr } -- Gitblit v1.8.0