51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
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) PushNotifyMQ(ctx context.Context, orderNo, outRequestNo string) error {
|
||
|
||
eventMap := v.bc.RocketMQ.EventMap["notify"]
|
||
sendOption := []mq.SendOption{
|
||
mq.WithSendShardingKeysOption(fmt.Sprintf("%s_%s", orderNo, outRequestNo)),
|
||
mq.WithOpenTelemetryOption(trace.SpanFromContext(ctx).SpanContext().TraceID().String()),
|
||
}
|
||
|
||
if err := v.MqSendMixRepo.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
||
return fmt.Errorf("notify,消费队列投递失败[%v]", err)
|
||
}
|
||
|
||
return nil
|
||
}
|
||
|
||
func (v *VoucherBiz) NotifyConsume(ctx context.Context, orderNo, orderOutRequestNo string) (err error) {
|
||
|
||
c := vo.NotifyConsume.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.Status.CanNotify() {
|
||
return fmt.Errorf("订单状态错误,不能通知:%s", order.Status.GetText())
|
||
}
|
||
|
||
if order.Type.IsCmb() {
|
||
return v.Cmb.NotifyConsume(ctx, order, orderOutRequestNo)
|
||
}
|
||
|
||
return fmt.Errorf("订单类型错误:%s", order.Type.GetText())
|
||
})
|
||
|
||
return
|
||
}
|