- first compilable version of order handler.
This commit is contained in:
74
business/controller/controller.go
Normal file
74
business/controller/controller.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user