From 91afffaa4f3eb9104d39044197e4140c2044a78c Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 21 十一月 2023 15:33:17 +0800 Subject: [PATCH] 合同管理列表修改筛选条件 --- model/request/contract.go | 1 + service/contract.go | 4 ++-- model/contract.go | 15 ++++++++++++++- api/v1/contract.go | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api/v1/contract.go b/api/v1/contract.go index 5cfdd31..22e46e4 100644 --- a/api/v1/contract.go +++ b/api/v1/contract.go @@ -169,7 +169,7 @@ params.SearchMap["member_ids"] = userInfo.SubUserIds } - contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap) + contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap, params.Keyword) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/model/contract.go b/model/contract.go index e437c6c..430e5c0 100644 --- a/model/contract.go +++ b/model/contract.go @@ -28,7 +28,7 @@ ContractSearch struct { Contract - + Keyword string Orm *gorm.DB SearchMap map[string]interface{} OrderBy string @@ -47,6 +47,11 @@ } } +func (slf *ContractSearch) SetKeyword(keyword string) *ContractSearch { + slf.Keyword = keyword + return slf +} + func (slf *ContractSearch) build() *gorm.DB { var db = slf.Orm.Model(&Contract{}) @@ -55,6 +60,10 @@ } if slf.Number != "" { db = db.Where("number = ?", slf.Number) + } + + if slf.Keyword != "" { + db = db.Joins("Client").Where("contract_name like ? or number like ? or Client.name like ?", fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword)) } if len(slf.SearchMap) > 0 { @@ -76,6 +85,10 @@ if key == "created_at" { db = db.Where(key+"= ?", v) } + + if key == "contract_name" { + db = db.Where("contract_name=?", "%"+v+"%") + } case int: if key == "member_id" { db = db.Where(key+"= ?", v) diff --git a/model/request/contract.go b/model/request/contract.go index ef09ea2..acc26ef 100644 --- a/model/request/contract.go +++ b/model/request/contract.go @@ -24,6 +24,7 @@ type GetContractList struct { PageInfo SearchMap map[string]interface{} `json:"search_map"` // 鎼滅储鏉′欢: map[string]interface{} {"member_name": "閿�鍞礋璐d汉", "number": "鍚堝悓缂栧彿", "created_at": "鍒涘缓鏃堕棿"} + Keyword string `json:"keyword"` } type DeleteContract struct { diff --git a/service/contract.go b/service/contract.go index 2910f87..b6825ef 100644 --- a/service/contract.go +++ b/service/contract.go @@ -31,9 +31,9 @@ return ecode.OK } -func (ContractService) GetContractList(page, pageSize int, data map[string]interface{}) ([]*model.Contract, int64, int) { +func (ContractService) GetContractList(page, pageSize int, data map[string]interface{}, keyword string) ([]*model.Contract, int64, int) { // get contact list - contacts, total, err := model.NewContractSearch().SetPage(page, pageSize).SetSearchMap(data).FindAll() + contacts, total, err := model.NewContractSearch().SetPage(page, pageSize).SetSearchMap(data).SetKeyword(keyword).FindAll() if err != nil { return nil, 0, ecode.ContractListErr } -- Gitblit v1.8.0