123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package authorized
- import (
- "github.com/xinliangnote/go-gin-api/internal/pkg/core"
- "github.com/xinliangnote/go-gin-api/internal/repository/mysql"
- "github.com/xinliangnote/go-gin-api/internal/repository/mysql/authorized"
- )
- 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.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.NewQueryBuilder()
- qb = qb.WhereIsDeleted(mysql.EqualPredicate, -1)
- if searchData.BusinessKey != "" {
- qb.WhereBusinessKey(mysql.EqualPredicate, searchData.BusinessKey)
- }
- if searchData.BusinessSecret != "" {
- qb.WhereBusinessSecret(mysql.EqualPredicate, searchData.BusinessSecret)
- }
- if searchData.BusinessDeveloper != "" {
- qb.WhereBusinessDeveloper(mysql.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
- }
|