From f7ec972d2e7fff227c7a1d087f6908baa70e5851 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 26 Jun 2019 10:34:05 +0800 Subject: [PATCH] =?UTF-8?q?-=20getStoreListByCoordinates=E4=BC=9A=E5=85=88?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E4=BC=9A=E5=90=A6=E8=BF=94=E5=9B=9E=E6=9C=89=E7=94=A8=E5=BA=97?= =?UTF-8?q?=E9=93=BA=EF=BC=8C=E4=BB=A5=E8=BF=87=E6=BB=A4=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9A=84=E5=9F=8E=E5=B8=82=EF=BC=8C=E7=9B=B8=E5=BA=94?= =?UTF-8?q?GetCityCoordinateList=E8=BF=94=E5=9B=9E=E7=9A=84=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=9D=90=E6=A0=87=E6=98=AF=E5=9F=8E=E5=B8=82?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/ditu/ditu.go | 29 ++++++++++-- business/model/dao/place.go | 22 +++++++-- business/netspider/netspider.go | 83 +++++++++++++++++---------------- 3 files changed, 87 insertions(+), 47 deletions(-) diff --git a/business/jxutils/ditu/ditu.go b/business/jxutils/ditu/ditu.go index 48ad29cb8..2e8695649 100644 --- a/business/jxutils/ditu/ditu.go +++ b/business/jxutils/ditu/ditu.go @@ -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 diff --git a/business/model/dao/place.go b/business/model/dao/place.go index 905e1a7fc..a912cc802 100644 --- a/business/model/dao/place.go +++ b/business/model/dao/place.go @@ -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 } diff --git a/business/netspider/netspider.go b/business/netspider/netspider.go index 09f75b50e..7f44e2ee0 100644 --- a/business/netspider/netspider.go +++ b/business/netspider/netspider.go @@ -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 }