- 将同步任务的名字改为中文

This commit is contained in:
gazebo
2019-03-29 16:28:12 +08:00
parent 2010560bf9
commit 9ff9447813

View File

@@ -129,9 +129,10 @@ func (v *VendorSync) GetSingleStoreHandler(vendorID int) partner.ISingleStoreHan
return nil return nil
} }
func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, multiStoresHandler partner.IMultipleStoresHandler, db *dao.DaoDB, cats []*model.SkuCategory, userName string) (err error) { func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, db *dao.DaoDB, cats []*model.SkuCategory, userName string) (err error) {
syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[multiStoresHandler.GetVendorID()]) multiStoresHandler := v.GetMultiStoreHandler(vendorID)
task := tasksch.NewParallelTask("syncCategories", nil, ctx, syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
task := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[vendorID]), nil, ctx,
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
cat := batchItemList[0].(*model.SkuCategory) cat := batchItemList[0].(*model.SkuCategory)
updateFields := []string{syncStatusFieldName} updateFields := []string{syncStatusFieldName}
@@ -162,29 +163,30 @@ func (v *VendorSync) syncCategories(ctx *jxcontext.Context, parentTask tasksch.I
func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) { func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) {
globals.SugarLogger.Debug(v.MultiStoreVendorIDs) globals.SugarLogger.Debug(v.MultiStoreVendorIDs)
hint, err = v.LoopMultiStoresVendors(ctx, db, "SyncCategory", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { hint, err = v.LoopMultiStoresVendors(ctx, db, "同步分类信息", isAsync, userName,
multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int)) func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
var cats []*model.SkuCategory vendorID := batchItemList[0].(int)
cond := make(map[string]interface{}) var cats []*model.SkuCategory
if categoryID > 0 { cond := make(map[string]interface{})
cond[model.FieldID] = categoryID if categoryID > 0 {
} else { cond[model.FieldID] = categoryID
cond[model.FieldLevel] = 1 } else {
} cond[model.FieldLevel] = 1
err := dao.GetEntitiesByKV(db, &cats, cond, true) }
if err == nil { err := dao.GetEntitiesByKV(db, &cats, cond, true)
err = v.syncCategories(ctx, t, multiStoresHandler, db, cats, userName) if err == nil {
} err = v.syncCategories(ctx, t, vendorID, db, cats, userName)
if err != nil || categoryID > 0 { }
if err != nil || categoryID > 0 {
return nil, err
}
cond[model.FieldLevel] = 2
err = dao.GetEntitiesByKV(db, &cats, cond, true)
if err == nil {
err = v.syncCategories(ctx, t, vendorID, db, cats, userName)
}
return nil, err return nil, err
} })
cond[model.FieldLevel] = 2
err = dao.GetEntitiesByKV(db, &cats, cond, true)
if err == nil {
err = v.syncCategories(ctx, t, multiStoresHandler, db, cats, userName)
}
return nil, err
})
return "", err return "", err
} }
@@ -211,11 +213,11 @@ func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID,
vendorID, vendorID,
} }
} }
hint, err = v.LoopStoresMap(ctx, db, "SyncStore", isAsync, false, vendorIDs, []int{storeID}, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { hint, err = v.LoopStoresMap(ctx, db, "同步门店信息", isAsync, false, vendorIDs, []int{storeID}, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
handler := v.GetStoreHandler(loopMapInfo.VendorID) handler := v.GetStoreHandler(loopMapInfo.VendorID)
if len(loopMapInfo.StoreMapList) > 1 { if len(loopMapInfo.StoreMapList) > 1 {
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("SyncStore loop store %s", model.VendorChineseNames[loopMapInfo.VendorID]), nil, ctx, loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), nil, ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap) storeMap := batchItemList[0].(*model.StoreMap)
if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil { if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil {
@@ -240,182 +242,188 @@ func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID,
func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) { func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) {
globals.SugarLogger.Debugf("SyncSku trackInfo:%s, nameID:%d, skuID:%d, userName:%s", ctx.GetTrackInfo(), nameID, skuID, userName) globals.SugarLogger.Debugf("SyncSku trackInfo:%s, nameID:%d, skuID:%d, userName:%s", ctx.GetTrackInfo(), nameID, skuID, userName)
return v.LoopMultiStoresVendors(ctx, db, "SyncSku", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { return v.LoopMultiStoresVendors(ctx, db, "同步商品信息", isAsync, userName,
multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int)) func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[multiStoresHandler.GetVendorID()]) vendorID := batchItemList[0].(int)
dbField := dao.ConvertDBFieldPrefix(model.VendorNames[multiStoresHandler.GetVendorID()]) multiStoresHandler := v.GetMultiStoreHandler(vendorID)
sql := fmt.Sprintf(` syncStatusFieldName := dao.GetSyncStatusStructField(model.VendorNames[multiStoresHandler.GetVendorID()])
SELECT DISTINCT t2.* dbField := dao.ConvertDBFieldPrefix(model.VendorNames[multiStoresHandler.GetVendorID()])
FROM sku t1 sql := fmt.Sprintf(`
JOIN sku_name t2 ON t2.id = t1.name_id SELECT DISTINCT t2.*
WHERE t1.%s_sync_status <> 0 FROM sku t1
`, dbField) JOIN sku_name t2 ON t2.id = t1.name_id
sqlParams := []interface{}{} WHERE t1.%s_sync_status <> 0
if nameID != -1 { `, dbField)
sql += " AND t1.name_id = ?" sqlParams := []interface{}{}
sqlParams = append(sqlParams, nameID) if nameID != -1 {
} sql += " AND t1.name_id = ?"
if skuID != -1 { sqlParams = append(sqlParams, nameID)
sql += " AND t1.id = ?" }
sqlParams = append(sqlParams, skuID) if skuID != -1 {
sql += " AND t1.id = ?"
sqlParams = append(sqlParams, skuID)
} }
sql += " ORDER BY t2.id" sql += " ORDER BY t2.id"
var skuNameList []*model.SkuName var skuNameList []*model.SkuName
err := dao.GetRows(db, &skuNameList, sql, sqlParams...) err := dao.GetRows(db, &skuNameList, sql, sqlParams...)
if err == nil && len(skuNameList) > 0 { if err == nil && len(skuNameList) > 0 {
// todo 同一skuName下的sku顺序处理的原因是京东SPU特殊类型必须要序列化同步才能正常处理, db可能会有多线程问题 // todo 同一skuName下的sku顺序处理的原因是京东SPU特殊类型必须要序列化同步才能正常处理, db可能会有多线程问题
task := tasksch.NewParallelTask("SyncSku loop sku", tasksch.NewParallelConfig().SetParallelCount(10).SetIsContinueWhenError(isContinueWhenError), ctx, task := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetParallelCount(10).SetIsContinueWhenError(isContinueWhenError), ctx,
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
skuName := batchItemList[0].(*model.SkuName) skuName := batchItemList[0].(*model.SkuName)
var skuList []*model.Sku var skuList []*model.Sku
if err = dao.GetRows(db, &skuList, fmt.Sprintf(` if err = dao.GetRows(db, &skuList, fmt.Sprintf(`
SELECT * SELECT *
FROM sku FROM sku
WHERE name_id = ? AND %s_sync_status <> 0 WHERE name_id = ? AND %s_sync_status <> 0
ORDER BY IF(spec_unit IN('kg', 'L'), 1000, 1) * spec_quality ORDER BY IF(spec_unit IN('kg', 'L'), 1000, 1) * spec_quality
`, dbField), skuName.ID); err == nil && len(skuList) > 0 { `, dbField), skuName.ID); err == nil && len(skuList) > 0 {
for _, sku := range skuList { for _, sku := range skuList {
syncStatus := refutil.GetObjFieldByName(sku, syncStatusFieldName).(int8) syncStatus := refutil.GetObjFieldByName(sku, syncStatusFieldName).(int8)
globals.SugarLogger.Debugf("SyncSku trackInfo:%s, skuID:%d, syncStatus:%d", ctx.GetTrackInfo(), sku.ID, syncStatus) globals.SugarLogger.Debugf("SyncSku trackInfo:%s, skuID:%d, syncStatus:%d", ctx.GetTrackInfo(), sku.ID, syncStatus)
if (skuID == -1 || skuID == sku.ID) && (syncStatus != 0) { if (skuID == -1 || skuID == sku.ID) && (syncStatus != 0) {
updateFields := []string{syncStatusFieldName} updateFields := []string{syncStatusFieldName}
if syncStatus&model.SyncFlagDeletedMask != 0 { // 删除 if syncStatus&model.SyncFlagDeletedMask != 0 { // 删除
if syncStatus&model.SyncFlagNewMask == 0 { if syncStatus&model.SyncFlagNewMask == 0 {
err = multiStoresHandler.DeleteSku(db, sku, userName) err = multiStoresHandler.DeleteSku(db, sku, userName)
}
} else if syncStatus&model.SyncFlagNewMask != 0 { // 新增
if err = multiStoresHandler.CreateSku(db, sku, userName); err == nil {
var tmpStruct struct {
MaxIndex int
} }
// todo hard code 得到京东spu中sku的顺序以方便以后修改销售属性这个必须要每次重新从数据库取 } else if syncStatus&model.SyncFlagNewMask != 0 { // 新增
if dao.GetRow(db, &tmpStruct, "SELECT MAX(sku_index) max_index FROM sku WHERE name_id = ? AND jd_id > 0 AND jd_id < 4024012631406 ", sku.NameID) == nil { if err = multiStoresHandler.CreateSku(db, sku, userName); err == nil {
sku.SkuIndex = tmpStruct.MaxIndex + 1 var tmpStruct struct {
updateFields = append(updateFields, "SkuIndex") MaxIndex int
}
// todo hard code 得到京东spu中sku的顺序以方便以后修改销售属性这个必须要每次重新从数据库取
if dao.GetRow(db, &tmpStruct, "SELECT MAX(sku_index) max_index FROM sku WHERE name_id = ? AND jd_id > 0 AND jd_id < 4024012631406 ", sku.NameID) == nil {
sku.SkuIndex = tmpStruct.MaxIndex + 1
updateFields = append(updateFields, "SkuIndex")
}
updateFields = append(updateFields, dao.GetVendorThingIDStructField(model.VendorNames[multiStoresHandler.GetVendorID()]))
} }
updateFields = append(updateFields, dao.GetVendorThingIDStructField(model.VendorNames[multiStoresHandler.GetVendorID()])) } else if syncStatus&model.SyncFlagModifiedMask != 0 { // 修改
err = multiStoresHandler.UpdateSku(db, sku, userName)
} }
} else if syncStatus&model.SyncFlagModifiedMask != 0 { // 修改 if err == nil {
err = multiStoresHandler.UpdateSku(db, sku, userName) refutil.SetObjFieldByName(sku, syncStatusFieldName, int8(0))
} if _, err = dao.UpdateEntity(db, sku, updateFields...); err != nil {
if err == nil { break
refutil.SetObjFieldByName(sku, syncStatusFieldName, int8(0)) }
if _, err = dao.UpdateEntity(db, sku, updateFields...); err != nil {
break
} }
} }
} }
} }
} if err == nil {
if err == nil { refutil.SetObjFieldByName(skuName, syncStatusFieldName, int8(0))
refutil.SetObjFieldByName(skuName, syncStatusFieldName, int8(0)) _, err = dao.UpdateEntity(db, skuName, syncStatusFieldName)
_, err = dao.UpdateEntity(db, skuName, syncStatusFieldName) }
} return nil, err
return nil, err }, skuNameList)
}, skuNameList) t.AddChild(task).Run()
t.AddChild(task).Run() _, err = task.GetResult(0)
_, err = task.GetResult(0) }
} return nil, err
return nil, err })
})
} }
func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync bool) (hint string, err error) { func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync bool) (hint string, err error) {
globals.SugarLogger.Debug("SyncStoresCategory") globals.SugarLogger.Debug("SyncStoresCategory")
isManageIt := len(storeIDs) != 1 isManageIt := len(storeIDs) != 1
return v.LoopStoresMap(ctx, db, "SyncStoresCategory", isAsync, isManageIt, vendorIDs, storeIDs, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { return v.LoopStoresMap(ctx, db, "同步门店分类信息", isAsync, isManageIt, vendorIDs, storeIDs,
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
if handler := v.GetSingleStoreHandler(loopMapInfo.VendorID); handler != nil { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
if len(loopMapInfo.StoreMapList) > 1 { if handler := v.GetSingleStoreHandler(loopMapInfo.VendorID); handler != nil {
loopStoreTask := tasksch.NewSeqTask("SyncStoresCategory loop stores", ctx, if len(loopMapInfo.StoreMapList) > 1 {
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { loopStoreTask := tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
storeID := loopMapInfo.StoreMapList[step].StoreID func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
_, err = handler.SyncStoreCategory(ctx, task, storeID, false) storeID := loopMapInfo.StoreMapList[step].StoreID
return nil, err _, err = handler.SyncStoreCategory(ctx, task, storeID, false)
}, len(loopMapInfo.StoreMapList)) return nil, err
t.AddChild(loopStoreTask).Run() }, len(loopMapInfo.StoreMapList))
_, err = loopStoreTask.GetResult(0) t.AddChild(loopStoreTask).Run()
return nil, err _, err = loopStoreTask.GetResult(0)
return nil, err
}
_, err = handler.SyncStoreCategory(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false)
} }
_, err = handler.SyncStoreCategory(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false) return nil, err
} })
return nil, err
})
} }
// //
func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debug("SyncStoresSkus") globals.SugarLogger.Debug("SyncStoresSkus")
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8 isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
return v.LoopStoresMap(ctx, db, "SyncStoresSkus顶层", isAsync, isManageIt, vendorIDs, storeIDs, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { return v.LoopStoresMap(ctx, db, "同步门店商品信息", isAsync, isManageIt, vendorIDs, storeIDs,
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
if len(loopMapInfo.StoreMapList) > 1 { if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
loopStoreTask := tasksch.NewSeqTask("SyncStoresSkus相同平台循环门店", ctx, if len(loopMapInfo.StoreMapList) > 1 {
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { loopStoreTask := tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
storeID := loopMapInfo.StoreMapList[step].StoreID func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
if _, err = handler.SyncStoreSkus(ctx, task, storeID, skuIDs, false, isContinueWhenError); err != nil { storeID := loopMapInfo.StoreMapList[step].StoreID
globals.SugarLogger.Debugf("SyncStoresSkus failed1 store:%d failed with error:%v", storeID, err) if _, err = handler.SyncStoreSkus(ctx, task, storeID, skuIDs, false, isContinueWhenError); err != nil {
if isContinueWhenError { globals.SugarLogger.Debugf("SyncStoresSkus failed1 store:%d failed with error:%v", storeID, err)
err = nil if isContinueWhenError {
err = nil
}
} }
} return nil, err
return nil, err }, len(loopMapInfo.StoreMapList))
}, len(loopMapInfo.StoreMapList)) t.AddChild(loopStoreTask).Run()
t.AddChild(loopStoreTask).Run() _, err = loopStoreTask.GetResult(0)
_, err = loopStoreTask.GetResult(0) return nil, err
return nil, err }
_, err = handler.SyncStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, skuIDs, false, isContinueWhenError)
} }
_, err = handler.SyncStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, skuIDs, false, isContinueWhenError) return nil, err
} })
return nil, err
})
} }
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debug("FullSyncStoresSkus") globals.SugarLogger.Debug("FullSyncStoresSkus")
return v.LoopStoresMap(ctx, db, "FullSyncStoresSkus顶层", isAsync, true, vendorIDs, storeIDs, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { return v.LoopStoresMap(ctx, db, "初始化门店商品信息", isAsync, true, vendorIDs, storeIDs,
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
if len(loopMapInfo.StoreMapList) > 1 { if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
loopStoreTask := tasksch.NewSeqTask("FullSyncStoresSkus相同平台循环门店", ctx, if len(loopMapInfo.StoreMapList) > 1 {
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { loopStoreTask := tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
storeID := loopMapInfo.StoreMapList[step].StoreID func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
_, err = handler.FullSyncStoreSkus(ctx, task, storeID, false, isContinueWhenError) storeID := loopMapInfo.StoreMapList[step].StoreID
return nil, err _, err = handler.FullSyncStoreSkus(ctx, task, storeID, false, isContinueWhenError)
}, len(loopMapInfo.StoreMapList)) return nil, err
t.AddChild(loopStoreTask).Run() }, len(loopMapInfo.StoreMapList))
_, err = loopStoreTask.GetResult(0) t.AddChild(loopStoreTask).Run()
return nil, err _, err = loopStoreTask.GetResult(0)
return nil, err
}
_, err = handler.FullSyncStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false, isContinueWhenError)
} }
_, err = handler.FullSyncStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false, isContinueWhenError) return nil, err
} })
return nil, err
})
} }
func (v *VendorSync) DeleteRemoteStoreSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { func (v *VendorSync) DeleteRemoteStoreSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debug("DeleteRemoteStoreSkus") globals.SugarLogger.Debug("DeleteRemoteStoreSkus")
return v.LoopStoresMap(ctx, db, "DeleteRemoteStoreSkus顶层", isAsync, true, vendorIDs, storeIDs, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { return v.LoopStoresMap(ctx, db, "删除远程门店商品信息", isAsync, true, vendorIDs, storeIDs,
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
if len(loopMapInfo.StoreMapList) > 1 { if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
loopStoreTask := tasksch.NewSeqTask("DeleteRemoteStoreSkus相同平台循环门店", ctx, if len(loopMapInfo.StoreMapList) > 1 {
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { loopStoreTask := tasksch.NewSeqTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), ctx,
storeID := loopMapInfo.StoreMapList[step].StoreID func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
_, err = handler.DeleteRemoteStoreSkus(ctx, task, storeID, false, isContinueWhenError) storeID := loopMapInfo.StoreMapList[step].StoreID
return nil, err _, err = handler.DeleteRemoteStoreSkus(ctx, task, storeID, false, isContinueWhenError)
}, len(loopMapInfo.StoreMapList)) return nil, err
t.AddChild(loopStoreTask).Run() }, len(loopMapInfo.StoreMapList))
_, err = loopStoreTask.GetResult(0) t.AddChild(loopStoreTask).Run()
return nil, err _, err = loopStoreTask.GetResult(0)
return nil, err
}
_, err = handler.DeleteRemoteStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false, isContinueWhenError)
} }
_, err = handler.DeleteRemoteStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false, isContinueWhenError) return nil, err
} })
return nil, err
})
} }
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc) (hint string, err error) { func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc) (hint string, err error) {
@@ -457,6 +465,9 @@ func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskNa
} }
index++ index++
} }
if len(loopInfoList) == 1 {
taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID])
}
task := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) task := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
tasksch.HandleTask(task, nil, isManageIt).Run() tasksch.HandleTask(task, nil, isManageIt).Run()
if !isAsync { if !isAsync {