From 2c24a623a7afc98a0389cbfb5d747c507e8d6d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Thu, 22 Jul 2021 17:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=85=E5=A7=94=E7=BB=8F=E7=BA=AC=E5=BA=A6?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/CommitteeGeoHash.groovy | 44 +++++++++++++++++++ .../temp/shenjian/poi/CommitteeLatLng.groovy | 27 ++++++++++-- 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeGeoHash.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeGeoHash.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeGeoHash.groovy new file mode 100644 index 000000000..53b0679f0 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeGeoHash.groovy @@ -0,0 +1,44 @@ +package com.fangjia.script.temp.shenjian.poi + +import com.fangjia.script.temp.shenjian.util.GaoDeUtils +import com.fangjia.script.temp.shenjian.util.SeaweedUtils +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 + +/** + * 国家标准居委会经纬度geohash化 + * + * @author shenjian + * @since 2021/7/22 + */ +class CommitteeGeoHash { + + static DBCollection villagesConn = MongoUtils.getCollectionByName("fangjia", "villages", "192.168.0.43", 28017) + static ExecutorService executorService = Executors.newFixedThreadPool(30) + + static void main(String[] args) { + dealPoi(new BasicDBObject("status_location", 0).append("lng", new BasicDBObject('$ne', null))) + executorService.shutdown() + } + + static dealPoi(DBObject query) { + villagesConn.find(query).batchSize(5000).each {objTemp -> + final def obj = objTemp + executorService.submit(new Runnable() { + @Override + void run() { + double lng = Double.valueOf(obj.lng) + double lat = Double.valueOf(obj.lat) + def geohash = SeaweedUtils.encodeByGeoHash(lng, lat, 8); + villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("geohash", geohash))) + println("已处理小区:" + obj) + } + }) + } + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeLatLng.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeLatLng.groovy index cadb279a7..1f5f696cf 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeLatLng.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/CommitteeLatLng.groovy @@ -22,6 +22,7 @@ class CommitteeLatLng { static void main(String[] args) { dealPoi(new BasicDBObject("status_location", new BasicDBObject('$ne', 0))) + //dealLocation() executorService.shutdown() } @@ -32,13 +33,16 @@ class CommitteeLatLng { @Override void run() { def city = obj.city_name + if (city == "市辖区") { + city = obj.province_name + } def address = obj.province_name + city + obj.area_name + obj.street_name + obj.name; def location = GaoDeUtils.parserByGaode(city, address); if (location && location.lng) { - def lng = location.lng - def lat = location.lat + def lng = Double.valueOf(location.lng) + def lat = Double.valueOf(location.lat) villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 0) - .append("lng", lng).append("lat", lat).append("flag_location", "已获取经纬度"))) + .append("location", new BasicDBObject("lat", lat).append("lon", lng)).append("flag_location", "已获取经纬度"))) } else { villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status_location", 2).append("flag_location", "经纬度为空"))) } @@ -47,4 +51,21 @@ class CommitteeLatLng { }) } } + + static dealLocation() { + villagesConn.find(new BasicDBObject("status_location", 0)).batchSize(5000).each {objTemp -> + final def obj = objTemp + executorService.submit(new Runnable() { + @Override + void run() { + if (obj.lng && obj.lat) { + def lng = Double.valueOf(obj.lng) + def lat = Double.valueOf(obj.lat) + villagesConn.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("location", new BasicDBObject("lat", lat).append("lon", lng)))) + } + println("已处理小区:" + obj) + } + }) + } + } }