同步京东商城库存优化
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) {
|
||||
var (
|
||||
mainSkusMap = make(map[int]*model.StoreSkuBind)
|
||||
skusMap = make(map[int]*model.StoreSkuBind)
|
||||
updateList []*model.StoreSkuBind
|
||||
addList []*model.StoreSkuBind
|
||||
skuBindInfos1 []*StoreSkuBindInfo
|
||||
skuBindInfos2 []*StoreSkuBindInfo
|
||||
resultInterface1 []interface{}
|
||||
resultInterface2 []interface{}
|
||||
mainSkusMap = make(map[int]*model.StoreSkuBind)
|
||||
skusMap = make(map[int]*model.StoreSkuBind)
|
||||
updateList []*model.StoreSkuBind
|
||||
addList []*model.StoreSkuBind
|
||||
skuBindInfos1 []*StoreSkuBindInfo
|
||||
skuBindInfos2 []*StoreSkuBindInfo
|
||||
)
|
||||
storeSkusMain, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
|
||||
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,
|
||||
func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
if len(updateList) > 0 {
|
||||
task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
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))
|
||||
for _, v := range updateList {
|
||||
skuBindInfos1 = append(skuBindInfos1, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||
}
|
||||
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false)
|
||||
}
|
||||
case 1:
|
||||
if len(addList) > 0 {
|
||||
task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
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))
|
||||
for _, v := range addList {
|
||||
skuBindInfos2 = append(skuBindInfos2, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
|
||||
}
|
||||
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user