From 920c67bb6f8918e8fce0ddd8b06ce3e7fee045f7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 28 Mar 2019 12:26:53 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=9B=A0=E4=B8=BA=E6=9C=89=E4=BA=9B?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=EF=BC=88=E6=AF=94=E5=A6=82=E7=BE=8E=E5=9B=A2?= =?UTF-8?q?=E5=A4=96=E5=8D=96=EF=BC=89=E7=9A=84=E5=AE=9A=E6=97=B6=E8=BE=BE?= =?UTF-8?q?=E5=8D=95=EF=BC=8C=E5=BE=88=E6=97=A9=E5=B0=B1=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=BF=90=E5=8D=95=E4=BA=86=EF=BC=8C=E7=89=B9=E6=AE=8A=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=B9=B3=E5=8F=B0=E7=9A=84=E6=96=B0=E8=BF=90=E5=8D=95?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=20-=20=E5=AE=9A=E6=97=B6=E8=BE=BE=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E4=B8=89=E6=96=B9=E8=BF=90=E5=8D=95=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=B8=8E=E4=B9=8B=E5=89=8D=E7=9A=84=E6=9C=89=E5=8F=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jxcallback/scheduler/defsch/defsch.go | 73 ++++++++++++------- business/jxcallback/scheduler/scheduler.go | 8 -- business/partner/partner.go | 9 +++ 3 files changed, 57 insertions(+), 33 deletions(-) diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 9da4ab600..90d1d1e83 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -23,7 +23,7 @@ import ( const ( time2Delivered = 1 * time.Hour // 正常从下单到送达的时间。 - time2Schedule3rdCarrier = 20 // 京东要求5分钟后才能转自送,保险起见,设置为5分半钟 + time2Schedule3rdCarrier = 20 // 收到平台方自有配送的新运单消息后,等待创建三方配送运单的时间(分钟),如果是定时达,会再根据ExpectedDeliveredTime与dingShiDaAheadTime做调整 // time2Schedule3rdCarrierGap4OrderStatus = 3 * time.Minute // 京东要求是运单状态为待抢单且超时5分钟,但为了防止没有运单事件,所以就拣货完成事件开始算,添加3分钟 time2AutoPickupMin = 15 * time.Minute // 自动拣货等待时间,这个只有在没有PickDeadline信息才有用,否则会根据PickDeadline设置 time2AutoPickupGap = 5 * 60 //随机5分钟 @@ -68,9 +68,7 @@ type WatchOrderInfo struct { } type StatusActionConfig struct { - TimerType int // 参见上面的相关常量定义 - Timeout time.Duration // 超时时间,0在GetStatusActionConfig返回时表示不修改缺省 - TimeoutGap int // 以秒为单位的随机时间,0在GetStatusActionConfig返回时表示不修改缺省 + partner.StatusActionParams TimeoutAction func(savedOrderInfo *WatchOrderInfo) (err error) // 超时后需要执行的动作,为nil表示此状态不需要执行监控, nil在GetStatusActionConfig返回时表示不修改缺省 } @@ -152,8 +150,10 @@ func init() { sch.defWorkflowConfig = []map[int]*StatusActionConfig{ map[int]*StatusActionConfig{ model.OrderStatusNew: &StatusActionConfig{ // 自动接单 - TimerType: scheduler.TimerTypeBaseStatusTime, - Timeout: 10 * time.Millisecond, + StatusActionParams: partner.StatusActionParams{ + TimerType: partner.TimerTypeBaseStatusTime, + Timeout: 10 * time.Millisecond, + }, TimeoutAction: func(savedOrderInfo *WatchOrderInfo) (err error) { order := savedOrderInfo.order mobile := order.ConsigneeMobile @@ -178,9 +178,11 @@ func init() { }, }, model.OrderStatusAccepted: &StatusActionConfig{ // 自动拣货 - TimerType: scheduler.TimerTypeBaseExpectedDeliveredTime, - Timeout: time2AutoPickupMin, // 此值会被门店设置覆盖 - TimeoutGap: time2AutoPickupGap, + StatusActionParams: partner.StatusActionParams{ + TimerType: partner.TimerTypeBaseExpectedDeliveredTime, + Timeout: time2AutoPickupMin, // 此值会被门店设置覆盖 + TimeoutGap: time2AutoPickupGap, + }, TimeoutAction: func(savedOrderInfo *WatchOrderInfo) (err error) { if savedOrderInfo.autoPickupTimeoutMinute > 0 { return sch.autoPickupGood(savedOrderInfo) @@ -189,9 +191,11 @@ func init() { }, }, model.OrderStatusFinishedPickup: &StatusActionConfig{ - TimerType: scheduler.TimerTypeBaseStatusTime, - Timeout: 1 * time.Second, - TimeoutGap: 0, + StatusActionParams: partner.StatusActionParams{ + TimerType: partner.TimerTypeBaseStatusTime, + Timeout: 1 * time.Second, + TimeoutGap: 0, + }, TimeoutAction: func(savedOrderInfo *WatchOrderInfo) (err error) { if savedOrderInfo.storeDeliveryType == scheduler.StoreDeliveryTypeByStore { // 自配送商家使用 return sch.createWaybillOn3rdProviders(savedOrderInfo, nil) @@ -202,8 +206,10 @@ func init() { }, map[int]*StatusActionConfig{ model.WaybillStatusNew: &StatusActionConfig{ - TimerType: scheduler.TimerTypeBaseStatusTime, - Timeout: time2Schedule3rdCarrier * time.Minute, + StatusActionParams: partner.StatusActionParams{ + TimerType: partner.TimerTypeBaseStatusTime, + Timeout: time2Schedule3rdCarrier * time.Minute, + }, TimeoutAction: func(savedOrderInfo *WatchOrderInfo) (err error) { if savedOrderInfo.storeDeliveryType != scheduler.StoreDeliveryTypeByStore { // 非自配置商家使用 return sch.createWaybillOn3rdProviders(savedOrderInfo, nil) @@ -696,15 +702,15 @@ func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, bill *model.Wa globals.SugarLogger.Debugf("resetTimer, orderID:%s statusType:%d status:%v", order.VendorOrderID, statusType, status) if statusType != savedOrderInfo.timerStatusType || status >= savedOrderInfo.timerStatus { // 新设置的TIMER不能覆盖状态在其后的TIMER,如果状态回绕,需要注意 config := s.mergeOrderStatusConfig(savedOrderInfo.order, statusType, status, order.VendorID) - if config == nil || config.TimerType != scheduler.TimerTypeByPass { + if config == nil || config.TimerType != partner.TimerTypeByPass { s.stopTimer(savedOrderInfo) } - if config != nil && config.TimeoutAction != nil && config.TimerType != scheduler.TimerTypeByPass { + if config != nil && config.TimeoutAction != nil && config.TimerType != partner.TimerTypeByPass { nowTime := time.Now() configTimerType := config.TimerType if statusType == scheduler.TimerStatusTypeOrder && status == model.OrderStatusAccepted { // 自动拣货的TIMER,特殊处理 if !utils.IsTimeZero(order.PickDeadline) { // 如果有PickDeadline值,特殊处理 - configTimerType = scheduler.TimerTypeBaseNow + configTimerType = partner.TimerTypeBaseNow config.Timeout = order.PickDeadline.Sub(nowTime) - 20*time.Second // 提前一点操作,防止超时 if config.TimeoutGap != 0 { config.Timeout -= time.Duration(config.TimeoutGap) * time.Second @@ -715,11 +721,11 @@ func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, bill *model.Wa } var timeout time.Duration switch configTimerType { - case scheduler.TimerTypeBaseNow: + case partner.TimerTypeBaseNow: timeout = config.Timeout - case scheduler.TimerTypeBaseStatusTime: + case partner.TimerTypeBaseStatusTime: timeout = statusTime.Sub(nowTime) + config.Timeout - case scheduler.TimerTypeBaseExpectedDeliveredTime: + case partner.TimerTypeBaseExpectedDeliveredTime: if order.BusinessType == model.BusinessTypeDingshida && !utils.IsTimeZero(order.ExpectedDeliveredTime) { statusTime = order.ExpectedDeliveredTime.Add(-time2Delivered) } @@ -804,18 +810,35 @@ func (s *DefScheduler) mergeOrderStatusConfig(order *model.GoodsOrder, statusTyp retVal = &StatusActionConfig{} *retVal = *defConfig - if statusType == scheduler.TimerStatusTypeOrder && status == model.OrderStatusFinishedPickup && order.BusinessType != model.BusinessTypeImmediate { + var vendorActionParams *partner.StatusActionParams + if order.BusinessType != model.BusinessTypeImmediate { if jxutils.IsTimeEmpty(order.ExpectedDeliveredTime) { globals.SugarLogger.Warnf("mergeOrderStatusConfig orderID:%s 非立即达订单没有预计送达时间", order.VendorOrderID) - } else { - retVal.Timeout = order.ExpectedDeliveredTime.Sub(time.Now()) - dingShiDaAheadTime - retVal.TimerType = scheduler.TimerTypeBaseNow + } else if statusType == scheduler.TimerStatusTypeOrder && status == model.OrderStatusFinishedPickup { // 这个只针对自配送门店才有效 + vendorActionParams = &partner.StatusActionParams{ + TimerType: partner.TimerTypeBaseNow, + Timeout: order.ExpectedDeliveredTime.Sub(time.Now()) - dingShiDaAheadTime, + TimeoutGap: -1, + } + } else if statusType == scheduler.TimerStatusTypeWaybill && status == model.WaybillStatusNew { // 因为有些平台(比如美团外卖)的定时达单,很早就创建运单了 + vendorActionParams = &partner.StatusActionParams{ + TimerType: partner.TimerTypeBaseNow, + Timeout: order.ExpectedDeliveredTime.Sub(time.Now()) - dingShiDaAheadTime, + TimeoutGap: -1, + } } - } else if vendorActionParams := partner.GetPurchasePlatformFromVendorID(purchaseVendorID).GetStatusActionTimeout(order, statusType, status); vendorActionParams != nil { + } + if vendorActionParams == nil { + vendorActionParams = partner.GetPurchasePlatformFromVendorID(purchaseVendorID).GetStatusActionTimeout(order, statusType, status) + } + if vendorActionParams != nil { retVal.Timeout = vendorActionParams.Timeout if vendorActionParams.TimeoutGap >= 0 { retVal.TimeoutGap = vendorActionParams.TimeoutGap } + if vendorActionParams.TimerType != partner.TimerTypeNoOverride { + retVal.TimerType = vendorActionParams.TimerType + } } return retVal } diff --git a/business/jxcallback/scheduler/scheduler.go b/business/jxcallback/scheduler/scheduler.go index a1f5002e8..a0654a64d 100644 --- a/business/jxcallback/scheduler/scheduler.go +++ b/business/jxcallback/scheduler/scheduler.go @@ -18,14 +18,6 @@ const ( TimerStatusTypeWaybill = 1 ) -const ( - TimerTypeNoOverride = 0 // GetStatusActionConfig 返回表示不修改缺省配置 - TimerTypeByPass = 1 - TimerTypeBaseNow = 2 - TimerTypeBaseStatusTime = 3 - TimerTypeBaseExpectedDeliveredTime = 4 // 如果是定时达,以expected delivery time倒推的时间当成statusTime(之后与TimerTypeBaseStatusTime一样),否则与TimerTypeBaseStatusTime相同 -) - var ( CurrentScheduler IScheduler ) diff --git a/business/partner/partner.go b/business/partner/partner.go index 95d2c9bda..8e0fa415f 100644 --- a/business/partner/partner.go +++ b/business/partner/partner.go @@ -22,7 +22,16 @@ const ( CancelWaybillReasonOther = 10 ) +const ( + TimerTypeNoOverride = 0 // GetStatusActionConfig 返回表示不修改缺省配置 + TimerTypeByPass = 1 + TimerTypeBaseNow = 2 + TimerTypeBaseStatusTime = 3 + TimerTypeBaseExpectedDeliveredTime = 4 // 如果是定时达,以expected delivery time倒推的时间当成statusTime(之后与TimerTypeBaseStatusTime一样),否则与TimerTypeBaseStatusTime相同 +) + type StatusActionParams struct { + TimerType int // 参见上面的相关常量定义 Timeout time.Duration // 超时时间,0在GetStatusActionConfig返回时表示不修改缺省 TimeoutGap int // 以秒为单位的随机时间,0在GetStatusActionConfig返回时表示不修改缺省 }