- getStoreListByCoordinates会先检测第一个坐标会否返回有用店铺,以过滤不支持的城市,相应GetCityCoordinateList返回的第一个坐标是城市中心点
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -46,47 +46,52 @@ 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 handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
||||
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)
|
||||
storeIDList, err := handler.GetStoreIDListByCoordinates(ctx, pos)
|
||||
if err != nil {
|
||||
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)
|
||||
storeIDList, err := handler.GetStoreIDListByCoordinates(ctx, pos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storeIDList, nil
|
||||
}, coordList)
|
||||
tasksch.AddChild(parentTask, task1).Run()
|
||||
fullStoreIDs, err2 := task1.GetResult(0)
|
||||
if err = err2; err != nil && len(fullStoreIDs) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
return storeIDList, nil
|
||||
}, coordList)
|
||||
tasksch.AddChild(parentTask, task1).Run()
|
||||
fullStoreIDs, err2 := task1.GetResult(0)
|
||||
if err = err2; err != nil && len(fullStoreIDs) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
storeIDMap := make(map[string]int)
|
||||
for _, v := range fullStoreIDs {
|
||||
storeIDMap[v.(string)] = 1
|
||||
}
|
||||
var storeIDs []string
|
||||
for storeID := range storeIDMap {
|
||||
storeIDs = append(storeIDs, storeID)
|
||||
}
|
||||
|
||||
task2 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get detail", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeID := batchItemList[0].(string)
|
||||
storePageInfo, err := handler.GetStorePageInfo(ctx, cityInfo, storeID)
|
||||
if err == nil && storePageInfo != nil {
|
||||
return []interface{}{storePageInfo}, nil
|
||||
storeIDMap := make(map[string]int)
|
||||
for _, v := range fullStoreIDs {
|
||||
storeIDMap[v.(string)] = 1
|
||||
}
|
||||
return nil, err
|
||||
}, storeIDs)
|
||||
tasksch.AddChild(parentTask, task2).Run()
|
||||
shopList, err2 := task2.GetResult(0)
|
||||
if err = err2; err != nil && len(shopList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
err = nil
|
||||
for _, v := range shopList {
|
||||
storeList = append(storeList, v.(*model.PageShop))
|
||||
var storeIDs []string
|
||||
for storeID := range storeIDMap {
|
||||
storeIDs = append(storeIDs, storeID)
|
||||
}
|
||||
|
||||
task2 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get detail", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeID := batchItemList[0].(string)
|
||||
storePageInfo, err := handler.GetStorePageInfo(ctx, cityInfo, storeID)
|
||||
if err == nil && storePageInfo != nil {
|
||||
return []interface{}{storePageInfo}, nil
|
||||
}
|
||||
return nil, err
|
||||
}, storeIDs)
|
||||
tasksch.AddChild(parentTask, task2).Run()
|
||||
shopList, err2 := task2.GetResult(0)
|
||||
if err = err2; err != nil && len(shopList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
err = nil
|
||||
for _, v := range shopList {
|
||||
storeList = append(storeList, v.(*model.PageShop))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return storeList, err
|
||||
@@ -95,7 +100,7 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user