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 }