同步京东商城库存优化
This commit is contained in:
@@ -1115,14 +1115,12 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
|
|||||||
|
|
||||||
func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
var (
|
var (
|
||||||
mainSkusMap = make(map[int]*model.StoreSkuBind)
|
mainSkusMap = make(map[int]*model.StoreSkuBind)
|
||||||
skusMap = make(map[int]*model.StoreSkuBind)
|
skusMap = make(map[int]*model.StoreSkuBind)
|
||||||
updateList []*model.StoreSkuBind
|
updateList []*model.StoreSkuBind
|
||||||
addList []*model.StoreSkuBind
|
addList []*model.StoreSkuBind
|
||||||
skuBindInfos1 []*StoreSkuBindInfo
|
skuBindInfos1 []*StoreSkuBindInfo
|
||||||
skuBindInfos2 []*StoreSkuBindInfo
|
skuBindInfos2 []*StoreSkuBindInfo
|
||||||
resultInterface1 []interface{}
|
|
||||||
resultInterface2 []interface{}
|
|
||||||
)
|
)
|
||||||
storeSkusMain, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
|
storeSkusMain, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
|
||||||
for _, v := range storeSkusMain {
|
for _, v := range storeSkusMain {
|
||||||
@@ -1142,46 +1140,28 @@ func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fmt.Println("updateList", utils.Format4Output(updateList, false))
|
|
||||||
// fmt.Println("addList", utils.Format4Output(addList, false))
|
|
||||||
task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
step := batchItemList[0].(int)
|
step := batchItemList[0].(int)
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
if len(updateList) > 0 {
|
if len(updateList) > 0 {
|
||||||
task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
for _, v := range updateList {
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
skuBindInfos1 = append(skuBindInfos1, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||||
storeBind := batchItemList[0].(*model.StoreSkuBind)
|
|
||||||
retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, false)}
|
|
||||||
return retVal, err
|
|
||||||
}, updateList)
|
|
||||||
tasksch.HandleTask(task, ptTask, false).Run()
|
|
||||||
resultInterface1, err = task.GetResult(0)
|
|
||||||
for _, v := range resultInterface1 {
|
|
||||||
skuBindInfos1 = append(skuBindInfos1, v.(*StoreSkuBindInfo))
|
|
||||||
}
|
}
|
||||||
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false)
|
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false)
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
if len(addList) > 0 {
|
if len(addList) > 0 {
|
||||||
task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
for _, v := range addList {
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
skuBindInfos2 = append(skuBindInfos2, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||||
storeBind := batchItemList[0].(*model.StoreSkuBind)
|
|
||||||
retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, true)}
|
|
||||||
return retVal, err
|
|
||||||
}, addList)
|
|
||||||
tasksch.HandleTask(task, ptTask, false).Run()
|
|
||||||
resultInterface2, err = task.GetResult(0)
|
|
||||||
for _, v := range resultInterface2 {
|
|
||||||
skuBindInfos2 = append(skuBindInfos2, v.(*StoreSkuBindInfo))
|
|
||||||
}
|
}
|
||||||
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false)
|
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}, []int{0, 1})
|
}, []int{0, 1})
|
||||||
tasksch.HandleTask(task, nil, true).Run()
|
tasksch.HandleTask(task, parentTask, true).Run()
|
||||||
if isAsync {
|
if isAsync {
|
||||||
hint = task.GetID()
|
hint = task.GetID()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user