add
add multi-criteria query to client
| | |
| | | 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 |
| | |
| | | "request.GetClientList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | | } |
| | | }, |
| | |
| | | "request.GetClientList": { |
| | | "type": "object", |
| | | "properties": { |
| | | "keyword": { |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | "pageSize": { |
| | | "description": "每页大小", |
| | | "type": "integer" |
| | | }, |
| | | "search_map": { |
| | | "type": "object", |
| | | "additionalProperties": true |
| | | } |
| | | } |
| | | }, |
| | |
| | | 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: |
| | |
| | | Client
|
| | |
|
| | | Orm *gorm.DB
|
| | | Keyword string
|
| | | SearchMap map[string]interface{} |
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | |
| | |
|
| | | 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
|
| | |
| | |
|
| | | 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
|
| | | }
|
| | |
|
| | |
| | | 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 {
|
| | |
| | | |
| | | type GetClientList struct { |
| | | PageInfo |
| | | Keyword string `json:"keyword"` |
| | | SearchMap map[string]interface{} `json:"search_map"` |
| | | } |
| | | |
| | | type DeleteClient struct { |
| | |
| | | return ecode.OK
|
| | | }
|
| | |
|
| | |
|
| | | // CheckClientExist check client exist
|
| | | func CheckClientExist(id int) int {
|
| | | _, err := model.NewClientSearch(nil).SetId(id).First()
|
| | |
| | | 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
|
| | | }
|