From 18f5a87f2b647a27417aaffd62f48ff38be1d0d8 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期一, 14 八月 2023 13:35:29 +0800 Subject: [PATCH] fix --- model/model.go | 2 model/request/contract.go | 2 model/contract.go | 53 ++++++++++++----- docs/swagger.yaml | 35 +++++++++-- docs/docs.go | 29 +++++++-- docs/swagger.json | 29 +++++++-- 6 files changed, 111 insertions(+), 39 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 57239a8..f7c9456 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -10709,16 +10709,16 @@ "model.CollectionProjection": { "type": "object", "properties": { + "_": { + "description": "The date when the item was deleted\nexample: 2023-08-10 15:48:25", + "type": "string" + }, "created_at": { "description": "The date when the item was created\nexample: 2023-08-10 15:48:25", "type": "string" }, "creator": { "type": "integer" - }, - "deleted_at": { - "description": "The date when the item was deleted\nexample: 2023-08-10 15:48:25", - "type": "string" }, "estimated_collection_amount": { "type": "number" @@ -10884,13 +10884,22 @@ "model.Contract": { "type": "object", "properties": { + "_": { + "description": "The date when the item was deleted\nexample: 2023-08-10 15:48:25", + "type": "string" + }, "clientId": { "type": "integer" + }, + "created_at": { + "description": "The date when the item was created\nexample: 2023-08-10 15:48:25", + "type": "string" }, "file": { "type": "string" }, "id": { + "description": "The ID of the item\nexample: 1", "type": "integer" }, "memberId": { @@ -10907,6 +10916,10 @@ }, "statusId": { "type": "integer" + }, + "updated_at": { + "description": "The date when the item was last updated\nexample: 2023-08-10 15:48:25", + "type": "string" } } }, @@ -14727,9 +14740,6 @@ "request.GetContractList": { "type": "object", "properties": { - "keyword": { - "type": "string" - }, "page": { "description": "椤电爜", "type": "integer" @@ -14737,6 +14747,11 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "search_map": { + "description": "鎼滅储鏉′欢: map[string]interface{} {\"member_name\": \"閿�鍞礋璐d汉\", \"number\": \"鍚堝悓缂栧彿\", \"created_at\": \"鍒涘缓鏃堕棿\"}", + "type": "object", + "additionalProperties": true } } }, diff --git a/docs/swagger.json b/docs/swagger.json index ebdb831..032e68f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -10697,16 +10697,16 @@ "model.CollectionProjection": { "type": "object", "properties": { + "_": { + "description": "The date when the item was deleted\nexample: 2023-08-10 15:48:25", + "type": "string" + }, "created_at": { "description": "The date when the item was created\nexample: 2023-08-10 15:48:25", "type": "string" }, "creator": { "type": "integer" - }, - "deleted_at": { - "description": "The date when the item was deleted\nexample: 2023-08-10 15:48:25", - "type": "string" }, "estimated_collection_amount": { "type": "number" @@ -10872,13 +10872,22 @@ "model.Contract": { "type": "object", "properties": { + "_": { + "description": "The date when the item was deleted\nexample: 2023-08-10 15:48:25", + "type": "string" + }, "clientId": { "type": "integer" + }, + "created_at": { + "description": "The date when the item was created\nexample: 2023-08-10 15:48:25", + "type": "string" }, "file": { "type": "string" }, "id": { + "description": "The ID of the item\nexample: 1", "type": "integer" }, "memberId": { @@ -10895,6 +10904,10 @@ }, "statusId": { "type": "integer" + }, + "updated_at": { + "description": "The date when the item was last updated\nexample: 2023-08-10 15:48:25", + "type": "string" } } }, @@ -14715,9 +14728,6 @@ "request.GetContractList": { "type": "object", "properties": { - "keyword": { - "type": "string" - }, "page": { "description": "椤电爜", "type": "integer" @@ -14725,6 +14735,11 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + }, + "search_map": { + "description": "鎼滅储鏉′欢: map[string]interface{} {\"member_name\": \"閿�鍞礋璐d汉\", \"number\": \"鍚堝悓缂栧彿\", \"created_at\": \"鍒涘缓鏃堕棿\"}", + "type": "object", + "additionalProperties": true } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fa108df..6f50cd2 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -532,6 +532,11 @@ type: object model.CollectionProjection: properties: + _: + description: |- + The date when the item was deleted + example: 2023-08-10 15:48:25 + type: string created_at: description: |- The date when the item was created @@ -539,11 +544,6 @@ type: string creator: type: integer - deleted_at: - description: |- - The date when the item was deleted - example: 2023-08-10 15:48:25 - type: string estimated_collection_amount: type: number estimated_collection_date: @@ -657,11 +657,24 @@ type: object model.Contract: properties: + _: + description: |- + The date when the item was deleted + example: 2023-08-10 15:48:25 + type: string clientId: type: integer + created_at: + description: |- + The date when the item was created + example: 2023-08-10 15:48:25 + type: string file: type: string id: + description: |- + The ID of the item + example: 1 type: integer memberId: type: integer @@ -673,6 +686,11 @@ type: integer statusId: type: integer + updated_at: + description: |- + The date when the item was last updated + example: 2023-08-10 15:48:25 + type: string type: object model.Country: properties: @@ -3245,14 +3263,17 @@ type: object request.GetContractList: properties: - keyword: - type: string page: description: 椤电爜 type: integer pageSize: description: 姣忛〉澶у皬 type: integer + search_map: + additionalProperties: true + description: '鎼滅储鏉′欢: map[string]interface{} {"member_name": "閿�鍞礋璐d汉", "number": + "鍚堝悓缂栧彿", "created_at": "鍒涘缓鏃堕棿"}' + type: object type: object request.GetFaqList: properties: diff --git a/model/contract.go b/model/contract.go index 024cf8b..505871d 100644 --- a/model/contract.go +++ b/model/contract.go @@ -15,18 +15,17 @@ Quotation Quotation `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"` StatusId int `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"` File string `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"` - gorm.Model `json:"-"` + gormModel } ContractSearch struct { Contract - Orm *gorm.DB - Keyword string - OrderBy string - PageNum int - PageSize int - + Orm *gorm.DB + SearchMap map[string]interface{} + OrderBy string + PageNum int + PageSize int } ) @@ -42,11 +41,33 @@ func (slf *ContractSearch) build() *gorm.DB { var db = slf.Orm.Model(&Contract{}) - 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 == "client_name" { + db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%") + } + + if key == "member_name" { + db = db.Joins("User").Where("User.username LIKE ?", "%"+v+"%") + } + + if key == "number" { + db = db.Where("number LIKE ?", "%"+v+"%") + } + + if key == "created_at" { + db = db.Where(key+"= ?", v) + } + case int: + } + } } return db @@ -98,11 +119,6 @@ return slf } -func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch { - slf.Keyword = keyword - return slf -} - func (slf *ContractSearch) SetPage(page, size int) *ContractSearch { slf.PageNum, slf.PageSize = page, size return slf @@ -111,4 +127,9 @@ func (slf *ContractSearch) SetOrder(order string) *ContractSearch { slf.OrderBy = order return slf -} \ No newline at end of file +} + +func (slf *ContractSearch) SetSearchMap(data map[string]interface{}) *ContractSearch { + slf.SearchMap = data + return slf +} diff --git a/model/model.go b/model/model.go index b95cec5..922de37 100644 --- a/model/model.go +++ b/model/model.go @@ -20,7 +20,7 @@ UpdatedAt time.Time `json:"updated_at"` // The date when the item was deleted // example: 2023-08-10 15:48:25 - DeletedAt *time.Time `json:"deleted_at,omitempty"` + DeletedAt *time.Time `json:"_"` } type CrmModel struct { diff --git a/model/request/contract.go b/model/request/contract.go index f86a93b..8480054 100644 --- a/model/request/contract.go +++ b/model/request/contract.go @@ -20,5 +20,5 @@ type GetContractList struct { PageInfo - Keyword string `json:"keyword"` + SearchMap map[string]interface{} `json:"search_map"` // 鎼滅储鏉′欢: map[string]interface{} {"member_name": "閿�鍞礋璐d汉", "number": "鍚堝悓缂栧彿", "created_at": "鍒涘缓鏃堕棿"} } -- Gitblit v1.8.0