diff --git a/internal/biz/alarm.go b/internal/biz/alarm.go index 280b8d3..526f45d 100644 --- a/internal/biz/alarm.go +++ b/internal/biz/alarm.go @@ -22,7 +22,7 @@ func (this *VoucherBiz) alarm(ctx context.Context, order *bo.OrderBo, errMsg str } if err != redis.Nil { - return fmt.Errorf(fmt.Sprintf("alarm 获取redis缓存%s异常:%this", c.Key, err)) + return fmt.Errorf(fmt.Sprintf("alarm 获取redis缓存%s异常:%v", c.Key, err)) } cl := vo.OrderConsumeFailAlarmLockKey.BuildCache([]string{order.ProductNo}) @@ -33,7 +33,7 @@ func (this *VoucherBiz) alarm(ctx context.Context, order *bo.OrderBo, errMsg str cacheValue, err3 := this.rdb.Rdb.Get(ctx, c.Key).Result() if err3 != nil && err3 != redis.Nil { - return fmt.Errorf(fmt.Sprintf("alarm 二次获取redis缓存%s异常:%this", c.Key, err)) + return fmt.Errorf(fmt.Sprintf("alarm 二次获取redis缓存%s异常:%v", c.Key, err)) } if len(cacheValue) > 0 { @@ -46,7 +46,7 @@ func (this *VoucherBiz) alarm(ctx context.Context, order *bo.OrderBo, errMsg str } if err = this.rdb.Rdb.Set(ctx, c.Key, order.ProductNo, c.TTL).Err(); err != nil { - return fmt.Errorf(fmt.Sprintf("设置redis缓存%s异常:%this", c.Key, err)) + return fmt.Errorf(fmt.Sprintf("设置redis缓存%s异常:%v", c.Key, err)) } return nil diff --git a/internal/biz/cron_notice.go b/internal/biz/cron_notice.go index cf9d469..49eade5 100644 --- a/internal/biz/cron_notice.go +++ b/internal/biz/cron_notice.go @@ -33,7 +33,7 @@ func (this *VoucherBiz) isCanNotice(ctx context.Context) error { } if err != redis.Nil { - return fmt.Errorf(fmt.Sprintf("订单定时通知,notice 获取redis缓存%s异常:%this", cache.Key, err)) + return fmt.Errorf(fmt.Sprintf("订单定时通知,notice 获取redis缓存%s异常:%v", cache.Key, err)) } c := vo.CmbBatchNoticeLockKey.BuildCache([]string{""}) @@ -45,7 +45,7 @@ func (this *VoucherBiz) isCanNotice(ctx context.Context) error { cacheValue, err2 := this.rdb.Rdb.Get(ctx, cache.Key).Result() if err2 != nil && err2 != redis.Nil { - return fmt.Errorf(fmt.Sprintf("订单定时通知,notice 二次获取redis缓存%s异常:%this", cache.Key, err2)) + return fmt.Errorf(fmt.Sprintf("订单定时通知,notice 二次获取redis缓存%s异常:%v", cache.Key, err2)) } if len(cacheValue) > 0 { @@ -53,7 +53,7 @@ func (this *VoucherBiz) isCanNotice(ctx context.Context) error { } if err = this.rdb.Rdb.Set(ctx, cache.Key, fmt.Sprintf("%d_%d", this.bc.Cmb.NoticeStartDays, this.bc.Cmb.NoticeEndDays), c.TTL).Err(); err != nil { - return fmt.Errorf(fmt.Sprintf("notice 设置redis缓存%s异常:%this", cache.Key, err)) + return fmt.Errorf(fmt.Sprintf("notice 设置redis缓存%s异常:%v", cache.Key, err)) } log.Warnf("订单定时通知,notice 获取redis缓存,不存在,开始处理") @@ -110,7 +110,7 @@ func (this *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime t defer func() { if err := recover(); err != nil { _, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息 - log.Errorf("订单定时通知,发生错误:req:%+this,err:%this,file:%s,line:%d", req, err, file, line) + log.Errorf("订单定时通知,发生错误:req:%+v,err:%v,file:%s,line:%d", req, err, file, line) } }() @@ -135,7 +135,7 @@ func (this *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatches num += 1 if err := this.notice(ctx, order, &useNum, &sucNum); err != nil { - log.Errorf("订单定时通知,err:%this", err) + log.Errorf("订单定时通知,err:%v", err) } } @@ -208,7 +208,7 @@ func (this *VoucherBiz) request(ctx context.Context, order *bo.OrderBo, notify * stackSize := runtime.Stack(stackBuf, false) // 获取调用栈信息 _, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息 - respErr = fmt.Errorf("request panic:%this, orderNo:%s, file:%s, line:%d, stack: %s", err, order.OrderNo, file, line, stackBuf[:stackSize]) + respErr = fmt.Errorf("request panic:%v, orderNo:%s, file:%s, line:%d, stack: %s", err, order.OrderNo, file, line, stackBuf[:stackSize]) } }() diff --git a/internal/biz/retry.go b/internal/biz/retry.go index f0a5957..ab15792 100644 --- a/internal/biz/retry.go +++ b/internal/biz/retry.go @@ -15,7 +15,7 @@ func (this *VoucherBiz) OrderRetry(ctx context.Context, outBizNos []string) erro order, err := this.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, outBizNo) if err != nil { - return fmt.Errorf(fmt.Sprintf("获取订单%s异常:%this", outBizNo, err)) + return fmt.Errorf(fmt.Sprintf("获取订单%s异常:%v", outBizNo, err)) } if !order.Status.IsIng() { diff --git a/internal/biz/warning_budget.go b/internal/biz/warning_budget.go index e293a52..f76ce44 100644 --- a/internal/biz/warning_budget.go +++ b/internal/biz/warning_budget.go @@ -83,7 +83,7 @@ func (this *VoucherBiz) CronWarningBudget(ctx context.Context) { log.Warnf("预警查询,执行开始: %s", start.Format(time.DateTime)) if err := this.cronWarningBudget(ctx); err != nil { - log.Errorf("预警查询,执行失败: %this", err) + log.Errorf("预警查询,执行失败: %s", err) } end := time.Now() @@ -100,7 +100,7 @@ func (this *VoucherBiz) cronWarningBudget(ctx context.Context) error { for _, row := range rows { if err := this.WarningBudget(ctx, row); err != nil { - log.Context(ctx).Errorf("预警查询,处理失败: %this", err) + log.Context(ctx).Errorf("预警查询,处理失败: %s", err) } time.Sleep(time.Second * 2) } @@ -111,6 +111,10 @@ func (this *VoucherBiz) cronWarningBudget(ctx context.Context) error { func (this *VoucherBiz) WarningBudget(ctx context.Context, product *bo.ProductBo) error { + if product.WarningBudget == 0 { + return fmt.Errorf("no warning budget") + } + wxResp, err := this.WechatCpnRepo.QueryProduct(ctx, product.MchId, product.BatchNo) if err != nil { return err @@ -158,12 +162,12 @@ func (this *VoucherBiz) Calculate(ctx context.Context, product *bo.ProductBo, wx func (this *VoucherBiz) WarningSend(ctx context.Context, product *bo.ProductBo, w *do.WxResp) error { - var warningPerson []*do.WarningPerson - if err := json.Unmarshal([]byte(product.WarningPerson), &warningPerson); err != nil { + if err := this.DingMixRepo.SendMarkdownMessage(ctx, "券预算不足", formatAsCard(product, w)); err != nil { return err } - if err := this.DingMixRepo.SendMarkdownMessage(ctx, "券预算不足", formatAsCard(product, w)); err != nil { + var warningPerson []*do.WarningPerson + if err := json.Unmarshal([]byte(product.WarningPerson), &warningPerson); err != nil { return err } @@ -172,7 +176,13 @@ func (this *VoucherBiz) WarningSend(ctx context.Context, product *bo.ProductBo, mobileList = append(mobileList, person.Mobile) } - return this.SmsMixRepo.Send(ctx, mobileList, buildTemplateParams(product, w)) + if len(mobileList) > 0 { + return this.SmsMixRepo.Send(ctx, mobileList, buildTemplateParams(product, w)) + } + + log.Warnf("no mobile to send, batchNo:%s", product.BatchNo) + + return nil } func buildTemplateParams(product *bo.ProductBo, req *do.WxResp) map[string]string { diff --git a/internal/biz/wechat_query.go b/internal/biz/wechat_query.go index 0aafe6d..e9964ac 100644 --- a/internal/biz/wechat_query.go +++ b/internal/biz/wechat_query.go @@ -47,7 +47,7 @@ func (this *VoucherBiz) PushWechatQuery(ctx http.Context, req *do.WechatQuery) e _, err = this.rdb.Rdb.RPush(ctx, queue.Name, strMsg).Result() if err != nil { this.Remove(uid) - return fmt.Errorf("添加到队列失败:%this", err) + return fmt.Errorf("添加到队列失败:%v", err) } return nil @@ -79,7 +79,7 @@ func (this *VoucherBiz) WechatQuery(ctx context.Context, msg string) error { num += 1 if err := this.wechatQuery(ctx, order, ¬ifyNum); err != nil { - log.Errorf("微信查询券订单状态发生错误,msg:%s,orderNo:%s,couponId:%s,appId:%s,openId:%s,stockId:%s,err:%this", + log.Errorf("微信查询券订单状态发生错误,msg:%s,orderNo:%s,couponId:%s,appId:%s,openId:%s,stockId:%s,err:%v", msg, order.OrderNo, order.VoucherNo, order.AppID, order.Account, order.BatchNo, err) } diff --git a/internal/biz/wechat_retry.go b/internal/biz/wechat_retry.go index 3df24da..4fa1fd6 100644 --- a/internal/biz/wechat_retry.go +++ b/internal/biz/wechat_retry.go @@ -22,7 +22,7 @@ func (this *VoucherBiz) PushWechatRetry(ctx context.Context, batchNo string) err _, err = this.rdb.Rdb.RPush(ctx, queue.Name, product.BatchNo).Result() if err != nil { - return fmt.Errorf("添加到队列失败:%this", err) + return fmt.Errorf("添加到队列失败:%v", err) } return nil @@ -46,7 +46,7 @@ func (this *VoucherBiz) WechatRetry(ctx context.Context, batchNo string) error { num += 1 if err := this.orderRetry(ctx, order); err != nil { - log.Errorf("失败订单重试发生错误,batchNo:%s,orderNo:%s,appId:%s,openId:%s,err:%this", + log.Errorf("失败订单重试发生错误,batchNo:%s,orderNo:%s,appId:%s,openId:%s,err:%v", batchNo, order.OrderNo, order.AppID, order.Account, err) }