diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index af0119781..da3aa113e 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -587,10 +587,10 @@ func checkRemoteCatExist(outRemoteCatMap map[string]int, localCatMap map[string] // 清除京西没有,平台有的商品与商家分类 // todo !!!,因为美团外卖分类当前是用的名字关联的,所以改名后如果没有及时同步,这个函数会导致美团平台的分类被误删 func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) { - return amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmendPruneOnlyPrune) + return amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmendPruneOnlyPrune, false) } -func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool, opType int) (hint string, err error) { +func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) { handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) if handler == nil { return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID]) @@ -599,7 +599,6 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v var sku2Delete []*partner.StoreSkuInfo var cat2Delete []*partner.BareCategoryInfo - var storeSkuBindIDs, storeCatBindIDs []int task := tasksch.NewParallelTask(fmt.Sprintf("修补平台:%s上的门店商品与分类", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { @@ -632,22 +631,27 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v } } - for _, v := range localSkuList { - if remoteSkuMap[v.SkuID] == 0 && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 { - storeSkuBindIDs = append(storeSkuBindIDs, v.BindID) + if opType == AmendPruneOnlyAmend || opType == AmendPruneAll { + for _, v := range localSkuList { + if !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 { + syncStatus := 0 + if remoteSkuMap[v.SkuID] == 0 { + if !model.IsSyncStatusNew(v.StoreSkuSyncStatus) { + syncStatus = model.SyncFlagNewMask + } + } else if isForceUpdate && !model.IsSyncStatusUpdate(v.StoreSkuSyncStatus) { + syncStatus = model.SyncFlagModifiedMask + } + if syncStatus != 0 { + skuBind := &model.StoreSkuBind{} + skuBind.ID = v.BindID + dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), syncStatus) + } + } } } } case 1: - if (opType == AmendPruneOnlyAmend || opType == AmendPruneAll) && len(storeSkuBindIDs) > 0 { - for _, bindID := range storeSkuBindIDs { - fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID]) - skuBind := &model.StoreSkuBind{} - skuBind.ID = bindID - dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask) - } - } - if (opType == AmendPruneOnlyPrune || opType == AmendPruneAll) && len(sku2Delete) > 0 { _, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { _, err = handler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList) @@ -673,21 +677,24 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v 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) + if !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 { + syncStatus := 0 + if remoteCatMap[v.VendorCatID] == 0 { + if !model.IsSyncStatusNew(v.StoreCatSyncStatus) { + syncStatus = model.SyncFlagNewMask + } + } else if isForceUpdate && !model.IsSyncStatusUpdate(v.StoreCatSyncStatus) { + syncStatus = model.SyncFlagModifiedMask + } + if syncStatus != 0 { + catBind := &model.StoreSkuCategoryMap{} + catBind.ID = v.MapID + dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, catBind, nil, ctx.GetUserName(), nil, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), syncStatus) + } } } } case 3: - if (opType == AmendPruneOnlyAmend || opType == AmendPruneAll) && len(storeCatBindIDs) > 0 { - for _, bindID := range storeCatBindIDs { - fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID]) - catBind := &model.StoreSkuCategoryMap{} - catBind.ID = bindID - dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, catBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask) - } - } - if (opType == AmendPruneOnlyPrune || opType == AmendPruneAll) && len(cat2Delete) > 0 { for i := 0; i < 2; i++ { level := 2 - i @@ -698,7 +705,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v } } if len(levelCat2Delete) > 0 { - task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除本地不存在的远程分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, + task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除商家分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { cat := batchItemList[0].(*partner.BareCategoryInfo) err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level) @@ -724,55 +731,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v // 把京西有,平台无且没有待创建标记的商品加上待创建标记 func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) { - return amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmendPruneOnlyAmend) - // handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) - // if handler == nil { - // return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID]) - // } - // db := dao.GetDB() - - // var storeSkuBindIDs []int - // seqTaskFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { - // switch step { - // case 0: - // localSkuList, err2 := dao.GetStoreSkus2(db, vendorID, storeID, nil, false) - // if err = err2; err != nil { - // return nil, err - // } - // remoteSkuList, err2 := handler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil) - // if err = err2; err == nil { - // remoteSkuMap := make(map[int]int) - // for _, value := range remoteSkuList { - // for _, skuInfo := range value.SkuList { - // remoteSkuMap[skuInfo.SkuID] = 1 - // } - // } - // for _, v := range localSkuList { - // if remoteSkuMap[v.SkuID] == 0 && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 { - // storeSkuBindIDs = append(storeSkuBindIDs, v.BindID) - // } - // } - // } - // case 1: - // if len(storeSkuBindIDs) > 0 { - // for _, bindID := range storeSkuBindIDs { - // fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID]) - // skuBind := &model.StoreSkuBind{} - // skuBind.ID = bindID - // dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask) - // } - // } - // } - // return nil, err - // } - // task := tasksch.NewSeqTask(fmt.Sprintf("处理京西门店商品加待创建标记:%s", model.VendorChineseNames[vendorID]), ctx, seqTaskFunc, 2) - // tasksch.HandleTask(task, parentTask, true).Run() - // if isAsync { - // hint = task.GetID() - // } else { - // _, err = task.GetResult(0) - // } - // return hint, err + return amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmendPruneOnlyAmend, false) } func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {