by Robin at 20230102; account count

This commit is contained in:
Leufolium 2024-01-02 19:34:05 +08:00
parent d7bc41aec6
commit db6670572e
7 changed files with 110 additions and 2 deletions

View File

@ -207,3 +207,19 @@ type OpUpdateByIdsResp struct {
base.BaseResponse
Data *OpUpdateByIdsData `json:"data"`
}
// 统计数量
type OpCountReq struct {
base.BaseRequest
CtUpperBound *int64 `json:"ct_upper_bound"`
CtLowerBound *int64 `json:"ct_lower_bound"`
}
type OpCountData struct {
Count int64 `json:"count"`
}
type OpCountResp struct {
base.BaseResponse
Data *OpCountData `json:"data"`
}

View File

@ -219,3 +219,20 @@ func OpGetAccountListForOthersByMids(ctx *gin.Context) {
ReplyOk(ctx, data)
}
func OpGetAccountCount(ctx *gin.Context) {
req := ctx.MustGet("client_req").(*accountproto.OpCountReq)
count, ec := service.DefaultService.OpGetAccountCount(ctx, req)
if ec != errcode.ErrCodeAccountSrvOk {
logger.Error("OpGetAccountCount fail, req: %v, ec: %v", util.ToJson(req), ec)
ReplyErrCodeMsg(ctx, ec)
return
}
data := &accountproto.OpCountData{
Count: count,
}
ReplyOk(ctx, data)
}

View File

@ -220,6 +220,7 @@ func Init(r *gin.Engine) {
opAccountGroup.POST("list_fuzzily_by_name", middleware.JSONParamValidator(accountproto.OpListFuzzilyByNameReq{}), middleware.JwtAuthenticator(), OpGetAccountListFuzzilyByName)
opAccountGroup.POST("list_others_by_mid", middleware.JSONParamValidator(accountproto.OpListOthersByMidReq{}), middleware.JwtAuthenticator(), OpGetAccountListForOthersByMid)
opAccountGroup.POST("list_others_by_mids", middleware.JSONParamValidator(accountproto.OpListOthersByMidsReq{}), middleware.JwtAuthenticator(), OpGetAccountListForOthersByMids)
opAccountGroup.POST("count", middleware.JSONParamValidator(accountproto.OpCountReq{}), middleware.JwtAuthenticator(), OpGetAccountCount)
// 动态
opMomentGroup := r.Group("/op/moment", PrepareOp())

View File

@ -988,6 +988,37 @@ func (m *Mongo) UpdateAccountByIds(ctx *gin.Context, account *dbstruct.Account,
return err
}
func (m *Mongo) GetAccountCount(ctx *gin.Context, req *accountproto.OpCountReq) (int64, error) {
col := m.getColAccount()
filterInClause := []qmgo.M{}
if req.CtLowerBound != nil {
filterInClause = append(filterInClause, qmgo.M{
"ct": qmgo.M{
"$gte": util.DerefInt64(req.CtLowerBound),
},
})
}
if req.CtUpperBound != nil {
filterInClause = append(filterInClause, qmgo.M{
"ct": qmgo.M{
"$lte": util.DerefInt64(req.CtUpperBound),
},
})
}
if len(filterInClause) == 0 {
return 0, nil
}
filter := qmgo.M{
"$and": filterInClause,
}
count, err := col.Find(ctx, filter).Count()
return count, err
}
// vericode相关
func (m *Mongo) CreateVeriCode(ctx *gin.Context, vericode *dbstruct.VeriCode) error {
col := m.getColVeriCode()

View File

@ -154,6 +154,15 @@ func (p *Account) OpUpdateByIds(ctx *gin.Context, req *accountproto.OpUpdateById
return nil
}
func (p *Account) OpCount(ctx *gin.Context, req *accountproto.OpCountReq) (int64, error) {
count, err := p.store.GetAccountCount(ctx, req)
if err != nil {
logger.Error("GetAccountCount fail, err: %v", err)
return -1, err
}
return count, err
}
func (p *Account) GenerateOriginalAccount() (*dbstruct.Account, error) {
key := "account_init"
cfg := apollostruct.AccountInitCfg{}

View File

@ -309,7 +309,7 @@ func (s *Service) OpGetAccountListForOthersByMiBusinessValidated(ctx *gin.Contex
Validate().
Collect()
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
logger.Error("OpGetAccountListFuzzilyByName business validation failed")
logger.Error("OpGetAccountListForOthersByMid business validation failed")
return
}
@ -327,7 +327,24 @@ func (s *Service) OpGetAccountListForOthersByMidsBusinessValidate(ctx *gin.Conte
Validate().
Collect()
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
logger.Error("OpGetAccountListFuzzilyByName business validation failed")
logger.Error("OpGetAccountListForOthersByMids business validation failed")
return
}
return
}
func (s *Service) OpGetAccountCountBusinessValidate(ctx *gin.Context, req *accountproto.OpCountReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 1.业务校验
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
QueryAccount(_DefaultAccount.OpListByMid).
EnsureAccountExist().
EnsureIsOpRole().
Validate().
Collect()
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
logger.Error("OpGetAccountCount business validation failed")
return
}
return

View File

@ -898,6 +898,23 @@ func (s *Service) OpGetAccountListForOthersByMids(ctx *gin.Context, req *account
return
}
func (s *Service) OpGetAccountCount(ctx *gin.Context, req *accountproto.OpCountReq) (count int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
if ec = s.OpGetAccountCountBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
count, err := _DefaultAccount.OpCount(ctx, req)
if err != nil {
logger.Error("OpCount fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
return
}
// Token
func (s *Service) OpVerifyToken(ctx *gin.Context, token string) (err error) {
if err = _DefaultToken.OpVerify(ctx, token); err != nil {