- getStoreListByCoordinates会先检测第一个坐标会否返回有用店铺,以过滤不支持的城市,相应GetCityCoordinateList返回的第一个坐标是城市中心点
This commit is contained in:
@@ -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