From 1f1036b503f3afd20ec8cc014fcbc98ed92dabe8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 19 Dec 2019 09:55:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=8F=E6=99=9A=E8=87=AA=E5=8A=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=97=B6=EF=BC=8C=E5=85=A8=E9=87=8F=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=20=E7=94=A8AmendAndPruneStoreStuff=E6=9B=BF=E4=BB=A3PruneMissi?= =?UTF-8?q?ngStoreSkus=E4=B8=8EAddCreateFlagForJxStoreSku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 23 +++++++++++++ business/jxstore/misc/misc.go | 48 ++++++++++++++++++++++----- business/model/dao/store_sku_test.go | 8 +++++ controllers/cms_sync.go | 26 +++++++++++++-- routers/commentsRouter_controllers.go | 9 +++++ 5 files changed, 103 insertions(+), 11 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 894c6796d..017a865dd 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -538,6 +538,29 @@ func (v *VendorSync) AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, vendorID return hint, makeSyncError(err) } +func (v *VendorSync) AmendAndPruneStoreStuff(ctx *jxcontext.Context, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool, optType int, isForceUpdate bool) (hint string, err error) { + globals.SugarLogger.Debug("AmendAndPruneStoreStuff") + hint, err = v.LoopStoresMap(ctx, dao.GetDB(), fmt.Sprintf("处理京西平台商家分类与商品差异:%v", storeIDs), isAsync, true, vendorIDs, storeIDs, + func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) { + loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) + if len(loopMapInfo.StoreMapList) > 1 { + loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), + tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(5), ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + storeMap := batchItemList[0].(*model.StoreMap) + _, err = amendAndPruneStoreStuff(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError, optType, isForceUpdate) + return nil, err + }, loopMapInfo.StoreMapList) + t.AddChild(loopStoreTask).Run() + _, err = loopStoreTask.GetResult(0) + } else { + _, err = amendAndPruneStoreStuff(ctx, t, loopMapInfo.VendorID, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, false, isContinueWhenError, optType, isForceUpdate) + } + return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) + }, isContinueWhenError) + return hint, makeSyncError(err) +} + func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) { var storeMapList []*model.StoreMap if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 7f51a3b3c..6fa55f25e 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -9,6 +9,7 @@ import ( "git.rosy.net.cn/jx-callback/business/jxstore/report" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/baseapi/utils/errlist" "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" "git.rosy.net.cn/jx-callback/business/jxstore/act" @@ -159,20 +160,49 @@ func Init() { } } -func doDailyWork() { - globals.SugarLogger.Debug("doDailyWork") - cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true) - netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true) +func syncStoreSku() { syncFlag := model.SyncFlagPriceMask if (time.Now().Unix()/24*3600)%10 == 0 { syncFlag |= model.SyncFlagSaleMask } - // cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, nil, []int{27379}, syncFlag, true, true) - cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, []int{27379}, true, true) + task := tasksch.NewParallelTask("同步京西与平台数据", nil, jxcontext.AdminCtx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + step := batchItemList[0].(int) + errList := errlist.New() + switch step { + case 0: + _, err = cms.CurVendorSync.LoopMultiStoresVendors(jxcontext.AdminCtx, dao.GetDB(), "同步多门店平台商品库", false, true, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + vendorInfo := batchItemList[0].(*cms.MultiStoreVendorInfo) + _, err = cms.FullSyncVendorStuff(jxcontext.AdminCtx, task, vendorInfo.VendorID, vendorInfo.OrgCode, false, true) + return retVal, err + }) + errList.AddErr(err) - SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID) - taskID, _ := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDEBAI, model.VendorIDMTWM}, nil, false, nil, nil, syncFlag, true, true) - SaveImportantTaskID(TaskNameSyncStoreSku, taskID) + // cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), partner.GetMultiStoreVendorIDs(), nil, false, nil, []int{27379}, syncFlag, true, true) + _, err = cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), partner.GetMultiStoreVendorIDs(), nil, false, []int{27379}, true, true) + errList.AddErr(err) + case 1: + _, err = cms.CurVendorSync.AmendAndPruneStoreStuff(jxcontext.AdminCtx, partner.GetSingleStoreVendorIDs(), nil, false, true, cms.AmendPruneAll, false) + errList.AddErr(err) + + SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID) + taskID, err2 := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), partner.GetSingleStoreVendorIDs(), nil, false, nil, nil, syncFlag, true, true) + errList.AddErr(err2) + SaveImportantTaskID(TaskNameSyncStoreSku, taskID) + } + err = errList.GetErrListAsOne() + return retVal, err + }, []int{0, 1}) + tasksch.HandleTask(task, nil, true).Run() +} + +func doDailyWork() { + globals.SugarLogger.Debug("doDailyWork") + cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true) + netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true) + + syncStoreSku() InitEx() diff --git a/business/model/dao/store_sku_test.go b/business/model/dao/store_sku_test.go index d787bb8c6..cf9e569d8 100644 --- a/business/model/dao/store_sku_test.go +++ b/business/model/dao/store_sku_test.go @@ -15,3 +15,11 @@ func TestGetFullStoreSkus(t *testing.T) { } globals.SugarLogger.Debug(utils.Format4Output(skuList, false)) } + +func TestGetStoreSkus(t *testing.T) { + skuList, err := GetStoreSkus(GetDB(), model.VendorIDMTWM, 100134, nil) + if err != nil { + t.Fatal(err) + } + globals.SugarLogger.Debug(utils.Format4Output(skuList, false)) +} diff --git a/controllers/cms_sync.go b/controllers/cms_sync.go index fd0dd2524..238f4e07a 100644 --- a/controllers/cms_sync.go +++ b/controllers/cms_sync.go @@ -205,7 +205,7 @@ func (c *SyncController) SyncSkuNames() { } // @Title 删除本地没有的平台门店商品信息 -// @Description 删除本地没有的平台门店商品信息 +// @Description 删除本地没有的平台门店商品信息(已废弃) // @Param token header string true "认证token" // @Param storeIDs query string true "门店ID列表" // @Param vendorIDs query string true "厂商ID列表" @@ -225,7 +225,7 @@ func (c *SyncController) PruneMissingStoreSkus() { } // @Title 把京西有,平台无且没有待创建标记的商品加上待创建标记 -// @Description 把京西有,平台无且没有待创建标记的商品加上待创建标记 +// @Description 把京西有,平台无且没有待创建标记的商品加上待创建标记(已废弃) // @Param token header string true "认证token" // @Param storeIDs formData string false "门店ID列表" // @Param vendorIDs formData string false "运营商ID列表(京东0 美团1 饿百3)" @@ -244,6 +244,28 @@ func (c *SyncController) AddCreateFlagForJxStoreSku() { }) } +// @Title 把京西有,平台无且没有待创建标记的商品加上待创建标记 +// @Description 把京西有,平台无且没有待创建标记的商品加上待创建标记 +// @Param token header string true "认证token" +// @Param storeIDs formData string false "门店ID列表" +// @Param vendorIDs formData string false "运营商ID列表(京东0 美团1 饿百3)" +// @Param optType formData int true "操作方式" +// @Param isForce formData bool false "是否强制刷新" +// @Param isAsync formData bool false "是否异步操作" +// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /AmendAndPruneStoreStuff [post] +func (c *SyncController) AmendAndPruneStoreStuff() { + c.callAmendAndPruneStoreStuff(func(params *tSyncAmendAndPruneStoreStuffParams) (retVal interface{}, errCode string, err error) { + var storeIDs, vendorIDs []int + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err == nil { + retVal, err = cms.CurVendorSync.AmendAndPruneStoreStuff(params.Ctx, vendorIDs, storeIDs, params.IsAsync, params.IsContinueWhenError, params.OptType, params.IsForce) + } + return retVal, "", err + }) +} + // @Title 初始化多门店平台商品库(及商家分类) // @Description 初始化多门店平台商品库(及商家分类) // @Param token header string true "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 6f94c278f..00a0509f9 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1764,6 +1764,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"], + beego.ControllerComments{ + Method: "AmendAndPruneStoreStuff", + Router: `/AmendAndPruneStoreStuff`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"], beego.ControllerComments{ Method: "DeleteRemoteStoreSkus",