diff --git a/business/netspider/netspider.go b/business/netspider/netspider.go index 8c0477d4e..860239f88 100644 --- a/business/netspider/netspider.go +++ b/business/netspider/netspider.go @@ -2,6 +2,7 @@ package netspider import ( "fmt" + "math/rand" "git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals/api" @@ -124,7 +125,7 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, return storeList, err } -func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeList []int, radius, gridWith int, isAsync bool) (hint string, err error) { +func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeList []int, radius, gridWith int, isShuffle, isAsync bool) (hint string, err error) { db := dao.GetDB() if len(cityCodeList) == 0 { placeList, err2 := dao.GetPlacesByCond(db, dao.EnableCondAll) @@ -134,7 +135,11 @@ func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeLis for _, v := range placeList { cityCodeList = append(cityCodeList, v.Code) } - // cityCodeList = []int{510100} + } + if isShuffle { + rand.Shuffle(len(cityCodeList), func(i, j int) { + cityCodeList[i], cityCodeList[j] = cityCodeList[j], cityCodeList[i] + }) } if len(vendorIDs) == 0 { vendorIDs = []int{model.VendorIDJD, model.VendorIDEBAI} diff --git a/controllers/net_spider.go b/controllers/net_spider.go index 38926cacf..34b85c128 100644 --- a/controllers/net_spider.go +++ b/controllers/net_spider.go @@ -11,13 +11,14 @@ type NetSpiderController struct { beego.Controller } -// @Title 同步商家商品信息 -// @Description 同步商家商品信息 +// @Title 从网页拉取平台门店信息 +// @Description 从网页拉取平台门店信息 // @Param token header string true "认证token" // @Param vendorIDs formData string false "厂商ID列表" // @Param cityCodes formData string false "城市列表,缺省为后台启用了的城市" // @Param radius formData int false "区域半径(市或街道的半径会自动增加或缩小),单位为米,缺省8000米" // @Param gridWith formData int false "网格大小,单位为米,缺省为2000米" +// @Param isShuffle formData bool false "是否将城市列表随机打乱" // @Param isAsync formData bool false "是否异步" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult @@ -27,7 +28,7 @@ func (c *NetSpiderController) GetAndStoreCitiesShops() { var vendorIDs, cityCodes []int err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.CityCodes, &cityCodes) if err == nil { - retVal, err = netspider.GetAndStoreCitiesShops(params.Ctx, vendorIDs, cityCodes, params.Radius, params.GridWith, params.IsAsync) + retVal, err = netspider.GetAndStoreCitiesShops(params.Ctx, vendorIDs, cityCodes, params.Radius, params.GridWith, params.IsShuffle, params.IsAsync) } return retVal, "", err })