123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package provider
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "encoding/json"
- "gd_management/common.in/utils"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- )
- const (
- PORVIDERAPIPAGESIZE = 10
- )
- func ManagementGetProviderApiList(ctx context.Context, req *apis.ManagementGetProviderApiListReq, reply *apis.ManagementGetProviderApiListReply) error {
- o := orm.NewOrm()
- var err error
- if req.ProviderId == 0 {
- err = o.Raw("select count(id) from t_gd_provider_api order by id").QueryRow(&reply.Total)
- } else {
- err = o.Raw("select count(id) from t_gd_provider_api where provider_id=? order by id", req.ProviderId).QueryRow(&reply.Total)
- }
- if err != nil && err != orm.ErrNoRows {
- l.Error("mysql",
- zap.String("sql", "select count(id) from t_gd_provider_api"),
- zap.String("fields", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- defer func() {
- for i, v := range reply.ProviderApis {
- reply.ProviderApis[i].Filters = []apis.ProviderParamFilter{}
- if v.Filter == "" {
- continue
- }
- json.Unmarshal([]byte(v.Filter), &reply.ProviderApis[i].Filters)
- }
- }()
- if req.IsAll {
- if req.ProviderId == 0 {
- _, err = o.Raw("select * from t_gd_provider_api order by id").QueryRows(&reply.ProviderApis)
- } else {
- _, err = o.Raw("select * from t_gd_provider_api where provider_id=? order by id", req.ProviderId).QueryRows(&reply.ProviderApis)
- }
- if err != nil && err != orm.ErrNoRows {
- l.Error("mysql",
- zap.String("sql", "select t_gd_provider_api"),
- zap.String("fields", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- return nil
- }
- if req.PageSize == 0 {
- req.PageSize = PORVIDERAPIPAGESIZE
- }
- if req.PageNumber == 0 {
- req.PageNumber = 1
- }
- if req.ProviderId == 0 {
- _, err = o.Raw("select * from t_gd_provider_api order by id limit ? offset ?", req.PageSize, (req.PageNumber-1)*req.PageSize).QueryRows(&reply.ProviderApis)
- } else {
- _, err = o.Raw("select * from t_gd_provider_api where provider_id=? order by id limit ? offset ?", req.ProviderId, req.PageSize, (req.PageNumber-1)*req.PageSize).QueryRows(&reply.ProviderApis)
- }
- if err != nil && err != orm.ErrNoRows {
- l.Error("mysql",
- zap.String("sql", "select t_gd_provider_api"),
- zap.String("fields", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- reply.PageNumber = req.PageNumber
- reply.PageSize = req.PageSize
- return nil
- }
|