diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 06a31c268..ba50d9730 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -530,7 +530,19 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa if err = dao.GetEntity(db, store); err != nil { return 0, err } + valid := dao.StrictMakeMapByStructObject(payload, store, userName) + if payload["lng"] != nil || payload["lat"] != nil { + intLng := jxutils.StandardCoordinate2Int(utils.Interface2Float64WithDefault(payload["lng"], 0.0)) + intLat := jxutils.StandardCoordinate2Int(utils.Interface2Float64WithDefault(payload["lat"], 0.0)) + if intLng != 0 && intLng != store.Lng { + valid["lng"] = intLng + } + if intLat != 0 && intLat != store.Lng { + valid["lat"] = intLat + } + } + if valid["originalName"] != nil { delete(valid, "originalName") } @@ -589,18 +601,15 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa "address", "deliveryRange", } { - if payload[v] != nil { + if valid[v] != nil { syncStatus |= model.SyncFlagStoreAddress break } } - var lng, lat float64 - if payload["lng"] != nil || payload["lat"] != nil { - lng = utils.Interface2Float64WithDefault(payload["lng"], 0.0) - lat = utils.Interface2Float64WithDefault(payload["lat"], 0.0) - valid["lng"] = jxutils.StandardCoordinate2Int(lng) - valid["lat"] = jxutils.StandardCoordinate2Int(lat) + if valid["status"] != nil { + syncStatus |= model.SyncFlagStoreStatus } + if valid["deliveryRange"] != nil { valid["deliveryRange"] = strings.Trim(valid["deliveryRange"].(string), ";") } @@ -830,7 +839,11 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor if err = dao.GetEntity(db, storeMap, model.FieldStoreID, model.FieldVendorID, model.FieldDeletedAt); err != nil { return 0, err } + syncStatus := model.SyncFlagModifiedMask valid := dao.StrictMakeMapByStructObject(payload, storeMap, userName) + if valid["status"] != nil { + syncStatus |= model.SyncFlagStoreStatus + } if valid["pricePercentagePack"] != nil { if pricePercentagePack := utils.Interface2String(valid["pricePercentagePack"]); pricePercentagePack != "" { _, err2 := dao.QueryConfigs(db, pricePercentagePack, model.ConfigTypePricePack, "") @@ -857,7 +870,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeMap, valid, userName, map[string]interface{}{ model.FieldStoreID: storeID, model.FieldVendorID: vendorID, - }, model.FieldSyncStatus, model.SyncFlagModifiedMask) + }, model.FieldSyncStatus, syncStatus) } else { num, err = dao.UpdateEntityLogically(db, storeMap, valid, userName, map[string]interface{}{ model.FieldStoreID: storeID, diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 3428e9280..08f2cb326 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -349,7 +349,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo switch step { case 0: if len(deleteList) > 0 { - _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var successList []*partner.StoreSkuInfo if successList, err = singleStoreHandler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); singleStoreHandler.IsErrSkuNotExist(err) { err = nil @@ -365,7 +365,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo } case 1: if len(createList) > 0 { - _, err = putils.FreeBatchStoreSkuSyncInfo(func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuSyncInfo("创建门店商品", func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { var successList []*dao.StoreSkuSyncInfo if successList, err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); singleStoreHandler.IsErrSkuExist(err) { if skuNameList, err2 := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, []*partner.StoreSkuInfo{ @@ -392,7 +392,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo } case 2: if len(updateList) > 0 { - _, err = putils.FreeBatchStoreSkuSyncInfo(func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuSyncInfo("更新门店商品基础信息", func(task tasksch.ITask, batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, successCount int, err error) { var successList []*dao.StoreSkuSyncInfo if successList, err = singleStoreHandler.UpdateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { successList = batchedStoreSkuList @@ -406,7 +406,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo case 3: for k, list := range [][]*partner.StoreSkuInfo{stockList /*, onlineList*/} { if len(list) > 0 { - _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var successList []*partner.StoreSkuInfo if successList, err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { successList = batchedStoreSkuList @@ -421,12 +421,14 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo case 4, 5: statusList := onlineList status := model.SkuStatusNormal + name := "可售门店商品" if step == 5 { statusList = offlineList status = model.SkuStatusDontSale + name = "不可售门店商品" } if len(statusList) > 0 { - _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuInfo(name, func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var successList []*partner.StoreSkuInfo if successList, err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeID, vendorStoreID, batchedStoreSkuList, status); err == nil { successList = batchedStoreSkuList @@ -439,7 +441,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo } case 6: if len(priceList) > 0 { - _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { var successList []*partner.StoreSkuInfo if successList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { successList = batchedStoreSkuList @@ -473,7 +475,7 @@ func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, ven localSkuMap[v.SkuID] = v } var sku2Delete []*partner.StoreSkuInfo - task := tasksch.NewSeqTask(fmt.Sprintf("PruneMissingStoreSkus平台:%s", model.VendorChineseNames[vendorID]), ctx, + task := tasksch.NewSeqTask(fmt.Sprintf("清除平台:%s上多余的门店商品", model.VendorChineseNames[vendorID]), ctx, func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: @@ -490,7 +492,7 @@ func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, ven } case 1: if len(sku2Delete) > 0 { - _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { _, err = handler.DeleteStoreSkus(ctx, storeID, vendorStoreID, sku2Delete) return nil, 0, err }, ctx, parentTask, sku2Delete, handler.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus), isContinueWhenError) diff --git a/business/jxstore/misc/misc2.go b/business/jxstore/misc/misc2.go index 436a3f157..b8fb90dc4 100644 --- a/business/jxstore/misc/misc2.go +++ b/business/jxstore/misc/misc2.go @@ -166,14 +166,14 @@ func StartOrEndOpStore(isStart bool, vendorIDList []int, storeIDList []int, star baseapi.SugarLogger.Errorf("StartOrEndOpStore GetStoreSkusFullInfo error:%v storeID:%d vendorID:%d vendorStoreID:%s", err, storeID, vendorID, vendorStoreID) } else { SetSkuStock(isStart, storeSkuNameList) - SetSpecialSkuStatus(storeID, vendorID, vendorStoreID,storeSkuNameList) + SetSpecialSkuStatus(storeID, vendorID, vendorStoreID, storeSkuNameList) storeSkuList := putils.StoreSkuFullList2Bare(storeSkuNameList) if len(storeSkuList) > 0 { if !isStart { AddOrDelExtraStoreOptime(vendorID, storeID, vendorStoreID, &storeListValue.Store, startOpStoreTime, endOpStoreTime, false) } - _, err = putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { //var successList []*partner.StoreSkuInfo if _, err = singleStoreHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { //successList = batchedStoreSkuList diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index adb93c9c2..f860333cc 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -9,7 +9,6 @@ import ( "regexp" "sort" "strings" - "sync" "time" "io/ioutil" @@ -28,11 +27,6 @@ var ( skuNamePat *regexp.Regexp ) -type SyncMapWithTimeout struct { - sync.Map - timers sync.Map -} - type OrderSkuList []*model.OrderSku func (l OrderSkuList) Len() int { @@ -61,22 +55,6 @@ func init() { skuNamePat = regexp.MustCompile(`([\((\[【][^\((\[【\))\]】]*[\))\]】])?(.*?)([((].*[))])?\s*约?([1-9][\d\.]*)(g|G|kg|kG|Kg|KG|l|L|ml|mL|Ml|ML|克)\s*([((].*[))])?\s*(?:\/|/|)\s*([^\s()()]{0,2})\s*([((].*[))])?$`) } -func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) { - m.Map.Store(key, value) - m.timers.Store(key, utils.AfterFuncWithRecover(timeout, func() { - m.Delete(key) - })) -} - -func (m *SyncMapWithTimeout) Delete(key interface{}) { - m.Map.Delete(key) - if value, ok := m.timers.Load(key); ok { - timer := value.(*time.Timer) - timer.Stop() - } - m.timers.Delete(key) -} - func getJxStoreIDFromOrder(order *model.GoodsOrder) (retVal int) { if order.JxStoreID != 0 { return order.JxStoreID diff --git a/business/jxutils/jxutils_sync_map.go b/business/jxutils/jxutils_sync_map.go new file mode 100644 index 000000000..92827aea6 --- /dev/null +++ b/business/jxutils/jxutils_sync_map.go @@ -0,0 +1,29 @@ +package jxutils + +import ( + "sync" + "time" + + "git.rosy.net.cn/baseapi/utils" +) + +type SyncMapWithTimeout struct { + sync.Map + timers sync.Map +} + +func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) { + m.Map.Store(key, value) + m.timers.Store(key, utils.AfterFuncWithRecover(timeout, func() { + m.Delete(key) + })) +} + +func (m *SyncMapWithTimeout) Delete(key interface{}) { + m.Map.Delete(key) + if value, ok := m.timers.Load(key); ok { + timer := value.(*time.Timer) + timer.Stop() + } + m.timers.Delete(key) +} diff --git a/business/jxutils/tasksch/parallel_task.go b/business/jxutils/tasksch/parallel_task.go index e5e85c121..de62f3cf8 100644 --- a/business/jxutils/tasksch/parallel_task.go +++ b/business/jxutils/tasksch/parallel_task.go @@ -130,9 +130,7 @@ func (task *ParallelTask) Run() { if err != nil { // 出错 // globals.SugarLogger.Infof("ParallelTask.Run %s, subtask(job:%s, params:%s) result:%v, failed with error:%v", task.Name, utils.Format4Output(job, true), utils.Format4Output(task.params, true), result, err) if task.IsContinueWhenError { - task.locker.Lock() - task.batchErrList = append(task.batchErrList, err) - task.locker.Unlock() + task.AddBatchErr(err) } else { chanRetVal = err goto end diff --git a/business/jxutils/tasksch/sequence_task.go b/business/jxutils/tasksch/sequence_task.go index 38cab7cf8..c443c85e6 100644 --- a/business/jxutils/tasksch/sequence_task.go +++ b/business/jxutils/tasksch/sequence_task.go @@ -44,9 +44,7 @@ func (task *SeqTask) Run() { if err != nil { // globals.SugarLogger.Infof("SeqTask.Run %s step:%d failed with error:%v", task.Name, i, err) if task.IsContinueWhenError { - task.locker.Lock() - task.batchErrList = append(task.batchErrList, err) - task.locker.Unlock() + task.AddBatchErr(err) } else { taskErr = err break diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index a364aa4fd..9228a6be1 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -3,6 +3,7 @@ package tasksch import ( "encoding/json" "fmt" + "strings" "sync" "time" @@ -283,6 +284,14 @@ func (t *BaseTask) getResult() []interface{} { return t.Result } +func (t *BaseTask) AddBatchErr(err error) { + if err != nil { + t.locker.Lock() + defer t.locker.Unlock() + t.batchErrList = append(t.batchErrList, err) + } +} + // func (t *BaseTask) GetOriginalErr() error { // t.locker.RLock() // defer t.locker.RUnlock() @@ -330,9 +339,11 @@ func (t *BaseTask) Error() (errMsg string) { errMsg += "," + t.mainErr.Error() } else { errMsg += fmt.Sprintf("部分失败, 总共:%d, 成功:%d, 失败:%d, 详情如下:\n", t.TotalItemCount, t.FinishedItemCount, t.FailedItemCount) - for _, v := range t.batchErrList { - errMsg += fmt.Sprintf("%s,\n", v.Error()) + strList := make([]string, len(t.batchErrList)) + for k, v := range t.batchErrList { + strList[k] = v.Error() } + errMsg += strings.Join(strList, ",\n") } t.locker.Lock() t.Err = errMsg diff --git a/business/jxutils/tasksch/task_man.go b/business/jxutils/tasksch/task_man.go index 4dd270358..556e85ea2 100644 --- a/business/jxutils/tasksch/task_man.go +++ b/business/jxutils/tasksch/task_man.go @@ -2,45 +2,44 @@ package tasksch import ( "sort" - "sync" "time" + + "git.rosy.net.cn/jx-callback/business/jxutils" ) var ( defTaskMan TaskMan defLastHours = 24 + maxStoreTime = 48 * time.Hour // 最多存两天时间 ) type TaskMan struct { - taskList map[string]ITask - locker sync.RWMutex + taskMap jxutils.SyncMapWithTimeout } func init() { - defTaskMan.taskList = make(map[string]ITask) } func (m *TaskMan) GetTasks(taskID string, fromStatus, toStatus int, lastHours int, createdBy string) (taskList TaskList) { - m.locker.RLock() - defer m.locker.RUnlock() if lastHours == 0 { lastHours = defLastHours } lastTime := time.Now().Add(time.Duration(-lastHours) * time.Hour).Unix() - for k, v := range m.taskList { + m.taskMap.Range(func(key, value interface{}) bool { + k := key.(string) + v := value.(ITask) status := v.GetStatus() if !((createdBy != "" && createdBy != v.GetCreatedBy()) || (taskID != "" && taskID != k) || status < fromStatus || status > toStatus || v.GetCreatedAt().Unix() < lastTime) { taskList = append(taskList, v) } - } + return true + }) sort.Sort(TaskList(taskList)) return taskList } func (m *TaskMan) ManageTask(task ITask) ITask { - m.locker.Lock() - defer m.locker.Unlock() - m.taskList[task.GetID()] = task + m.taskMap.StoreWithTimeout(task.GetID(), task, maxStoreTime) return task } @@ -53,7 +52,7 @@ func ManageTask(task ITask) ITask { } func IsTaskRunning(taskID string) bool { - if taskList := GetTasks(taskID, TaskStatusBegin, TaskStatusWorking, 36, ""); len(taskList) > 0 { + if taskList := GetTasks(taskID, TaskStatusBegin, TaskStatusWorking, 0, ""); len(taskList) > 0 { return true } return false diff --git a/business/model/dao/dao_user2.go b/business/model/dao/dao_user2.go index 06802f6a8..b06d601ae 100644 --- a/business/model/dao/dao_user2.go +++ b/business/model/dao/dao_user2.go @@ -30,7 +30,7 @@ func GetUsers(db *DaoDB, userType int, keyword string, userIDs []string, userID2 sql := ` SELECT * FROM user t1 - WHERE t1.deleted_at = ? AND t1.type & ? <> 0` + WHERE t1.status = 1 AND t1.deleted_at = ? AND t1.type & ? <> 0` sqlParams := []interface{}{ utils.DefaultTimeValue, userType, diff --git a/business/model/model.go b/business/model/model.go index d46d57e25..c8c2ca3e5 100644 --- a/business/model/model.go +++ b/business/model/model.go @@ -81,6 +81,7 @@ const ( SyncFlagStoreName = 8 SyncFlagStoreAddress = 16 + SyncFlagStoreStatus = 32 ) func IsSyncStatusNew(syncStatus int8) bool { diff --git a/business/partner/purchase/ebai/store.go b/business/partner/purchase/ebai/store.go index b4e9884c7..f34187abb 100644 --- a/business/partner/purchase/ebai/store.go +++ b/business/partner/purchase/ebai/store.go @@ -177,9 +177,11 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin } } if err == nil { - mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus) - if err = p.updateStoreStatus(userName, storeID, store.VendorStoreID, mergeStatus, store2.Status); err != nil { - return err + if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreStatus) != 0 { + mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus) + if err = p.updateStoreStatus(userName, storeID, store.VendorStoreID, mergeStatus, store2.Status); err != nil { + return err + } } params := genStoreMapFromStore(store) if err = api.EbaiAPI.ShopUpdate(params); err == nil { diff --git a/business/partner/purchase/jd/store.go b/business/partner/purchase/jd/store.go index 144ed378d..6682e81a1 100644 --- a/business/partner/purchase/jd/store.go +++ b/business/partner/purchase/jd/store.go @@ -142,7 +142,9 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin params["deliveryRangeRadius"] = utils.Str2Int64WithDefault(store.DeliveryRange, 0) } } - _, params["closeStatus"] = JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus)) + if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreStatus) != 0 { + _, params["closeStatus"] = JxStoreStatus2JdStatus(jxutils.MergeStoreStatus(store.Status, store.JdStoreStatus)) + } globals.SugarLogger.Debug(utils.Format4Output(params, false)) if globals.EnableJdStoreWrite { if err = api.JdAPI.UpdateStoreInfo4Open(store.VendorStoreID, store.RealLastOperator, params); err != nil { diff --git a/business/partner/purchase/jd/store_sku2.go b/business/partner/purchase/jd/store_sku2.go index d5c7e140e..ec790bd9f 100644 --- a/business/partner/purchase/jd/store_sku2.go +++ b/business/partner/purchase/jd/store_sku2.go @@ -65,7 +65,7 @@ func (p *PurchaseHandler) getStoreSkusBareInfoLimitSize(ctx *jxcontext.Context, } func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) { - result, err := putils.FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + result, err := putils.FreeBatchStoreSkuInfo("获取门店商品信息", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { list, err := p.getStoreSkusBareInfoLimitSize(ctx, task, storeID, vendorStoreID, batchedStoreSkuList) if err == nil { result = list diff --git a/business/partner/purchase/mtwm/store.go b/business/partner/purchase/mtwm/store.go index 6444b41a7..9e7491c06 100644 --- a/business/partner/purchase/mtwm/store.go +++ b/business/partner/purchase/mtwm/store.go @@ -129,7 +129,9 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin // if globals.EnableMtwmStoreWrite { // err = api.MtwmAPI.PoiSave(storeDetail.VendorStoreID, params) // } - errList.AddErr(p.UpdateStoreStatus(jxcontext.AdminCtx, storeID, storeDetail.VendorStoreID, jxutils.MergeStoreStatus(storeDetail.Status, storeDetail.VendorStatus))) + if storeDetail.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagStoreStatus) != 0 { + errList.AddErr(p.UpdateStoreStatus(jxcontext.AdminCtx, storeID, storeDetail.VendorStoreID, jxutils.MergeStoreStatus(storeDetail.Status, storeDetail.VendorStatus))) + } errList.AddErr(p.UpdateStoreOpTime(jxcontext.AdminCtx, storeID, storeDetail.VendorStoreID, storeDetail.GetOpTimeList())) return errList.GetErrListAsOne() } diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index ece7b5d7e..ada0a7537 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -94,8 +94,10 @@ func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID in panic("catName is empty") } globals.SugarLogger.Debugf("mtwm CreateStoreCategory vendorStoreID:%s, originName:%s, catName:%s, subCatName:%s, seq:%d", vendorStoreID, originName, catName, subCatName, storeCat.Seq) - if globals.EnableMtwmStoreWrite { - err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, originName, catName, subCatName, storeCat.Seq) + if !(originName == catName && subCatName == "") { + if globals.EnableMtwmStoreWrite { + err = api.MtwmAPI.RetailCatUpdate(vendorStoreID, originName, catName, subCatName, storeCat.Seq) + } } if err == nil { storeCat.VendorCatID = storeCat.Name diff --git a/business/partner/putils/store_sku.go b/business/partner/putils/store_sku.go index 57da5d120..652d519b1 100644 --- a/business/partner/putils/store_sku.go +++ b/business/partner/putils/store_sku.go @@ -29,7 +29,7 @@ func (p *DefSingleStorePlatform) DeleteStoreAllSkus(ctx *jxcontext.Context, pare VendorSkuID: v.SkuList[0].VendorSkuID, } } - _, err = FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + _, err = FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { _, err = p.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList) return nil, 0, err }, ctx, parentTask, storeStoreList, p.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus), isContinueWhenError) @@ -76,7 +76,7 @@ func flatCatList(catList []*partner.BareCategoryInfo) (flattedCatList []*partner } func (p *DefSingleStorePlatform) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) { - resultList, err := FreeBatchStoreSkuInfo(func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + resultList, err := FreeBatchStoreSkuInfo("获取门店商品信息", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { result, err = p.GetStoreSkusFullInfo(ctx, parentTask, storeID, vendorStoreID, batchedStoreSkuList) return result, successCount, err }, ctx, parentTask, inStoreSkuList, p.GetStoreSkusBatchSize(partner.FuncGetStoreSkusFullInfo), true) @@ -134,9 +134,9 @@ func (p *DefSingleStorePlatform) GetStoreCategory(ctx *jxcontext.Context, storeI return cat, err } -func FreeBatchStoreSkuInfo(handler func(tasksch.ITask, []*partner.StoreSkuInfo) (interface{}, int, error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*partner.StoreSkuInfo, batchSize int, isContinueWhenError bool) (resultList []interface{}, err error) { +func FreeBatchStoreSkuInfo(name string, handler func(tasksch.ITask, []*partner.StoreSkuInfo) (interface{}, int, error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*partner.StoreSkuInfo, batchSize int, isContinueWhenError bool) (resultList []interface{}, err error) { if true { //len(storeSkuList) > batchSize { - task := tasksch.NewParallelTask2("FreeBatchStoreSkuInfo", tasksch.NewParallelConfig().SetParallelCount(1).SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx, + task := tasksch.NewParallelTask2(fmt.Sprintf("FreeBatchStoreSkuInfo:%s", name), tasksch.NewParallelConfig().SetParallelCount(1).SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, successCount int, err error) { batchStoreSkuList := make([]*partner.StoreSkuInfo, len(batchItemList)) for k, v := range batchItemList { @@ -159,9 +159,9 @@ func FreeBatchStoreSkuInfo(handler func(tasksch.ITask, []*partner.StoreSkuInfo) return resultList, err } -func FreeBatchStoreSkuSyncInfo(handler func(tasksch.ITask, []*dao.StoreSkuSyncInfo) (interface{}, int, error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*dao.StoreSkuSyncInfo, batchSize int, isContinueWhenError bool) (resultList []interface{}, err error) { +func FreeBatchStoreSkuSyncInfo(name string, handler func(tasksch.ITask, []*dao.StoreSkuSyncInfo) (interface{}, int, error), ctx *jxcontext.Context, parentTask tasksch.ITask, storeSkuList []*dao.StoreSkuSyncInfo, batchSize int, isContinueWhenError bool) (resultList []interface{}, err error) { if true { //len(storeSkuList) > batchSize { - task := tasksch.NewParallelTask2("FreeBatchStoreSkuSyncInfo", tasksch.NewParallelConfig().SetParallelCount(1).SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx, + task := tasksch.NewParallelTask2(fmt.Sprintf("FreeBatchStoreSkuSyncInfo:%s", name), tasksch.NewParallelConfig().SetParallelCount(1).SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, successCount int, err error) { batchStoreSkuList := make([]*dao.StoreSkuSyncInfo, len(batchItemList)) for k, v := range batchItemList {