You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.2 KiB
Go

package service
import (
"context"
"joybuywork/internal/app"
"joybuywork/internal/repository/cache"
"joybuywork/internal/repository/dao"
"joybuywork/internal/repository/finder"
"joybuywork/internal/repository/model"
"joybuywork/internal/repository/mtype"
"joybuywork/internal/utils/merr"
"joybuywork/proto/go_proto/workerr"
)
type Service struct {
ctx context.Context
dao *dao.Query
svcErr error
be *merr.BusinessError
}
// Init 初始化服务对象
func (s *Service) Init(ctx context.Context) {
s.ctx = ctx
s.dao = dao.Q
s.be = merr.NewBE(ctx)
}
func (s *Service) checkErr() {
if s.svcErr != nil {
app.Logger.Error(s.ctx, s.svcErr.Error())
}
}
func (s *Service) BE() *merr.BusinessError {
return s.be
}
func (s *Service) GetDao() *dao.Query {
return s.dao
}
func (s *Service) ProjectErrNil(idVal ...any) (project *model.Project, err error) {
project, err = finder.Project(s.ctx, idVal...)
if err != nil {
err = s.BE().CacheError(err)
return
}
if project == nil || project.IsDel == mtype.Yes {
err = workerr.NotFound("not found project")
return
}
return
}
func (s *Service) CpnAndUser(cpnId, userId int64) (cpn *model.FissionCampaign, user *model.FissionUser, err error) {
cpn, err = cache.NewCampaign(s.ctx).FindById(cpnId)
if err != nil {
err = s.BE().CacheError(err)
return
}
if cpn == nil || cpn.IsDel == mtype.Yes {
err = workerr.NotFound("not found cpn")
return
}
user, err = cache.NewFissionUser(s.ctx, cpn.ID).FindById(userId)
if err != nil {
err = s.BE().CacheError(err)
return
}
if user == nil {
err = workerr.NotFound("not found user")
return
}
return
}
func (s *Service) CpnAndUserStr(cpnId, userId string) (cpn *model.FissionCampaign, user *model.FissionUser, err error) {
cpn, err = cache.NewCampaign(s.ctx).FindByHashId(cpnId)
if err != nil {
err = s.BE().CacheError(err)
return
}
if cpn == nil || cpn.IsDel == mtype.Yes {
err = workerr.NotFound("not found cpn")
return
}
user, err = cache.NewFissionUser(s.ctx, cpn.ID).FindByHashId(userId)
if err != nil {
err = s.BE().CacheError(err)
return
}
if user == nil {
err = workerr.NotFound("not found user")
return
}
return
}