This commit is contained in:
ziming 2025-06-18 14:07:56 +08:00
parent e1fc391984
commit 62cd85166d
4 changed files with 29 additions and 31 deletions

View File

@ -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, &notifyNum); 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
}

View File

@ -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, &notifyNum); 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)

View File

@ -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)

View File

@ -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,