From d6f7803c6cd27b7263a2b3e539b714289afceef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 13 Apr 2021 14:38:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=95=86=E5=9C=88=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=BB=8F=E7=BA=AC=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/BusinessDianpingAddr.groovy | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/BusinessDianpingAddr.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/BusinessDianpingAddr.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/BusinessDianpingAddr.groovy new file mode 100644 index 000000000..dd8719a3f --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/BusinessDianpingAddr.groovy @@ -0,0 +1,60 @@ +package com.fangjia.script.temp.shenjian + +import com.fangjia.script.util.MongoUtils +import com.fangjia.script.yinjihaun.amap.GaoDeApiUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection +import com.mongodb.DBObject +import net.sf.json.JSONObject +import org.bson.types.ObjectId + +/** + * 获取商圈地标 + * + * @author shenjian + * @since 2021/4/13 + */ +class BusinessDianpingAddr { + + static DBCollection collection = MongoUtils.getCollectionByName("fangjia_crawl", "business", "192.168.0.235", 27018) + + static void main(String[] args) { + def cities = ["苏州", "西安", "合肥"] + for (def city : cities) { + DBObject query = new BasicDBObject() + query.put("city", city) + collection.find(query).batchSize(300).each {obj -> + def id = obj._id + if (obj.lng == null || obj.lat == null) { + // 查询坐标位置,并更新 + def location = this.parserByGaode(city, obj.address) + if (location != null) { + DBObject updateField = new BasicDBObject() + updateField.put("lng", location.lng) + updateField.put("lat", location.lat) + collection.update(new BasicDBObject('url', obj.url), new BasicDBObject('$set', updateField), false, true) + } + } + } + } + collection.find() + } + + static def parserByGaode(def city, def address) { + JSONObject json = GaoDeApiUtils.geo(city, address) + if (json && json.status == "1") { + def ret = json.geocodes + if (ret) { + def str = ret.get(0).location + def level = ret.get(0).level + if (str && ["门牌号", "单元号", "热点商圈", "兴趣点"].contains(level)) { + def arrs = str.split(",") + return ["lng": arrs[0], "lat": arrs[1]] + } else { + println address + " " + level + return null + } + } + } + } +}