log
This commit is contained in:
parent
e1fc391984
commit
62cd85166d
|
|
@ -107,13 +107,6 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time
|
||||||
EndTime: &end,
|
EndTime: &end,
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
default:
|
|
||||||
// 继续执行
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
_, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息
|
_, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息
|
||||||
|
|
@ -133,14 +126,15 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
num := 0
|
num := 0
|
||||||
notifyNum := 0
|
useNum := 0
|
||||||
|
sucNum := 0
|
||||||
|
|
||||||
err := v.OrderRepo.FindInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error {
|
err := v.OrderRepo.FindInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error {
|
||||||
|
|
||||||
for _, order := range rows {
|
for _, order := range rows {
|
||||||
|
|
||||||
num += 1
|
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)
|
log.Errorf("订单定时通知,err:%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,9 +144,10 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
||||||
})
|
})
|
||||||
|
|
||||||
logFields := map[string]interface{}{
|
logFields := map[string]interface{}{
|
||||||
"searchTime": req.StartTime.Format(time.DateTime) + "到" + req.EndTime.Format(time.DateTime),
|
"sTime": req.StartTime.Format(time.DateTime) + "到" + req.EndTime.Format(time.DateTime),
|
||||||
"num": num,
|
"num": num, // 查询总量
|
||||||
"notifyNum": notifyNum,
|
"useNum": useNum, // 核销通知数量
|
||||||
|
"sucNum": sucNum, // 重置为成功数量
|
||||||
"elapsed": time.Now().Sub(start).String(),
|
"elapsed": time.Now().Sub(start).String(),
|
||||||
}
|
}
|
||||||
log.Warnf("订单定时通知,%+v", logFields)
|
log.Warnf("订单定时通知,%+v", logFields)
|
||||||
|
|
@ -160,7 +155,7 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
||||||
return err
|
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 {
|
if order == nil {
|
||||||
|
|
@ -204,7 +199,11 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, notifyNum *i
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
*notifyNum += 1
|
if event.IsUsed() {
|
||||||
|
*useNum += 1
|
||||||
|
} else if event.IsSendDEd() {
|
||||||
|
*sucNum += 1
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,22 +43,22 @@ func (v *Query) callbackFunc(ctx context.Context, req *timeslice.Task) error {
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
x := &do.WechatQuery{
|
bReq := &do.WechatQuery{
|
||||||
StartTime: currentStartTimeStr,
|
StartTime: currentStartTimeStr,
|
||||||
EndTime: currentEndTimeStr,
|
EndTime: currentEndTimeStr,
|
||||||
ProductNo: req.Process.Manager.ProductNo,
|
ProductNo: req.Process.Manager.ProductNo,
|
||||||
}
|
}
|
||||||
|
|
||||||
num := 0
|
num := 0
|
||||||
notifyNum := 0
|
|
||||||
errNum := 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 {
|
for _, order := range rows {
|
||||||
|
|
||||||
num += 1
|
num += 1
|
||||||
if err := v.wechatQuery(ctx, order, ¬ifyNum); err != nil {
|
if err := v.wechatQuery(ctx, order, &useNum); err != nil {
|
||||||
|
|
||||||
errNum += 1
|
errNum += 1
|
||||||
|
|
||||||
|
|
@ -84,9 +84,9 @@ func (v *Query) callbackFunc(ctx context.Context, req *timeslice.Task) error {
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
|
|
||||||
logFields := map[string]any{
|
logFields := map[string]any{
|
||||||
"searchTime": currentStartTimeStr + "到" + currentEndTimeStr,
|
"sTime": currentStartTimeStr + "到" + currentEndTimeStr,
|
||||||
"num": num,
|
"num": num,
|
||||||
"notifyNum": notifyNum,
|
"useNum": useNum,
|
||||||
"errNum": errNum,
|
"errNum": errNum,
|
||||||
"elapsed": end.Sub(start).String(),
|
"elapsed": end.Sub(start).String(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"voucher/internal/biz/bo"
|
"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)
|
status, err := v.wechatCpnRepo.Query(ctx, order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -13,7 +13,10 @@ func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, notifyNum *i
|
||||||
}
|
}
|
||||||
|
|
||||||
if status.IsUse() {
|
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() {
|
} else if status.IsExpired() {
|
||||||
return v.queryExpired(ctx, order)
|
return v.queryExpired(ctx, order)
|
||||||
}
|
}
|
||||||
|
|
@ -21,9 +24,7 @@ func (v *Query) wechatQuery(ctx context.Context, order *bo.OrderBo, notifyNum *i
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Query) queryUsed(ctx context.Context, order *bo.OrderBo, notifyNum *int) error {
|
func (v *Query) queryUsed(ctx context.Context, order *bo.OrderBo) error {
|
||||||
|
|
||||||
*notifyNum += 1
|
|
||||||
|
|
||||||
if order.Status.IsUse() {
|
if order.Status.IsUse() {
|
||||||
return v.notify(ctx, order)
|
return v.notify(ctx, order)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ const (
|
||||||
OrderConsumeFailAlarmKey CacheKey = "order_consume_fail_alarm"
|
OrderConsumeFailAlarmKey CacheKey = "order_consume_fail_alarm"
|
||||||
OrderConsumeFailAlarmLockKey CacheKey = "order_consume_fail_alarm_lock"
|
OrderConsumeFailAlarmLockKey CacheKey = "order_consume_fail_alarm_lock"
|
||||||
|
|
||||||
WechatNotifyRegisterTagCacheKey CacheKey = "register"
|
|
||||||
WechatNotifyRegisterTagCacheLockKey CacheKey = "register_tag_lock"
|
WechatNotifyRegisterTagCacheLockKey CacheKey = "register_tag_lock"
|
||||||
|
|
||||||
WechatNotifyConsumeLockKey CacheKey = "wechat_notify_consume"
|
WechatNotifyConsumeLockKey CacheKey = "wechat_notify_consume"
|
||||||
|
|
@ -39,7 +38,6 @@ var CacheKeyMap = map[CacheKey]time.Duration{
|
||||||
OrderConsumeFailAlarmKey: 3 * time.Hour, // 3小时
|
OrderConsumeFailAlarmKey: 3 * time.Hour, // 3小时
|
||||||
OrderConsumeFailAlarmLockKey: 60 * time.Second,
|
OrderConsumeFailAlarmLockKey: 60 * time.Second,
|
||||||
NotifyRetryConsume: 60 * time.Second,
|
NotifyRetryConsume: 60 * time.Second,
|
||||||
WechatNotifyRegisterTagCacheKey: 30 * 86400 * time.Second, // 30天
|
|
||||||
WechatNotifyRegisterTagCacheLockKey: 60 * time.Second,
|
WechatNotifyRegisterTagCacheLockKey: 60 * time.Second,
|
||||||
WechatNotifyConsumeLockKey: 30 * time.Second,
|
WechatNotifyConsumeLockKey: 30 * time.Second,
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue