From 70c2f65dbfa938c2ebd94b4a4c5a397a76564c41 Mon Sep 17 00:00:00 2001 From: ziming Date: Thu, 5 Jun 2025 14:48:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=86=E5=8F=96=E6=88=90=E5=8A=9F=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=A0=B8=E9=94=80=E7=8A=B6=E6=80=81=EF=BC=8C=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E4=B8=8D=E5=81=9A=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/wechat_query.go | 9 +++++++++ internal/data/repoimpl/order.go | 2 +- internal/service/wechat_query.go | 13 ++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/internal/biz/wechat_query.go b/internal/biz/wechat_query.go index df37155..83a0561 100644 --- a/internal/biz/wechat_query.go +++ b/internal/biz/wechat_query.go @@ -34,10 +34,19 @@ func (v *VoucherBiz) WechatQuery(ctx context.Context, batchNo string) error { return fmt.Errorf("batchNo is empty") } + log.Infof("微信查询券订单状态,batchNo:%s", batchNo) + + num := 0 return v.OrderRepo.FinByStockIdInBatches(ctx, batchNo, func(ctx context.Context, rows []*bo.OrderBo) error { + if len(rows) == 0 { + log.Infof("微信查询券订单状态,batchNo[%s],已处理[%d]单,无订单,结束执行", batchNo, num) + return nil + } + for _, order := range rows { + num += 1 if err := v.wechatQuery(ctx, order); err != nil { log.Errorf("微信查询券订单状态发生错误,batchNo:%s,orderNo:%s,couponId:%s,appId:%s,openId:%s,err:%v", batchNo, order.OrderNo, order.VoucherNo, order.AppID, order.Account, err) diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index 33a78e9..79d388e 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -37,7 +37,7 @@ func (p *OrderRepoImpl) FinByStockIdInBatches(ctx context.Context, batchNo strin result := p.DB(ctx). Where("batch_no = ?", batchNo). Where("status = ?", vo.OrderStatusSuccess.GetValue()). - FindInBatches(&results, 10, func(tx *gorm.DB, batch int) error { + FindInBatches(&results, 20, func(tx *gorm.DB, batch int) error { return fun(ctx, p.ToBos(results)) }) diff --git a/internal/service/wechat_query.go b/internal/service/wechat_query.go index 96f3209..89a4b4c 100644 --- a/internal/service/wechat_query.go +++ b/internal/service/wechat_query.go @@ -4,8 +4,6 @@ import ( "context" "fmt" "github.com/go-kratos/kratos/v2/log" - "time" - "voucher/internal/pkg/lock" "voucher/internal/pkg/rdsmq" ) @@ -39,12 +37,9 @@ func (s *VoucherService) Handle(ctx context.Context, msg string) error { return nil } - return lock.NewMutex(s.rdb.Rdb, time.Hour*10).Lock(ctx, fmt.Sprintf("cmb_wechant_query_%s", msg), func(ctx context.Context) error { + if err := s.VoucherBiz.WechatQuery(ctx, msg); err != nil { + s.logHelper.Error(err) + } - if err := s.VoucherBiz.WechatQuery(ctx, msg); err != nil { - s.logHelper.Error(err) - } - - return nil - }) + return nil }