From 55fdde9be29512dba11e350fac94fa3802d7760a Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 3 Dec 2019 18:27:53 +0800 Subject: [PATCH] =?UTF-8?q?LoopMultiStoresVendors=E5=BC=95=E5=85=A5OrgCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 36 +++++++++++++++++++++------- business/partner/partner_api.go | 1 - business/partner/purchase/jd/jd.go | 4 ++-- globals/api/apimanager/apimanager.go | 12 ---------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 543c09ca6..14498bcfa 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -38,6 +38,11 @@ type SingleStoreHandlerWrapper struct { partner.ISingleStoreHandler } +type tMultiStoreVendorInfo struct { + VendorID int + OrgCode string +} + var ( CurVendorSync VendorSync ) @@ -96,6 +101,20 @@ func (v *VendorSync) GetSingleStoreHandler(vendorID int) partner.ISingleStoreHan return nil } +func getMultiStoreVendorInfoList() (list []*tMultiStoreVendorInfo) { + vendorIDs := partner.GetMultiStoreVendorIDs() + for _, vendorID := range vendorIDs { + orgCodeList := partner.CurAPIManager.GetAppOrgCodeList(vendorID) + for _, v := range orgCodeList { + list = append(list, &tMultiStoreVendorInfo{ + VendorID: vendorID, + OrgCode: v, + }) + } + } + return list +} + func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, db *dao.DaoDB, cats []*model.SkuCategory, userName string) (err error) { multiStoresHandler := v.GetMultiStoreHandler(vendorID) syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[vendorID]) @@ -132,7 +151,7 @@ func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categor globals.SugarLogger.Debug("SyncCategory") hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步分类信息:%d", categoryID), isAsync, false, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { - vendorID := batchItemList[0].(int) + vendorInfo := batchItemList[0].(*tMultiStoreVendorInfo) var cats []*model.SkuCategory cond := make(map[string]interface{}) if categoryID > 0 { @@ -142,7 +161,7 @@ func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categor } err := dao.GetEntitiesByKV(db, &cats, cond, true) if err == nil { - err = v.syncCategories(ctx, t, vendorID, db, cats, userName) + err = v.syncCategories(ctx, t, vendorInfo.VendorID, db, cats, userName) } if err != nil || categoryID > 0 { return nil, err @@ -150,7 +169,7 @@ func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categor cond[model.FieldLevel] = 2 err = dao.GetEntitiesByKV(db, &cats, cond, true) if err == nil { - err = v.syncCategories(ctx, t, vendorID, db, cats, userName) + err = v.syncCategories(ctx, t, vendorInfo.VendorID, db, cats, userName) } return nil, err }) @@ -159,7 +178,8 @@ func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categor func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) { hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("分类重排序:%d", categoryID), isAsync, false, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { - multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int)) + vendorInfo := batchItemList[0].(*tMultiStoreVendorInfo) + multiStoresHandler := v.GetMultiStoreHandler(vendorInfo.VendorID) err2 := multiStoresHandler.ReorderCategories(db, categoryID, userName) if err2 == nil { cat := &model.SkuCategory{} @@ -236,8 +256,8 @@ func (v *VendorSync) SyncSkus(ctx *jxcontext.Context, db *dao.DaoDB, nameIDs []i return v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步商品信息, nameIDs:%v, skuIDs:%v", nameIDs, skuIDs), isAsync, isManagedIt, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { var resultList []interface{} - vendorID := batchItemList[0].(int) - multiStoresHandler := v.GetMultiStoreHandler(vendorID) + vendorInfo := batchItemList[0].(*tMultiStoreVendorInfo) + multiStoresHandler := v.GetMultiStoreHandler(vendorInfo.VendorID) syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[multiStoresHandler.GetVendorID()]) dbField := dao.ConvertDBFieldPrefix(model.VendorNames[multiStoresHandler.GetVendorID()]) skuMap := make(map[int]bool) @@ -266,7 +286,7 @@ func (v *VendorSync) SyncSkus(ctx *jxcontext.Context, db *dao.DaoDB, nameIDs []i err := dao.GetRows(db, &skuNameList, sql, sqlParams...) if err == nil && len(skuNameList) > 0 { // todo 同一skuName下的sku顺序处理的原因是京东SPU特殊类型必须要序列化同步才能正常处理, db可能会有多线程问题 - task := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetParallelCount(10).SetIsContinueWhenError(isContinueWhenError), ctx, + task := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[vendorInfo.VendorID]), tasksch.NewParallelConfig().SetParallelCount(10).SetIsContinueWhenError(isContinueWhenError), ctx, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { var resultList []interface{} skuName := batchItemList[0].(*model.SkuName) @@ -562,7 +582,7 @@ func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskNa } func (v *VendorSync) LoopMultiStoresVendors(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, isManageIt bool, handler tasksch.WorkFunc) (hint string, err error) { - task := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, partner.GetMultiStoreVendorIDs()) + task := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, getMultiStoreVendorInfoList()) tasksch.HandleTask(task, nil, isManageIt).Run() if !isAsync { result, err2 := task.GetResult(0) diff --git a/business/partner/partner_api.go b/business/partner/partner_api.go index 3e1b15a17..386527933 100644 --- a/business/partner/partner_api.go +++ b/business/partner/partner_api.go @@ -2,7 +2,6 @@ package partner type IAPIManager interface { GetAPI(vendorID int, appOrgCode string) interface{} - GetAPIList(vendorID int) []interface{} GetAppOrgCodeList(vendorID int) (appOrgCodeList []string) } diff --git a/business/partner/purchase/jd/jd.go b/business/partner/purchase/jd/jd.go index 66b30d0f8..7e5e7740d 100644 --- a/business/partner/purchase/jd/jd.go +++ b/business/partner/purchase/jd/jd.go @@ -30,9 +30,9 @@ func GetAPIByToken(token string) (apiObj *jdapi.API) { if token == "" { apiObj = getAPI("") } else { - apiList := partner.CurAPIManager.GetAPIList(model.VendorIDJD) + apiList := partner.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD) for _, v := range apiList { - jdAPI := v.(*jdapi.API) + jdAPI := partner.CurAPIManager.GetAPI(model.VendorIDJD, v).(*jdapi.API) if jdAPI.GetToken() == token { apiObj = jdAPI break diff --git a/globals/api/apimanager/apimanager.go b/globals/api/apimanager/apimanager.go index 88d2c7ca6..6e62c34b6 100644 --- a/globals/api/apimanager/apimanager.go +++ b/globals/api/apimanager/apimanager.go @@ -38,18 +38,6 @@ func (a *APIManager) GetAPI(vendorID int, appOrgCode string) (pfAPI interface{}) return pfAPI } -func (a *APIManager) GetAPIList(vendorID int) (pfAPIList []interface{}) { - switch vendorID { - case model.VendorIDJD: - pfAPIList = []interface{}{api.JdAPI} - case model.VendorIDMTWM: - pfAPIList = []interface{}{api.MtwmAPI} - case model.VendorIDEBAI: - pfAPIList = []interface{}{api.EbaiAPI} - } - return pfAPIList -} - func (a *APIManager) GetAppOrgCodeList(vendorID int) (appOrgCodeList []string) { switch vendorID { case model.VendorIDJD: