Merge branch 'script_gj' of http://gitlab.fangjia.com/dev0/main into script_gj

This commit is contained in:
2022-07-20 16:45:47 +08:00
@@ -24,10 +24,6 @@ import java.util.concurrent.atomic.AtomicInteger
*/ */
class GaoDeUtils { class GaoDeUtils {
// 新获取key
def static GAO_DE_AK = ["4e9592208336433ee1b7aa4d1d434418", "10bcb421d2ee4e51ed9268d6dca58ad1"]
def static AtomicInteger keyUsed = new AtomicInteger(0)
def static codeNameMap = new HashMap<String, String>(){{ def static codeNameMap = new HashMap<String, String>(){{
put("150500", "地铁"); put("150500", "地铁");
put("1507", "公交"); put("1507", "公交");
@@ -54,6 +50,20 @@ class GaoDeUtils {
put("0601", "商场") put("0601", "商场")
}}; }};
/**
* 获取高德KEY
* @return
*/
static String getGaodeKey(String type) {
Map<String, String> params = new HashMap<>();
params.put("type", type)
JSONObject json = HttpRequestUtil.getJsonContent("http://192.168.0.100:38080/FangJiaDataService/getAmapKey", params)
if (json.status == 0 && json.result != null) {
return json.result
}
System.exit(1);
}
/** /**
* 查找周边配套 * 查找周边配套
* @param city * @param city
@@ -66,7 +76,7 @@ class GaoDeUtils {
*/ */
static List searchNearByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){ static List searchNearByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){
def params = [:] def params = [:]
params.key = GAO_DE_AK[keyUsed]
if (types) { if (types) {
params.types = types params.types = types
@@ -83,25 +93,17 @@ class GaoDeUtils {
while (result.size() < count) { while (result.size() < count) {
params.page = "${page}".toString() params.page = "${page}".toString()
page++ page++
params.key = this.getGaodeKey("v3/place/around")
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params); JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params);
if (json == null) { if (json == null) {
params.key = this.getGaodeKey("v3/place/around")
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params); json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
count = json.getString("count").toInteger() count = json.getString("count").toInteger()
result.addAll(DataUtil.toMongoDbObj(json.pois)) result.addAll(DataUtil.toMongoDbObj(json.pois))
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
break;
}
} else if (json && json.infocode && json.infocode == "10004") { } else if (json && json.infocode && json.infocode == "10004") {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
@@ -128,7 +130,6 @@ class GaoDeUtils {
*/ */
static List searchNearDtoByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){ static List searchNearDtoByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){
def params = [:] def params = [:]
params.key = GAO_DE_AK[keyUsed.intValue()]
if (types) { if (types) {
params.types = types params.types = types
@@ -145,8 +146,10 @@ class GaoDeUtils {
while (result.size() < count) { while (result.size() < count) {
params.page = "${page}".toString() params.page = "${page}".toString()
page++ page++
params.key = this.getGaodeKey("v5/place/around")
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params); JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params);
if (json == null) { if (json == null) {
params.key = this.getGaodeKey("v5/place/around")
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params); json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
@@ -158,26 +161,14 @@ class GaoDeUtils {
ex.printStackTrace() ex.printStackTrace()
} }
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
break;
}
} else if (json && json.infocode && json.infocode == "10004") { } else if (json && json.infocode && json.infocode == "10004") {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
break; break;
} else if (json && json.infocode && json.infocode == "10017") { } else if (json && json.infocode && json.infocode == "10017") {
// 所请求的资源不可用 // 所请求的资源不可用
//System.exit(1) System.exit(1)
Thread.sleep(60000)
break;
} else { } else {
break break
} }
@@ -225,11 +216,12 @@ class GaoDeUtils {
*/ */
static List<AmapPoi> getAmapById(id){ static List<AmapPoi> getAmapById(id){
def params = [:] def params = [:]
params.key = GAO_DE_AK[keyUsed.intValue()]
params.id = id params.id = id
params.output = 'json' params.output = 'json'
params.key = this.getGaodeKey("v3/place/detail")
JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
if (json == null) { if (json == null) {
params.key = this.getGaodeKey("v3/place/detail")
json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
@@ -240,23 +232,13 @@ class GaoDeUtils {
ex.printStackTrace() ex.printStackTrace()
} }
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
}
} else if (json && json.infocode && json.infocode == "10004") { } else if (json && json.infocode && json.infocode == "10004") {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
} else if (json && json.infocode && json.infocode == "10017") { } else if (json && json.infocode && json.infocode == "10017") {
// 所请求的资源不可用 // 所请求的资源不可用
//System.exit(1) System.exit(1)
Thread.sleep(60000)
} }
return Collections.emptyList() return Collections.emptyList()
} }
@@ -266,11 +248,12 @@ class GaoDeUtils {
*/ */
static List<AmapPoiDetail> getAmapDetailById(id){ static List<AmapPoiDetail> getAmapDetailById(id){
def params = [:] def params = [:]
params.key = GAO_DE_AK[keyUsed.intValue()]
params.id = id params.id = id
params.output = 'json' params.output = 'json'
params.key = this.getGaodeKey("v3/place/detail")
JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
if (json == null) { if (json == null) {
params.key = this.getGaodeKey("v3/place/detail")
json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
@@ -281,23 +264,13 @@ class GaoDeUtils {
ex.printStackTrace() ex.printStackTrace()
} }
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
}
} else if (json && json.infocode && json.infocode == "10004") { } else if (json && json.infocode && json.infocode == "10004") {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
} else if (json && json.infocode && json.infocode == "10017") { } else if (json && json.infocode && json.infocode == "10017") {
// 所请求的资源不可用 // 所请求的资源不可用
//System.exit(1) System.exit(1)
Thread.sleep(60000)
} }
return Collections.emptyList() return Collections.emptyList()
} }
@@ -307,7 +280,6 @@ class GaoDeUtils {
*/ */
static List searchPoi(String city, String keywords, String region, String typecodes){ static List searchPoi(String city, String keywords, String region, String typecodes){
def params = [:] def params = [:]
params.key = GAO_DE_AK[keyUsed.intValue()]
params.keywords = keywords params.keywords = keywords
params.city = city params.city = city
params.region = region params.region = region
@@ -324,8 +296,10 @@ class GaoDeUtils {
while (result.size() < count) { while (result.size() < count) {
params.page = "${page}".toString() params.page = "${page}".toString()
page++ page++
params.key = this.getGaodeKey("v5/place/text")
JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params); JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params);
if (json == null) { if (json == null) {
params.key = this.getGaodeKey("v5/place/text")
json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params); json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params);
} }
if (json && json.info && json.info == "OK") { if (json && json.info && json.info == "OK") {
@@ -337,17 +311,7 @@ class GaoDeUtils {
ex.printStackTrace() ex.printStackTrace()
} }
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
break;
}
} else if (json && json.infocode && (json.infocode == "10004" || json.infocode == "10021" || json.infocode == "10017")) { } else if (json && json.infocode && (json.infocode == "10004" || json.infocode == "10021" || json.infocode == "10017")) {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
@@ -377,12 +341,13 @@ class GaoDeUtils {
*/ */
static def getGaoDeAddress(location) { static def getGaoDeAddress(location) {
Map<String, String> params = new HashMap<String, String>() Map<String, String> params = new HashMap<String, String>()
params.put("key", GAO_DE_AK[keyUsed.intValue()])
params.put("location", location) params.put("location", location)
String content String content
try { try {
params.put("key", this.getGaodeKey("v3/geocode/regeo"))
content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8") content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8")
} catch (Exception e) { } catch (Exception e) {
params.put("key", this.getGaodeKey("v3/geocode/regeo"))
content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8") content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8")
} }
net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content) net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content)
@@ -393,16 +358,7 @@ class GaoDeUtils {
return regeocode.formatted_address; return regeocode.formatted_address;
} }
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
}
} else if (json && json.infocode && json.infocode == "10004") { } else if (json && json.infocode && json.infocode == "10004") {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
@@ -418,13 +374,14 @@ class GaoDeUtils {
*/ */
static def parserByGaode(def city, def address) { static def parserByGaode(def city, def address) {
Map<String, String> params = new HashMap<String, String>() Map<String, String> params = new HashMap<String, String>()
params.put("key", GAO_DE_AK[keyUsed.intValue()])
params.put("city", city) params.put("city", city)
params.put("address", address) params.put("address", address)
String content String content
try { try {
params.put("key", this.getGaodeKey("v3/geocode/geo"))
content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8") content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8")
} catch (Exception e) { } catch (Exception e) {
params.put("key", this.getGaodeKey("v3/geocode/geo"))
content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8") content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8")
} }
net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content) net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content)
@@ -437,16 +394,7 @@ class GaoDeUtils {
return ["lng": arrs[0], "lat": arrs[1]] return ["lng": arrs[0], "lat": arrs[1]]
} }
} else if (json && json.infocode && json.infocode == "10044") { } else if (json && json.infocode && json.infocode == "10044") {
synchronized (this) { System.exit(1)
for (int i = 0; i < GAO_DE_AK.size(); i++) {
if (GAO_DE_AK[i] == params.key) {
if (i + 1 >= GAO_DE_AK.size()) {
System.exit(1)
}
keyUsed = new AtomicInteger(i+1)
}
}
}
} else if (json && json.infocode && json.infocode == "10004") { } else if (json && json.infocode && json.infocode == "10004") {
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000) Thread.sleep(60000)
@@ -455,4 +403,8 @@ class GaoDeUtils {
System.exit(1) System.exit(1)
} }
} }
static void main(String[] args) {
println(this.getGaodeKey("v3/geocode/geo"))
}
} }