From 977b932d32802dc754c6ab07d51615da76d5f34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 15 Mar 2024 09:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B9=9D=E7=82=B9=E5=8D=8A?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E4=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E4=B8=8B=E7=BA=BF=E4=B8=94=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E7=BE=8E=E5=9B=A2=E9=97=A8=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 57 +++++++++++++++++++++++++-- business/partner/purchase/jd/store.go | 1 - 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 99e2e9de2..1f8e74631 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -219,7 +219,7 @@ func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB func (v *VendorSync) SyncStore2Time(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs, storeIDs []int, mustDirty, isAsync bool) (hint string, err error) { userName := ctx.GetUserName() isManageIt := len(storeIDs) == 0 || len(storeIDs) > 5 - _, hint, err = v.LoopStoresMap2(ctx, nil, db, fmt.Sprintf("同步门店信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, mustDirty, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) { + _, hint, err = v.LoopStoresMapNotDisable(ctx, nil, db, fmt.Sprintf("同步门店信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, mustDirty, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) { loopMapInfo := batchItemList[0].(*LoopStoreMapInfo) var failedList []*partner.StoreSkuInfoWithErr handler := v.GetStoreHandler(loopMapInfo.VendorID) @@ -234,9 +234,7 @@ func (v *VendorSync) SyncStore2Time(ctx *jxcontext.Context, db *dao.DaoDB, vendo if len(loopMapInfo.StoreMapList) > 1 { db2 = dao.GetDB() } - if storeMap.Status == model.StoreStatusDisabled { // 会出现已经禁用的门店还去调用下线操作,这儿给筛选一下 - resultList = append(resultList, 1) - } else if model.IsSyncStatusNew(storeMap.SyncStatus) { + if model.IsSyncStatusNew(storeMap.SyncStatus) { storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, storeMap.VendorID, storeMap.VendorOrgCode) if vendorStoreID, err = handler.CreateStore2(db2, storeMap.StoreID, userName, nil, storeDetail); err == nil { resultList = append(resultList, 1) @@ -811,6 +809,57 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, parentTask tasksch.I return task, hint, err } +// LoopStoresMapNotDisable 获取非禁用门店去同步上下线 +func (v *VendorSync) LoopStoresMapNotDisable(ctx *jxcontext.Context, parentTask tasksch.ITask, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, mustDirty bool, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) { + var storeMapList []*model.StoreMap + if storeMapList, err = dao.GetStoresMapList2(db, vendorIDs, storeIDs, []int{model.StoreStatusOpened, model.StoreStatusClosed, model.StoreStatusHaveRest}, model.StoreStatusAll, model.StoreIsSyncYes, "", "", "", mustDirty); err != nil { + return nil, "", err + } + if len(storeMapList) == 0 { + return nil, "", nil + } + vendorStoreMap := make(map[int][]*model.StoreMap) + for _, v := range storeMapList { + vendorStoreMap[v.VendorID] = append(vendorStoreMap[v.VendorID], v) + } + loopInfoList := make([]*LoopStoreMapInfo, len(vendorStoreMap)) + index := 0 + for k, v := range vendorStoreMap { + loopInfoList[index] = &LoopStoreMapInfo{ + VendorID: k, + StoreMapList: v, + } + 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) + if isAsync { + buildSetFinishHook(task, ctx) + } + tasksch.HandleTask(task, parentTask, isManageIt).Run() + if !isAsync { + resultList, err2 := task.GetResult(0) + if len(task.GetFailedList()) > 0 { + err2 = buildErrMsg(task) + err = err2 + } + if err = err2; err == nil { + if len(resultList) == 0 { + hint = "1" // todo 暂时这样 + } else { + hint = jxutils.TaskResult2Hint(resultList) + } + } + } else { + hint = task.GetID() + } + return task, hint, err +} + func buildSetFinishHook(task tasksch.ITask, ctx *jxcontext.Context) { task.SetFinishHook(func(task tasksch.ITask) { var noticeMsg = "您此次的同步任务错误详情返回如下: \n" diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index bcb0ca42a..eb2408e38 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -221,7 +221,6 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin } fillOpTimeParams(storeParams, store.GetOpTimeList()) errList := errlist.New() - globals.SugarLogger.Debugf("=========================1") if globals.EnableJdStoreWrite { store1 := fmt.Sprintf("门店id:%d,门店名称:%s,第三方门店状态:%d,本地修改前门店状态%d,本地门店修改后状态:%d,第三方平台Id(ebai):%s", storeID, store.Name, 100, store.Status, 100, store.VendorOrgCode) event.AddOperateEvent(jxcontext.AdminCtx, jxcontext.AdminCtx.GetTrackInfo(), store1, "", "", 10, "UpdateStore")