timeSliceQueryPush
This commit is contained in:
parent
32c3b6c7a8
commit
21bb6f53eb
|
|
@ -93,6 +93,8 @@ func (v *VoucherBiz) timeSliceQuery(ctx context.Context, startTime, endTime time
|
||||||
end := start.Add(duration) // 计算每次请求的结束时间
|
end := start.Add(duration) // 计算每次请求的结束时间
|
||||||
if end.After(endTime) {
|
if end.After(endTime) {
|
||||||
end = endTime
|
end = endTime
|
||||||
|
} else {
|
||||||
|
end = end.Add(-1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &bo.FindInBatchesUseBo{
|
req := &bo.FindInBatchesUseBo{
|
||||||
|
|
@ -150,8 +152,7 @@ func (v *VoucherBiz) notice(ctx context.Context, order *bo.OrderBo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if order.Status == status {
|
if order.Status == status {
|
||||||
//log.Warnf("notice 券状态未改变:%s,忽略不处理,orderNo:%s", order.Status.GetText(), order.OrderNo)
|
return nil // 券状态未改变,忽略不处理
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
event, err := status.GetOrderNotifyEvent()
|
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 {
|
func (v *VoucherBiz) cmbNotice(ctx context.Context, order *bo.OrderBo, orderNotify *bo.OrderNotifyBo) error {
|
||||||
|
|
||||||
if !orderNotify.Event.CanNotify() {
|
if orderNotify.Event.CanNotify() {
|
||||||
//log.Warnf("notice 券状态:%s,忽略不通知,orderNo:%s", orderNotify.Event.GetText(), order.OrderNo)
|
return nil // 不可通知,忽略
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request, err := v.Cmb.NotifyRequest(ctx, order, orderNotify)
|
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)
|
reply, err := v.CmbMixRepo.Request(ctx, request, order.NotifyUrl)
|
||||||
if err != nil {
|
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() {
|
if reply.RespCode != vo.CmbResponseStatusSuccess.GetValue() {
|
||||||
return errors.New("订单定时通知,招行返回:" + reply.RespMsg)
|
return errors.New("订单定时通知,招行返回错误:" + reply.RespMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func (s OrderNotifyEvent) IsExpired() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s OrderNotifyEvent) CanNotify() bool {
|
func (s OrderNotifyEvent) CanNotify() bool {
|
||||||
return s.IsSendDEd() || s.IsUsed() || s.IsExpired()
|
return s.IsSendDEd() || s.IsUsed()
|
||||||
}
|
}
|
||||||
|
|
||||||
var OrderNotifyEventMapCmbStatus = map[OrderNotifyEvent]CmbStatus{
|
var OrderNotifyEventMapCmbStatus = map[OrderNotifyEvent]CmbStatus{
|
||||||
|
|
|
||||||
|
|
@ -98,13 +98,13 @@ func (p *OrderRepoImpl) FindIngInBatches(ctx context.Context, fun func(ctx conte
|
||||||
return nil
|
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)
|
var results = make([]*model.Order, 0)
|
||||||
|
|
||||||
result := p.DB(ctx).
|
result := p.DB(ctx).
|
||||||
Where("status IN (?)", []uint8{vo.OrderStatusSuccess.GetValue(), vo.OrderStatusUse.GetValue()}).
|
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 {
|
FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
||||||
// tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch)
|
// tx.RowsAffected 提供当前批处理中记录的计数(the count of records in the current batch)
|
||||||
// 'batch' 变量表示当前批号(the current batch number)
|
// 'batch' 变量表示当前批号(the current batch number)
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ func (s *VoucherService) CronOrderNotice(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *VoucherService) OrderNotice(ctx context.Context) {
|
func (s *VoucherService) OrderNotice(ctx context.Context) {
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
log.Errorf("订单定时通知,执行开始: %v", start.Format(time.DateTime))
|
||||||
|
|
||||||
if err := s.VoucherBiz.Notice(ctx); err != nil {
|
if err := s.VoucherBiz.Notice(ctx); err != nil {
|
||||||
log.Errorf("订单定时通知,执行失败: %v", err)
|
log.Errorf("订单定时通知,执行失败: %v", err)
|
||||||
|
|
@ -81,11 +83,10 @@ func (s *VoucherService) OrderNotice(ctx context.Context) {
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
elapsed := end.Sub(start)
|
elapsed := end.Sub(start)
|
||||||
log.Warnf("订单定时通知,开始执行时间%s,执行结束时间%s,代码块执行耗时: %s", start.Format(time.DateTime), end.Format(time.DateTime), elapsed)
|
log.Warnf("订单定时通知,开始执行时间%s,执行结束时间%s,代码块执行耗时: %s", start.Format(time.DateTime), end.Format(time.DateTime), elapsed)
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *VoucherService) GetNotifyRetryConfig() *mq.ConsumerConfig {
|
func (j *VoucherService) GetNotifyRetryConfig() *mq.ConsumerConfig {
|
||||||
|
|
||||||
elm, ok := j.bc.RocketMQ.EventMap["notifyRetry"]
|
elm, ok := j.bc.RocketMQ.EventMap["notifyRetry"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue