商圈经纬度新方式

This commit is contained in:
沈健
2021-09-03 14:04:54 +08:00
parent 78e4bbfb03
commit d78e6a664a
@@ -0,0 +1,46 @@
package com.fangjia.script.temp.shenjian.poi
import com.fangjia.script.temp.shenjian.util.GaoDeUtils
import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import com.mongodb.DBObject
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
/**
* 商圈经纬度
*/
class BusinessLatLng {
static DBCollection collection = MongoUtils.getCollectionByName("fangjia_crawl", "business", "192.168.0.235", 27018)
static ExecutorService executorService = Executors.newFixedThreadPool(1)
static void main(String[] args) {
dealPoi(new BasicDBObject("city", "上海").append("region", "浦东新区"))
executorService.shutdown()
}
static dealPoi(DBObject query) {
collection.find(query).batchSize(5000).each {objTemp ->
final def obj = objTemp
executorService.submit(new Runnable() {
@Override
void run() {
def city = obj.city
def address = city + obj.region + obj.address;
def location = GaoDeUtils.parserByGaode(city, address);
if (location && location.lng) {
def lng = Double.valueOf(location.lng)
def lat = Double.valueOf(location.lat)
collection.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 0)
.append("location", new BasicDBObject("lat", lat).append("lon", lng)).append("flag_location", "已获取经纬度")))
} else {
collection.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 2).append("flag_location", "经纬度为空")))
}
println("已处理小区:" + obj)
}
})
}
}
}