diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index dabaf2c41..792ec6ef2 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -3,11 +3,12 @@ package cms import ( "errors" "fmt" - "git.rosy.net.cn/baseapi/platformapi/mtpsapi" "strconv" "sync" "time" + "git.rosy.net.cn/baseapi/platformapi/mtpsapi" + "git.rosy.net.cn/jx-callback/business/partner/putils" "git.rosy.net.cn/jx-callback/globals/api" @@ -714,18 +715,19 @@ func buildSetFinishHook(task tasksch.ITask, ctx *jxcontext.Context) { } else { globals.SugarLogger.Debugf("同步错误发送钉钉消息失败, authinfo [%v] , [%v]", *authInfo, err) } - } else { - if len(task.GetFailedList()) > 1 { - if time.Now().Hour() >= 20 || time.Now().Hour() < 7 { - downloadURL, _, _ := WirteToExcelBySyncFailed(task) - user, err := dao.GetUserByID(dao.GetDB(), "mobile", "18160030913") - noticeMsg += fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL) - if user != nil && err == nil { - ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "同步错误返回", noticeMsg) - } - } - } } + // else { + // if len(task.GetFailedList()) > 1 { + // if time.Now().Hour() >= 20 || time.Now().Hour() < 7 { + // downloadURL, _, _ := WirteToExcelBySyncFailed(task) + // user, err := dao.GetUserByID(dao.GetDB(), "mobile", "18160030913") + // noticeMsg += fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL) + // if user != nil && err == nil { + // ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "同步错误返回", noticeMsg) + // } + // } + // } + // } }) } @@ -1102,9 +1104,9 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil { for _, storeMap := range loopMapInfo.StoreMapList { if storeMap.Status > model.StoreStatusDisabled && storeMap.StoreID != model.JdShopMainStoreID && storeMap.SyncRule != 0 { - err = syncJdsStoresSkus(ctx, db, nil, storeMap, isAsync, isContinueWhenError) + err = syncJdsStoresSkus(ctx, db, t, storeMap, isAsync, isContinueWhenError) } - err = syncJdsStoreStock(ctx, db, storeSkus, storeMap) + err = syncJdsStoreStock(ctx, db, t, storeSkus, storeMap, isAsync, isContinueWhenError) } } return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID) @@ -1112,31 +1114,46 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i return hint, err } -func syncJdsStoreStock(ctx *jxcontext.Context, db *dao.DaoDB, storeSkus []*model.StoreSkuBind, storeMap *model.StoreMap) (err error) { - for _, storeSku := range storeSkus { - stock := 0 - if storeSku.Status == model.StoreSkuBindStatusNormal { - stock = 9999 - } - storeSku2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{storeSku.SkuID}) - if storeSku.JdsID != 0 { - if len(storeSku2) > 0 { - if storeSku.Status != storeSku2[0].Status && storeMap.VendorStoreID != "" { - err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, stock, utils.Str2Int(storeMap.VendorStoreID)) - } - } else { - err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, 0, utils.Str2Int(storeMap.VendorStoreID)) +func syncJdsStoreStock(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeSkus []*model.StoreSkuBind, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (err error) { + // for _, storeSku := range storeSkus { + // stock := 0 + // if storeSku.Status == model.StoreSkuBindStatusNormal { + // stock = 9999 + // } + // storeSku2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{storeSku.SkuID}) + // if storeSku.JdsID != 0 { + // if len(storeSku2) > 0 { + // if storeSku.Status != storeSku2[0].Status && storeMap.VendorStoreID != "" { + // err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, stock, utils.Str2Int(storeMap.VendorStoreID)) + // } + // } else { + // err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, 0, utils.Str2Int(storeMap.VendorStoreID)) + // } + // } + // } + task := tasksch.NewParallelTask("syncJdsStoreStock", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + storeSku := batchItemList[0].(*model.StoreSkuBind) + stock := 0 + if storeSku.Status == model.StoreSkuBindStatusNormal { + stock = 9999 } - } + storeSku2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{storeSku.SkuID}) + if storeSku.JdsID != 0 { + if len(storeSku2) > 0 { + if storeSku.Status != storeSku2[0].Status && storeMap.VendorStoreID != "" { + err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, stock, utils.Str2Int(storeMap.VendorStoreID)) + } + } else { + err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, 0, utils.Str2Int(storeMap.VendorStoreID)) + } + } + return retVal, err + }, storeSkus) + tasksch.HandleTask(task, parentTask, true).Run() + if !isAsync { + _, err = task.GetResult(0) } - // task := tasksch.NewParallelTask("syncJdsStoreStock", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, - // func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - // storeSku := batchItemList[0].(*model.StoreSkuBind) - - // return retVal, err - // }, storeSkus) - // tasksch.HandleTask(task, nil, true).Run() - // _, err = task.GetResult(0) return err }