timeSliceQuery
This commit is contained in:
parent
6329e6b37f
commit
ca8f9955cb
|
|
@ -128,13 +128,19 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time
|
|||
|
||||
func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUseBo) error {
|
||||
|
||||
log.Warnf("订单定时通知:%+v", req)
|
||||
start := time.Now()
|
||||
|
||||
return v.OrderRepo.FindInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error {
|
||||
num := 0
|
||||
notifyNum := 0
|
||||
errNum := 0
|
||||
|
||||
err := v.OrderRepo.FindInBatches(ctx, req, func(ctx context.Context, rows []*bo.OrderBo) error {
|
||||
|
||||
for _, order := range rows {
|
||||
|
||||
if err := v.notice(ctx, order); err != nil {
|
||||
num += 1
|
||||
if err := v.notice(ctx, order, ¬ifyNum); err != nil {
|
||||
errNum += 1
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
|
|
@ -143,9 +149,18 @@ func (v *VoucherBiz) ExecuteNotice(ctx context.Context, req *bo.FindInBatchesUse
|
|||
return nil
|
||||
})
|
||||
|
||||
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(),
|
||||
}
|
||||
log.Warnf("订单定时通知,%+v", logFields)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo) error {
|
||||
func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo, notifyNum *int) error {
|
||||
// 批量通知不做数据存储,量会很大
|
||||
|
||||
status, err := v.WechatCpnRepo.Query(ctx, order)
|
||||
|
|
@ -170,19 +185,21 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo) error {
|
|||
Type: order.Type,
|
||||
}
|
||||
|
||||
if err = v.cmbNotice(ctx, order, orderNotify); err != nil {
|
||||
if err = v.cmbNotice(ctx, order, orderNotify, notifyNum); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return v.UpdateOrderStatus(ctx, order.ID, status)
|
||||
}
|
||||
|
||||
func (v *VoucherBiz) cmbNotice(ctx context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) error {
|
||||
func (v *VoucherBiz) cmbNotice(ctx context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo, notifyNum *int) error {
|
||||
|
||||
if orderNotify.Event.CanNotify() {
|
||||
return nil // 不可通知,忽略
|
||||
}
|
||||
|
||||
*notifyNum += 1
|
||||
|
||||
request, err := v.Cmb.NotifyRequest(ctx, order, orderNotify)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ func (v *Query) callbackFunc(ctx context.Context, req *timeslice.Task) error {
|
|||
"searchTime": currentStartTimeStr + "到" + currentEndTimeStr,
|
||||
"num": num,
|
||||
"notifyNum": notifyNum,
|
||||
"duration": end.Sub(start).String(),
|
||||
"elapsed": end.Sub(start).String(),
|
||||
}
|
||||
log.Warnf("微信券查询处理,%s到%s,taskId:%d,处理完毕:%+v", startTimeStr, endTimeStr, req.TaskID, logFields)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue