- 优化net_spider

This commit is contained in:
gazebo
2019-09-11 11:54:54 +08:00
parent 85c8354873
commit f2a1cff346
4 changed files with 35 additions and 18 deletions

View File

@@ -26,7 +26,7 @@ func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []
task := tasksch.NewParallelTask(fmt.Sprintf("GetCityShops:%d", cityCode), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorID := batchItemList[0].(int)
storeList, err2 := getStoreListByCoordinates(ctx, task, vendorID, utils.Int2Str(cityCode), coordList)
storeList, err2 := getStoreListByCoordinates(ctx, task, vendorID, cityCode, coordList)
if err = err2; err == nil {
retVal = storeList
}
@@ -40,8 +40,6 @@ func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []
}
err = nil
for _, v := range list {
v2 := v.(*model.PageShop)
v2.CityCode = cityCode
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
pageStoreList = append(pageStoreList, v.(*model.PageShop))
}
@@ -49,7 +47,32 @@ func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []
return pageStoreList, err
}
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, cityInfo string, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) {
func getStorePageInfo(ctx *jxcontext.Context, handler partner.IPurchasePlatformNetSpiderHandler, cityCode int, vendorStoreID string) (storePageInfo *model.PageShop, err error) {
storePageInfo, err = handler.GetStorePageInfo(ctx, vendorStoreID)
if err == nil && storePageInfo != nil {
if !(storePageInfo.Lng != 0 && storePageInfo.Lat != 0) {
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, utils.Int2Str(cityCode))
if storePageInfo.DistrictCode == 0 && cityCode != 0 {
storePageInfo.Lng, storePageInfo.Lat, storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateFromAddress(storePageInfo.Address, "")
}
} else if storePageInfo.DistrictCode == 0 {
storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(storePageInfo.Lng, storePageInfo.Lat)
}
if storePageInfo.CityCode == 0 {
if storePageInfo.DistrictCode != 0 {
if place, err := dao.GetPlaceByCode(dao.GetDB(), storePageInfo.DistrictCode); err == nil {
storePageInfo.CityCode = place.ParentCode
}
}
if storePageInfo.CityCode == 0 {
storePageInfo.CityCode = cityCode
}
}
}
return storePageInfo, err
}
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, cityCode int, 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])
@@ -80,11 +103,8 @@ func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask,
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)
storePageInfo, err := getStorePageInfo(ctx, handler, cityCode, storeID)
if err == nil && storePageInfo != nil {
if storePageInfo.DistrictCode == 0 && (storePageInfo.Lng != 0 && storePageInfo.Lat != 0) {
storePageInfo.DistrictCode = api.AutonaviAPI.GetCoordinateDistrictCode(storePageInfo.Lng, storePageInfo.Lat)
}
return []interface{}{storePageInfo}, nil
}
return nil, err
@@ -178,7 +198,7 @@ func RefreshPageStore(ctx *jxcontext.Context) (err error) {
}
for _, v := range shopList {
if handler, _ := partner.GetPurchasePlatformFromVendorID(v.VendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
storePageInfo, err2 := handler.GetStorePageInfo(ctx, "", v.VendorStoreID)
storePageInfo, err2 := getStorePageInfo(ctx, handler, v.CityCode, v.VendorStoreID)
if err2 == nil {
v.RecentOrderNum = storePageInfo.RecentOrderNum
v.SkuCount = storePageInfo.SkuCount