新增多线程方式调用周边POI
This commit is contained in:
+24
-13
@@ -16,6 +16,9 @@ import com.mongodb.DBObject
|
|||||||
import org.apache.commons.collections.CollectionUtils
|
import org.apache.commons.collections.CollectionUtils
|
||||||
import org.bson.types.ObjectId
|
import org.bson.types.ObjectId
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小区周边POI数据获取
|
* 小区周边POI数据获取
|
||||||
*
|
*
|
||||||
@@ -26,26 +29,34 @@ class SeaweedAroundPoi {
|
|||||||
|
|
||||||
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
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 final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
|
||||||
|
static ExecutorService executorService = Executors.newFixedThreadPool(30)
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
def types = listAllType()
|
def types = listAllType()
|
||||||
//def types = "0601"
|
//def types = "0601"
|
||||||
DBObject query = new BasicDBObject()
|
DBObject query = new BasicDBObject()
|
||||||
query.put("status", 1)
|
query.put("status", 1)
|
||||||
conn136.find(query).batchSize(5000).each {obj ->
|
conn136.find(query).batchSize(5000).each {objTemp ->
|
||||||
def city = obj.city
|
final def obj = objTemp
|
||||||
def lng = obj.lng
|
executorService.submit(new Runnable() {
|
||||||
def lat = obj.lat
|
@Override
|
||||||
List<AmapPoi> pois = GaoDeUtils.searchNearDtoByPoi(city, types, lng, lat, 1000, "")
|
void run() {
|
||||||
if (CollectionUtils.isNotEmpty(pois)) {
|
def city = obj.city
|
||||||
String jsonStr = JSONObject.toJSONString(pois)
|
def lng = obj.lng
|
||||||
HttpUtils.postForJson(URL, jsonStr)
|
def lat = obj.lat
|
||||||
conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 0).append("flag", "已获取周边POI")))
|
List<AmapPoi> pois = GaoDeUtils.searchNearDtoByPoi(city, types, lng, lat, 1000, "")
|
||||||
} else {
|
if (CollectionUtils.isNotEmpty(pois)) {
|
||||||
conn136.update(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 2).append("flag", "周边POI为空")))
|
String jsonStr = JSONObject.toJSONString(pois)
|
||||||
}
|
HttpUtils.postForJson(URL, jsonStr)
|
||||||
println("已处理小区:" + obj)
|
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() {
|
static getNewSeaweed() {
|
||||||
|
|||||||
+5
-3
@@ -135,9 +135,11 @@ class GaoDeUtils {
|
|||||||
} catch(Exception ex) {
|
} catch(Exception ex) {
|
||||||
ex.printStackTrace()
|
ex.printStackTrace()
|
||||||
}
|
}
|
||||||
} else if (json && json.infocode && json.infocode == 10003) {
|
} else if (json && json.infocode && json.infocode == "10044") {
|
||||||
throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封")
|
//throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封")
|
||||||
} else if (json && json.infocode && json.infocode == 10004) {
|
// 多线程情况下还是exit有效果,抛异常不会停止程序
|
||||||
|
System.exit(1)
|
||||||
|
} else if (json && json.infocode && json.infocode == "10004") {
|
||||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||||
Thread.sleep(60000)
|
Thread.sleep(60000)
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user