|
|
|
|
@@ -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)
|
|
|
|
|
|