From 21163dc79adf14d00c783be8c00390932df2a865 Mon Sep 17 00:00:00 2001 From: ziming Date: Mon, 11 Aug 2025 17:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=AC=94=E7=AB=8B=E5=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/biz/retry.go | 67 ++++++++++++++++---------------- internal/biz/wechat_retry.go | 66 +++++++++++++++---------------- internal/service/wechat_retry.go | 57 +++++++++++++-------------- 3 files changed, 93 insertions(+), 97 deletions(-) diff --git a/internal/biz/retry.go b/internal/biz/retry.go index ab15792..ab98b31 100644 --- a/internal/biz/retry.go +++ b/internal/biz/retry.go @@ -2,44 +2,43 @@ package biz import ( "context" - "fmt" - "voucher/internal/biz/bo" - "voucher/internal/biz/vo" ) func (this *VoucherBiz) OrderRetry(ctx context.Context, outBizNos []string) error { - if len(outBizNos) > 0 { + return nil - for _, outBizNo := range outBizNos { - - order, err := this.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, outBizNo) - if err != nil { - return fmt.Errorf(fmt.Sprintf("获取订单%s异常:%v", outBizNo, err)) - } - - if !order.Status.IsIng() { - return fmt.Errorf(fmt.Sprintf("订单%s状态异常:%s", order.OrderNo, order.Status)) - } - - if err4 := this.orderRetry(ctx, order); err4 != nil { - return err4 - } - } - - return nil - } - - return this.OrderRepo.FindIngInBatches(ctx, func(ctx context.Context, rows []*bo.OrderBo) error { - - for _, order := range rows { - - if err4 := this.orderRetry(ctx, order); err4 != nil { - return err4 - } - } - - return nil - }) + //if len(outBizNos) > 0 { + // + // for _, outBizNo := range outBizNos { + // + // order, err := this.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, outBizNo) + // if err != nil { + // return fmt.Errorf(fmt.Sprintf("获取订单%s异常:%v", outBizNo, err)) + // } + // + // if !order.Status.IsIng() { + // return fmt.Errorf(fmt.Sprintf("订单%s状态异常:%s", order.OrderNo, order.Status)) + // } + // + // if err4 := this.orderRetry(ctx, order); err4 != nil { + // return err4 + // } + // } + // + // return nil + //} + // + //return this.OrderRepo.FindIngInBatches(ctx, func(ctx context.Context, rows []*bo.OrderBo) error { + // + // for _, order := range rows { + // + // if err4 := this.orderRetry(ctx, order); err4 != nil { + // return err4 + // } + // } + // + // return nil + //}) } diff --git a/internal/biz/wechat_retry.go b/internal/biz/wechat_retry.go index 4fa1fd6..8838c82 100644 --- a/internal/biz/wechat_retry.go +++ b/internal/biz/wechat_retry.go @@ -3,9 +3,6 @@ package biz import ( "context" "fmt" - "github.com/go-kratos/kratos/v2/log" - "time" - "voucher/internal/biz/bo" ) func (this *VoucherBiz) PushWechatRetry(ctx context.Context, batchNo string) error { @@ -30,35 +27,36 @@ func (this *VoucherBiz) PushWechatRetry(ctx context.Context, batchNo string) err func (this *VoucherBiz) WechatRetry(ctx context.Context, batchNo string) error { - start := time.Now() - log.Warnf("失败订单重试开始:%s,batchNo:%s", start.String(), batchNo) - fmt.Printf("失败订单重试开始:%s,batchNo:%s", start.String(), batchNo) - - num := 0 - err := this.OrderRepo.FinFailByStockIdInBatches(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 := this.orderRetry(ctx, order); err != nil { - log.Errorf("失败订单重试发生错误,batchNo:%s,orderNo:%s,appId:%s,openId:%s,err:%v", - batchNo, order.OrderNo, order.AppID, order.Account, err) - } - - } - - time.Sleep(1 * time.Second) - - return nil - }) - - log.Warnf("微信券查询处理耗时:%s,batchNo:%s,处理%d单", time.Now().Sub(start).String(), batchNo, num) - fmt.Printf("微信券查询处理耗时:%s,batchNo:%s,处理%d单", time.Now().Sub(start).String(), batchNo, num) - - return err + return nil + //start := time.Now() + //log.Warnf("失败订单重试开始:%s,batchNo:%s", start.String(), batchNo) + //fmt.Printf("失败订单重试开始:%s,batchNo:%s", start.String(), batchNo) + // + //num := 0 + //err := this.OrderRepo.FinFailByStockIdInBatches(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 := this.orderRetry(ctx, order); err != nil { + // log.Errorf("失败订单重试发生错误,batchNo:%s,orderNo:%s,appId:%s,openId:%s,err:%v", + // batchNo, order.OrderNo, order.AppID, order.Account, err) + // } + // + // } + // + // time.Sleep(1 * time.Second) + // + // return nil + //}) + // + //log.Warnf("微信券查询处理耗时:%s,batchNo:%s,处理%d单", time.Now().Sub(start).String(), batchNo, num) + //fmt.Printf("微信券查询处理耗时:%s,batchNo:%s,处理%d单", time.Now().Sub(start).String(), batchNo, num) + // + //return err } diff --git a/internal/service/wechat_retry.go b/internal/service/wechat_retry.go index 1ba4d76..3b38228 100644 --- a/internal/service/wechat_retry.go +++ b/internal/service/wechat_retry.go @@ -2,44 +2,43 @@ package service import ( "context" - "fmt" - "github.com/go-kratos/kratos/v2/log" "voucher/internal/pkg/rdsmq" ) func (s *VoucherService) GetWechatRetryConfig() *rdsmq.ConsumeConfig { - queue := s.bc.RdsMQ.GetWechatRetry() - if queue == nil { - return nil - } - - if !queue.GetIsOpen() { - log.Warn(fmt.Sprintf("[%s]RdsMQ is not open", queue.Name)) - return nil - } - - return &rdsmq.ConsumeConfig{ - Rdb: s.rdb.Rdb, - QueueName: queue.Name, - NumWorkers: queue.NumWorkers, - WaitTime: queue.GetWaitTime().AsDuration(), - RetryNum: queue.RetryNum, - Fn: s.HandleWechatRetry, - Logger: s.logHelper, - } + return nil + //queue := s.bc.RdsMQ.GetWechatRetry() + //if queue == nil { + // return nil + //} + // + //if !queue.GetIsOpen() { + // log.Warn(fmt.Sprintf("[%s]RdsMQ is not open", queue.Name)) + // return nil + //} + // + //return &rdsmq.ConsumeConfig{ + // Rdb: s.rdb.Rdb, + // QueueName: queue.Name, + // NumWorkers: queue.NumWorkers, + // WaitTime: queue.GetWaitTime().AsDuration(), + // RetryNum: queue.RetryNum, + // Fn: s.HandleWechatRetry, + // Logger: s.logHelper, + //} } func (s *VoucherService) HandleWechatRetry(ctx context.Context, batchNo string) error { - if batchNo == "" { - s.logHelper.Errorf("RdsMQ keySend error: batchNo is empty") - return nil - } - - if err := s.VoucherBiz.WechatRetry(ctx, batchNo); err != nil { - s.logHelper.Error(err) - } + //if batchNo == "" { + // s.logHelper.Errorf("RdsMQ keySend error: batchNo is empty") + // return nil + //} + // + //if err := s.VoucherBiz.WechatRetry(ctx, batchNo); err != nil { + // s.logHelper.Error(err) + //} return nil }