cmb
This commit is contained in:
parent
ce81f41693
commit
e96e3dc777
|
|
@ -49,9 +49,9 @@ func wireApp(bootstrap *conf.Bootstrap, logger log.Logger, accessLogger *log2.Ac
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
generateMixRepo := mixrepoimpl.NewGenerateMixRepoImpl(rdb)
|
generateMixRepo := mixrepoimpl.NewGenerateMixRepoImpl(rdb)
|
||||||
cmbCmb := cmb.NewCmb(rdb, orderRepo, productRepo, mqSendMixRepo, wechatCpnRepo, generateMixRepo)
|
cmbCmb := cmb.NewCmb(bootstrap, rdb, orderRepo, productRepo, mqSendMixRepo, wechatCpnRepo, generateMixRepo)
|
||||||
voucherBiz := biz.NewVoucherBiz(rdb, cmbCmb, orderRepo)
|
voucherBiz := biz.NewVoucherBiz(rdb, cmbCmb, orderRepo)
|
||||||
voucherService := service.NewVoucherService(bootstrap, voucherBiz, cmbCmb)
|
voucherService := service.NewVoucherService(bootstrap, voucherBiz)
|
||||||
httpServer := server.NewHTTPServer(bootstrap, helper, accessLogger, voucherService)
|
httpServer := server.NewHTTPServer(bootstrap, helper, accessLogger, voucherService)
|
||||||
consumer := server.NewConsumer(helper, bootstrap, voucherService)
|
consumer := server.NewConsumer(helper, bootstrap, voucherService)
|
||||||
app := newApp(logger, httpServer, consumer)
|
app := newApp(logger, httpServer, consumer)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package biz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
"voucher/internal/biz/bo"
|
||||||
|
"voucher/internal/pkg/lock"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
|
||||||
|
|
||||||
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error {
|
||||||
|
|
||||||
|
if orderNo, err = v.Cmb.Order(ctx, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *bo.OrderCreateRepBo, err error) {
|
||||||
|
|
||||||
|
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_query_%s", productNo), func(ctx context.Context) error {
|
||||||
|
|
||||||
|
if reps, err = v.Cmb.Query(ctx, productNo); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
@ -2,26 +2,16 @@ package cmb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
"voucher/internal/pkg/lock"
|
|
||||||
"voucher/internal/pkg/uid"
|
"voucher/internal/pkg/uid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *Cmb) Order(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
|
func (v *Cmb) Order(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo string, err error) {
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error {
|
orderNo, err = v.order(ctx, req)
|
||||||
|
|
||||||
if orderNo, err = v.order(ctx, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -71,12 +61,7 @@ func (v *Cmb) order(ctx context.Context, req *bo.OrderCreateReqBo) (orderNo stri
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Cmb) Query(ctx context.Context, req *bo.OrderCreateReqBo) (reps *bo.OrderCreateRepBo, err error) {
|
func (v *Cmb) Query(ctx context.Context, productNo string) (reps *bo.OrderCreateRepBo, err error) {
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_order_%s", req.OutBizNo), func(ctx context.Context) error {
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||||
AccountType: vo.OrderAccountTypeOpenId,
|
AccountType: vo.OrderAccountTypeOpenId,
|
||||||
}
|
}
|
||||||
|
|
||||||
orderNo, err := s.Cmb.Order(ctx, boReq)
|
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,20 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"voucher/internal/biz"
|
"voucher/internal/biz"
|
||||||
"voucher/internal/biz/cmb"
|
|
||||||
"voucher/internal/conf"
|
"voucher/internal/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VoucherService struct {
|
type VoucherService struct {
|
||||||
bc *conf.Bootstrap
|
bc *conf.Bootstrap
|
||||||
VoucherBiz *biz.VoucherBiz
|
VoucherBiz *biz.VoucherBiz
|
||||||
Cmb *cmb.Cmb
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVoucherService(
|
func NewVoucherService(
|
||||||
bc *conf.Bootstrap,
|
bc *conf.Bootstrap,
|
||||||
VoucherBiz *biz.VoucherBiz,
|
VoucherBiz *biz.VoucherBiz,
|
||||||
Cmb *cmb.Cmb,
|
|
||||||
) *VoucherService {
|
) *VoucherService {
|
||||||
return &VoucherService{
|
return &VoucherService{
|
||||||
bc: bc,
|
bc: bc,
|
||||||
VoucherBiz: VoucherBiz,
|
VoucherBiz: VoucherBiz,
|
||||||
Cmb: Cmb,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue