- empty scheduler added.
This commit is contained in:
@@ -1,59 +1,25 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
const (
|
||||
WaybillStatusUnknown = 0
|
||||
|
||||
WaybillStatusNew = 5
|
||||
WaybillStatusAcceptCanceled = 8
|
||||
WaybillStatusAccepted = 10
|
||||
WaybillStatusCourierArrived = 15 // 此状态是可选的,明确写出来是因为还是较重要的状态,但业务逻辑不应依赖此状态
|
||||
WaybillStatusDelivering = 20
|
||||
|
||||
WaybillStatusDelivered = 105
|
||||
WaybillStatusCanceled = 115
|
||||
WaybillStatusFailed = 120
|
||||
)
|
||||
|
||||
type DeliveryProvider interface {
|
||||
}
|
||||
|
||||
// 所有公共接口调用前,要求在order里或status中设置合适的Status
|
||||
type WaybillController struct {
|
||||
WaybillMap SyncMapWithTimeout
|
||||
deliveryProviders map[int]DeliveryProvider
|
||||
WaybillMap SyncMapWithTimeout
|
||||
}
|
||||
|
||||
func NewWaybillManager() *WaybillController {
|
||||
return &WaybillController{
|
||||
deliveryProviders: make(map[int]DeliveryProvider),
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WaybillController) RegisterDeliveryProvider(vendorID int, handler DeliveryProvider) {
|
||||
if !(vendorID >= VendorIDDeliveryBegin && vendorID <= VendorIDDeliveryEnd ||
|
||||
vendorID >= VendorIDPurchaseBegin && vendorID <= VendorIDPurchaseEnd) {
|
||||
panic(fmt.Sprintf("delivery provider vendor:%d is illegal", vendorID))
|
||||
}
|
||||
if _, ok := w.deliveryProviders[vendorID]; ok {
|
||||
panic(fmt.Sprintf("delivery provider vendor:%d, already exists", vendorID))
|
||||
}
|
||||
w.deliveryProviders[vendorID] = handler
|
||||
return &WaybillController{}
|
||||
}
|
||||
|
||||
func (w *WaybillController) onWaybillNew(bill *model.Waybill) (err error) {
|
||||
db := orm.NewOrm()
|
||||
bill.Status = WaybillStatusNew
|
||||
isDuplicated, err := addOrderOrWaybillStatus(w.waybill2Status(bill), db)
|
||||
if !isDuplicated {
|
||||
bill.Status = WaybillStatusNew
|
||||
bill.WaybillFinishedAt = DefaultTimeValue
|
||||
bill.ID = 0
|
||||
created, _, err2 := db.ReadOrCreate(bill, "VendorWaybillID", "WaybillVendorID")
|
||||
@@ -73,9 +39,9 @@ func (w *WaybillController) onWaybillNew(bill *model.Waybill) (err error) {
|
||||
}
|
||||
|
||||
func (w *WaybillController) OnWaybillStatusChanged(bill *model.Waybill) (err error) {
|
||||
if bill.Status == WaybillStatusNew {
|
||||
if bill.Status == model.WaybillStatusNew {
|
||||
err = w.onWaybillNew(bill)
|
||||
} else if bill.Status == WaybillStatusAccepted {
|
||||
} else if bill.Status == model.WaybillStatusAccepted {
|
||||
err = w.onWaybillAccepted(bill)
|
||||
} else {
|
||||
db := orm.NewOrm()
|
||||
@@ -89,7 +55,6 @@ func (w *WaybillController) OnWaybillStatusChanged(bill *model.Waybill) (err err
|
||||
|
||||
func (w *WaybillController) onWaybillAccepted(bill *model.Waybill) (err error) {
|
||||
db := orm.NewOrm()
|
||||
bill.Status = WaybillStatusAccepted
|
||||
isDuplicated, err := w.addWaybillStatus(bill, db)
|
||||
if !isDuplicated {
|
||||
if err = w.updateWaybillPKID(bill, db); err == nil {
|
||||
@@ -111,13 +76,13 @@ func (w *WaybillController) addWaybillStatus(bill *model.Waybill, db orm.Ormer)
|
||||
}
|
||||
waybillStatus := w.waybill2Status(bill)
|
||||
isDuplicated, err = addOrderOrWaybillStatus(waybillStatus, db)
|
||||
if !isDuplicated && waybillStatus.Status > WaybillStatusUnknown {
|
||||
if !isDuplicated && waybillStatus.Status > model.WaybillStatusUnknown {
|
||||
if err = w.updateWaybillPKID(bill, db); err == nil {
|
||||
bill.Status = waybillStatus.Status
|
||||
bill.VendorStatus = waybillStatus.VendorStatus
|
||||
utils.CallFuncLogError(func() error {
|
||||
columns := []string{"Status", "VendorStatus"}
|
||||
if waybillStatus.Status >= OrderStatusEndBegin {
|
||||
if waybillStatus.Status >= model.OrderStatusEndBegin {
|
||||
bill.WaybillFinishedAt = waybillStatus.StatusTime
|
||||
columns = append(columns, "WaybillFinishedAt")
|
||||
}
|
||||
@@ -133,7 +98,7 @@ func (w *WaybillController) waybill2Status(bill *model.Waybill) (retVal *model.O
|
||||
retVal = &model.OrderStatus{
|
||||
VendorOrderID: bill.VendorWaybillID,
|
||||
VendorID: bill.WaybillVendorID,
|
||||
OrderType: OrderTypeWaybill,
|
||||
OrderType: model.OrderTypeWaybill,
|
||||
Status: bill.Status,
|
||||
VendorStatus: bill.VendorStatus,
|
||||
StatusTime: bill.WaybillCreatedAt,
|
||||
|
||||
Reference in New Issue
Block a user