- GetAndStoreCitiesShops添加参数isShuffle

This commit is contained in:
gazebo
2019-09-11 16:49:56 +08:00
parent 37c9acc407
commit 3919aafe83
2 changed files with 11 additions and 5 deletions

View File

@@ -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}

View File

@@ -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
})