diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index b9edac9a8..82c148616 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -808,9 +808,9 @@ func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*St } func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) { - if len(skuBindInfos) > maxStoreNameBind { - return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind) - } + // if len(skuBindInfos) > maxStoreNameBind { + // return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind) + // } skuBindInfosMap := make(map[int][]*StoreSkuBindInfo) storeIDMap := make(map[int]int) for _, v := range skuBindInfos { @@ -824,17 +824,17 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, sk var num int64 skuIDMap := make(map[int]int) db := dao.GetDB() - dao.Begin(db) - defer func() { - if r := recover(); r != nil { - dao.Rollback(db) - panic(r) - } - }() + // dao.Begin(db) + // defer func() { + // if r := recover(); r != nil { + // dao.Rollback(db) + // panic(r) + // } + // }() for _, storeID := range storeIDs { skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID], false) if err = err2; err != nil { - dao.Rollback(db) + // dao.Rollback(db) return "", err } for _, v := range skuIDs { @@ -842,7 +842,7 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, sk } num += int64(len(skuIDs)) } - dao.Commit(db) + // dao.Commit(db) isAsync = asyncStoreSkuOpFilter(ctx, isAsync) if num > 0 { skuIDs := jxutils.IntMap2List(skuIDMap) @@ -2405,7 +2405,7 @@ func GetTopCategoriesByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCate return skuCategory, err } -func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error) { +func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int, isCountry bool) (err error) { db := dao.GetDB() if len(storeIDs) == 0 { return err @@ -2424,7 +2424,12 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error } storeSkuList, err := dao.GetStoresSkusInfo(db, []int{v}, nil) for _, storeSku := range storeSkuList { - priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, []int{storeSku.SkuID}, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1))) + var priceReferList []*model.PriceReferSnapshot + if isCountry { + priceReferList, err = dao.GetPriceReferSnapshotNoPage(db, []int{0}, []int{storeSku.SkuID}, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1))) + } else { + priceReferList, err = dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, []int{storeSku.SkuID}, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1))) + } if err != nil { return err } @@ -3096,12 +3101,6 @@ func AutoFocusStoreSkusForTopSkus(ctx *jxcontext.Context, isAsync, isContinueWhe db := dao.GetDB() var ( result1 []interface{} - // cityCodes = []int{ - // 530100, //昆明 - // 430300, //湘潭市 - // 510700, //绵阳市 - // 520100, //贵阳市 - // } ) storeList, err := dao.GetStoreList(db, nil, nil, nil, nil, "") taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { @@ -3132,8 +3131,8 @@ func AutoFocusStoreSkusForTopSkus(ctx *jxcontext.Context, isAsync, isContinueWhe utils.DefaultTimeValue, } err = dao.GetRows(db, &skuName, sql, sqlParams...) - for _, v := range skuName { - skuNameMap[v.ID] = v.ID + for _, name := range skuName { + skuNameMap[name.ID] = name.ID } skuNameAndPlaceList, err2 := GetTopSkusByCityCode(ctx, v.CityCode, 0) if err2 != nil { @@ -3167,19 +3166,19 @@ func AutoFocusStoreSkusForTopSkus(ctx *jxcontext.Context, isAsync, isContinueWhe } return retVal, err } - taskParallel := tasksch.NewParallelTask("自动关注畅销品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList) + taskParallel := tasksch.NewParallelTask("自动关注畅销品-设置数据", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList) tasksch.HandleTask(taskParallel, task, true).Run() result1, _ = taskParallel.GetResult(0) - case 2: + case 1: var skuBindInfos []*StoreSkuBindInfo for _, v := range result1 { skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo)) } - UpdateStoresSkusByBind(ctx, nil, skuBindInfos, isAsync, isContinueWhenError) + hint, err = UpdateStoresSkusByBind(ctx, nil, skuBindInfos, isAsync, isContinueWhenError) } return result, err } - taskSeq := tasksch.NewSeqTask2("自动关注畅销品", ctx, isContinueWhenError, taskSeqFunc, 3) + taskSeq := tasksch.NewSeqTask2("自动关注畅销品", ctx, isContinueWhenError, taskSeqFunc, 2) tasksch.HandleTask(taskSeq, nil, true).Run() if !isAsync { _, err = taskSeq.GetResult(0) diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index 81a9659b1..48b4fd9dd 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -517,7 +517,8 @@ func (c *StoreSkuController) GetTopCategoriesByStoreIDs() { // @Title 根据门店刷新中位价 // @Description 根据门店刷新中位价 // @Param token header string true "认证token" -// @Param storeIDs query string true "门店列表" +// @Param isCountry formData bool true "是否按全国中位价刷新" +// @Param storeIDs formData string true "门店列表" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /RefershStoreSkusMidPrice [put] @@ -525,7 +526,7 @@ func (c *StoreSkuController) RefershStoreSkusMidPrice() { var storeIDList []int c.callRefershStoreSkusMidPrice(func(params *tStoreSkuRefershStoreSkusMidPriceParams) (retVal interface{}, errCode string, err error) { if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil { - err = cms.RefershStoreSkusMidPrice(params.Ctx, storeIDList) + err = cms.RefershStoreSkusMidPrice(params.Ctx, storeIDList, params.IsCountry) } return retVal, "", err })