- refactor jd RefreshAllSkusID

This commit is contained in:
gazebo
2018-10-31 12:54:37 +08:00
parent 0e09f42468
commit bbccf09d02
3 changed files with 13 additions and 12 deletions

View File

@@ -259,6 +259,7 @@ func (p *PurchaseHandler) RefreshAllSkusID(ctx *jxcontext.Context, parentTask ta
db := dao.GetDB()
var skuPairs []*jdapi.SkuIDPair
const stepCount = 2
rootTask := tasksch.NewSeqTask("jd RefreshAllSkusID", ctx.GetUserName(), func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
@@ -270,10 +271,10 @@ func (p *PurchaseHandler) RefreshAllSkusID(ctx *jxcontext.Context, parentTask ta
`, utils.DefaultTimeValue)
default:
taskName := "RefreshAllSkusID update id"
if step == 1 {
if step != stepCount-1 {
taskName = "RefreshAllSkusID update uuid"
}
task1 := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx.GetUserName(), func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
task1 := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetBatchSize(jdapi.MaxBatchSize4BatchUpdateOutSkuId), ctx.GetUserName(), func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
skuPairs := make([]*jdapi.SkuIDPair, len(batchItemList))
for k, v := range batchItemList {
pair := v.(*jdapi.SkuIDPair)
@@ -281,11 +282,12 @@ func (p *PurchaseHandler) RefreshAllSkusID(ctx *jxcontext.Context, parentTask ta
SkuId: pair.SkuId,
OutSkuId: pair.OutSkuId,
}
if step == 1 {
if step != stepCount-1 {
skuPairs[k].OutSkuId = utils.GetUUID()
}
}
if globals.EnableStoreWrite {
globals.SugarLogger.Debug(utils.Format4Output(skuPairs, false))
if true { //globals.EnableStoreWrite {
_, err = api.JdAPI.BatchUpdateOutSkuId(skuPairs)
}
return nil, err
@@ -294,7 +296,7 @@ func (p *PurchaseHandler) RefreshAllSkusID(ctx *jxcontext.Context, parentTask ta
_, err = task1.GetResult(0)
}
return nil, err
}, 3)
}, stepCount)
ctx.SetTaskOrAddChild(rootTask, parentTask)
rootTask.Run()
if !isAsync {

View File

@@ -195,7 +195,7 @@ func (p *PurchaseHandler) GetAllStoresFromRemote() ([]*model.Store, error) {
func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
globals.SugarLogger.Debugf("jd RefreshAllStoresID")
const stepCount = 3
var stores []*tJdStoreInfo
db := dao.GetDB()
rootTask := tasksch.NewSeqTask("jd RefreshAllStoresID", ctx.GetUserName(), func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
@@ -209,7 +209,7 @@ func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask
`, utils.DefaultTimeValue, model.VendorIDJD, utils.DefaultTimeValue)
default:
taskName := "jd RefreshAllStoresID update outSystemId"
if step == 1 {
if step != stepCount-1 {
taskName = "jd RefreshAllStoresID update to uuid"
}
task1 := tasksch.NewParallelTask(taskName, nil, ctx.GetUserName(), func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
@@ -217,7 +217,7 @@ func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask
storeParams := map[string]interface{}{
"outSystemId": utils.Int2Str(int(store.ID)),
}
if step == 1 {
if step != stepCount-1 {
storeParams["outSystemId"] = utils.GetUUID()
}
if true { //globals.EnableStoreWrite {
@@ -229,7 +229,7 @@ func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask
_, err = task1.GetResult(0)
}
return nil, err
}, 3)
}, stepCount)
ctx.SetTaskOrAddChild(rootTask, parentTask)
rootTask.Run()