cmb
This commit is contained in:
parent
5dfd3c39c3
commit
90a398800b
|
|
@ -54,6 +54,7 @@ func (v *Cmb) OrderConsume(ctx context.Context, order *bo.OrderBo) (outRequestNo
|
||||||
func (v *Cmb) registerNotifyTag(ctx context.Context, stockCreatorMchID, stockID string) error {
|
func (v *Cmb) registerNotifyTag(ctx context.Context, stockCreatorMchID, stockID string) error {
|
||||||
|
|
||||||
c := vo.WechatNotifyRegisterTagCacheKey.BuildRegisterCache(v.bc.WechatNotifyMQ.Tag, stockCreatorMchID, stockID)
|
c := vo.WechatNotifyRegisterTagCacheKey.BuildRegisterCache(v.bc.WechatNotifyMQ.Tag, stockCreatorMchID, stockID)
|
||||||
|
|
||||||
_, err := v.rdb.Rdb.Get(ctx, c.Key).Result()
|
_, err := v.rdb.Rdb.Get(ctx, c.Key).Result()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -177,7 +178,7 @@ func (v *Cmb) orderWechat(ctx context.Context, order *bo.OrderBo, orderOutReques
|
||||||
|
|
||||||
orderWechat, err := v.OrderWechatRepo.GetByOutRequestNo(ctx, orderOutRequestNo)
|
orderWechat, err := v.OrderWechatRepo.GetByOutRequestNo(ctx, orderOutRequestNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("根据订单号%s获取微信订单失败:%s", orderWechat.OrderNo, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !orderWechat.Status.CanNotify() {
|
if !orderWechat.Status.CanNotify() {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
"time"
|
"voucher/internal/biz/vo"
|
||||||
"voucher/internal/pkg/lock"
|
"voucher/internal/pkg/lock"
|
||||||
"voucher/internal/pkg/mq"
|
"voucher/internal/pkg/mq"
|
||||||
)
|
)
|
||||||
|
|
@ -26,7 +26,9 @@ func (v *VoucherBiz) PushOrderMQ(ctx context.Context, orderNo string) error {
|
||||||
|
|
||||||
func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err error) {
|
func (v *VoucherBiz) OrderConsume(ctx context.Context, orderNo string) (err error) {
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("order_consume_%s", orderNo), func(ctx context.Context) 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)
|
order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -67,7 +69,9 @@ func (v *VoucherBiz) PushNotifyMQ(ctx context.Context, orderNo, outRequestNo str
|
||||||
|
|
||||||
func (v *VoucherBiz) NotifyConsume(ctx context.Context, orderNo, orderOutRequestNo string) (err error) {
|
func (v *VoucherBiz) NotifyConsume(ctx context.Context, orderNo, orderOutRequestNo string) (err error) {
|
||||||
|
|
||||||
err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("notify_consume_%s", orderNo), func(ctx context.Context) 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)
|
order, err := v.OrderRepo.GetByOrderNo(ctx, orderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ const (
|
||||||
CmbQueryLockKey CacheKey = "cmb_query"
|
CmbQueryLockKey CacheKey = "cmb_query"
|
||||||
CmbProductQueryLockKey CacheKey = "cmb_product_query"
|
CmbProductQueryLockKey CacheKey = "cmb_product_query"
|
||||||
|
|
||||||
|
OrderConsume CacheKey = "order_consume"
|
||||||
|
NotifyConsume CacheKey = "notify_consume"
|
||||||
|
|
||||||
WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag"
|
WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag"
|
||||||
WechatNotifyRegisterTagCacheLockKey CacheKey = "wechat_notify_register_tag_lock"
|
WechatNotifyRegisterTagCacheLockKey CacheKey = "wechat_notify_register_tag_lock"
|
||||||
|
|
||||||
|
|
@ -22,6 +25,8 @@ var CacheKeyMap = map[CacheKey]time.Duration{
|
||||||
CmbOrderLockKey: 30 * time.Second,
|
CmbOrderLockKey: 30 * time.Second,
|
||||||
CmbQueryLockKey: 30 * time.Second,
|
CmbQueryLockKey: 30 * time.Second,
|
||||||
CmbProductQueryLockKey: 30 * time.Second,
|
CmbProductQueryLockKey: 30 * time.Second,
|
||||||
|
OrderConsume: 30 * time.Second,
|
||||||
|
NotifyConsume: 30 * time.Second,
|
||||||
WechatNotifyRegisterTagCacheKey: 86400 * time.Second,
|
WechatNotifyRegisterTagCacheKey: 86400 * time.Second,
|
||||||
WechatNotifyRegisterTagCacheLockKey: 30 * time.Second,
|
WechatNotifyRegisterTagCacheLockKey: 30 * time.Second,
|
||||||
WechatNotifyConsumeLockKey: 30 * time.Second,
|
WechatNotifyConsumeLockKey: 30 * time.Second,
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ func (j *VoucherBiz) WechatNotifyConsumer(ctx context.Context, tag string, req *
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//req.PlainText.StockCreatorMchid = "1676203838"
|
req.PlainText.StockCreatorMchid = "1676203838"
|
||||||
//req.PlainText.StockID = "20215869"
|
req.PlainText.StockID = "20215869"
|
||||||
//req.PlainText.CouponID = "96059179220"
|
req.PlainText.CouponID = "96059179220"
|
||||||
|
|
||||||
orderWechat, err := j.OrderWechatRepo.GetByMSCId(ctx, req.PlainText.StockCreatorMchid, req.PlainText.StockID, req.PlainText.CouponID)
|
orderWechat, err := j.OrderWechatRepo.GetByMSCId(ctx, req.PlainText.StockCreatorMchid, req.PlainText.StockID, req.PlainText.CouponID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -55,7 +55,7 @@ func (v *VoucherBiz) wechatVoucherUsed(ctx context.Context, orderWechat *bo.Orde
|
||||||
|
|
||||||
order, err := v.OrderRepo.GetByOrderNo(ctx, orderWechat.OrderNo)
|
order, err := v.OrderRepo.GetByOrderNo(ctx, orderWechat.OrderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("根据订单号%s获取订单失败:%s", orderWechat.OrderNo, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = v.OrderWechatRepo.Used(ctx, orderWechat.ID); err != nil {
|
if err = v.OrderWechatRepo.Used(ctx, orderWechat.ID); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func wechatNotifyProducer(bodyStr string) error {
|
func wechatNotifyProducer(tag, bodyStr string) error {
|
||||||
// 设置HTTP协议客户端接入点,进入消息队列RocketMQ版控制台实例详情页面的接入点区域查看。
|
// 设置HTTP协议客户端接入点,进入消息队列RocketMQ版控制台实例详情页面的接入点区域查看。
|
||||||
endpoint := "http://1389288909295870.mqrest.cn-hangzhou.aliyuncs.com"
|
endpoint := "http://1389288909295870.mqrest.cn-hangzhou.aliyuncs.com"
|
||||||
// 请确保环境变量ALIBABA_CLOUD_ACCESS_KEY_ID、ALIBABA_CLOUD_ACCESS_KEY_SECRET已设置。
|
// 请确保环境变量ALIBABA_CLOUD_ACCESS_KEY_ID、ALIBABA_CLOUD_ACCESS_KEY_SECRET已设置。
|
||||||
|
|
@ -19,8 +19,6 @@ func wechatNotifyProducer(bodyStr string) error {
|
||||||
// Topic所属的实例ID,在消息队列RocketMQ版控制台创建。
|
// Topic所属的实例ID,在消息队列RocketMQ版控制台创建。
|
||||||
// 若实例有命名空间,则实例ID必须传入;若实例无命名空间,则实例ID传入null空值或字符串空值。实例的命名空间可以在消息队列RocketMQ版控制台的实例详情页面查看。
|
// 若实例有命名空间,则实例ID必须传入;若实例无命名空间,则实例ID传入null空值或字符串空值。实例的命名空间可以在消息队列RocketMQ版控制台的实例详情页面查看。
|
||||||
instanceId := "MQ_INST_1389288909295870_BYSoMttI"
|
instanceId := "MQ_INST_1389288909295870_BYSoMttI"
|
||||||
|
|
||||||
tag := "voucher_notify_dev"
|
|
||||||
//tag := "voucher_notify_pro"
|
//tag := "voucher_notify_pro"
|
||||||
|
|
||||||
client := mq_http_sdk.NewAliyunMQClient(endpoint, accessKey, secretKey, "")
|
client := mq_http_sdk.NewAliyunMQClient(endpoint, accessKey, secretKey, "")
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@ import (
|
||||||
|
|
||||||
func Test_WechatNotifyProducer(t *testing.T) {
|
func Test_WechatNotifyProducer(t *testing.T) {
|
||||||
|
|
||||||
|
tag := "voucher_notify_dev"
|
||||||
|
|
||||||
bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}`
|
bodyStr := `{"id":"5465699d-de6a-5414-a8df-283167b577ca","create_time":"2025-03-07T15:57:24+08:00","resource_type":"encrypt-resource","event_type":"COUPON.USE","summary":"代金券核销通知","original_type":"coupon","associated_data":"coupon","plain_text":{"stock_creator_mchid":"1605446142","stock_id":"19990623","coupon_id":"95952277058","coupon_name":"萧山农商新客激活礼","description":"","status":"USED","create_time":"2025-03-07T15:49:31+08:00","coupon_type":"NORMAL","no_cash":false,"singleitem":false,"consume_information":{"consume_time":"2025-03-07T15:57:24+08:00","consume_mchid":"1800002761","transaction_id":"4200002544202503077103159055"}}}`
|
||||||
err := wechatNotifyProducer(bodyStr)
|
|
||||||
if err != nil {
|
if err := wechatNotifyProducer(tag, bodyStr); err != nil {
|
||||||
t.Errorf("入队失败 error = %v", err)
|
t.Errorf("入队失败 error = %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue