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 + } + } + } + } +}