req 副本
This commit is contained in:
parent
89e0d8d598
commit
1dc83a8c23
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
|
|
@ -100,13 +99,13 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time
|
||||||
end = end.Add(-1 * time.Second)
|
end = end.Add(-1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &bo.FindInBatchesUseBo{
|
|
||||||
StartTime: &start,
|
|
||||||
EndTime: &end,
|
|
||||||
}
|
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
|
|
||||||
|
req := &bo.FindInBatchesUseBo{
|
||||||
|
StartTime: &start,
|
||||||
|
EndTime: &end,
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|
@ -116,12 +115,7 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
|
log.Errorf("订单定时通知,发生错误:req:%+v,err:%v", req, err)
|
||||||
// 获取当前堆栈信息
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
stackSize := runtime.Stack(buf, false)
|
|
||||||
|
|
||||||
log.Errorf("订单定时通知,发生错误:req:%+v,err:%v\n堆栈信息:\n%s", req, err, string(buf[:stackSize]))
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -138,22 +132,13 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
||||||
|
|
||||||
num := 0
|
num := 0
|
||||||
notifyNum := 0
|
notifyNum := 0
|
||||||
errNum := 0
|
|
||||||
emptyNum := 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 {
|
||||||
|
|
||||||
if order == nil {
|
|
||||||
emptyNum += 1
|
|
||||||
log.Errorf("订单对象为 nil, req:%+v", req)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
num += 1
|
num += 1
|
||||||
if err := v.notice(ctx, order, ¬ifyNum); err != nil {
|
if err := v.orderNotice(ctx, order, ¬ifyNum); err != nil {
|
||||||
errNum += 1
|
|
||||||
log.Errorf("订单定时通知,err:%v", err)
|
log.Errorf("订单定时通知,err:%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,8 +151,6 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
||||||
"searchTime": req.StartTime.Format(time.DateTime) + "到" + req.EndTime.Format(time.DateTime),
|
"searchTime": req.StartTime.Format(time.DateTime) + "到" + req.EndTime.Format(time.DateTime),
|
||||||
"num": num,
|
"num": num,
|
||||||
"notifyNum": notifyNum,
|
"notifyNum": notifyNum,
|
||||||
"errNum": errNum,
|
|
||||||
"emptyNum": emptyNum,
|
|
||||||
"elapsed": time.Now().Sub(start).String(),
|
"elapsed": time.Now().Sub(start).String(),
|
||||||
}
|
}
|
||||||
log.Warnf("订单定时通知,%+v", logFields)
|
log.Warnf("订单定时通知,%+v", logFields)
|
||||||
|
|
@ -175,6 +158,15 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *VoucherBiz) orderNotice(ctx context.Context, order *bo.OrderBo, notifyNum *int) (respErr error) {
|
||||||
|
|
||||||
|
if order == nil {
|
||||||
|
return fmt.Errorf("订单对象为 nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.notice(ctx, order, notifyNum)
|
||||||
|
}
|
||||||
|
|
||||||
func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, notifyNum *int) error {
|
func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, notifyNum *int) error {
|
||||||
// 批量通知不做数据存储,量会很大
|
// 批量通知不做数据存储,量会很大
|
||||||
|
|
||||||
|
|
@ -213,8 +205,6 @@ func (v *VoucherBiz) request(ctx context.Context, order *bo.OrderBo, orderNotify
|
||||||
return nil // 不可通知,忽略
|
return nil // 不可通知,忽略
|
||||||
}
|
}
|
||||||
|
|
||||||
*notifyNum += 1
|
|
||||||
|
|
||||||
request, err := v.Cmb.NotifyRequest(ctx, order, orderNotify)
|
request, err := v.Cmb.NotifyRequest(ctx, order, orderNotify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -224,8 +214,9 @@ func (v *VoucherBiz) request(ctx context.Context, order *bo.OrderBo, orderNotify
|
||||||
return fmt.Errorf("request is nil,orderNo:%s,outBizNo:%s,stockId:%s,err:%s", order.OrderNo, order.OutBizNo, order.BatchNo)
|
return fmt.Errorf("request is nil,orderNo:%s,outBizNo:%s,stockId:%s,err:%s", order.OrderNo, order.OutBizNo, order.BatchNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = v.CmbMixRepo.Request(ctx, request, order.NotifyUrl)
|
*notifyNum += 1
|
||||||
if err != nil {
|
|
||||||
|
if _, err = v.CmbMixRepo.Request(ctx, request, order.NotifyUrl); err != nil {
|
||||||
return fmt.Errorf("orderNo:%s,outBizNo:%s,stockId:%s,err:%s", order.OrderNo, order.OutBizNo, order.BatchNo, err.Error())
|
return fmt.Errorf("orderNo:%s,outBizNo:%s,stockId:%s,err:%s", order.OrderNo, order.OutBizNo, order.BatchNo, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue