From d4f9df6a0abd25bbd780f26e734d79bc332cafd5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 24 Oct 2019 16:31:50 +0800 Subject: [PATCH] =?UTF-8?q?checkRemoteCatExist=E5=88=A4=E6=96=AD=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=98=AF=E5=90=A6=E4=B8=80=E8=87=B4=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=BF=98=E8=A6=81=E5=88=A4=E6=96=ADLevel=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 34 +++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index d63747668..af0119781 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -568,23 +568,22 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo return err } -func checkRemoteCatExist(localCatMap map[string]*dao.SkuStoreCatInfo, catList []*partner.BareCategoryInfo) (cat2Delete []*partner.BareCategoryInfo) { - for _, v := range catList { - if localCatMap[v.VendorCatID] == nil && localCatMap[v.Name] == nil { - cat2Delete = append(cat2Delete, v) +func checkRemoteCatExist(outRemoteCatMap map[string]int, localCatMap map[string]*dao.SkuStoreCatInfo, remoteCatList []*partner.BareCategoryInfo) (cat2Delete []*partner.BareCategoryInfo) { + for _, v := range remoteCatList { + localCat := localCatMap[v.VendorCatID] + if localCat == nil { + localCat = localCatMap[v.Name] } - cat2Delete = append(cat2Delete, checkRemoteCatExist(localCatMap, v.Children)...) + if localCat == nil || v.Level != int(localCat.Level) { + cat2Delete = append(cat2Delete, v) + } else { + outRemoteCatMap[v.VendorCatID] = 1 + } + cat2Delete = append(cat2Delete, checkRemoteCatExist(outRemoteCatMap, localCatMap, v.Children)...) } return cat2Delete } -func fillRemoteCatMap(catList []*partner.BareCategoryInfo, catMap map[string]int) { - for _, v := range catList { - catMap[v.VendorCatID] = 1 - fillRemoteCatMap(v.Children, catMap) - } -} - // 清除京西没有,平台有的商品与商家分类 // todo !!!,因为美团外卖分类当前是用的名字关联的,所以改名后如果没有及时同步,这个函数会导致美团平台的分类被误删 func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) { @@ -627,12 +626,8 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v SkuID: skuID, VendorSkuID: v.SkuList[0].VendorSkuID, }) - } - if remoteSkuMap[skuID] == 0 { - remoteSkuMap[skuID] = 1 } else { - // 重复的删除后,再打上待创建标记 - remoteSkuMap[skuID] = 0 + remoteSkuMap[skuID] = 1 } } } @@ -674,10 +669,9 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v remoteCatList, err2 := handler.GetStoreAllCategories(ctx, storeID, vendorStoreID) if err = err2; err == nil { - cat2Delete = checkRemoteCatExist(localCatMap, remoteCatList) - remoteCatMap := make(map[string]int) - fillRemoteCatMap(remoteCatList, remoteCatMap) + cat2Delete = checkRemoteCatExist(remoteCatMap, localCatMap, remoteCatList) + for _, v := range localCatList { if remoteCatMap[v.VendorCatID] == 0 && !model.IsSyncStatusNew(v.StoreCatSyncStatus) && !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 { storeCatBindIDs = append(storeCatBindIDs, v.MapID)