add
wangpengfei
2023-08-02 1ba1ecb2760ff21fc66db7a91fa099db489dd385
add

add multi-criteria query to client
7个文件已修改
58 ■■■■■ 已修改文件
api/v1/client.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/client.go 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/client.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/client.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/client.go
@@ -191,7 +191,7 @@
        return
    }
    clients, total, errCode := clientService.GetClientList(params.Page, params.PageSize, params.Keyword)
    clients, total, errCode := clientService.GetClientList(params.Page, params.PageSize, params.SearchMap)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
docs/docs.go
@@ -10000,9 +10000,6 @@
        "request.GetClientList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
@@ -10010,6 +10007,10 @@
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                },
                "search_map": {
                    "type": "object",
                    "additionalProperties": true
                }
            }
        },
docs/swagger.json
@@ -9988,9 +9988,6 @@
        "request.GetClientList": {
            "type": "object",
            "properties": {
                "keyword": {
                    "type": "string"
                },
                "page": {
                    "description": "页码",
                    "type": "integer"
@@ -9998,6 +9995,10 @@
                "pageSize": {
                    "description": "每页大小",
                    "type": "integer"
                },
                "search_map": {
                    "type": "object",
                    "additionalProperties": true
                }
            }
        },
docs/swagger.yaml
@@ -1950,14 +1950,15 @@
    type: object
  request.GetClientList:
    properties:
      keyword:
        type: string
      page:
        description: 页码
        type: integer
      pageSize:
        description: 每页大小
        type: integer
      search_map:
        additionalProperties: true
        type: object
    type: object
  request.GetContactList:
    properties:
model/client.go
@@ -36,7 +36,7 @@
        Client
        Orm      *gorm.DB
        Keyword  string
        SearchMap map[string]interface{}
        OrderBy  string
        PageNum  int
        PageSize int
@@ -59,14 +59,26 @@
func (slf *ClientSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Client{})
    if slf.Keyword != "" {
        db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
    }
    if slf.Id != 0 {
        db.Where("id = ?", slf.Id)
    }
    if slf.Name != "" {
        db.Where("name = ?", slf.Name)
    }
    if len(slf.SearchMap) > 0 {
        for key, value := range slf.SearchMap {
            switch v := value.(type) {
            case string:
                if key == "name" || key == "number" || key == "phone" || key == "detail_address" {
                    db = db.Where(key+" LIKE ?", "%"+v+"%")
                }
            case int:
                if key == "id" || key == "client_type_id" || key == "client_status_id" {
                    db = db.Where(key+" = ?", v)
                }
            }
        }
    }
    return db
@@ -94,6 +106,11 @@
func (slf *ClientSearch) SetName(name string) *ClientSearch {
    slf.Name = name
    return slf
}
func (slf *ClientSearch) SetSearchMap(data map[string]interface{}) *ClientSearch {
    slf.SearchMap = data
    return slf
}
@@ -127,11 +144,6 @@
func (slf *ClientSearch) UpdateByMap(data map[string]interface{}) error {
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *ClientSearch) SetKeyword(keyword string) *ClientSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *ClientSearch) SetPage(page, size int) *ClientSearch {
model/request/client.go
@@ -29,7 +29,7 @@
type GetClientList struct {
    PageInfo
    Keyword string `json:"keyword"`
    SearchMap map[string]interface{} `json:"search_map"`
}
type DeleteClient struct {
service/client.go
@@ -15,7 +15,6 @@
    return ecode.OK
}
// CheckClientExist check client exist
func CheckClientExist(id int) int {
    _, err := model.NewClientSearch(nil).SetId(id).First()
@@ -42,9 +41,9 @@
    return ecode.OK
}
func (ClientService) GetClientList(page, pageSize int, keyword string) ([]*model.Client, int64, int) {
func (ClientService) GetClientList(page, pageSize int, data map[string]interface{}) ([]*model.Client, int64, int) {
    // get contact list
    contacts, total, err := model.NewClientSearch(nil).SetKeyword(keyword).SetPage(page, pageSize).Find()
    contacts, total, err := model.NewClientSearch(nil).SetPage(page, pageSize).SetSearchMap(data).Find()
    if err != nil {
        return nil, 0, ecode.ClientListErr
    }