From 9f5d0ca222cf4ff53f92862fc3849acb97a3e09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 25 May 2021 14:19:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=B0=83=E7=94=A8=E5=91=A8=E8=BE=B9POI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/SeaweedAroundPoi.groovy | 37 ++++++++++++------- .../temp/shenjian/util/GaoDeUtils.groovy | 8 ++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy index 9b2599516..28ac4a0ab 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy @@ -16,6 +16,9 @@ import com.mongodb.DBObject import org.apache.commons.collections.CollectionUtils import org.bson.types.ObjectId +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + /** * 小区周边POI数据获取 * @@ -26,26 +29,34 @@ class SeaweedAroundPoi { static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017) static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi" + static ExecutorService executorService = Executors.newFixedThreadPool(30) static void main(String[] args) { def types = listAllType() //def types = "0601" DBObject query = new BasicDBObject() query.put("status", 1) - conn136.find(query).batchSize(5000).each {obj -> - def city = obj.city - def lng = obj.lng - def lat = obj.lat - List pois = GaoDeUtils.searchNearDtoByPoi(city, types, lng, lat, 1000, "") - if (CollectionUtils.isNotEmpty(pois)) { - String jsonStr = JSONObject.toJSONString(pois) - HttpUtils.postForJson(URL, jsonStr) - conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 0).append("flag", "已获取周边POI"))) - } else { - conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 2).append("flag", "周边POI为空"))) - } - println("已处理小区:" + obj) + conn136.find(query).batchSize(5000).each {objTemp -> + final def obj = objTemp + executorService.submit(new Runnable() { + @Override + void run() { + def city = obj.city + def lng = obj.lng + def lat = obj.lat + List pois = GaoDeUtils.searchNearDtoByPoi(city, types, lng, lat, 1000, "") + if (CollectionUtils.isNotEmpty(pois)) { + String jsonStr = JSONObject.toJSONString(pois) + HttpUtils.postForJson(URL, jsonStr) + conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 0).append("flag", "已获取周边POI"))) + } else { + conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 2).append("flag", "周边POI为空"))) + } + println("已处理小区:" + obj) + } + }) } + executorService.shutdown() } static getNewSeaweed() { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index 9f277a4b2..e384c35fb 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -135,9 +135,11 @@ class GaoDeUtils { } catch(Exception ex) { ex.printStackTrace() } - } else if (json && json.infocode && json.infocode == 10003) { - throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封") - } else if (json && json.infocode && json.infocode == 10004) { + } else if (json && json.infocode && json.infocode == "10044") { + //throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封") + // 多线程情况下还是exit有效果,抛异常不会停止程序 + System.exit(1) + } else if (json && json.infocode && json.infocode == "10004") { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000) break;