- call SyncStoreSkus synchronously in mtwm.FullSyncStoreSkus

- handle mtps except event in status event handler too (美团配送的运单异常事件会发到status的回调来)
This commit is contained in:
gazebo
2019-03-17 21:48:05 +08:00
parent 071ae8c5d8
commit efec73afc4
2 changed files with 19 additions and 8 deletions

View File

@@ -62,7 +62,7 @@ func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask t
panic("catName is empty") panic("catName is empty")
} }
globals.SugarLogger.Debugf("RetailCatUpdate vendorStoreID:%s, originName:%s, catName:%s, subCatName:%s, seq:%d", vendorStoreID, originName, catName, subCatName, catInfo.Seq) globals.SugarLogger.Debugf("RetailCatUpdate vendorStoreID:%s, originName:%s, catName:%s, subCatName:%s, seq:%d", vendorStoreID, originName, catName, subCatName, catInfo.Seq)
if err := api.MtwmAPI.RetailCatUpdate(vendorStoreID, originName, catName, subCatName, catInfo.Seq); err == nil { if err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, originName, catName, subCatName, catInfo.Seq); err == nil {
catInfo.MtwmID = catInfo.CatName catInfo.MtwmID = catInfo.CatName
updateFields = append(updateFields, dao.GetVendorThingIDStructField(model.VendorNames[model.VendorIDMTWM])) updateFields = append(updateFields, dao.GetVendorThingIDStructField(model.VendorNames[model.VendorIDMTWM]))
} }
@@ -97,7 +97,7 @@ func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask t
// 远程无,本地有,映射无, --> 添加本地 // 远程无,本地有,映射无, --> 添加本地
// 远程无,本地有,映射有, --> 同步标记改为新增 // 远程无,本地有,映射有, --> 同步标记改为新增
// hint如果是异步返回的是任务ID如果是同步返回是本次需要同步的目录数 // hint如果是异步返回的是任务ID如果是同步返回是本次需要同步的目录数
func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, isCheckRemote, isAsync bool) (hint string, err error) { func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, isCheckRemote bool) (hint string, err error) {
if db == nil { if db == nil {
db = dao.GetDB() db = dao.GetDB()
} }
@@ -214,7 +214,7 @@ func TranverseRemoteCatList(parentCatName string, remoteCats []*mtwmapi.RetailCa
func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB() db := dao.GetDB()
for i := 0; i < 3; i++ { // 最多重试三次 for i := 0; i < 3; i++ { // 最多重试三次
if hint, err = p.SyncLocalStoreCategory(ctx, db, storeID, false, false); err != nil { if hint, err = p.SyncLocalStoreCategory(ctx, db, storeID, false); err != nil {
return "", err return "", err
} }
if hint != "0" { if hint != "0" {
@@ -317,11 +317,11 @@ func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask t
case 1: case 1:
_, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDMTWM, storeID, nil, model.SyncFlagNewMask) _, err = dao.SetStoreSkuSyncStatus(db, model.VendorIDMTWM, storeID, nil, model.SyncFlagNewMask)
case 2: case 2:
_, err = p.SyncLocalStoreCategory(ctx, db, storeID, true, false) _, err = p.SyncLocalStoreCategory(ctx, db, storeID, true)
case 3: case 3:
_, err = p.SyncStoreCategory(ctx, rootTask, storeID, false) _, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
case 4: case 4:
_, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, true, isContinueWhenError) _, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, false, isContinueWhenError)
} }
return nil, err return nil, err
}, 5) }, 5)

View File

@@ -3,6 +3,7 @@ package controllers
import ( import (
"net/http" "net/http"
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
"git.rosy.net.cn/jx-callback/business/partner/delivery/mtps" "git.rosy.net.cn/jx-callback/business/partner/delivery/mtps"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego" "github.com/astaxie/beego"
@@ -15,9 +16,19 @@ type MtpsController struct {
func (c *MtpsController) Status() { func (c *MtpsController) Status() {
if c.Ctx.Input.Method() == http.MethodPost { if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request) var callbackResponse *mtpsapi.CallbackResponse
if callbackResponse == nil { if c.GetString("exception_id") != "" { // 美团配送的回调设置好象有问题,配送异常也会发到这里来,作一下兼容处理
callbackResponse = mtps.OnWaybillMsg(obj) var obj *mtpsapi.CallbackOrderExceptionMsg
obj, callbackResponse = api.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request)
if callbackResponse == nil {
callbackResponse = mtps.OnWaybillExcept(obj)
}
} else {
var obj *mtpsapi.CallbackOrderMsg
obj, callbackResponse = api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request)
if callbackResponse == nil {
callbackResponse = mtps.OnWaybillMsg(obj)
}
} }
c.Data["json"] = callbackResponse c.Data["json"] = callbackResponse
c.ServeJSON() c.ServeJSON()