预警15
This commit is contained in:
parent
6f96e22f5f
commit
9cab8c7aa4
|
|
@ -22,7 +22,7 @@ func (this *VoucherBiz) alarm(ctx context.Context, order *bo.OrderBo, errMsg str
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != redis.Nil {
|
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})
|
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()
|
cacheValue, err3 := this.rdb.Rdb.Get(ctx, c.Key).Result()
|
||||||
|
|
||||||
if err3 != nil && err3 != redis.Nil {
|
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 {
|
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 {
|
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
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func (this *VoucherBiz) isCanNotice(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != redis.Nil {
|
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{""})
|
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()
|
cacheValue, err2 := this.rdb.Rdb.Get(ctx, cache.Key).Result()
|
||||||
|
|
||||||
if err2 != nil && err2 != redis.Nil {
|
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 {
|
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 {
|
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缓存,不存在,开始处理")
|
log.Warnf("订单定时通知,notice 获取redis缓存,不存在,开始处理")
|
||||||
|
|
@ -110,7 +110,7 @@ func (this *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime t
|
||||||
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 表示获取当前调用者的调用信息
|
||||||
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
|
num += 1
|
||||||
if err := this.notice(ctx, order, &useNum, &sucNum); err != nil {
|
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)
|
stackSize := runtime.Stack(stackBuf, false)
|
||||||
// 获取调用栈信息
|
// 获取调用栈信息
|
||||||
_, file, line, _ := runtime.Caller(1) // 1 表示获取当前调用者的调用信息
|
_, 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])
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ func (this *VoucherBiz) OrderRetry(ctx context.Context, outBizNos []string) erro
|
||||||
|
|
||||||
order, err := this.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, outBizNo)
|
order, err := this.OrderRepo.GetByOutBizNo(ctx, vo.OrderTypeCmb, outBizNo)
|
||||||
if err != nil {
|
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() {
|
if !order.Status.IsIng() {
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ func (this *VoucherBiz) CronWarningBudget(ctx context.Context) {
|
||||||
log.Warnf("预警查询,执行开始: %s", start.Format(time.DateTime))
|
log.Warnf("预警查询,执行开始: %s", start.Format(time.DateTime))
|
||||||
|
|
||||||
if err := this.cronWarningBudget(ctx); err != nil {
|
if err := this.cronWarningBudget(ctx); err != nil {
|
||||||
log.Errorf("预警查询,执行失败: %this", err)
|
log.Errorf("预警查询,执行失败: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
|
|
@ -100,7 +100,7 @@ func (this *VoucherBiz) cronWarningBudget(ctx context.Context) error {
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
|
|
||||||
if err := this.WarningBudget(ctx, row); err != nil {
|
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)
|
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 {
|
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)
|
wxResp, err := this.WechatCpnRepo.QueryProduct(ctx, product.MchId, product.BatchNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
func (this *VoucherBiz) WarningSend(ctx context.Context, product *bo.ProductBo, w *do.WxResp) error {
|
||||||
|
|
||||||
var warningPerson []*do.WarningPerson
|
if err := this.DingMixRepo.SendMarkdownMessage(ctx, "券预算不足", formatAsCard(product, w)); err != nil {
|
||||||
if err := json.Unmarshal([]byte(product.WarningPerson), &warningPerson); err != nil {
|
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,9 +176,15 @@ func (this *VoucherBiz) WarningSend(ctx context.Context, product *bo.ProductBo,
|
||||||
mobileList = append(mobileList, person.Mobile)
|
mobileList = append(mobileList, person.Mobile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(mobileList) > 0 {
|
||||||
return this.SmsMixRepo.Send(ctx, mobileList, buildTemplateParams(product, w))
|
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 {
|
func buildTemplateParams(product *bo.ProductBo, req *do.WxResp) map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"stock_name": product.BatchName,
|
"stock_name": product.BatchName,
|
||||||
|
|
|
||||||
|
|
@ -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()
|
_, err = this.rdb.Rdb.RPush(ctx, queue.Name, strMsg).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Remove(uid)
|
this.Remove(uid)
|
||||||
return fmt.Errorf("添加到队列失败:%this", err)
|
return fmt.Errorf("添加到队列失败:%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -79,7 +79,7 @@ func (this *VoucherBiz) WechatQuery(ctx context.Context, msg string) error {
|
||||||
|
|
||||||
num += 1
|
num += 1
|
||||||
if err := this.wechatQuery(ctx, order, ¬ifyNum); err != nil {
|
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)
|
msg, order.OrderNo, order.VoucherNo, order.AppID, order.Account, order.BatchNo, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()
|
_, err = this.rdb.Rdb.RPush(ctx, queue.Name, product.BatchNo).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("添加到队列失败:%this", err)
|
return fmt.Errorf("添加到队列失败:%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -46,7 +46,7 @@ func (this *VoucherBiz) WechatRetry(ctx context.Context, batchNo string) error {
|
||||||
|
|
||||||
num += 1
|
num += 1
|
||||||
if err := this.orderRetry(ctx, order); err != nil {
|
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)
|
batchNo, order.OrderNo, order.AppID, order.Account, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue