- first compilable version of order handler.

This commit is contained in:
gazebo
2018-07-10 13:37:35 +08:00
parent 49ec11baf8
commit a76213e8f0
15 changed files with 1319 additions and 5 deletions

View File

@@ -0,0 +1,74 @@
package controller
import (
"fmt"
"strings"
"sync"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/routinepool"
"git.rosy.net.cn/jx-callback/globals"
)
const (
VenderIDUnknown = -1
VendorIDJD = 0
VendorIDMTWM = 1
VendorIDELM = 2
VendorIDDada = 101
VendorIDMTPS = 102
)
const (
OrderTypeOrder = 1
OrderTypeWaybill = 2
)
const (
DefaultOrderCacheTimeout = 24 * time.Hour
)
var (
RoutinePool *routinepool.Pool
)
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 GetVendorIDFromUniversalOrderID(orderID string) (vendorID int) {
index := strings.Index(orderID, "|")
if index != -1 {
vendorID = int(utils.Str2Int64(orderID[index:]))
} else {
// 800402581000221 jd order
// 3022716176275221584 elm order
orderIDLen := len(orderID)
if orderIDLen == len("800402581000221") {
vendorID = VendorIDJD
} else if orderIDLen == len("3022716176275221584") {
vendorID = VendorIDELM
} else {
globals.SugarLogger.Errorf("unkown order type:%v", orderID)
vendorID = VenderIDUnknown
}
}
return vendorID
}
func ComposeUniversalOrderID(orderID string, vendorID int) string {
return fmt.Sprintf("%s|%d", orderID, vendorID)
}