新增学校经纬度获取

This commit is contained in:
shenjian@fangjia.com
2022-10-28 18:45:01 +08:00
parent 2122bf3847
commit 110118291e
2 changed files with 59 additions and 9 deletions
@@ -1,6 +1,7 @@
package com.fangjia.script.temp.shenjian.poi
import com.alibaba.fastjson.JSONObject
import com.fangjia.script.temp.shenjian.util.BaiDuUtils
import com.fangjia.script.temp.shenjian.util.EsUtils
import com.fangjia.script.temp.shenjian.util.GaoDeUtils
import com.fangjia.script.util.ElasticUtils
@@ -15,25 +16,26 @@ import java.util.concurrent.Executors
*/
class FillLngLat {
static ExecutorService executorService = Executors.newFixedThreadPool(4)
// static ExecutorService executorService = Executors.newFixedThreadPool(4)
static void main(String[] args) {
ElasticUtils.executeSqlQuery("select * from dws_poi where location is not null", { dataT ->
ElasticUtils.executeSqlQuery("select * from dws_poi where location is null", { dataT ->
final def data = dataT
executorService.submit(new Runnable() {
@Override
void run() {
// executorService.submit(new Runnable() {
// @Override
// void run() {
println(data)
def lngLat = GaoDeUtils.parserByGaode(data.city, data.region + data.name + data.address)
def lngLat = BaiDuUtils.parserByBaidu(data.city, data.region + data.name + data.address)
Thread.sleep(1000)
if (lngLat != null && lngLat.size() == 2 ) {
JSONObject jsonObject = new JSONObject()
jsonObject.put("lon", Double.valueOf(lngLat['lng']))
jsonObject.put("lat", Double.valueOf(lngLat['lat']))
EsUtils.bulkUpdateFieldByIds("dws_poi", "location", jsonObject, Arrays.asList(data.source_id))
}
}
})
// }
// })
})
executorService.shutdown()
//executorService.shutdown()
}
}
@@ -0,0 +1,48 @@
package com.fangjia.script.temp.shenjian.util
import com.alibaba.fastjson.JSONObject
import com.fangjia.core.util.GeoUtils
import com.fangjia.core.util.HttpRequest
import com.fangjia.script.util.DataUtil
import org.apache.commons.lang.StringUtils
/**
* 百度工具类
*
* @author shenjian
* @since 2022/10/28
*/
class BaiDuUtils {
def static final String KEY = "6w9SEHS3hnAFjmY2oEhqIDdgvLPKWXu5"
/**
* 百度地址逆解析,返回高德坐标!!!!!!!!!!!!!!!
* @param city
* @param address
*/
def static parserByBaidu(def city, def address) {
Map<String, String> params = new HashMap<String, String>()
params.put("city", city)
if (StringUtils.isBlank(address)) {
return []
}
params.put("address", address.replaceAll("null", ""))
params.put("output", "json")
params.put("ak", KEY)
params.put("callback", "showLocation")
String content
content = new HttpRequest().get("https://api.map.baidu.com/geocoding/v3/", params, "utf-8")
//content = "showLocation&&showLocation({\"status\":0,\"result\":{\"location\":{\"lng\":131.04009309945693,\"lat\":45.78426770180344},\"precise\":1,\"confidence\":70,\"comprehension\":100,\"level\":\"地产小区\"}})"
content = content.replaceAll("showLocation&&showLocation\\(", "").replaceAll("\\)", "")
JSONObject json = JSONObject.parseObject(content)
if (json.status == 0 && json.result && json.result.location) {
def bd_lng = json.result.location.lng
def bd_lat = json.result.location.lat
Map<String, Double> locationMap = GeoUtils.bd09ToGcj02(bd_lat, bd_lng)
return ["lng": com.fangjia.core.util.DataUtil.getDoubleRound(6, locationMap['lng']), "lat": com.fangjia.core.util.DataUtil.getDoubleRound(6, locationMap['lat'])]
}
return []
}
}