From 62cd85166d78cec74512cb562d396e63ee2ab1a8 Mon Sep 17 00:00:00 2001 From: ziming Date: Wed, 18 Jun 2025 14:07:56 +0800 Subject: [PATCH] log --- internal/biz/cron_notice.go | 29 +++++++++++++------------- internal/biz/timeslicequery/execute.go | 18 ++++++++-------- internal/biz/timeslicequery/query.go | 11 +++++----- internal/biz/vo/cache.go | 2 -- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/internal/biz/cron_notice.go b/internal/biz/cron_notice.go index 100e37a..9d2d8e4 100644 --- a/internal/biz/cron_notice.go +++ b/internal/biz/cron_notice.go @@ -107,13 +107,6 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time EndTime: &end, } - select { - case <-ctx.Done(): - return ctx.Err() - default: - // 继续执行 - } - defer func() { if err := recover(); err != nil { _, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息 @@ -133,14 +126,15 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse start := time.Now() num := 0 - notifyNum := 0 + useNum := 0 + sucNum := 0 err := v.OrderRepo.FindInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error { for _, order := range rows { num += 1 - if err := v.notice(ctx, order, ¬ifyNum); err != nil { + if err := v.notice(ctx, order, &useNum, &sucNum); err != nil { log.Errorf("订单定时通知,err:%v", err) } @@ -150,17 +144,18 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse }) logFields := map[string]interface{}{ - "searchTime": req.StartTime.Format(time.DateTime) + "到" + req.EndTime.Format(time.DateTime), - "num": num, - "notifyNum": notifyNum, - "elapsed": time.Now().Sub(start).String(), + "sTime": req.StartTime.Format(time.DateTime) + "到" + req.EndTime.Format(time.DateTime), + "num": num, // 查询总量 + "useNum": useNum, // 核销通知数量 + "sucNum": sucNum, // 重置为成功数量 + "elapsed": time.Now().Sub(start).String(), } log.Warnf("订单定时通知,%+v", logFields) return err } -func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, notifyNum *int) (respErr error) { +func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, useNum, sucNum *int) (respErr error) { // 批量通知不做数据存储,量会很大 if order == nil { @@ -204,7 +199,11 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, notifyNum *i return err } - *notifyNum += 1 + if event.IsUsed() { + *useNum += 1 + } else if event.IsSendDEd() { + *sucNum += 1 + } return nil } diff --git a/internal/biz/timeslicequery/execute.go b/internal/biz/timeslicequery/execute.go index 55e5acd..c0f0059 100644 --- a/internal/biz/timeslicequery/execute.go +++ b/internal/biz/timeslicequery/execute.go @@ -43,22 +43,22 @@ func (v *Query) callbackFunc(ctx context.Context, req *timeslice.Task) error { start := time.Now() - x := &do.WechatQuery{ + bReq := &do.WechatQuery{ StartTime: currentStartTimeStr, EndTime: currentEndTimeStr, ProductNo: req.Process.Manager.ProductNo, } num := 0 - notifyNum := 0 errNum := 0 + useNum := 0 - err := v.orderRepo.FinSucByStockIdInBatches(ctx, x, func(ctx context.Context, rows []*bo.OrderBo) error { + err := v.orderRepo.FinSucByStockIdInBatches(ctx, bReq, func(ctx context.Context, rows []*bo.OrderBo) error { for _, order := range rows { num += 1 - if err := v.wechatQuery(ctx, order, ¬ifyNum); err != nil { + if err := v.wechatQuery(ctx, order, &useNum); err != nil { errNum += 1 @@ -84,11 +84,11 @@ func (v *Query) callbackFunc(ctx context.Context, req *timeslice.Task) error { end := time.Now() logFields := map[string]any{ - "searchTime": currentStartTimeStr + "到" + currentEndTimeStr, - "num": num, - "notifyNum": notifyNum, - "errNum": errNum, - "elapsed": end.Sub(start).String(), + "sTime": currentStartTimeStr + "到" + currentEndTimeStr, + "num": num, + "useNum": useNum, + "errNum": errNum, + "elapsed": end.Sub(start).String(), } log.Warnf("微信券查询,%s到%s,taskId:%d,处理完毕:%+v", startTimeStr, endTimeStr, req.TaskID, logFields) diff --git a/internal/biz/timeslicequery/query.go b/internal/biz/timeslicequery/query.go index 5126621..30ef5c5 100644 --- a/internal/biz/timeslicequery/query.go +++ b/internal/biz/timeslicequery/query.go @@ -5,7 +5,7 @@ import ( "voucher/internal/biz/bo" ) -func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, notifyNum *int) error { +func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, useNum *int) error { status, err := v.wechatCpnRepo.Query(ctx, order) if err != nil { @@ -13,7 +13,10 @@ func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, notifyNum *i } if status.IsUse() { - return v.queryUsed(ctx, order, notifyNum) + if err = v.queryUsed(ctx, order); err != nil { + return err + } + *useNum += 1 } else if status.IsExpired() { return v.queryExpired(ctx, order) } @@ -21,9 +24,7 @@ func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, notifyNum *i return nil } -func (v *Query) queryUsed(ctx context.Context, order *bo.OrderBo, notifyNum *int) error { - - *notifyNum += 1 +func (v *Query) queryUsed(ctx context.Context, order *bo.OrderBo) error { if order.Status.IsUse() { return v.notify(ctx, order) diff --git a/internal/biz/vo/cache.go b/internal/biz/vo/cache.go index 052accc..038bb7e 100644 --- a/internal/biz/vo/cache.go +++ b/internal/biz/vo/cache.go @@ -19,7 +19,6 @@ const ( OrderConsumeFailAlarmKey CacheKey = "order_consume_fail_alarm" OrderConsumeFailAlarmLockKey CacheKey = "order_consume_fail_alarm_lock" - WechatNotifyRegisterTagCacheKey CacheKey = "register" WechatNotifyRegisterTagCacheLockKey CacheKey = "register_tag_lock" WechatNotifyConsumeLockKey CacheKey = "wechat_notify_consume" @@ -39,7 +38,6 @@ var CacheKeyMap = map[CacheKey]time.Duration{ OrderConsumeFailAlarmKey: 3 * time.Hour, // 3小时 OrderConsumeFailAlarmLockKey: 60 * time.Second, NotifyRetryConsume: 60 * time.Second, - WechatNotifyRegisterTagCacheKey: 30 * 86400 * time.Second, // 30天 WechatNotifyRegisterTagCacheLockKey: 60 * time.Second, WechatNotifyConsumeLockKey: 30 * time.Second,