- getStoreListByCoordinates会先检测第一个坐标会否返回有用店铺,以过滤不支持的城市,相应GetCityCoordinateList返回的第一个坐标是城市中心点

This commit is contained in:
gazebo
2019-06-26 10:34:05 +08:00
parent 4de91f4298
commit f7ec972d2e
3 changed files with 87 additions and 47 deletions

View File

@@ -63,7 +63,14 @@ func GetDistrictCoordinateList(districtCode int, radius, gridWith int) (coordLis
if err == nil {
if len(districts) > 0 {
roundLng, roundLat := GetRound4Radius(districts[0].Lng, districts[0].Lat, gridWith)
coordList = getDistrictCoordinateList(districts, radius, gridWith, roundLng, roundLat)
tmpCoordList := getDistrictCoordinateList(districts, radius, gridWith, roundLng, roundLat)
if len(tmpCoordList) > 0 {
coordList = append(coordList, &Coordinate{
Lng: districts[0].Lng,
Lat: districts[0].Lat,
})
coordList = append(coordList, tmpCoordList...)
}
}
}
return coordList
@@ -74,16 +81,32 @@ func GetCityCoordinateList(cityCode int, radius, gridWith int) (coordList []*Coo
if err == nil {
if len(districts) > 0 {
roundLng, roundLat := GetRound4Radius(districts[0].Lng, districts[0].Lat, gridWith)
coordList = getDistrictCoordinateList(districts, radius, gridWith, roundLng, roundLat)
tmpCoordList := getDistrictCoordinateList(districts, radius, gridWith, roundLng, roundLat)
if len(tmpCoordList) > 0 {
coordList = append(coordList, &Coordinate{
Lng: districts[0].Lng,
Lat: districts[0].Lat,
})
coordList = append(coordList, tmpCoordList...)
}
}
}
return coordList
}
func needCheckTown(place *autonavi.District) bool {
for _, v := range []string{"街道", "镇"} {
if strings.Index(place.Name, v) >= 0 {
return true
}
}
return false
}
func getDistrictCoordinateList(districtList []*autonavi.District, radius, gridWith, roundLng, roundLat int) (coordList []*Coordinate) {
coordMap := make(map[int64]*Coordinate)
for _, v := range districtList {
if (v.Level <= 3 || (v.Level == 4 && strings.Index(v.Name, "街道") >= 0)) && v.Lng != 0 && v.Lat != 0 {
if (v.Level <= 3 || (v.Level == 4 && needCheckTown(v))) && v.Lng != 0 && v.Lat != 0 {
realRadius := radius
if v.Level == 2 {
realRadius = 2 * radius

View File

@@ -5,6 +5,12 @@ import (
"github.com/astaxie/beego/orm"
)
const (
EnableCondAll = 0
EnableCondEnalbed = 1
EnableCondDisabled = 2
)
func GetPlaceByCode(db *DaoDB, code int) (place *model.Place, err error) {
if db == nil {
db = GetDB()
@@ -16,16 +22,22 @@ func GetPlaceByCode(db *DaoDB, code int) (place *model.Place, err error) {
return place, err
}
func GetEnabledPlaces(db *DaoDB) (placeList []*model.Place, err error) {
func GetPlacesByCond(db *DaoDB, enableCond int) (placeList []*model.Place, err error) {
if db == nil {
db = GetDB()
}
err = GetRows(db, &placeList, `
sql := `
SELECT *
FROM place
WHERE enabled = 1 AND level = 2
ORDER BY code
`)
WHERE level = 2
`
if enableCond == 1 {
sql += " AND enabled = 1"
} else if enableCond == 2 {
sql += " AND enabled = 0"
}
sql += " ORDER BY code"
err = GetRows(db, &placeList, sql)
return placeList, err
}

View File

@@ -46,7 +46,10 @@ func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []
}
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, cityInfo string, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) {
if len(coordList) > 0 {
if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
mainStoreIDList, _ := handler.GetStoreIDListByCoordinates(ctx, coordList[0])
if len(mainStoreIDList) > 0 {
task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
pos := batchItemList[0].(*ditu.Coordinate)
@@ -89,13 +92,15 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask,
storeList = append(storeList, v.(*model.PageShop))
}
}
}
}
return storeList, err
}
func GetAndStoreCitiesShops(ctx *jxcontext.Context, vendorIDs []int, cityCodeList []int, radius, gridWith int) (hint string, err error) {
db := dao.GetDB()
if len(cityCodeList) == 0 {
placeList, err2 := dao.GetEnabledPlaces(db)
placeList, err2 := dao.GetPlacesByCond(db, dao.EnableCondAll)
if err = err2; err != nil {
return "", err
}