This commit is contained in:
苏尹岚
2021-01-27 17:57:20 +08:00
parent 7772f9bfaa
commit 812ad592f2
6 changed files with 52 additions and 17 deletions

View File

@@ -264,7 +264,7 @@ func getThingMap(db *dao.DaoDB, thingMap *model.ThingMap) (err error) {
return dao.GetEntity(db, thingMap, "ThingID", "ThingType", "VendorID", "VendorOrgCode", model.FieldDeletedAt)
}
func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*MultiStoreVendorInfo, thingID int64, thingType int8) (err error) {
func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*MultiStoreVendorInfo, thingID int64, thingType, syncFlag int8) (err error) {
if thingType == model.ThingTypeSkuName {
return nil
}
@@ -278,7 +278,7 @@ func OnCreateThing(ctx *jxcontext.Context, db *dao.DaoDB, vendorInfoList []*Mult
ThingType: thingType,
VendorID: v.VendorID,
VendorOrgCode: v.OrgCode,
SyncStatus: model.SyncFlagNewMask,
SyncStatus: syncFlag,
}
dao.WrapAddIDCULDEntity(thingMap, ctx.GetUserName())
if err2 := dao.CreateEntity(db, thingMap); err2 != nil {
@@ -445,7 +445,7 @@ func updateThingMapEntity(db *dao.DaoDB, thingMap *model.ThingMap) {
// }
}
func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) {
func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) {
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
if handler == nil {
return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID])
@@ -496,7 +496,21 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
})
}
}
StoreSkuMap := make(map[int]*dao.StoreSkuSyncInfo)
if storeID != 0 {
skuList2, _ := dao.GetStoreSkuListWithVendor(db, storeID, vendorID, vendorOrgCode)
for _, v := range skuList2 {
if _, ok := StoreSkuMap[v.ID]; !ok {
StoreSkuMap[v.ID] = v
}
}
}
getSyncFlag := func(skuID int) int8 {
if StoreSkuMap[skuID] != nil {
return model.SyncFlagNewMask
}
return 0
}
if opType == AmendPruneOnlyAmend || opType == AmendPruneAll {
for _, v := range localSkuList {
if v.ExdSkuID == "" {
@@ -504,14 +518,17 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
if !model.IsSyncStatusDelete(v.SkuSyncStatus) {
if remoteSkuMap[v.VendorSkuID] == 0 {
if !model.IsSyncStatusNew(v.SkuSyncStatus) {
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku)
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku, getSyncFlag(v.SkuID))
}
} else if isForceUpdate {
OnUpdateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku)
}
}
} else {
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku)
//表示根据某门店的门店商品同步京东商品库中这个门店关注并可售了这个商品插到thingmap里同步标志是待创建SyncFlagNewMask才会创建
//若该门店没关注可售那插到thingmap里的话就该同步标志为0就不会创建
//getSyncFlag
OnCreateThing(ctx, db, vendorInfo, int64(v.SkuID), model.ThingTypeSku, getSyncFlag(v.SkuID))
}
}
}
@@ -550,14 +567,14 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
if !model.IsSyncStatusDelete(v.CatSyncStatus) {
if remoteCatMap[v.VendorCatID] == 0 {
if !model.IsSyncStatusNew(v.CatSyncStatus) {
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory)
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory, model.SyncFlagNewMask)
}
} else if isForceUpdate && !model.IsSyncStatusUpdate(v.CatSyncStatus) {
OnUpdateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory)
}
}
} else {
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory)
OnCreateThing(ctx, db, vendorInfo, int64(v.ID), model.ThingTypeCategory, model.SyncFlagNewMask)
}
}
}
@@ -598,7 +615,7 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
return hint, err
}
func FullSyncVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool) (hint string, err error) {
func FullSyncVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool) (hint string, err error) {
multiStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
if multiStoreHandler == nil {
return "", fmt.Errorf("vendorID:%d不是多门店平台", vendorID)
@@ -608,7 +625,7 @@ func FullSyncVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
step := batchItemList[0].(int)
switch step {
case 0:
_, err = amendAndPruneVendorStuff(ctx, task, vendorID, vendorOrgCode, false, isContinueWhenError, AmendPruneAll, false)
_, err = amendAndPruneVendorStuff(ctx, task, storeID, vendorID, vendorOrgCode, false, isContinueWhenError, AmendPruneAll, false)
case 1:
_, err = SyncCategories(ctx, task, []int{vendorID}, []string{vendorOrgCode}, nil, false)
case 2: