-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_pagelist.go
57 lines (45 loc) · 1.58 KB
/
service_pagelist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package authorized_service
import (
"github.com/skyzhouzj/xhframwork/internal/api/repository/db_repo"
"github.com/skyzhouzj/xhframwork/internal/api/repository/db_repo/authorized_repo"
"github.com/skyzhouzj/xhframwork/internal/pkg/core"
)
type SearchData struct {
Page int `json:"page"` // 第几页
PageSize int `json:"page_size"` // 每页显示条数
BusinessKey string `json:"business_key"` // 调用方key
BusinessSecret string `json:"business_secret"` // 调用方secret
BusinessDeveloper string `json:"business_developer"` // 调用方对接人
Remark string `json:"remark"` // 备注
}
func (s *service) PageList(ctx core.Context, searchData *SearchData) (listData []*authorized_repo.Authorized, err error) {
page := searchData.Page
if page == 0 {
page = 1
}
pageSize := searchData.PageSize
if pageSize == 0 {
pageSize = 10
}
offset := (page - 1) * pageSize
qb := authorized_repo.NewQueryBuilder()
qb = qb.WhereIsDeleted(db_repo.EqualPredicate, -1)
if searchData.BusinessKey != "" {
qb.WhereBusinessKey(db_repo.EqualPredicate, searchData.BusinessKey)
}
if searchData.BusinessSecret != "" {
qb.WhereBusinessSecret(db_repo.EqualPredicate, searchData.BusinessSecret)
}
if searchData.BusinessDeveloper != "" {
qb.WhereBusinessDeveloper(db_repo.EqualPredicate, searchData.BusinessDeveloper)
}
listData, err = qb.
Limit(pageSize).
Offset(offset).
OrderById(false).
QueryAll(s.db.GetDbR().WithContext(ctx.RequestContext()))
if err != nil {
return nil, err
}
return
}