- first version of order schedule.
This commit is contained in:
84
business/jxutils/jxutils.go
Normal file
84
business/jxutils/jxutils.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package jxutils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultOrderCacheTimeout = 24 * time.Hour
|
||||
)
|
||||
|
||||
type SyncMapWithTimeout struct {
|
||||
sync.Map
|
||||
}
|
||||
|
||||
func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) {
|
||||
m.Map.Store(key, value)
|
||||
time.AfterFunc(timeout, func() {
|
||||
m.Delete(key)
|
||||
})
|
||||
}
|
||||
|
||||
func (m *SyncMapWithTimeout) Store(key, value interface{}) {
|
||||
m.StoreWithTimeout(key, value, DefaultOrderCacheTimeout)
|
||||
}
|
||||
|
||||
func GetJxStoreIDFromOrder(order *model.GoodsOrder) (retVal int) {
|
||||
if order.JxStoreID != 0 {
|
||||
return order.JxStoreID
|
||||
}
|
||||
return order.StoreID
|
||||
}
|
||||
|
||||
func SplitUniversalOrderID(universalOrderID string) (orderID string, vendorID int) {
|
||||
index := strings.Index(universalOrderID, "|")
|
||||
if index != -1 {
|
||||
orderID = universalOrderID[:index]
|
||||
vendorID = int(utils.Str2Int64(universalOrderID[index:]))
|
||||
} else {
|
||||
// 800402581000221 jd order
|
||||
// 3022716176275221584 elm order
|
||||
orderIDLen := len(universalOrderID)
|
||||
if orderIDLen == len("800402581000221") {
|
||||
vendorID = model.VendorIDJD
|
||||
} else if orderIDLen == len("3022716176275221584") {
|
||||
vendorID = model.VendorIDELM
|
||||
} else {
|
||||
globals.SugarLogger.Errorf("unkown order type:%v", universalOrderID)
|
||||
vendorID = model.VendorIDUnknown
|
||||
}
|
||||
orderID = universalOrderID
|
||||
}
|
||||
return orderID, vendorID
|
||||
}
|
||||
|
||||
func ComposeUniversalOrderID(orderID string, vendorID int) string {
|
||||
// return fmt.Sprintf("%s|%d", orderID, vendorID)
|
||||
return orderID // 当前用长度就能区分,先不加上vendorID
|
||||
}
|
||||
|
||||
func GetUniversalOrderIDFromWaybill(bill *model.Waybill) string {
|
||||
return ComposeUniversalOrderID(bill.VendorOrderID, bill.OrderVendorID)
|
||||
}
|
||||
|
||||
func GetUniversalOrderIDFromOrder(order *model.GoodsOrder) string {
|
||||
return ComposeUniversalOrderID(order.VendorOrderID, order.VendorID)
|
||||
}
|
||||
|
||||
func GetUniversalOrderIDFromOrderStatus(status *model.OrderStatus) string {
|
||||
return ComposeUniversalOrderID(status.VendorOrderID, status.VendorID)
|
||||
}
|
||||
|
||||
func GetRealTimeout(beginTime time.Time, timeout time.Duration) time.Duration {
|
||||
retVal := beginTime.Add(timeout).Sub(time.Now())
|
||||
if retVal < 0 {
|
||||
retVal = 0
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
Reference in New Issue
Block a user