From 4c9028330fa2281ca8bc5a1422a69fe974818d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Mon, 10 Feb 2020 17:47:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E7=BB=9F=E8=AE=A1=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/report/report.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/business/jxstore/report/report.go b/business/jxstore/report/report.go index 3df659e26..073a47914 100644 --- a/business/jxstore/report/report.go +++ b/business/jxstore/report/report.go @@ -258,17 +258,18 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn } dao.Commit(db) case 3: - dao.Begin(db) - defer func() { - if r := recover(); r != nil || err != nil { - dao.Rollback(db) - if r != nil { - panic(r) - } - } - }() priceReferSnapshotList, err = dao.GetPriceReferSnapshotNoPage(db, []int{0}, nil, nil, snapshotAt) - for _, v := range priceReferSnapshotList { + taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + dao.Begin(db) + defer func() { + if r := recover(); r != nil || err != nil { + dao.Rollback(db) + if r != nil { + panic(r) + } + } + }() + v := batchItemList[0].(*model.PriceReferSnapshot) for _, appOrg := range apimanager.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD) { directPrice, _ := jd.GetAPI(appOrg).GetJdSkuDirectPrice(v.SkuID) if directPrice == 0 { @@ -278,8 +279,12 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int, isAsyn dao.UpdateEntity(db, v, "JdDirectPrice") } } + dao.Commit(db) + return retVal, err } - dao.Commit(db) + taskParallel := tasksch.NewParallelTask("获取并更新京东指导价格", tasksch.NewParallelConfig(), ctx, taskFunc, priceReferSnapshotList) + tasksch.HandleTask(taskParallel, task, true).Run() + _, err = taskParallel.GetResult(0) } return result, err }