From e925327e8a1509eb0a38cfe776783608c37d89a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 15 Jan 2020 13:56:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=8C=E6=AD=A5=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=BA=93=E9=94=99=E8=AF=AF=E8=BF=94=E5=9B=9E=EF=BC=88?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 38 +++++++++++++++++++---------------- business/jxstore/cms/sync2.go | 19 ++++++++++++++++++ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 140eea868..d401bf3cc 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -621,23 +621,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, parentTask tasksch.I } task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList) if isAsync { - task.SetFinishHook(func(task tasksch.ITask) { - var noticeMsg string - if ctx.GetUserName() != "jxadmin" { - if len(task.GetFailedList()) > 10 { - downloadURL, _, _ := WirteToExcelBySyncFailed(task) - noticeMsg = "您此次的同步任务错误详情返回如下: " - noticeMsg += fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL) - } else if len(task.GetFailedList()) > 0 && len(task.GetFailedList()) <= 10 { - if task.GetErr() != nil { - noticeMsg = utils.Format4Output(buildErrMsgJson(task), true) - } - } - if authInfo, err := ctx.GetV2AuthInfo(); err == nil { - ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg) - } - } - }) + buildSetFinishHook(task, ctx) } tasksch.HandleTask(task, parentTask, isManageIt).Run() if !isAsync { @@ -658,6 +642,26 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, parentTask tasksch.I return task, hint, err } +func buildSetFinishHook(task tasksch.ITask, ctx *jxcontext.Context) { + task.SetFinishHook(func(task tasksch.ITask) { + var noticeMsg string + if ctx.GetUserName() != "jxadmin" { + if len(task.GetFailedList()) > 10 { + downloadURL, _, _ := WirteToExcelBySyncFailed(task) + noticeMsg = "您此次的同步任务错误详情返回如下: " + noticeMsg += fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL) + } else if len(task.GetFailedList()) > 0 && len(task.GetFailedList()) <= 10 { + if task.GetErr() != nil { + noticeMsg = utils.Format4Output(buildErrMsgJson(task), true) + } + } + if authInfo, err := ctx.GetV2AuthInfo(); err == nil { + ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg) + } + } + }) +} + func buildErrMsg(task tasksch.ITask) (err error) { err = fmt.Errorf(utils.Format4Output(buildErrMsgJson(task), true)) return makeSpecSyncError(err) diff --git a/business/jxstore/cms/sync2.go b/business/jxstore/cms/sync2.go index c4adde26d..a8f16de87 100644 --- a/business/jxstore/cms/sync2.go +++ b/business/jxstore/cms/sync2.go @@ -137,6 +137,7 @@ func SyncSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int, task := tasksch.NewParallelTask(fmt.Sprintf("同步商品:%v,%v", nameIDs, skuIDs), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { skuVendorInfo := batchItemList[0].(*dao.StoreSkuSyncInfo) + var failedList []*partner.StoreSkuInfoWithErr if skuVendorInfo.VendorCatID == "" { return nil, fmt.Errorf("商品:%d的商家分类没有同步", skuVendorInfo.SkuID) } @@ -150,25 +151,43 @@ func SyncSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int, if !dao.IsVendorThingIDEmpty(skuVendorInfo.VendorSkuID) && model.IsSyncStatusNeedDelete(skuVendorInfo.SkuSyncStatus) { err = multiStoresHandler.DeleteSku2(ctx, skuVendorInfo.VendorOrgCode, storeSkuSyncInfo2Bare(skuVendorInfo)) + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(skuVendorInfo, err, 0, skuVendorInfo.VendorID, "删除商品") + } } } else if model.IsSyncStatusNew(skuVendorInfo.SkuSyncStatus) { // 新增 err = multiStoresHandler.CreateSku2(ctx, skuVendorInfo) + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(skuVendorInfo, err, 0, skuVendorInfo.VendorID, "新增商品") + } } else if model.IsSyncStatusUpdate(skuVendorInfo.SkuSyncStatus) { // 修改 err = multiStoresHandler.UpdateSku2(ctx, skuVendorInfo) + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(skuVendorInfo, err, 0, skuVendorInfo.VendorID, "修改商品") + } } } else { err = fmt.Errorf("平台:%d不合法", skuVendorInfo.VendorID) } + if len(failedList) > 0 { + task.AddFailedList(failedList) + } if err = OnThingSync(ctx, dao.GetDB(), SkuVendor2ThingMap(skuVendorInfo), err); err == nil { retVal = []int{1} } return retVal, err }, skuList) + if isAsync { + buildSetFinishHook(task, ctx) + } tasksch.HandleTask(task, parentTask, len(skuList) == 0 || len(skuList) > 10).Run() if isAsync { hint = task.GetID() } else { resultList, err2 := task.GetResult(0) + if len(task.GetFailedList()) > 0 { + err2 = buildErrMsg(task) + } if err = err2; err == nil { hint = utils.Int2Str(len(resultList)) }