cmb
This commit is contained in:
parent
efd8dd03ec
commit
41aa1d379e
|
|
@ -9,49 +9,6 @@ import (
|
||||||
"voucher/internal/pkg/mq"
|
"voucher/internal/pkg/mq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *VoucherBiz) PushOrderMQ(ctx context.Context, orderNo string) error {
|
|
||||||
|
|
||||||
eventMap := v.bc.RocketMQ.EventMap["order"]
|
|
||||||
sendOption := []mq.SendOption{
|
|
||||||
mq.WithSendShardingKeysOption(fmt.Sprintf("%s", orderNo)),
|
|
||||||
mq.WithOpenTelemetryOption(trace.SpanFromContext(ctx).SpanContext().TraceID().String()),
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := v.MqSendMixRepo.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
|
||||||
return fmt.Errorf("收单成功,消费队列投递失败[%v]", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err error) {
|
|
||||||
|
|
||||||
c := vo.OrderConsume.BuildCache([]string{orderNo})
|
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
|
|
||||||
|
|
||||||
order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if order.Type.IsCmb() {
|
|
||||||
|
|
||||||
outRequestNo, err := v.Cmb.OrderConsume(ctx, order)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.PushNotifyMQ(ctx, orderNo, outRequestNo)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("订单类型错误:%s", order.Type.GetText())
|
|
||||||
})
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *VoucherBiz) PushNotifyMQ(ctx context.Context, orderNo, outRequestNo string) error {
|
func (v *VoucherBiz) PushNotifyMQ(ctx context.Context, orderNo, outRequestNo string) error {
|
||||||
|
|
||||||
eventMap := v.bc.RocketMQ.EventMap["notify"]
|
eventMap := v.bc.RocketMQ.EventMap["notify"]
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package biz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
"voucher/internal/biz/vo"
|
||||||
|
"voucher/internal/pkg/lock"
|
||||||
|
"voucher/internal/pkg/mq"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (v *VoucherBiz) PushOrderMQ(ctx context.Context, orderNo string) error {
|
||||||
|
|
||||||
|
eventMap := v.bc.RocketMQ.EventMap["order"]
|
||||||
|
sendOption := []mq.SendOption{
|
||||||
|
mq.WithSendShardingKeysOption(fmt.Sprintf("%s", orderNo)),
|
||||||
|
mq.WithOpenTelemetryOption(trace.SpanFromContext(ctx).SpanContext().TraceID().String()),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := v.MqSendMixRepo.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
||||||
|
return fmt.Errorf("收单成功,消费队列投递失败[%v]", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err error) {
|
||||||
|
|
||||||
|
c := vo.OrderConsume.BuildCache([]string{orderNo})
|
||||||
|
|
||||||
|
err = lock.NewMutex(v.rdb.Rdb, c.TTL).Lock(ctx, c.Key, func(ctx context.Context) error {
|
||||||
|
|
||||||
|
order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if order.Type.IsCmb() {
|
||||||
|
|
||||||
|
outRequestNo, err := v.Cmb.OrderConsume(ctx, order)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.PushNotifyMQ(ctx, orderNo, outRequestNo)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("订单类型错误:%s", order.Type.GetText())
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue