From 21bb6f53ebee646814b3c7dc5554a5cce966be76 Mon Sep 17 00:00:00 2001 From: ziming Date: Thu, 12 Jun 2025 14:30:49 +0800 Subject: [PATCH] timeSliceQueryPush --- internal/biz/cron_notice.go | 14 +++++++------- internal/biz/vo/order_notify_event.go | 2 +- internal/data/repoimpl/order.go | 4 ++-- internal/service/voucher.go | 5 +++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/biz/cron_notice.go b/internal/biz/cron_notice.go index b605bb5..79a339b 100644 --- a/internal/biz/cron_notice.go +++ b/internal/biz/cron_notice.go @@ -93,6 +93,8 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time end := start.Add(duration) // 计算每次请求的结束时间 if end.After(endTime) { end = endTime + } else { + end = end.Add(-1 * time.Second) } req := &bo.FindInBatchesUseBo{ @@ -150,8 +152,7 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo) error { } if order.Status == status { - //log.Warnf("notice 券状态未改变:%s,忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo) - return nil + return nil // 券状态未改变,忽略不处理 } event, err := status.GetOrderNotifyEvent() @@ -176,9 +177,8 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo) error { func (v *VoucherBiz) cmbNotice(ctx context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) error { - if !orderNotify.Event.CanNotify() { - //log.Warnf("notice 券状态:%s,忽略不通知,orderNo:%s", orderNotify.Event.GetText(), order.OrderNo) - return nil + if orderNotify.Event.CanNotify() { + return nil // 不可通知,忽略 } request, err := v.Cmb.NotifyRequest(ctx, order, orderNotify) @@ -188,11 +188,11 @@ func (v *VoucherBiz) cmbNotice(ctx context.Context, order *bo.OrderBo, orderNoti reply, err := v.CmbMixRepo.Request(ctx, request, order.NotifyUrl) if err != nil { - return fmt.Errorf("订单定时通知,orderNo:%s,outBizNo:%s,%s", order.OrderNo, order.OutBizNo, err.Error()) + return fmt.Errorf("订单定时通知,orderNo:%s,outBizNo:%s,err:%s", order.OrderNo, order.OutBizNo, err.Error()) } if reply.RespCode != vo.CmbResponseStatusSuccess.GetValue() { - return errors.New("订单定时通知,招行返回:" + reply.RespMsg) + return errors.New("订单定时通知,招行返回错误:" + reply.RespMsg) } return nil diff --git a/internal/biz/vo/order_notify_event.go b/internal/biz/vo/order_notify_event.go index db5fb45..84c6782 100644 --- a/internal/biz/vo/order_notify_event.go +++ b/internal/biz/vo/order_notify_event.go @@ -40,7 +40,7 @@ func (s OrderNotifyEvent) IsExpired() bool { } func (s OrderNotifyEvent) CanNotify() bool { - return s.IsSendDEd() || s.IsUsed() || s.IsExpired() + return s.IsSendDEd() || s.IsUsed() } var OrderNotifyEventMapCmbStatus = map[OrderNotifyEvent]CmbStatus{ diff --git a/internal/data/repoimpl/order.go b/internal/data/repoimpl/order.go index b9ec73d..916fc5a 100644 --- a/internal/data/repoimpl/order.go +++ b/internal/data/repoimpl/order.go @@ -98,13 +98,13 @@ func (p *OrderRepoImpl) FindIngInBatches(ctx context.Context, fun func(ctx conte return nil } -func (p *OrderRepoImpl) FindInBatches(ctx context.Context, w *bo.FindInBatchesUseBo, fun func(ctx context.Context, rows []*bo.OrderBo) error) error { +func (p *OrderRepoImpl) FindInBatches(ctx context.Context, req *bo.FindInBatchesUseBo, fun func(ctx context.Context, rows []*bo.OrderBo) error) error { var results = make([]*model.Order, 0) result := p.DB(ctx). Where("status IN (?)", []uint8{vo.OrderStatusSuccess.GetValue(), vo.OrderStatusUse.GetValue()}). - Where("receive_success_time BETWEEN ? AND ?", w.StartTime, w.EndTime). + Where("receive_success_time BETWEEN ? AND ?", req.StartTime, req.EndTime). FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error { // tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch) // 'batch' 变量表示当前批号(the current batch number) diff --git a/internal/service/voucher.go b/internal/service/voucher.go index 83f1acb..50b1cfe 100644 --- a/internal/service/voucher.go +++ b/internal/service/voucher.go @@ -72,7 +72,9 @@ func (s *VoucherService) CronOrderNotice(ctx context.Context) error { } func (s *VoucherService) OrderNotice(ctx context.Context) { + start := time.Now() + log.Errorf("订单定时通知,执行开始: %v", start.Format(time.DateTime)) if err := s.VoucherBiz.Notice(ctx); err != nil { log.Errorf("订单定时通知,执行失败: %v", err) @@ -81,11 +83,10 @@ func (s *VoucherService) OrderNotice(ctx context.Context) { end := time.Now() elapsed := end.Sub(start) log.Warnf("订单定时通知,开始执行时间%s,执行结束时间%s,代码块执行耗时: %s", start.Format(time.DateTime), end.Format(time.DateTime), elapsed) - - return } func (j *VoucherService) GetNotifyRetryConfig() *mq.ConsumerConfig { + elm, ok := j.bc.RocketMQ.EventMap["notifyRetry"] if !ok { return nil