- first version of order schedule.

This commit is contained in:
gazebo
2018-07-18 22:52:30 +08:00
parent 15439779b2
commit cc9e1dc5d2
15 changed files with 455 additions and 128 deletions

View File

@@ -3,39 +3,24 @@ package controller
import (
"fmt"
"math"
"strings"
"sync"
"time"
"git.rosy.net.cn/baseapi/platformapi/autonavi"
"github.com/astaxie/beego/orm"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/routinepool"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/scheduler"
_ "git.rosy.net.cn/jx-callback/business/scheduler/defsch" // 导入缺省订单调度器
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
const (
DefaultOrderCacheTimeout = 24 * time.Hour
"github.com/astaxie/beego/orm"
)
var (
OrderManager *OrderController
WaybillManager *WaybillController
routinePool *routinepool.Pool
routinePool *routinepool.Pool
)
type SyncMapWithTimeout struct {
sync.Map
}
func init() {
routinePool = routinepool.New(1000, 1000)
OrderManager = NewOrderManager()
@@ -43,44 +28,6 @@ func init() {
scheduler.CurrentScheduler.RegisterOrderManager(OrderManager)
}
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 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 StandardCoordinate2Int(value float64) int {
return int(math.Round(value * 1000000))
}
@@ -172,10 +119,3 @@ func GetDataCityCodeFromOrder(order *model.GoodsOrder) (retVal string, err error
}
return retVal, err
}
func GetJxStoreIDFromOrder(order *model.GoodsOrder) (retVal int) {
if order.JxStoreID != 0 {
return order.JxStoreID
}
return order.StoreID
}