- don't treat multiple accept as warning.
- every time jd dada create new bill, must wait some time.
This commit is contained in:
@@ -37,6 +37,7 @@ type WatchOrderInfo struct {
|
|||||||
storeDeliveryType int
|
storeDeliveryType int
|
||||||
isNeed3rdDelivery bool
|
isNeed3rdDelivery bool
|
||||||
|
|
||||||
|
isSwitched2SelfDelivery bool
|
||||||
order *model.GoodsOrder // order里的信息是保持更新的
|
order *model.GoodsOrder // order里的信息是保持更新的
|
||||||
waybills map[int]*model.Waybill // 这个waybills里的状态信息是不真实的,只使用id相关的信息
|
waybills map[int]*model.Waybill // 这个waybills里的状态信息是不真实的,只使用id相关的信息
|
||||||
|
|
||||||
@@ -188,7 +189,7 @@ func (s *DefScheduler) OnOrderNew(order *model.GoodsOrder, isPending bool) (err
|
|||||||
} else {
|
} else {
|
||||||
savedOrderInfo.SetOrder(order) // 调整单或消息错序都可能进到这里来
|
savedOrderInfo.SetOrder(order) // 调整单或消息错序都可能进到这里来
|
||||||
}
|
}
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeOrder, savedOrderInfo.order.Status, isPending)
|
s.resetTimer(savedOrderInfo, nil, isPending)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ func (s *DefScheduler) OnOrderStatusChanged(status *model.OrderStatus, isPending
|
|||||||
globals.SugarLogger.Debugf("OnOrderStatusChanged orderID:%s %s, status:%v", status.VendorOrderID, model.OrderStatusName[status.Status], status)
|
globals.SugarLogger.Debugf("OnOrderStatusChanged orderID:%s %s, status:%v", status.VendorOrderID, model.OrderStatusName[status.Status], status)
|
||||||
savedOrderInfo := s.loadSavedOrderFromMap(status, true)
|
savedOrderInfo := s.loadSavedOrderFromMap(status, true)
|
||||||
s.updateOrderByStatus(savedOrderInfo.order, status)
|
s.updateOrderByStatus(savedOrderInfo.order, status)
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeOrder, savedOrderInfo.order.Status, isPending)
|
s.resetTimer(savedOrderInfo, nil, isPending)
|
||||||
if status.Status >= model.OrderStatusEndBegin {
|
if status.Status >= model.OrderStatusEndBegin {
|
||||||
s.cancelOtherWaybills(savedOrderInfo, nil)
|
s.cancelOtherWaybills(savedOrderInfo, nil)
|
||||||
s.orderMap.Delete(jxutils.GetUniversalOrderIDFromOrderStatus(status))
|
s.orderMap.Delete(jxutils.GetUniversalOrderIDFromOrderStatus(status))
|
||||||
@@ -236,32 +237,36 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
}
|
}
|
||||||
// 只有购物平台的新运单消息才会启动抢单TIMER
|
// 只有购物平台的新运单消息才会启动抢单TIMER
|
||||||
if bill.OrderVendorID == bill.WaybillVendorID {
|
if bill.OrderVendorID == bill.WaybillVendorID {
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch bill.Status {
|
switch bill.Status {
|
||||||
case model.WaybillStatusAccepted:
|
case model.WaybillStatusAccepted:
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if !isPending {
|
if !isPending {
|
||||||
if order.WaybillVendorID == model.VendorIDUnknown || bill.WaybillVendorID == order.VendorID { // 购买平台的运单,优先级最高
|
// todo 购买平台的运单,优先级最高,但这样写也可能带来问题,即在这个时间,因为之前3方已经接单,已经发出了转自送请求(而且可能成功了),所以加个isSwitched2SelfDelivery状态判断
|
||||||
|
if order.WaybillVendorID == model.VendorIDUnknown || (bill.WaybillVendorID == order.VendorID && !savedOrderInfo.isSwitched2SelfDelivery) {
|
||||||
|
if order.WaybillVendorID != model.VendorIDUnknown {
|
||||||
|
globals.SugarLogger.Warnf("OnWaybillStatusChanged orderID:%s purchase platform waybill arrvied later, may case problem", order.VendorOrderID)
|
||||||
|
}
|
||||||
s.updateOrderByBill(order, bill, false)
|
s.updateOrderByBill(order, bill, false)
|
||||||
s.cancelOtherWaybills(savedOrderInfo, bill)
|
s.cancelOtherWaybills(savedOrderInfo, bill)
|
||||||
if bill.WaybillVendorID != bill.OrderVendorID {
|
if bill.WaybillVendorID != bill.OrderVendorID {
|
||||||
if savedOrderInfo.storeDeliveryType == scheduler.StoreDeliveryTypeByStore {
|
if savedOrderInfo.storeDeliveryType == scheduler.StoreDeliveryTypeByStore {
|
||||||
s.SelfDeliverDelievering(savedOrderInfo.order)
|
s.SelfDeliverDelievering(savedOrderInfo.order)
|
||||||
} else {
|
} else {
|
||||||
s.swtich2SelfDeliverWithRetry(savedOrderInfo.order, bill, 2, 10*time.Second)
|
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, 2, 10*time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !s.isBillCandidate(order, bill) && bill.WaybillVendorID != order.VendorID {
|
} else if !s.isBillCandidate(order, bill) && bill.WaybillVendorID != order.VendorID {
|
||||||
// todo 当前逻辑,加载PENDING的ORDER时,正常状态也可能进这里
|
// 发生这种情况的原因就是两个接单事件几乎同时到达(来不及取消),也算正常
|
||||||
s.CancelWaybill(bill)
|
s.CancelWaybill(bill)
|
||||||
globals.SugarLogger.Warnf("OnWaybillStatusChanged Accepted orderID:%s got multiple bill:%v, order details:%v", order.VendorOrderID, bill, order)
|
globals.SugarLogger.Infof("OnWaybillStatusChanged Accepted orderID:%s got multiple bill:%v", order.VendorOrderID, bill)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case model.WaybillStatusAcceptCanceled:
|
case model.WaybillStatusAcceptCanceled:
|
||||||
if s.isBillCandidate(order, bill) {
|
if s.isBillCandidate(order, bill) {
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if !isPending {
|
if !isPending {
|
||||||
bill.WaybillVendorID = model.VendorIDUnknown
|
bill.WaybillVendorID = model.VendorIDUnknown
|
||||||
s.updateOrderByBill(order, bill, false)
|
s.updateOrderByBill(order, bill, false)
|
||||||
@@ -273,7 +278,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
globals.SugarLogger.Warnf("OnWaybillStatusChanged AcceptCanceled orderID:%s got multiple bill:%v, order details:%v", order.VendorOrderID, bill, order)
|
globals.SugarLogger.Warnf("OnWaybillStatusChanged AcceptCanceled orderID:%s got multiple bill:%v, order details:%v", order.VendorOrderID, bill, order)
|
||||||
}
|
}
|
||||||
case model.WaybillStatusCourierArrived: // do nothing
|
case model.WaybillStatusCourierArrived: // do nothing
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if s.isBillCandidate(order, bill) {
|
if s.isBillCandidate(order, bill) {
|
||||||
} else {
|
} else {
|
||||||
// s.CancelWaybill(bill)
|
// s.CancelWaybill(bill)
|
||||||
@@ -282,7 +287,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
case model.WaybillStatusFailed: // todo WaybillStatusFailed理解成订单整个失败了,不需要再尝试创建运单了,注意这里应该加个zabbix日志的报警
|
case model.WaybillStatusFailed: // todo WaybillStatusFailed理解成订单整个失败了,不需要再尝试创建运单了,注意这里应该加个zabbix日志的报警
|
||||||
s.removeWaybillFromMap(savedOrderInfo, bill)
|
s.removeWaybillFromMap(savedOrderInfo, bill)
|
||||||
if s.isBillCandidate(order, bill) {
|
if s.isBillCandidate(order, bill) {
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if !isPending {
|
if !isPending {
|
||||||
globals.SugarLogger.Infof("OnWaybillStatusChanged WaybillStatusFailed, bill:%v", bill)
|
globals.SugarLogger.Infof("OnWaybillStatusChanged WaybillStatusFailed, bill:%v", bill)
|
||||||
bill.WaybillVendorID = model.VendorIDUnknown
|
bill.WaybillVendorID = model.VendorIDUnknown
|
||||||
@@ -294,7 +299,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
case model.WaybillStatusCanceled:
|
case model.WaybillStatusCanceled:
|
||||||
s.removeWaybillFromMap(savedOrderInfo, bill)
|
s.removeWaybillFromMap(savedOrderInfo, bill)
|
||||||
if s.isBillCandidate(order, bill) || order.WaybillVendorID == model.VendorIDUnknown {
|
if s.isBillCandidate(order, bill) || order.WaybillVendorID == model.VendorIDUnknown {
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if !isPending {
|
if !isPending {
|
||||||
if order.WaybillVendorID != model.VendorIDUnknown {
|
if order.WaybillVendorID != model.VendorIDUnknown {
|
||||||
bill.WaybillVendorID = model.VendorIDUnknown
|
bill.WaybillVendorID = model.VendorIDUnknown
|
||||||
@@ -306,7 +311,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case model.WaybillStatusDelivering:
|
case model.WaybillStatusDelivering:
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if s.isBillCandidate(order, bill) {
|
if s.isBillCandidate(order, bill) {
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
@@ -314,7 +319,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
globals.SugarLogger.Warnf("OnWaybillStatusChanged Delivering order(%d, %s) bill(%d, %s), bill:%v shouldn't got here", order.WaybillVendorID, order.VendorWaybillID, bill.WaybillVendorID, bill.VendorWaybillID, bill)
|
globals.SugarLogger.Warnf("OnWaybillStatusChanged Delivering order(%d, %s) bill(%d, %s), bill:%v shouldn't got here", order.WaybillVendorID, order.VendorWaybillID, bill.WaybillVendorID, bill.VendorWaybillID, bill)
|
||||||
}
|
}
|
||||||
case model.WaybillStatusDelivered:
|
case model.WaybillStatusDelivered:
|
||||||
s.resetTimer(savedOrderInfo, scheduler.TimerStatusTypeWaybill, bill.Status, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
s.removeWaybillFromMap(savedOrderInfo, bill)
|
s.removeWaybillFromMap(savedOrderInfo, bill)
|
||||||
if order.VendorID != bill.WaybillVendorID && !isPending {
|
if order.VendorID != bill.WaybillVendorID && !isPending {
|
||||||
s.SelfDeliverDelievered(order)
|
s.SelfDeliverDelievered(order)
|
||||||
@@ -394,14 +399,15 @@ func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DefScheduler) swtich2SelfDeliverWithRetry(order *model.GoodsOrder, bill *model.Waybill, retryCount int, duration time.Duration) {
|
func (s *DefScheduler) swtich2SelfDeliverWithRetry(savedOrderInfo *WatchOrderInfo, bill *model.Waybill, retryCount int, duration time.Duration) {
|
||||||
|
order := savedOrderInfo.order
|
||||||
globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID)
|
globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID)
|
||||||
if err := s.Swtich2SelfDeliver(order); err != nil {
|
if err := s.Swtich2SelfDeliver(order); err != nil {
|
||||||
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err)
|
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err)
|
||||||
if retryCount > 0 {
|
if retryCount > 0 {
|
||||||
time.AfterFunc(duration, func() {
|
time.AfterFunc(duration, func() {
|
||||||
jxutils.CallMsgHandlerAsync(func() {
|
jxutils.CallMsgHandlerAsync(func() {
|
||||||
s.swtich2SelfDeliverWithRetry(order, bill, retryCount-1, duration)
|
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, retryCount-1, duration)
|
||||||
}, order.VendorOrderID)
|
}, order.VendorOrderID)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -423,6 +429,8 @@ func (s *DefScheduler) swtich2SelfDeliverWithRetry(order *model.GoodsOrder, bill
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
savedOrderInfo.isSwitched2SelfDelivery = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,9 +476,17 @@ func (s *DefScheduler) stopTimer(savedOrderInfo *WatchOrderInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, statusType, status int, isPending bool) {
|
func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, bill *model.Waybill, isPending bool) {
|
||||||
order := savedOrderInfo.order
|
order := savedOrderInfo.order
|
||||||
globals.SugarLogger.Debugf("resetTimer, orderID:%s status:%v", order.VendorOrderID, status)
|
status := order.Status
|
||||||
|
statusType := scheduler.TimerStatusTypeOrder
|
||||||
|
statusTime := order.StatusTime
|
||||||
|
if bill != nil {
|
||||||
|
status = bill.Status
|
||||||
|
statusType = scheduler.TimerStatusTypeWaybill
|
||||||
|
statusTime = bill.StatusTime
|
||||||
|
}
|
||||||
|
globals.SugarLogger.Debugf("resetTimer, orderID:%s statusType:%d status:%v", order.VendorOrderID, statusType, status)
|
||||||
if statusType != savedOrderInfo.timerStatusType || status >= savedOrderInfo.timerStatus { // 新设置的TIMER不能覆盖状态在其后的TIMER,如果状态回绕,需要注意
|
if statusType != savedOrderInfo.timerStatusType || status >= savedOrderInfo.timerStatus { // 新设置的TIMER不能覆盖状态在其后的TIMER,如果状态回绕,需要注意
|
||||||
config := s.mergeOrderStatusConfig(statusType, status, order.VendorID)
|
config := s.mergeOrderStatusConfig(statusType, status, order.VendorID)
|
||||||
if config == nil || config.TimerType != scheduler.TimerTypeByPass {
|
if config == nil || config.TimerType != scheduler.TimerTypeByPass {
|
||||||
@@ -482,9 +498,8 @@ func (s *DefScheduler) resetTimer(savedOrderInfo *WatchOrderInfo, statusType, st
|
|||||||
case scheduler.TimerTypeBaseNow:
|
case scheduler.TimerTypeBaseNow:
|
||||||
timeout = config.Timeout
|
timeout = config.Timeout
|
||||||
case scheduler.TimerTypeBaseStatusTime:
|
case scheduler.TimerTypeBaseStatusTime:
|
||||||
timeout = order.StatusTime.Sub(time.Now()) + config.Timeout
|
timeout = statusTime.Sub(time.Now()) + config.Timeout
|
||||||
case scheduler.TimerTypeBaseExpectedDeliveredTime:
|
case scheduler.TimerTypeBaseExpectedDeliveredTime:
|
||||||
statusTime := order.StatusTime
|
|
||||||
if order.BusinessType == model.BusinessTypeDingshida && order.ExpectedDeliveredTime != utils.DefaultTimeValue {
|
if order.BusinessType == model.BusinessTypeDingshida && order.ExpectedDeliveredTime != utils.DefaultTimeValue {
|
||||||
statusTime = order.ExpectedDeliveredTime.Add(-time2Delivered)
|
statusTime = order.ExpectedDeliveredTime.Add(-time2Delivered)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user