From edf9694804d7669d685ef0f532149e62a922d545 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Mon, 23 May 2022 11:08:27 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E5=BA=A6=E5=90=8C=E6=AD=A5=E8=87=B385?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OracleDistrict2Mongo85.groovy | 2 +- .../OracleDistrictBasePrice2Mongo85.groovy | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrict2Mongo85.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrict2Mongo85.groovy index 0855b1a8e..93f18dfce 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrict2Mongo85.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrict2Mongo85.groovy @@ -30,7 +30,7 @@ import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicLong /** - * oralce中小区统计数据同步至85中 + * oracle中小区统计数据同步至85中 */ class OracleDistrict2Mongo85 { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy new file mode 100644 index 000000000..64449541a --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy @@ -0,0 +1,52 @@ +package com.fangjia.script.ccbevaluation + +import com.fangjia.core.RegionData +import com.fangjia.core.util.DistrictCodeUtils +import com.fangjia.script.commData.CommonDatautils +import com.fangjia.script.gj.district.FangjiaClientUtils +import com.fangjia.script.lixue.util.DBUtils +import com.fangjia.script.util.DataUtil +import com.fangjia.script.util.DateUtils +import com.fangjia.script.util.DbUtils +import com.fangjia.script.util.ElasticUtils +import com.fangjia.script.util.ExcelUtils +import com.fangjia.script.util.MongoUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection +import com.mongodb.DBObject +import groovy.sql.Sql + +/** + * oracle中小区置信度数据同步至85中 + */ +class OracleDistrictBasePrice2Mongo85 { + + static def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", + "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") + + static final DBCollection communityBasePriceConn = MongoUtils.getCollectionByName("business", "community_base_price_gj", "192.168.0.85", 28017) + + static main(args) { + def sql = "SELECT cityname, distname, commid, commname, confi_rate FROM community_base_price_gj WHERE YEAR_MONTH='202205'" + def count = 0 + sqlInstance.eachRow(sql, { r -> + def city = r['cityname'] + def region = RegionData.formatRegion(city, r['distname']) + DBObject dbObject = new BasicDBObject("_id", r['commid']) + if (r['confi_rate'] != null) { + def credit = new BigDecimal(r['confi_rate']).setScale(2, BigDecimal.ROUND_HALF_UP).toDouble() + DBObject updateObject = new BasicDBObject("city", city).append("region", region) + .append("name", r['commname']) + .append("credit", credit) + .append("c_date", new Date()); + communityBasePriceConn.update(dbObject, updateObject, true, false) + count++; + } else { + print "置信度为空:" + r.toString() + } + if (count % 500 == 0) { + println "已写入" + count + "条小区数据" + } + }); + } +} From a9e7c4fa4b668c1209c24b52809a7c4bedd41db5 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Mon, 23 May 2022 11:45:50 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E5=BA=A6=E5=90=8C=E6=AD=A5=E8=87=B385?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy index 64449541a..a824a3d7e 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/OracleDistrictBasePrice2Mongo85.groovy @@ -27,14 +27,14 @@ class OracleDistrictBasePrice2Mongo85 { static final DBCollection communityBasePriceConn = MongoUtils.getCollectionByName("business", "community_base_price_gj", "192.168.0.85", 28017) static main(args) { - def sql = "SELECT cityname, distname, commid, commname, confi_rate FROM community_base_price_gj WHERE YEAR_MONTH='202205'" + def sql = "SELECT cityname, distname, commid, commname, confidence FROM community_base_price_gj WHERE YEAR_MONTH='202205'" def count = 0 sqlInstance.eachRow(sql, { r -> def city = r['cityname'] def region = RegionData.formatRegion(city, r['distname']) DBObject dbObject = new BasicDBObject("_id", r['commid']) - if (r['confi_rate'] != null) { - def credit = new BigDecimal(r['confi_rate']).setScale(2, BigDecimal.ROUND_HALF_UP).toDouble() + if (r['confidence'] != null) { + def credit = new BigDecimal(r['confidence']).setScale(2, BigDecimal.ROUND_HALF_UP).toDouble() DBObject updateObject = new BasicDBObject("city", city).append("region", region) .append("name", r['commname']) .append("credit", credit) From 41b0b31b7587bdd87d8bfe60e2ebc4d29c39837d Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 14:05:55 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=86=99=E5=85=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poi/SeaweedAroundPoiSingal.groovy | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy index 1a620af34..08b77989b 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy @@ -13,7 +13,13 @@ import com.fangjia.script.wenyan.auto.KeywordSearchUtils import com.mongodb.BasicDBObject import com.mongodb.DBCollection import com.mongodb.DBObject +import com.mongodb.client.model.Filters +import com.mongodb.client.model.UpdateOneModel +import com.mongodb.client.model.UpdateOptions +import com.mongodb.client.model.WriteModel import org.apache.commons.collections.CollectionUtils +import org.bson.Document +import org.bson.conversions.Bson import org.bson.types.ObjectId import java.util.concurrent.ExecutorService @@ -27,74 +33,82 @@ import java.util.concurrent.Executors */ class SeaweedAroundPoiSingal { - static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017) + static def conn136 = MongoUtils.getCollectionByName3("fangjia", "seaweed_poi_sync", "mongodb://developer:G00IDCDEV12385@192.168.0.136:28017") static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi" static void main(String[] args) { - def types = listAllType() - //def types = "0601" - DBObject query = new BasicDBObject() - query.put("status", 1) - conn136.find(query).batchSize(30).each {objTemp -> - final def obj = objTemp - def city = obj.city - def lng = obj.lng - def lat = obj.lat - List pois = GaoDeUtils.searchNearDtoByPoi(city, types, lng, lat, 1000, "") - if (CollectionUtils.isNotEmpty(pois)) { - String jsonStr = JSONObject.toJSONString(pois) - HttpUtils.postForJson(URL, jsonStr) - 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) - } + getNewSeaweed() +// def types = listAllType() +// //def types = "0601" +// DBObject query = new BasicDBObject() +// query.put("status", 1) +// conn136.find(query).batchSize(30).each {objTemp -> +// final def obj = objTemp +// def city = obj.city +// def lng = obj.lng +// def lat = obj.lat +// List pois = GaoDeUtils.searchNearDtoByPoi(city, types, lng, lat, 1000, "") +// if (CollectionUtils.isNotEmpty(pois)) { +// String jsonStr = JSONObject.toJSONString(pois) +// HttpUtils.postForJson(URL, jsonStr) +// 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) +// } } static getNewSeaweed() { DBObject query = new BasicDBObject() query.put("cat", "district") query.put("visible", 0) - //query.put("_id", new ObjectId("50c96f82e4b0e15299cb018a")) DBObject filter = new BasicDBObject() filter.put("_id", 1) filter.put("city", 1) filter.put("region", 1) filter.put("name", 1) + filter.put("alias", 1) + filter.put("address", 1) + filter.put("addr_alias", 1) filter.put("lng", 1) filter.put("lat", 1) - List list = [] + List> writeModelList = new ArrayList<>() DbUtils.seaweed.find(query, filter).batchSize(10000).each {obj -> - if (conn136.count(new BasicDBObject("_id", obj._id)) > 0) { - // 已存在小区,无需同步 - } else { - DBObject newObj = new BasicDBObject() - newObj.put("_id", obj._id) - newObj.put("city", obj.city) - newObj.put("region", obj.region) - newObj.put("name", obj.name) - try { - newObj.put("lng", SeaweedUtils.formatLatLng(obj.lng)) - newObj.put("lat", SeaweedUtils.formatLatLng(obj.lat)) - } catch (Exception ex) { - print("经纬度为空:" + obj._id + " " + obj) - ex.printStackTrace() - } - newObj.put("status", 1) - newObj.put("flag", "未获取周边POI") + Document updateBson = new Document() + Document update = new Document() + update.put("city", obj.city) + update.put("region", obj.region) + update.put("name", obj.name) + update.put("alias", obj.alias) + update.put("address", obj.address) + update.put("addr_alias", obj.addr_alias) + try { + update.put("lng", SeaweedUtils.formatLatLng(obj.lng)) + update.put("lat", SeaweedUtils.formatLatLng(obj.lat)) + } catch (Exception ex) { + print("经纬度为空:" + obj._id + " " + obj) + } + update.put("status", 1) + update.put("flag", "未精确获取高德信息") + updateBson.append('$set', update) - list << newObj - if (list.size() == 5000) { - conn136.insert(list) - list.clear() - } + Bson filterBson = Filters.eq("_id", obj._id) + UpdateOptions updateOptions = new UpdateOptions(); + updateOptions.upsert(true) + UpdateOneModel updateOneModel = new UpdateOneModel(filterBson, updateBson, updateOptions); + writeModelList.add(updateOneModel) + if (writeModelList.size() == 5000) { + conn136.bulkWrite(writeModelList) + writeModelList.clear() } } - conn136.insert(list) - list.clear() + if (writeModelList.size() > 0) { + conn136.bulkWrite(writeModelList) + writeModelList.clear() + } } static def getByIdAndInsert(String id) { From 4f2e84a5d96045f408e2d16f11ccf1f96c574868 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 14:40:20 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=86=99=E5=85=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy index 08b77989b..20def0a9b 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy @@ -76,6 +76,7 @@ class SeaweedAroundPoiSingal { filter.put("lat", 1) List> writeModelList = new ArrayList<>() + def count = 0 DbUtils.seaweed.find(query, filter).batchSize(10000).each {obj -> Document updateBson = new Document() Document update = new Document() @@ -102,6 +103,8 @@ class SeaweedAroundPoiSingal { writeModelList.add(updateOneModel) if (writeModelList.size() == 5000) { conn136.bulkWrite(writeModelList) + count += 5000 + println(count) writeModelList.clear() } } From d57955ef1ee42fce708bae97e15fd33edd2860ae Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 16:43:10 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B0=8F=E5=8C=BA?= =?UTF-8?q?=E9=AB=98=E5=BE=B7=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/SeaweedPoiDetail.groovy | 157 ++++++++++++++++++ .../temp/shenjian/util/GaoDeUtils.groovy | 31 ++++ .../script/statistics/poi/AmapPoiDetail.java | 71 ++++++++ 3 files changed, 259 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy create mode 100644 projects/fangjia-script/src/main/java/com/fangjia/script/statistics/poi/AmapPoiDetail.java diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy new file mode 100644 index 000000000..feffbc12b --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy @@ -0,0 +1,157 @@ +package com.fangjia.script.temp.shenjian.poi + + +import com.alibaba.fastjson.JSONObject +import com.fangjia.script.lixue.util.DBUtils +import com.fangjia.script.statistics.poi.AmapPoi +import com.fangjia.script.statistics.poi.AmapPoiDetail +import com.fangjia.script.temp.shenjian.util.GaoDeUtils +import com.fangjia.script.temp.shenjian.util.HttpUtils +import com.fangjia.script.temp.shenjian.util.SeaweedUtils +import com.fangjia.script.util.DbUtils +import com.fangjia.script.util.MongoUtils +import com.fangjia.script.wenyan.auto.KeywordSearchUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection +import com.mongodb.DBObject +import com.mongodb.client.model.Filters +import com.mongodb.client.model.UpdateOneModel +import com.mongodb.client.model.UpdateOptions +import com.mongodb.client.model.WriteModel +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang.StringUtils +import org.bson.Document +import org.bson.conversions.Bson +import org.bson.types.ObjectId + +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +/** + * 小区POI信息精确查找 + * + * @author shenjian + * @since 2022/5/25 + */ +class SeaweedPoiDetail { + + static def conn136 = MongoUtils.getCollectionByName3("fangjia", "seaweed_poi_sync", "mongodb://developer:G00IDCDEV12385@192.168.0.136:28017") + static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoiDetail" + // 住宅类 + static final String typecodes = "120000|120100|120200|120201|120202|120203|120300|120301|120302|120303|120304"; + static final ExecutorService executorService = Executors.newFixedThreadPool(20) + + static void main(String[] args) { + DBObject query = new BasicDBObject() + query.put("status", 1) + query.put("city", "东莞") + conn136.find(query).batchSize(1000).each {objTemp -> + final def obj = objTemp + executorService.submit(new Runnable() { + @Override + void run() { + def city = obj.city + def region = obj.region + def name = obj.name + def alias = obj.alias + def address = obj.address + def addr_alias = obj.addr_alias + StringJoiner stringJoiner = new StringJoiner("|") + // 主小区名搜索 + stringJoiner.add(name) + // 根据别名搜 + if (alias != null && CollectionUtils.isNotEmpty(alias)) { + for (String str : alias) { + stringJoiner.add(str) + } + } + // 根据路名搜 + if (StringUtils.isNotBlank(address)) { + stringJoiner.add(address) + } + // 根据路别名搜 + if (addr_alias != null && CollectionUtils.isNotEmpty(addr_alias)) { + for (String str : addr_alias) { + stringJoiner.add(str) + } + } + + String keywords = stringJoiner.toString() + List pois = GaoDeUtils.searchPoi(city, keywords, region, typecodes) + + List detailList = new ArrayList<>() + for (AmapPoi amapPoi : pois) { + List amapPoiList = GaoDeUtils.getAmapDetailById(amapPoi.getId()); + if (CollectionUtils.isNotEmpty(amapPoiList)) { + detailList.addAll(amapPoiList) + } + } + if (CollectionUtils.isNotEmpty(detailList)) { + String jsonStr = JSONObject.toJSONString(detailList) + HttpUtils.postForJson(URL, jsonStr) + conn136.updateOne(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 0).append("flag", "已获取到"))) + } else { + conn136.updateOne(new BasicDBObject("_id", obj._id), new BasicDBObject('$set', new BasicDBObject("status", 2).append("flag", "未获取到小区"))) + } + println("已处理小区:" + obj) + } + }) + } + executorService.shutdown() + } + + static getNewSeaweed() { + DBObject query = new BasicDBObject() + query.put("cat", "district") + query.put("visible", 0) + + DBObject filter = new BasicDBObject() + filter.put("_id", 1) + filter.put("city", 1) + filter.put("region", 1) + filter.put("name", 1) + filter.put("alias", 1) + filter.put("address", 1) + filter.put("addr_alias", 1) + filter.put("lng", 1) + filter.put("lat", 1) + + List> writeModelList = new ArrayList<>() + def count = 0 + DbUtils.seaweed.find(query, filter).batchSize(10000).each {obj -> + Document updateBson = new Document() + Document update = new Document() + update.put("city", obj.city) + update.put("region", obj.region) + update.put("name", obj.name) + update.put("alias", obj.alias) + update.put("address", obj.address) + update.put("addr_alias", obj.addr_alias) + try { + update.put("lng", SeaweedUtils.formatLatLng(obj.lng)) + update.put("lat", SeaweedUtils.formatLatLng(obj.lat)) + } catch (Exception ex) { + print("经纬度为空:" + obj._id + " " + obj) + } + update.put("status", 1) + update.put("flag", "未精确获取高德信息") + updateBson.append('$set', update) + + Bson filterBson = Filters.eq("_id", obj._id) + UpdateOptions updateOptions = new UpdateOptions(); + updateOptions.upsert(true) + UpdateOneModel updateOneModel = new UpdateOneModel(filterBson, updateBson, updateOptions); + writeModelList.add(updateOneModel) + if (writeModelList.size() == 5000) { + conn136.bulkWrite(writeModelList) + count += 5000 + println(count) + writeModelList.clear() + } + } + if (writeModelList.size() > 0) { + conn136.bulkWrite(writeModelList) + writeModelList.clear() + } + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index 49c7c18de..aae3318c9 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -7,10 +7,12 @@ import com.fangjia.core.util.DataUtil import com.fangjia.core.util.HttpRequest import com.fangjia.script.common.DataHandleUtils import com.fangjia.script.statistics.poi.AmapPoi +import com.fangjia.script.statistics.poi.AmapPoiDetail import com.fangjia.script.util.GeoHelper import com.fangjia.script.util.HttpRequestUtil import com.fangjia.script.yinjihaun.amap.GaoDeApiUtils import org.apache.commons.lang.StringUtils +import org.openqa.selenium.json.Json import java.util.concurrent.atomic.AtomicInteger @@ -232,6 +234,35 @@ class GaoDeUtils { return Collections.emptyList() } + /** + * 获取详情 + */ + static List getAmapDetailById(id){ + def params = [:] + params.key = GAO_DE_AK[keyUsed.intValue()] + params.id = id + params.output = 'json' + JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); + if (json == null) { + json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); + } + if (json && json.info && json.info == "OK") { + try { + List ret = JSONObject.parseArray(json.pois.toString(), AmapPoi.class) + return ret + } catch(Exception ex) { + ex.printStackTrace() + } + } else if (json && json.infocode && json.infocode == "10004") { + // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 + Thread.sleep(60000) + } else if (json && json.infocode && json.infocode == "10017") { + // 所请求的资源不可用 + System.exit(1) + } + return Collections.emptyList() + } + /** * 查找关键字经纬度 */ diff --git a/projects/fangjia-script/src/main/java/com/fangjia/script/statistics/poi/AmapPoiDetail.java b/projects/fangjia-script/src/main/java/com/fangjia/script/statistics/poi/AmapPoiDetail.java new file mode 100644 index 000000000..8192b359c --- /dev/null +++ b/projects/fangjia-script/src/main/java/com/fangjia/script/statistics/poi/AmapPoiDetail.java @@ -0,0 +1,71 @@ +package com.fangjia.script.statistics.poi; + +import java.util.List; + +/** + * @author shenjian + * @since 2022/5/25 + */ +@lombok.NoArgsConstructor +@lombok.Data +public class AmapPoiDetail { + + @com.alibaba.fastjson.annotation.JSONField(name = "id") + private String id; + @com.alibaba.fastjson.annotation.JSONField(name = "parent") + private List parent; + @com.alibaba.fastjson.annotation.JSONField(name = "childtype") + private List childtype; + @com.alibaba.fastjson.annotation.JSONField(name = "name") + private String name; + @com.alibaba.fastjson.annotation.JSONField(name = "type") + private String type; + @com.alibaba.fastjson.annotation.JSONField(name = "typecode") + private String typecode; + @com.alibaba.fastjson.annotation.JSONField(name = "biz_type") + private List bizType; + @com.alibaba.fastjson.annotation.JSONField(name = "address") + private String address; + @com.alibaba.fastjson.annotation.JSONField(name = "location") + private String location; + @com.alibaba.fastjson.annotation.JSONField(name = "tel") + private String tel; + @com.alibaba.fastjson.annotation.JSONField(name = "pname") + private String pname; + @com.alibaba.fastjson.annotation.JSONField(name = "cityname") + private String cityname; + @com.alibaba.fastjson.annotation.JSONField(name = "adname") + private String adname; + @com.alibaba.fastjson.annotation.JSONField(name = "importance") + private List importance; + @com.alibaba.fastjson.annotation.JSONField(name = "shopid") + private List shopid; + @com.alibaba.fastjson.annotation.JSONField(name = "shopinfo") + private String shopinfo; + @com.alibaba.fastjson.annotation.JSONField(name = "poiweight") + private List poiweight; + @com.alibaba.fastjson.annotation.JSONField(name = "distance") + private String distance; + @com.alibaba.fastjson.annotation.JSONField(name = "biz_ext") + private BizExtDTO bizExt; + @com.alibaba.fastjson.annotation.JSONField(name = "photos") + private List photos; + + @lombok.NoArgsConstructor + @lombok.Data + public static class BizExtDTO { + @com.alibaba.fastjson.annotation.JSONField(name = "rating") + private List rating; + @com.alibaba.fastjson.annotation.JSONField(name = "cost") + private String cost; + } + + @lombok.NoArgsConstructor + @lombok.Data + public static class PhotosDTO { + @com.alibaba.fastjson.annotation.JSONField(name = "title") + private List title; + @com.alibaba.fastjson.annotation.JSONField(name = "url") + private String url; + } +} From 3b5b567a3c6c469b4c29d1e9773e3798ed9ca72c Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 17:49:59 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy index feffbc12b..b40ae6cbf 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy @@ -78,6 +78,9 @@ class SeaweedPoiDetail { String keywords = stringJoiner.toString() List pois = GaoDeUtils.searchPoi(city, keywords, region, typecodes) + if (CollectionUtils.isEmpty(pois)) { + pois = GaoDeUtils.searchPoi(city, name, region, typecodes) + } List detailList = new ArrayList<>() for (AmapPoi amapPoi : pois) { From 3b97cb5c8c80389f0566eabddb5adbb6bc33468d Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 19:31:45 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E8=B6=85=E9=99=90=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/SeaweedPoiDetail.groovy | 1 - .../temp/shenjian/util/GaoDeUtils.groovy | 52 +++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy index b40ae6cbf..dbdd337aa 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy @@ -44,7 +44,6 @@ class SeaweedPoiDetail { static void main(String[] args) { DBObject query = new BasicDBObject() query.put("status", 1) - query.put("city", "东莞") conn136.find(query).batchSize(1000).each {objTemp -> final def obj = objTemp executorService.submit(new Runnable() { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index aae3318c9..33ae920f4 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -90,12 +90,25 @@ class GaoDeUtils { if (json && json.info && json.info == "OK") { count = json.getString("count").toInteger() result.addAll(DataUtil.toMongoDbObj(json.pois)) - } else if (json && json.infocode && json.infocode == 10003) { - throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封") - } else if (json && json.infocode && json.infocode == 10004) { + } else if (json && json.infocode && json.infocode == "10044") { + synchronized (this) { + 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") { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000) break; + } else if (json && json.infocode && json.infocode == "10017") { + // 所请求的资源不可用 + System.exit(1) } else { break } @@ -224,6 +237,17 @@ class GaoDeUtils { } catch(Exception ex) { ex.printStackTrace() } + } else if (json && json.infocode && json.infocode == "10044") { + synchronized (this) { + 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") { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000) @@ -253,6 +277,17 @@ class GaoDeUtils { } catch(Exception ex) { ex.printStackTrace() } + } else if (json && json.infocode && json.infocode == "10044") { + synchronized (this) { + 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") { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000) @@ -398,7 +433,16 @@ class GaoDeUtils { return ["lng": arrs[0], "lat": arrs[1]] } } else if (json && json.infocode && json.infocode == "10044") { - System.exit(1) + synchronized (this) { + 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") { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000) From 299e9e81a013d9cc698afe9fd6546c80589f0b21 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 19:37:59 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E8=B6=85=E9=99=90=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/temp/shenjian/util/GaoDeUtils.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index 33ae920f4..ca4a2ab38 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -94,7 +94,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) @@ -161,7 +161,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) @@ -241,7 +241,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) @@ -281,7 +281,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) @@ -336,7 +336,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) @@ -392,7 +392,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) @@ -436,7 +436,7 @@ class GaoDeUtils { synchronized (this) { for (int i = 0; i < GAO_DE_AK.size(); i++) { if (GAO_DE_AK[i] == params.key) { - if (i + 1 > GAO_DE_AK.size()) { + if (i + 1 >= GAO_DE_AK.size()) { System.exit(1) } keyUsed = new AtomicInteger(i+1) From 082f7fff2080af428ca5b91ec2c472ff9dc32575 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 19:42:57 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/SeaweedPoiDetail.groovy | 15 +++---- .../temp/shenjian/util/CommonDtoUtils.groovy | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy index dbdd337aa..3ae943007 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedPoiDetail.groovy @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject import com.fangjia.script.lixue.util.DBUtils import com.fangjia.script.statistics.poi.AmapPoi import com.fangjia.script.statistics.poi.AmapPoiDetail +import com.fangjia.script.temp.shenjian.util.CommonDtoUtils import com.fangjia.script.temp.shenjian.util.GaoDeUtils import com.fangjia.script.temp.shenjian.util.HttpUtils import com.fangjia.script.temp.shenjian.util.SeaweedUtils @@ -81,13 +82,13 @@ class SeaweedPoiDetail { pois = GaoDeUtils.searchPoi(city, name, region, typecodes) } - List detailList = new ArrayList<>() - for (AmapPoi amapPoi : pois) { - List amapPoiList = GaoDeUtils.getAmapDetailById(amapPoi.getId()); - if (CollectionUtils.isNotEmpty(amapPoiList)) { - detailList.addAll(amapPoiList) - } - } + List detailList = CommonDtoUtils.transformListV(AmapPoiDetail.class, pois); +// for (AmapPoi amapPoi : pois) { +// List amapPoiList = GaoDeUtils.getAmapDetailById(amapPoi.getId()); +// if (CollectionUtils.isNotEmpty(amapPoiList)) { +// detailList.addAll(amapPoiList) +// } +// } if (CollectionUtils.isNotEmpty(detailList)) { String jsonStr = JSONObject.toJSONString(detailList) HttpUtils.postForJson(URL, jsonStr) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy new file mode 100644 index 000000000..89dda4684 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/CommonDtoUtils.groovy @@ -0,0 +1,40 @@ +package com.fangjia.script.temp.shenjian.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +/** + * 通用实体与DTO互相转换工具类 + * + * @author shenjian + * @date 2021/06/16 + */ +public class CommonDtoUtils { + + public static T transformV(Class targetClass, Object source) { + if (source == null) { + return null; + } else { + try { + String jsonSource = JSON.toJSONString(source); + return JSONObject.parseObject(jsonSource, targetClass); + } catch (Exception var3) { + throw var3; + } + } + } + + public static List transformListV(Class targetClass, List listSource) { + if (listSource == null) { + return null; + } else { + try { + String jsonSource = JSON.toJSONString(listSource); + return JSONArray.parseArray(jsonSource, targetClass); + } catch (Exception var3) { + throw var3; + } + } + } +} \ No newline at end of file From cfa7fa9e7e726699afa94f8fdb39634878d1c5a6 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 25 May 2022 19:46:27 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=90=9C=E7=B4=A2key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index ca4a2ab38..b345ef414 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger class GaoDeUtils { // 新获取key - def static GAO_DE_AK = ["4e9592208336433ee1b7aa4d1d434418"] + def static GAO_DE_AK = ["4ccfe3c898a9489884bd2bcb1ef6dcde", "4e9592208336433ee1b7aa4d1d434418"] def static AtomicInteger keyUsed = new AtomicInteger(0) def static codeNameMap = new HashMap(){{ From df815639794d2e2781c534fd73a5a9a58d74e213 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Thu, 26 May 2022 13:38:48 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=B8=8D=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/temp/shenjian/util/GaoDeUtils.groovy | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index b345ef414..9853b7e79 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -175,7 +175,9 @@ class GaoDeUtils { break; } else if (json && json.infocode && json.infocode == "10017") { // 所请求的资源不可用 - System.exit(1) + //System.exit(1) + Thread.sleep(60000) + break; } else { break } @@ -253,7 +255,8 @@ class GaoDeUtils { Thread.sleep(60000) } else if (json && json.infocode && json.infocode == "10017") { // 所请求的资源不可用 - System.exit(1) + //System.exit(1) + Thread.sleep(60000) } return Collections.emptyList() } @@ -293,7 +296,8 @@ class GaoDeUtils { Thread.sleep(60000) } else if (json && json.infocode && json.infocode == "10017") { // 所请求的资源不可用 - System.exit(1) + //System.exit(1) + Thread.sleep(60000) } return Collections.emptyList() } @@ -350,7 +354,9 @@ class GaoDeUtils { break; } else if (json && json.infocode && json.infocode == "10017") { // 所请求的资源不可用 - System.exit(1) + //System.exit(1) + Thread.sleep(60000) + break; } } return result From 2dec82149d0c13acc4f36c831790e73fbfff04b3 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Thu, 26 May 2022 15:38:17 +0800 Subject: [PATCH 12/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fangjia/script/temp/shenjian/util/GaoDeUtils.groovy | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index 9853b7e79..ea456aa50 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -348,14 +348,12 @@ class GaoDeUtils { } break; } - } else if (json && json.infocode && json.infocode == "10004") { + } else if (json && json.infocode && (json.infocode == "10004" || json.infocode == "10021" || json.infocode == "10017")) { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000) break; - } else if (json && json.infocode && json.infocode == "10017") { - // 所请求的资源不可用 - //System.exit(1) - Thread.sleep(60000) + } else if (json && json.infocode && (json.infocode == "20000")) { + // 无效参数 break; } } From 24609324fbb65083c943f131e80759e76d5ab5a3 Mon Sep 17 00:00:00 2001 From: gaojuan Date: Fri, 27 May 2022 15:15:33 +0800 Subject: [PATCH 13/13] update --- .../ccbevaluation/BigdataForsaleBatch.groovy | 11 +- .../DealAndThirdPriceDataProcess.groovy | 11 +- .../script/ccbevaluation/LoadGuide.groovy | 52 +- .../ccbevaluation/data/CcbDistrictToDB.groovy | 128 ++--- .../ccbevaluation/data/DistrictMarge.groovy | 79 ++- .../ccbevaluation/data/MatchMapData.groovy | 29 +- .../ccbevaluation/data/OracleHouse.groovy | 108 ++++ .../chongqing/MatchEvaluateRegionTest.groovy | 399 +++++++++++++- .../fangjia/script/chongqing/PocStat.groovy | 498 +++++++++++++++++- .../fangjia/script/chongqing/PocTest.groovy | 101 +++- .../script/commData/CommonDatautils.groovy | 20 +- .../fuzhou/DistrictPriceExportBatch.groovy | 91 +++- .../script/fuzhou/FzDataResultStat.groovy | 80 ++- .../com/fangjia/script/fuzhou/Test1.groovy | 4 +- .../script/fuzhou/TradeExportBatch.groovy | 27 +- .../script/gj/crawl/AnjukeAppCrawl.groovy | 79 ++- .../fangjia/script/gj/crawl/AnjukeToDB.groovy | 23 +- .../script/gj/district/NameProcess.groovy | 3 +- .../script/gj/level/DistrictIndexBatch.groovy | 5 +- .../script/gj/meituan/MatchTest.groovy | 50 +- .../gj/paimai/BeiKeCrawlByChrome.groovy | 22 +- .../gj/paimai/LianjiaCrawlByChrome.groovy | 14 +- .../script/jiangnanblank/CZDataBatch.groovy | 48 +- .../thirdPriceCrawl/DataStandardBatch.groovy | 2 +- .../script/thirdPriceCrawl/DataStat.groovy | 2 +- .../script/thirdPriceCrawl/Esf58Crawl.groovy | 54 +- .../fangjia/script/util/OpenApiClient.groovy | 36 +- 27 files changed, 1736 insertions(+), 240 deletions(-) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/OracleHouse.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/BigdataForsaleBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/BigdataForsaleBatch.groovy index 8d7bf9732..0bc461cc5 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/BigdataForsaleBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/BigdataForsaleBatch.groovy @@ -97,7 +97,7 @@ class BigdataForsaleBatch extends BaseBatch{ totalCount.addAndGet(1) def commId = rMap.get("_id").toString() - def ret = findHouses(city, rMap.region, "sell", startDate,endDate, rMap.name, rMap.alias) + def ret = findHouses(city, rMap.region, "sell", startDate,endDate, rMap.name, rMap.alias, rMap.estate_type2) //def ret = findHousesByDistId(city, commId, "sell", startDate,endDate) // if(ret && ret.size()<100){//导历史房源需要,以后不需要 // ret = findHouses(city, rMap.region, "sell", 20190701, endDate, rMap.name, rMap.alias) @@ -408,7 +408,7 @@ class BigdataForsaleBatch extends BaseBatch{ } - def findHouses(def city, def region, def cat, def startDate, def endDate, def name, def alias){ + def findHouses(def city, def region, def cat, def startDate, def endDate, def name, def alias, def estate_type2){ QueryBuilder date_range = QueryBuilders.rangeQuery("p_date").from(startDate).to(endDate).includeLower(false).includeUpper(false); QueryBuilder area_range = QueryBuilders.rangeQuery("area").from(20).to(500).includeLower(true).includeUpper(false); @@ -449,6 +449,13 @@ class BigdataForsaleBatch extends BaseBatch{ def map = houses[k]; DBObject seawater = new BasicDBObject(map) + if(estate_type2 && estate_type2=="普通住宅"){ + if(seawater.estate_type&& seawater.estate_type.contains("商住")){ + println city +" "+name+" "+seawater._id.toString()+" "+seawater.estate_type + continue; + } + } + if(!seawater.total_price){ continue; } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/DealAndThirdPriceDataProcess.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/DealAndThirdPriceDataProcess.groovy index d7840e5bb..c8697c956 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/DealAndThirdPriceDataProcess.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/DealAndThirdPriceDataProcess.groovy @@ -15,8 +15,8 @@ class DealPriceDataProcess { - def sqlInstance2 = Sql.newInstance("jdbc:oracle:thin:@192.168.0.94:1521:orcl", - "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") +// def sqlInstance2 = Sql.newInstance("jdbc:oracle:thin:@192.168.0.94:1521:orcl", +// "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") def sqlInstance236 = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") @@ -373,16 +373,17 @@ class DealPriceDataProcess { def citys = CcbCommonUtils.citys def cityCodeDataMap = CcbCommonUtils.findCityCodeValue() def publishTime = '2021-10-01' - def month = 202203 + def month = 202204 def rows = [] for(def city : citys) { - def rets = findPeGteThirdParty(city, 202204) + def rets = findPeGteThirdParty(city, 202205) def total = 0 + println city +" "+rets.size() for(def m : rets){ def sql = "delete from BIGDATA_THIRD_PARTY_PRICE_GJ where commid='${m.commid}' and price_date=${month} and community_price=${m.price}" sqlInstance236.executeUpdate(sql) } - println city +" "+rets.size() + } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/LoadGuide.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/LoadGuide.groovy index 42ad78607..b0476927d 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/LoadGuide.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/LoadGuide.groovy @@ -1,21 +1,29 @@ package com.fangjia.script.ccbevaluation +import com.fangjia.script.commData.CommonDatautils +import com.fangjia.script.util.DateUtils import com.fangjia.script.util.ExcelUtils import com.fangjia.script.util.MongoUtils import com.mongodb.BasicDBObject import com.mongodb.DBCollection import com.fangjia.core.RegionData import com.fangjia.script.gj.district.SeaweedDataMatchProcess +import groovy.sql.Sql +import org.bson.types.ObjectId class LoadGuide { public static final DBCollection DISTRICT_GUIDE_PRICE_COLL = MongoUtils.getCollectionByName("fangjia", "district_guide_price", "mongo.db.fangjia.com", 28017) + def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", + "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") + static main(args) { def task = new LoadGuide() task.run() } def run(){ + addPersonGuided("D:\\数据\\建行\\人工指导价更新.xlsx") // match("D:\\数据\\建行\\房产估值\\指导价\\西安指导价2-103.xlsx") // saveDongGuangPrice("D:\\数据\\建行\\房产估值\\指导价\\东莞指导价218.xlsx") @@ -26,9 +34,51 @@ class LoadGuide { // savePrice("D:\\数据\\建行\\房产估值\\指导价\\西安指导价2-103.xlsx") // savePrice("D:\\数据\\建行\\房产估值\\指导价\\无锡100 广州96 二手住房成交参考价格表.xlsx") // savePrice("D:\\数据\\建行\\房产估值\\指导价\\深圳指导价 - 210909 -.xlsx") - savePrice("D:\\数据\\建行\\房产估值\\指导价\\三亚指导价30.xlsx") +// savePrice("D:\\数据\\建行\\房产估值\\指导价\\三亚指导价30.xlsx") } + + def addPersonGuided(filename){ + ExcelUtils.modify(filename, { d -> + def city = d['B'] + if(city){ + def cityCodeDatas = CcbCommonUtils.findCityCodeValue() + + def distCodeMap = CcbCommonUtils.findAllDistrictCodeValue(city) + createSql( d, cityCodeDatas, distCodeMap) + } + + }) + } + + def createSql(d, cityCodeDatas, distCodeMap){ + def id = new ObjectId() + def commid = d['A'] + def cityId = cityCodeDatas.get(d['B']) + def sampleRegion = d['C'].replace("街道","").replace("镇","") + def distRegion = distCodeMap.get(sampleRegion) + def cityName = d['B'] + def distName = d['C'] + def commName = d['D'] + def price = d['E'].toDouble().toInteger() + + def dist = CommonDatautils.findDistrict(cityName, sampleRegion, commName, "district") + if(dist){ + def createtime = DateUtils.formatDateByPattern(new Date(), "yyyy-MM-dd HH:mm:ss") + def dealDate = DateUtils.formatDateByPattern(new Date(), "yyyy-MM-dd") + + + def sql = "insert into guided_price_gj(ID,COMMID,COMMNAME,CITYID,CITYNAME,DISTID,DISTNAME,DEALDATE,AVG_PRICE,GUIDING_PERSON,REMARK,CREATETIME,UPDATETIME,SOURCECODE) VALUES " + + "('${id.toString()}','${dist._id.toString()}', '${commName}','${cityId}','${cityName}','${distRegion.district_code}','${distName}',to_date('${dealDate}','yyyy-mm-dd'),${price},'房价网','',to_date('${createtime}','yyyy-mm-dd hh24:mi:ss'),to_date('${createtime}','yyyy-mm-dd hh24:mi:ss'),'FJW')" + println sql + sqlInstance.executeUpdate(sql) + }else{ + println " 没查到 "+commName + } + + + } + def match(def filename){ def city = "西安" ExcelUtils.modify(filename,{d-> diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDistrictToDB.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDistrictToDB.groovy index 2db54e10a..98d755434 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDistrictToDB.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/CcbDistrictToDB.groovy @@ -7,6 +7,7 @@ import com.fangjia.core.util.GeoUtils import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.common.DataHandleUtils import com.fangjia.script.gj.OpenApiUtils +import com.fangjia.script.gj.district.NameProcess import com.fangjia.script.linxsh.util.AddressUtil import com.fangjia.script.util.ABuYunUtil import com.fangjia.script.util.CommonUtils @@ -26,9 +27,9 @@ class CcbDistrictToDB { // task.run() // task.run1() // task.meituanRun() -// task.meituanSqrentRun() + task.meituanSqrentRun() // task.updateDistrict() - task.updateDongguangRegion() +// task.updateDongguangRegion() } def updateDongguangRegion(){ @@ -80,13 +81,17 @@ class CcbDistrictToDB { } def meituanSqrentRun(){ - ExcelUtils.modify("D:\\数据\\美团\\美团需入库小区合并后.xlsx", { d -> + def index = 0 + ExcelUtils.modify("D:\\数据\\美团\\美团待入库.xlsx", { d -> + index++ + println index+" "+d['H'] def city = d['F'] def region = d['G'] def newRegion = RegionData.formatRegion(city, region) if(newRegion) { - def name = d['H'] + def name = NameProcess.nameStandard(city, newRegion, d['H']) name = nameFileter(name) + if(name){ def estateType2 = "普通住宅" if(name.contains("别墅")){ @@ -103,7 +108,6 @@ class CcbDistrictToDB { } } } - def lastMonthDay = DateUtil.truncateDay(DateUtil.getLastDayOfMonth(new Date(), -1)); CommonUtils.recalculationSqRent(city, region, name, estateType2, lastMonthDay,false,0) } @@ -115,97 +119,100 @@ class CcbDistrictToDB { def index = 0//美团需入库小区合并后.xlsx def keys = new CopyOnWriteArrayList() - ExcelUtils.multiThreadingModify("D:\\数据\\美团\\美团需入库小区合并后.xlsx", { d -> + ExcelUtils.multiThreadingModify("D:\\数据\\美团\\美团待入库.xlsx", { d -> + index++ + println index+" "+d['H'] def city = d['F'] def region = d['G'] def newRegion = RegionData.formatRegion(city, region) - if(newRegion){ - def name = d['H'] + if(newRegion) { + def name = NameProcess.nameStandard(city, newRegion, d['H']) name = nameFileter(name) + if (name) { def formatAddress = null - if(d['E']){ - formatAddress = AddressUtil.formatAddress(city, d['E']) + if (d['I']) { + formatAddress = AddressUtil.formatAddress(city, d['I']) } - if(!formatAddress || (formatAddress && !formatAddress.contains("号") && !formatAddress.contains("交叉"))){ - def rets = OpenApiUtils.getGaoDeSearchLocation(city, region, name) - def map = findStandardObject2(city,region, name, d['E'], rets); - if(map && map.address){ - formatAddress = AddressUtil.formatAddress(city, map.address) - if(!formatAddress){ - if(map.address.contains("交叉口")){ - formatAddress = map.address.substring(0, map.address.toString().indexOf("交叉口")+3) - }else if(map.address.contains("交叉")){ - formatAddress = map.address.substring(0, map.address.toString().indexOf("交叉")+2) - } - } - } - } +// if(!formatAddress || (formatAddress && !formatAddress.contains("号") && !formatAddress.contains("交叉"))){ +// def rets = OpenApiUtils.getGaoDeSearchLocation(city, region, name) +// def map = findStandardObject2(city,region, name, d['E'], rets); +// if(map && map.address){ +// formatAddress = AddressUtil.formatAddress(city, map.address) +// if(!formatAddress){ +// if(map.address.contains("交叉口")){ +// formatAddress = map.address.substring(0, map.address.toString().indexOf("交叉口")+3) +// }else if(map.address.contains("交叉")){ +// formatAddress = map.address.substring(0, map.address.toString().indexOf("交叉")+2) +// } +// } +// } +// } Long glat = null Long glng = null Long blat = null Long blng = null - if(d['K']){ - glat = d['L'].toString().toDouble() * 10000000000L - glng = d['K'].toString().toDouble() * 10000000000L - def baidu = BaiDuApiUtils.geoconv(d['K'].toString().toDouble(), d['L'].toString().toDouble(), 3) + if (d['L']) { + glat = d['M'].toString().toDouble() * 10000000000L + glng = d['L'].toString().toDouble() * 10000000000L + def baidu = BaiDuApiUtils.geoconv(d['L'].toString().toDouble(), d['M'].toString().toDouble(), 3) blng = baidu.x * 10000000000L blat = baidu.y * 10000000000L } def estateType2 = "普通住宅" - if(name.contains("别墅")){ + if (name.contains("别墅")) { estateType2 = "别墅" - }else if(name.contains("商住")){ + } else if (name.contains("商住")) { estateType2 = "商住" - }else{ - def type = d['I'] - if(type){ - if(type.contains("别墅")){ + } else { + def type = d['J'] + if (type) { + if (type.contains("别墅")) { estateType2 = "别墅" - }else if(type.contains("商住")){ + } else if (type.contains("商住")) { estateType2 = "商住" } } } - def key = city+"##"+newRegion+"##"+name - if(name && !keys.contains(key)){ + def key = city + "##" + newRegion + "##" + name + if (name && !keys.contains(key)) { def dist = CommonDatautils.findDistrict(city, newRegion, name, "district") - if(!dist){ + if (!dist) { keys << key def data = new BasicDBObject(); - data.put("name_cat",0) - data.put("status",0) - data.put("cat","district") + data.put("name_cat", 12) + data.put("status", 0) + data.put("cat", "district") data.put("c_date", new Date()) data.put("m_date", new Date()) data.put("city", city) - data.put("region",newRegion) + data.put("region", newRegion) data.put("name", name) - data.put("estate_type2",estateType2) + data.put("estate_type2", estateType2) data.put("address", formatAddress) - if(glat){ - data.put("lat",glat) - data.put("lng",glng) - data.put("lat2",blat) - data.put("lng2",blng) + if (glat) { + data.put("lat", glat) + data.put("lng", glng) + data.put("lat2", blat) + data.put("lng2", blng) } def markMap = [:] markMap.put("data_source", "机器入库") - data.put("mark_map",markMap) + data.put("mark_map", markMap) index++ DbUtils.seaweed.save(data); - println index+" "+data + println index + " " + data def stop = false - while (!stop){ - if(data._id.toString()){ + while (!stop) { + if (data._id.toString()) { addPrice(data) stop = true; } @@ -213,19 +220,17 @@ class CcbDistrictToDB { } } + } }else{ println city +" "+region +" 区域无法标准化" } },0); - - - } def addPrice(dist){ - def startDate = DateUtils.parseFromTightYYYYMMDD("2022-03-01") - def endDate = DateUtils.parseFromTightYYYYMMDD("2022-04-25") + def startDate = DateUtils.parseFromTightYYYYMMDD("2022-05-01") + def endDate = DateUtils.parseFromTightYYYYMMDD("2022-05-24") def weekends = DateUtils.getWeekendBetweenDates(startDate, endDate) for(def weekend : weekends){ @@ -435,9 +440,12 @@ class CcbDistrictToDB { } def nameFileter(def name){ - name = name.replace("·","").replace(".","").replace("|","") - name = name.replace("1期","一期").replace("2期","二期").replace("3期","三期").replace("4期","四期").replace("5期","五期").replace("6期","6期") - name = name.replace("1区","一区").replace("2区","二区").replace("3区","三区").replace("4区","四区").replace("5区","五区").replace("6区","六区") + if(name){ + name = name.replace("·","").replace(".","").replace("|","") + name = name.replace("1期","一期").replace("2期","二期").replace("3期","三期").replace("4期","四期").replace("5期","五期").replace("6期","6期") + name = name.replace("1区","一区").replace("2区","二区").replace("3区","三区").replace("4区","四区").replace("5区","五区").replace("6区","六区") + } + return name; } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/DistrictMarge.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/DistrictMarge.groovy index a1e095a7f..afa2233b6 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/DistrictMarge.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/DistrictMarge.groovy @@ -1,10 +1,12 @@ package com.fangjia.script.ccbevaluation.data +import com.fangjia.core.RegionData import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.linxsh.util.AddressUtil import com.fangjia.script.util.DbUtils import com.fangjia.script.util.ExcelUtils import com.mongodb.BasicDBObject +import com.mongodb.DBObject import org.apache.poi.ss.util.RegionUtil import org.bson.types.ObjectId import com.fangjia.core.util.BaiDuApiUtils @@ -13,7 +15,82 @@ class DistrictMarge { static main(args) { def task = new DistrictMarge() //task.run() - task.repeatAddress() +// task.repeatAddress() +// task.removeDist() + task.updateAddress() +// task.addMappingAlias() + } + def updateAddress(){ + ExcelUtils.multiThreadingModify("D:\\数据\\建行\\更新小区地址.xlsx", { d -> + if (d['A']) { + def region = d['B'].trim() + def newRegion = RegionData.formatRegion(d['A'], region) + if (newRegion) { + def dist = CommonDatautils.findDistrict(d['A'], newRegion, d['C'], "district") + if (dist) { + DBObject udata = new BasicDBObject() + udata.put("address", d['D']) + udata.put("m_date", new Date()) + DbUtils.seaweed.update(new BasicDBObject('_id', dist._id),new BasicDBObject('$set', udata)) + } + }else{ + println d['A'] + " 格式化失败 "+d['B'] + } + } + }); + } + + def removeDist(){ + ExcelUtils.multiThreadingModify("D:\\数据\\建行\\删除小区.xlsx", { d -> + if (d['A']) { + def region = d['B'] + def newRegion = RegionData.formatRegion(d['A'], region) + if (newRegion) { + def dist = CommonDatautils.findDistrict(d['A'], newRegion, d['C'], "district") + if (dist) { + DBObject udata = new BasicDBObject() + udata.put("status", 1) + udata.put("m_date", new Date()) + DbUtils.seaweed.update(new BasicDBObject('_id', dist._id),new BasicDBObject('$set', udata)) + } + }else{ + println d['A'] + " 格式化失败 "+d['B'] + } + } + }) + } + + def addMappingAlias(){ + def index = 0 + ExcelUtils.multiThreadingModify("D:\\数据\\建行\\新增映射别名.xlsx", { d -> + index ++ + if (d['A']) { + def region = d['B'].trim() + def newRegion = RegionData.formatRegion(d['A'], region) + if (newRegion) { + def dist = CommonDatautils.findDistrict(d['A'], newRegion, d['C'], "district") + if (dist) { + def mapping_alias = dist.mapping_alias + if(!dist.mapping_alias){ + mapping_alias = [] + } + def alias = d['D'] + def arrs = alias.split("、") + for(def s : arrs){ + if(!mapping_alias.contains(s)){ + mapping_alias << s + } + } + DBObject udata = new BasicDBObject() + udata.put("mapping_alias", mapping_alias) + udata.put("m_date", new Date()) + DbUtils.seaweed.update(new BasicDBObject('_id', dist._id),new BasicDBObject('$set', udata)) + } + }else{ + println d['A'] + " 格式化失败 "+d['B'] + } + } + }) } def repeatAddress(){ diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/MatchMapData.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/MatchMapData.groovy index 2f5d02c2f..a62cf530f 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/MatchMapData.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/MatchMapData.groovy @@ -36,10 +36,37 @@ class MatchMapData { // task.run3() // task.exportHouse() // task.addDistrictLevel() - task.run4() +// task.run4() + task.run5() } + def run5(){ + ExcelUtils.multiThreadingModify("D:\\数据\\建行\\数据核实.xlsx", { d -> + if (d['A']) { + def region = d['B'] + def newRegion = RegionData.formatRegion(d['A'], region) + if (newRegion) { + def dist = CommonDatautils.findDistrict(d['A'], newRegion, d['C'], "district") + if(dist){ + if(dist.mapping_alias){ + d['D'] = dist.mapping_alias.join(",") + } + d['E'] = dist.address + } + + def dist1 = CommonDatautils.findDistrict(d['A'], newRegion, d['G'], "district") + if(dist1){ + if(dist1.mapping_alias){ + d['H'] = dist1.mapping_alias.join(",") + } + d['I'] = dist1.address + } + } + } + }); + } + def run4() { ExcelUtils.multiThreadingModify("D:\\数据\\建行\\房产估值\\小区\\核实小区是否存在.xlsx", { d -> def regionCode = null diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/OracleHouse.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/OracleHouse.groovy new file mode 100644 index 000000000..ebb9c165b --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/ccbevaluation/data/OracleHouse.groovy @@ -0,0 +1,108 @@ +package com.fangjia.script.ccbevaluation.data + +import com.fangjia.script.commData.CommonDatautils +import com.fangjia.script.gj.ccb.FileUtils +import com.fangjia.script.util.ElasticUtils +import com.mongodb.BasicDBObject +import groovy.sql.Sql +import org.elasticsearch.index.query.BoolQueryBuilder +import org.elasticsearch.index.query.QueryBuilder +import org.elasticsearch.index.query.QueryBuilders +import org.elasticsearch.xpack.sql.jdbc.EsDataSource + +import java.sql.ResultSet +import java.util.concurrent.CountDownLatch +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors +import java.util.concurrent.atomic.AtomicLong + +class OracleHouse { + def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", + "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") + + + public static String address = "jdbc:es://http://seawater.es.db.fangjia.com:9200/timezone=UTC&page.size=250&connect.timeout=120s&network.timeout=120s&page.timeout=120s" + public static EsDataSource dataSource = new EsDataSource() + static { + dataSource.setUrl(address) + Properties connectionProperties = new Properties() + connectionProperties.put("user", "developer") + connectionProperties.put("password", "5e8edd851d2fdfbd7415232c67367cc3") + dataSource.setProperties(connectionProperties) + } + + + public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(30) + + static main(args) { + def task = new OracleHouse() + task.run() + } + + def run(){ + def rets = findAllHouse("2022-04-19") + def totalCount = new AtomicLong() + println rets.size() + final CountDownLatch latch = new CountDownLatch(rets.size()) + for(def i=0;i + index = index + 1 + println index + def data = [] + data << r.FORSALEID + data << r.COMMID + allRows << data + }); + return allRows + } + + def removeHouse(houseid){ + def sql = "delete from bigdata_forsale_gj where FORSALEID='${houseid}' "; + sqlInstance.executeUpdate(sql) + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/MatchEvaluateRegionTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/MatchEvaluateRegionTest.groovy index b35f27015..9ac21fba3 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/MatchEvaluateRegionTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/MatchEvaluateRegionTest.groovy @@ -2,28 +2,43 @@ package com.fangjia.script.chongqing import com.fangjia.core.RegionData import com.fangjia.core.util.BaiDuApiUtils +import com.fangjia.core.util.DateUtil +import com.fangjia.httpclient.UserAgents import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.common.DataHandleUtils import com.fangjia.script.gj.OpenApiUtils import com.fangjia.script.gj.district.FangjiaClientUtils import com.fangjia.script.gj.paimai.DataUtil import com.fangjia.script.linxsh.util.AddressUtil +import com.fangjia.script.util.ABuYunUtil import com.fangjia.script.util.CommonUtils import com.fangjia.script.util.DateUtils import com.fangjia.script.util.DbUtils +import com.fangjia.script.util.ElasticUtils import com.fangjia.script.util.ExcelUtils +import com.fangjia.script.util.GeoHelper +import com.fangjia.script.util.JacksonUtil import com.fangjia.script.util.OpenApiClient +import com.fangjia.script.yinjihaun.amap.GaoDeApiUtils +import com.google.gson.JsonObject import com.mongodb.BasicDBObject +import com.mongodb.DBObject import groovy.sql.Sql +import net.sf.json.JSONObject +import org.apache.commons.lang.StringUtils +import org.elasticsearch.index.query.QueryBuilder +import org.elasticsearch.index.query.QueryBuilders import java.util.concurrent.CopyOnWriteArrayList +import java.util.zip.GZIPInputStream class MatchEvaluateRegionTest { + static def targetUrl = "http://192.168.0.12:9200/district_comp_potential/" def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") - def path = "D:\\数据\\重庆农商行\\2022-05-06\\估值限时测试-重庆农商行1.0.xlsx" + def path = "D:\\数据\\美团\\10城小区明细-V10.xlsx" def total = 1500 static main(args) { @@ -31,14 +46,26 @@ class MatchEvaluateRegionTest { // task.run()//小区匹配 // task.run1()//地图匹配 // task.addDistrict();//新增人工处理小区,原文件匹配不上的去除 - task.addPrice() +// task.addPrice() // task.addArroundPrice() +// task.addArroundPriceByLat() +// task.addRentRate() // task.addAuthor() +// task.addLevel() +// task.addSorce() +// task.addArroundScore() + + task.pkPrice() + } def run(){ + + def index = 0 ExcelUtils.multiThreadingModify(path, { row -> + index ++ if(!row['F']){ - def jsonObject = OpenApiClient.addressMatch("重庆", row['C'], "property", false,null,null,) + println index+" "+row['E'] + def jsonObject = OpenApiClient.addressMatch(row['A'], row['C'], "property", false,row['B'],null) if(jsonObject != null && jsonObject.precise!=-1) { row['F'] = jsonObject.get("id") row['G'] = jsonObject.get("city") @@ -47,8 +74,8 @@ class MatchEvaluateRegionTest { row['J'] = jsonObject.get("address") row['K'] = jsonObject.get("propertyType") row['L'] = jsonObject.get("map") -// row['K'] = jsonObject.get("lng") -// row['L'] = jsonObject.get("lat") + row['M'] = jsonObject.get("lng") + row['N'] = jsonObject.get("lat") } } }); @@ -56,8 +83,8 @@ class MatchEvaluateRegionTest { def run1(){ ExcelUtils.multiThreadingModify(path, { row -> - if(!row['F']){ - def jsonObject = OpenApiClient.addressMatch("重庆", row['C'], null, true, null, null) + if(!row['F'] && row['A']){ + def jsonObject = OpenApiClient.addressMatch(row['A'], row['E'], null, true, row['B'],row['C'].toString()) if(jsonObject != null && jsonObject.precise!=-1) { row['F'] = jsonObject.get("id") row['G'] = jsonObject.get("city") @@ -66,42 +93,81 @@ class MatchEvaluateRegionTest { row['J'] = jsonObject.get("address") row['K'] = jsonObject.get("propertyType") row['L'] = jsonObject.get("map") -// row['K'] = jsonObject.get("lng") -// row['L'] = jsonObject.get("lat") + row['M'] = jsonObject.get("lng") + row['N'] = jsonObject.get("lat") } } }); } + def pkPrice(){ + ExcelUtils.multiThreadingModify(path, { row -> + if(row['R'] && row['R'].toString().toDouble().toInteger()==1){ + def obj = CommonDatautils.queryDistrictPrice(row['G'], row['H'], row['I'], DateUtils.parseFromTightByPattern("2022-05-22","yyyy-MM-dd")) + if(!obj){ + row['R'] = '' + row['S'] = "无最新价" + } + } + }); + + } + def addPrice(){ ExcelUtils.multiThreadingModify(path, { row -> if(!row['L']){ def priceObj = CommonDatautils.findDistrictPrice(row['G'], row['H'], row['I']) if(priceObj){ - row['M'] = priceObj.avg_price - row['N']= (int)(priceObj.avg_price * row['E']) + row['O'] = priceObj.avg_price + // row['N']= (int)(priceObj.avg_price * row['E']) } - def avg_price = findAvgPrice(row['F']) - if(row['M'] && avg_price){ - def weekendPrice = row['M'].toString().toDouble() - def ppe15 = Math.abs((weekendPrice - avg_price) * 100 / avg_price) - row['O'] = com.fangjia.script.common.DataHandleUtils.getDoubleRound(2, ppe15) + def sqmetreRentPrice = CommonDatautils.findNewSqmetreRent(row['G'], row['H'], row['I']) + if(sqmetreRentPrice){ + row['P'] = sqmetreRentPrice } + +// def avg_price = findAvgPrice(row['F']) +// if(row['M'] && avg_price){ +// def weekendPrice = row['M'].toString().toDouble() +// def ppe15 = Math.abs((weekendPrice - avg_price) * 100 / avg_price) +// row['O'] = com.fangjia.script.common.DataHandleUtils.getDoubleRound(2, ppe15) +// } } }); } + def addRentRate(){ + def citys = ["昆明","南宁","郑州","长沙","贵阳","乌鲁木齐","中山","湛江","南昌","海口"] + def radioMap = [:] + for(def city : citys) { + def lastMonthDay = DateUtil.truncateDay(DateUtil.getLastDayOfMonth(new Date(), -1)); + def avg_radio = CommonDatautils.findCityAvgRentRadio(city, lastMonthDay) + radioMap.put(city, avg_radio) + } + + ExcelUtils.multiThreadingModify(path, { row -> + def city = row['G'] + if (row['F'] && row['O'] && !row['P']) { + def avg_rent_radio = radioMap.get(city) + if(avg_rent_radio){ + row['P'] = (int)(row['O']/avg_rent_radio) + row['S'] = "租金推算1" + } + } + }) + } + def addArroundPrice(){ ExcelUtils.multiThreadingModify(path, { row -> - if(!row['M']) { - def arroundObj = FangjiaClientUtils.arroundPrice(row['B'], row['D']) + if(!row['O']) { + def arroundObj = FangjiaClientUtils.arroundPrice(row['A'], row['E']) if (arroundObj && arroundObj.msgCode == 200 && arroundObj.result) { def priceObj = arroundObj.result - row['M'] = priceObj.unitPrice - row['N'] = (int) (priceObj.unitPrice * row['E']) - row['Q'] = "周边价格" + row['O'] = priceObj.unitPrice +// row['N'] = (int) (priceObj.unitPrice * row['E']) + row['S'] = "周边价格" } } }); @@ -252,4 +318,295 @@ class MatchEvaluateRegionTest { }); return avg_price } + + def addSorce(){ + ExcelUtils.multiThreadingModify(path, { d -> + if(d['F']){ + def score = findDistrictScore(d['F']) + if(score){ + d['R'] = score + } + } + }); + } + + def addArroundScore(){ + ExcelUtils.multiThreadingModify(path, { d -> + if(!d['R'] && d['F']){ + def dist = null + if(d['F'].toString().size()>16){ + dist = CommonDatautils.findDistrictById(d['F']) + } + + if(!dist){ + dist = new BasicDBObject() + dist.city = d['G'] + dist.lng = d['M'].toString().toDouble()*10000000000L + dist.lat = d['N'].toString().toDouble()*10000000000L + } + if(dist.lat){ + List list = DbUtils.findAroundDistrict(dist) + if (list) { + list = sortByDistance(dist, list); + if(list && list.size()>10){ + list = list[0..9] + } + if(list){ + def scores = [] + for(def s : list){ + def score = findDistrictScore(s._id.toString()) + if(score){ + scores << score + } + } + def arround_score =(int)(scores.sum()/scores.size()) + d['R'] = arround_score + d['T'] = "周边小区评分2" + } + } + } + } + }); + } + + def addArroundPriceByLat(){ + ExcelUtils.multiThreadingModify(path, { d -> + if(!d['O'] && d['F'] && (d['K'].contains("住宅") || d['K'].contains("商住") ||d['K'].contains("别墅"))){ + def dist = null + if(d['F'].toString().size()>16){ + dist = CommonDatautils.findDistrictById(d['F']) + } + + if(!dist){ + dist = new BasicDBObject() + dist.city = d['G'] + dist.lng = d['M'].toString().toDouble()*10000000000L + dist.lat = d['N'].toString().toDouble()*10000000000L + } + if(dist.lat){ + List list = DbUtils.findAroundDistrict(dist) + if (list) { + list = sortByDistance(dist, list); + if(list && list.size()>10){ + list = list[0..9] + } + if(list){ + def prices = [] + for(def s : list){ + def priceObj = CommonDatautils.findDistrictPrice(s.city, s.region, s.name) + if(priceObj){ + prices << priceObj.avg_price + } + } + if(prices){ + def arround_price =(int)(prices.sum()/prices.size()) + d['O'] = arround_price + d['S'] = "周边均价3" + } + } + } + } + } + }); + } + + + def sortByDistance(d, list){ + def newList = [] + for(def nb : list){ + def distance = GeoHelper.GetDistance(d.lat/10000000000.0, d.lng/10000000000.0, nb.lat/10000000000.0, nb.lng/10000000000.0) + nb.distance = distance + newList << nb + } + //排序 + Collections.sort(newList, new Comparator() { + @Override + int compare(Object o1, Object o2) { + if(o1.distance > o2.distance) + return 1;//第二个元素(o1)比第一个元素(o2)大,返回-1 + if(o1.distance == o2.distance) + return 0; + return -1; + } + }) + + return newList; + } + + + + def findDistrictScore(id){ + QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("_id", id)) + def indexObj = ElasticUtils.executeSimpleQuery("192.168.0.12", "district_comp_potential", queryBuilder); + def score = 0 + for(def h : indexObj){ + score = h.total_price_rate + if(score){ + break; + } + } + return score + } + + + def addLevel() { + def citys = ["昆明","南宁","郑州","长沙","贵阳","乌鲁木齐","中山","湛江","南昌","海口"]// + def weekend = DateUtils.getFirstDayOfWeek(new Date()); + def cityLevelMap = [:] + for(def city : citys){ + def dists = CommonDatautils.findAllDistrictByCity(city, "district", ["city", "region","name"]) + def priceMap = CommonDatautils.queryDistrictPrice(city, weekend) + def datas = addPriceData(dists, priceMap); + datas = calcuteLevel(datas); + cityLevelMap.put(city, ["price":priceMap, "level":datas]) + println city +" 楼盘评级同步完成" + } + + ExcelUtils.multiThreadingModify(path, { row -> + + def address = row['E'] + def city = RegionData.formatCity(row['A']) + + if(row['K'] && !row['K'].contains("住宅") && !row['K'].contains("商住") && !row['K'].contains("别墅")){ + if(city){ + def map = cityLevelMap.get(city) + def rMap = null + if(map){ + rMap = getArroundDistrictPriceByAddress(city, address, map.level) + } + + if(rMap){ + if(rMap.rank){ + row['Q'] = rMap.rank + } + } + } + } + }) + } + + def addPriceData(dists, priceMap){ + def newLists = [] + for(def d : dists){ + def price = priceMap.get(d.city+"##"+d.region+"##"+d.name); + if(price){ + d.avg_price = price; + newLists << d; + } + } + if(newLists){ + newLists.sort {a,b-> + def v1 = a.avg_price + def v2 = b.avg_price + return v1.compareTo(v2) + } + } + return newLists; + } + + def calcuteLevel(def datas){ + def total = datas.size() + def v = (int)(total/10) + def start = 0; + def end = 0; + def map = [:] + for(int i=1;i<=10;i++){ + end = end + v; + if(i == 10){ + map.put(i, [start, total]) + }else{ + map.put(i, [start, end]) + } + start = end; + } + for(def d=0;dm && d<=n){ + dist.level = 10 - o.key + 1 + break + } + } + } + } + return datas; + } + + def getArroundDistrictPriceByAddress(def city, def address, def levels){ + def json = GaoDeApiUtils.geo(city, address) + def location = null + def detail = new BasicDBObject() + def level = null + def rank = null + if(json && json.count>=1){ + def m = json.geocodes[0] + if(m){ + location = m.location + level = m.level + } + } + if(location){ + def arrs = location.split(",") + detail.lng = arrs[0].toString().toDouble()*10000000000L + detail.lat = arrs[1].toString().toDouble()*10000000000L + } + if(detail.lng){ + detail.city = city + + List list = DbUtils.findAroundDistrictByRadius(detail, 3000) + if(list && list.size()>10){ + list = sortByDistance(detail, list); + try{ + list = list[0..9] + }catch(Exception e){ + println list.size() + } + + } + def arroundAvgPrice = getArroundAvgPrice(list) + if(arroundAvgPrice){ + + def mod = Integer.MAX_VALUE; + for(def d : levels){ + def newMod = java.lang.Math.abs( d.avg_price - arroundAvgPrice) + if(newMod + def floorsCount = 0; + def buildYearCount = 0 + def householdsCount = 0 + def elevatorNumberCount = 0 + def roomCount = 0 + + def f_floorsCount = 0; + def f_buildYearCount = 0 + def f_householdsCount = 0 + def f_elevatorNumberCount = 0 + def f_roomCount = 0 + + def dist = CommonDatautils.findDistrictById(key) + + if(zRegions.contains(dist.region)){ + z_count++ + }else{ + f_count++ + } + + for(def row : lists){ + + if(zRegions.contains(dist.region)){ + + if(row.floors){ + floorsCount++ + } + if(dist.finish_building_date){ + buildYearCount++ + } + if(row.households){ + householdsCount++ + }else{ + if(row.room_count && row.floors){ + householdsCount++ + } + } + if(row.elevatorNumber && row.elevatorNumber>0){ + elevatorNumberCount++ + } + + if(row.room_count>0){ + roomCount++ + } + + }else{ + if(row.floors){ + f_floorsCount++ + } + if(dist.finish_building_date){ + f_buildYearCount++ + } + if(row.households){ + f_householdsCount++ + }else{ + if(row.room_count && row.floors){ + f_householdsCount++ + } + } + if(row.elevatorNumber && row.elevatorNumber>0){ + f_elevatorNumberCount++ + } + + if(row.room_count>0){ + f_roomCount++ + } + } + + } + + def dist_total_count = lists.size()*0.6 + if(floorsCount >= dist_total_count){ + all_floorsCount ++ + } + + if(buildYearCount >= dist_total_count){ + all_buildYearCount ++ + } + + if(householdsCount >= dist_total_count){ + all_householdsCount ++ + } + + if(elevatorNumberCount >= dist_total_count){ + all_elevatorNumberCount ++ + } + + if(roomCount >= dist_total_count){ + all_roomCount ++ + } + + + if(f_floorsCount >= dist_total_count){ + f_all_floorsCount ++ + } + + if(f_buildYearCount >= dist_total_count){ + f_all_buildYearCount ++ + } + + if(f_householdsCount >= dist_total_count){ + f_all_householdsCount ++ + } + + if(f_elevatorNumberCount >= dist_total_count){ + f_all_elevatorNumberCount ++ + } + if(f_roomCount >= dist_total_count){ + f_all_roomCount ++ + } + } + def floor_prec = DataHandleUtils.getDoubleRound(2, all_floorsCount*100/z_count) + def year_prec = DataHandleUtils.getDoubleRound(2, all_buildYearCount*100/z_count) + def households_prec = DataHandleUtils.getDoubleRound(2, all_householdsCount*100/z_count) + def elevatorNum_prec = DataHandleUtils.getDoubleRound(2, all_elevatorNumberCount*100/z_count) + def roomcount_prec = DataHandleUtils.getDoubleRound(2, all_roomCount*100/z_count) + + + def f_floor_prec = DataHandleUtils.getDoubleRound(2, f_all_floorsCount*100/f_count) + def f_year_prec = DataHandleUtils.getDoubleRound(2, f_all_buildYearCount*100/f_count) + def f_households_prec = DataHandleUtils.getDoubleRound(2, f_all_householdsCount*100/f_count) + def f_elevatorNum_prec = DataHandleUtils.getDoubleRound(2, f_all_elevatorNumberCount*100/f_count) + def f_roomcount_prec = DataHandleUtils.getDoubleRound(2, f_all_roomCount*100/f_count) + + println "floor "+ floor_prec + println "year "+ year_prec + println "households "+ households_prec + println "elevator "+ elevatorNum_prec + + def rets = [] + rets << ["城区","楼栋号","楼栋ID","物业类型","主朝向","地上层数","地下层数","竣工日期","梯","户","总户数","景观"] + rets << ["主城区",100,100,100,0,floor_prec,0,year_prec,elevatorNum_prec,roomcount_prec,households_prec,0] + rets << ["非主城区",100,100,100,0,f_floor_prec,0,f_year_prec,f_elevatorNum_prec,f_roomcount_prec,f_households_prec,0] + ExcelUtils.write("D:\\数据\\重庆农商行\\poc\\底层数据统计.xlsx",rets, "楼栋") + } + + + def houseLoudongStat2(){ + def zRegions = ["渝中","大渡口","江北","沙坪坝","九龙坡","南岸","北碚","渝北","巴南"] + def dists = CommonDatautils.findAllDistrictByCity("重庆","district", ["city","region","name"]) + def z_count = 0 + def f_count = 0 + + def z_directionCount = 0 + def f_directionCount = 0 + + def f_sightCount = 0 + def z_sightCount = 0 + def index = 0 + for(def dist : dists){ + index ++ + def rets = getAllHouseLoudong2(dist._id.toString()) + println index +" "+rets.size() + if(rets){ + def directionCount = 0 + def sightCount = 0 + for(def d : rets){ + if(d.direction){ + directionCount ++ + } + if(d.sight){ + sightCount ++ + } + } + + def total = rets.size()*0.6 + if(zRegions.contains(dist.region)){ + z_count++ + + if(directionCount>=total){ + z_directionCount++ + } + if(sightCount >=total){ + z_sightCount++ + } + }else{ + f_count++ + + if(directionCount>=total){ + f_directionCount++ + } + if(sightCount >=total){ + f_sightCount++ + } + } + } + } + + def z_direct_prec = DataHandleUtils.getDoubleRound(2, z_directionCount*100/z_count) + def z_sight_prec = DataHandleUtils.getDoubleRound(2, z_sightCount*100/z_count) + + def f_direct_prec = DataHandleUtils.getDoubleRound(2, f_directionCount*100/f_count) + def f_sight_prec = DataHandleUtils.getDoubleRound(2, f_sightCount*100/f_count) + def rets = [] + rets << ["城区","户号","户ID","主朝向","景观","户型结构"] + rets << ["主城区",100,100,z_direct_prec, z_sight_prec, 100] + rets << ["非主城区",100,100, f_direct_prec, f_sight_prec, 100] + ExcelUtils.write("D:\\数据\\重庆农商行\\poc\\底层数据统计.xlsx",rets, "户1") + } + + def houseLoudongStat(){ + def map = getAllHouseLoudong() + def zRegions = ["渝中","大渡口","江北","沙坪坝","九龙坡","南岸","北碚","渝北","巴南"] + + def z_count = 0 + def f_count = 0 + + def z_directionCount = 0 + def f_directionCount = 0 + + def f_sightCount = 0 + def z_sightCount = 0 + map.each{key,list-> + def dist = CommonDatautils.findDistrictById(key) + def directionCount = 0 + def sightCount = 0 + for(def d : list){ + if(d.direction){ + directionCount ++ + } + if(d.sight){ + sightCount ++ + } + } + + def total = list.size()*0.6 + if(zRegions.contains(dist.region)){ + z_count++ + + if(directionCount>=total){ + z_directionCount++ + } + if(sightCount >=total){ + z_sightCount++ + } + }else{ + f_count++ + + if(directionCount>=total){ + f_directionCount++ + } + if(sightCount >=total){ + f_sightCount++ + } + } + } + + def z_direct_prec = DataHandleUtils.getDoubleRound(2, z_directionCount*100/z_count) + def z_sight_prec = DataHandleUtils.getDoubleRound(2, z_sightCount*100/z_count) + + def f_direct_prec = DataHandleUtils.getDoubleRound(2, f_directionCount*100/f_count) + def f_sight_prec = DataHandleUtils.getDoubleRound(2, f_sightCount*100/f_count) + def rets = [] + rets << ["城区","户号","户ID","主朝向","景观","户型结构"] + rets << ["主城区",100,100,z_direct_prec, z_sight_prec, 100] + rets << ["非主城区",100,100, f_direct_prec, f_sight_prec, 100] + ExcelUtils.write("D:\\数据\\重庆农商行\\poc\\底层数据统计.xlsx",rets, "户") + } + + def getAllHouseLoudong(){ + def q = new BasicDBObject() + q.put("city","重庆") + q.put("district_id", new BasicDBObject(QueryOperators.EXISTS, true)) + + def keys = new BasicDBObject() + keys.put("district_id",1) + keys.put("direction",1) + keys.put("sight",1) + def dbcursor = HOUSE_LOUDONG_COLL.find(q).batchSize(5000) + def retMap = [:] + for(def d : dbcursor){ + def districtId = d.district_id + if(districtId){ + def lists = retMap.get(districtId) + if(!lists){ + lists = [] + retMap.put(districtId, lists) + } + lists << d + } + } + return retMap; + } + + + def getAllHouseLoudong2(districtId){ + def q = new BasicDBObject() + q.put("city","重庆") + q.put("district_id", districtId) + + def keys = new BasicDBObject() + keys.put("district_id",1) + keys.put("direction",1) + keys.put("sight",1) + def dbcursor = HOUSE_LOUDONG_COLL.find(q).batchSize(5000) + def lists = [] + for(def d : dbcursor){ + lists << d + } + return lists; + } + + def getAllLouDong(){ + def q = new BasicDBObject() + q.put("city","重庆") + q.put("id_in_seaweed", new BasicDBObject(QueryOperators.EXISTS, true)) + def dbcursor = LOUDONG_LINE_COLL.find(q).batchSize(5000) + def retMap = [:] + for(def d : dbcursor){ + def districtId = d.id_in_seaweed + if(districtId){ + def lists = retMap.get(districtId) + if(!lists){ + lists = [] + retMap.put(districtId, lists) + } + lists << d + } + } + return retMap; + } + + def updteHoledCount(){ + def datas = findAllLouDong() + def totalCount = new AtomicLong() + println datas.size() + final CountDownLatch latch = new CountDownLatch(datas.size()) + for(def i=0;i2){ + q.put("unit_num", arrs[2]) + } + + def udata = new BasicDBObject() + udata.put("room_count", max_room) + LOUDONG_LINE_COLL.update(q, new BasicDBObject('$set', udata), false, true); + } + } catch (Exception e) { + e.printStackTrace() + } finally { + latch.countDown() + } + }; + }) + } + latch.await() + } + + def findAllLouDong(){ + def q = new BasicDBObject() + q.put("city","重庆") + q.put("id_in_seaweed", new BasicDBObject(QueryOperators.EXISTS, true)) + def dbcursor = LOUDONG_LINE_COLL.find(q) + def keys = new HashSet() + for(def d : dbcursor){ + def districtId = d.id_in_seaweed + def key = districtId +"##"+d.house_num + if(d.unit_num && d.unit_num!="0"){ + key = key + "##"+d.unit_num + } + if(!keys.contains(key)){ + keys << key + } + } + return keys + } + + def findHouseLouDongRoom(def arrs){ + def q = new BasicDBObject() + q.put("city","重庆") + q.put("district_id", arrs[0]) + q.put("house_num", arrs[1]) + if(arrs.size()>2){ + q.put("unit_num", arrs[2]) + } + def dbcursor = HOUSE_LOUDONG_COLL.find(q) + def max_room = 0 + for(def d : dbcursor){ + def room = null + if(d.room_num && d.room_num.contains("-")){ + room = d.room_num.substring(d.room_num.indexOf("-")+1, d.room_num.length()) + }else if(d.room_num && d.room_num.contains("0")){ + room = d.room_num.substring(d.room_num.toString().lastIndexOf("0")+1, d.room_num.length()) + } + if(room && room.isNumber()){ + if(room.toInteger()>max_room){ + max_room = room.toInteger() + } + } + } + return max_room; + } + def removeDelete(){ + def dists = CommonDatautils.findAllDistrictByCity("重庆","district", ["city","region","name", "name_cat"]) + for(def obj : dists){ + def name_cat = obj.name_cat; + if(name_cat==12){ + def count = CommonDatautils.findDistrictCount(obj.city, obj.region, obj.name, "district") + if(count>1){ + println obj.name +" "+count + DbUtils.seaweed.remove(new BasicDBObject("_id", obj._id)) + } + } + } } def regionDistStat(){ @@ -36,25 +494,25 @@ class PocStat { for(def region : set){ def count = CommonDatautils.findDistrictCountByRegionBlock(city, region, null, "district") - def regionCount = 0 - def regionHouseLDCount = 0 - for(def d : dists){ - if(d.region == region){ - def loudongCount = CommonDatautils.findLoudong(d._id.toString()) - if(loudongCount && loudongCount>0){ - regionCount = regionCount+ loudongCount - } - - def houseLouDongCount = CommonDatautils.findHouseLoudong(d._id.toString()) - if(houseLouDongCount && houseLouDongCount>0){ - regionHouseLDCount = regionHouseLDCount + houseLouDongCount - } - } - } - rows << [region, count, regionCount, regionHouseLDCount] +// def regionCount = 0 +// def regionHouseLDCount = 0 +// for(def d : dists){ +// if(d.region == region){ +// def loudongCount = CommonDatautils.findLoudong(d._id.toString()) +// if(loudongCount && loudongCount>0){ +// regionCount = regionCount+ loudongCount +// } +// +// def houseLouDongCount = CommonDatautils.findHouseLoudong(d._id.toString()) +// if(houseLouDongCount && houseLouDongCount>0){ +// regionHouseLDCount = regionHouseLDCount + houseLouDongCount +// } +// } +// } + rows << [region, count] println region +" 完成" } - ExcelUtils.write("D:\\数据\\重庆农商行\\poc\\底层数据统计.xlsx",rows, "各区楼盘量统计") + ExcelUtils.write("D:\\数据\\重庆农商行\\poc\\底层数据统计.xlsx",rows, "各区楼盘量统计1") } def sampleStat(){ diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/PocTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/PocTest.groovy index 7cb4b8ae2..29a2403b5 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/PocTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/chongqing/PocTest.groovy @@ -6,12 +6,17 @@ import com.fangjia.script.gj.district.FangjiaClientUtils import com.fangjia.script.temp.shenjian.util.SeaweedUtils import com.fangjia.script.util.ExcelUtils import com.fangjia.script.util.OpenApiClient +import groovy.sql.Sql import org.bson.types.ObjectId import java.util.concurrent.CopyOnWriteArrayList class PocTest { + def total = 3259 + def sqlInstance = Sql.newInstance("jdbc:oracle:thin:@192.168.0.236:1521:orcl", + "GOOJIA", "GOOJIA", "oracle.jdbc.driver.OracleDriver") + static main(args) { def task = new PocTest(); task.run(); @@ -27,17 +32,21 @@ class PocTest { * @return */ def run(){ - def inputfile = "D:\\数据\\重庆农商行\\poc\\重庆农商行.xlsx" - match(inputfile) - addPrice(inputfile) - addArroundPrice(inputfile) + def inputfile = "D:\\数据\\重庆农商行\\poc\\test.xls" +// match(inputfile) +// addPrice(inputfile) +// addArroundPrice(inputfile) +// standard(inputfile) +// addLoudongNum(inputfile) + + +// addAuthor(inputfile) + +// pkPrice(inputfile) + +// addPpeValue(inputfile) + // matchMap(inputfile) - - standard(inputfile) - addLoudongNum(inputfile) - - - // addDetail(inputfile, "D:\\数据\\重庆农商行\\poc\\楼盘详情.xlsx") // // createLoudong(inputfile,"D:\\数据\\重庆农商行\\poc\\底层数据-楼栋-户.xlsx") @@ -47,6 +56,36 @@ class PocTest { // createEvaluation(inputfile,"D:\\数据\\重庆农商行\\poc\\挂牌成交评估案例.xlsx") } + def addPpeValue(inputfile){ + ExcelUtils.multiThreadingModify(inputfile, { row -> + if(row['F'] && row['R']){ + def avg_price = findAvgPrice(row['R']) + if(avg_price){ + def ppe15 = Math.abs((row['F'] - avg_price) * 100 / avg_price) + row['Z'] = com.fangjia.script.common.DataHandleUtils.getDoubleRound(2, ppe15) + } + } + }); + } + + def pkPrice(path){ + ExcelUtils.multiThreadingModify(path, { row -> + def commid = row['R'] + if(commid){ + def dist = CommonDatautils.findDistrictById(commid.trim()) + if(dist){ + def jsonObject = OpenApiClient.webankEvaluate(dist.city, dist.region, dist.name, row['E'].toString()) + if(jsonObject != null && jsonObject.code==200) { + def result = jsonObject.result + if(result){ + row['Y'] = result.get("unitPrice") + } + } + } + } + }) + } + def match(path){ ExcelUtils.multiThreadingModify(path, { row -> @@ -54,7 +93,7 @@ class PocTest { def city = row['B'] def address = row['D'] def region = row['C'] - println "city:"+city+" region:"+region+" address:"+address + println "[match] city:"+city+" region:"+region+" address:"+address def jsonObject = OpenApiClient.addressMatch(city, address, "property", false, region, null) if(jsonObject != null && jsonObject.precise!=-1) { row['Q'] = jsonObject.get("name") @@ -95,8 +134,9 @@ class PocTest { ExcelUtils.multiThreadingModify(path, { row -> def commid = row['R'] if(commid){ - def dist = CommonDatautils.findDistrictById(commid) + def dist = CommonDatautils.findDistrictById(commid.trim()) if(dist){ + row['Q'] = dist.name def priceObj = CommonDatautils.findDistrictPrice(dist.city, dist.region, dist.name) if(priceObj){ row['F'] = priceObj.avg_price @@ -106,6 +146,8 @@ class PocTest { }) } + + def addArroundPrice(path){ ExcelUtils.multiThreadingModify(path, { row -> if(!row['F']) { @@ -156,8 +198,8 @@ class PocTest { if (jsonObject && jsonObject.result) { if(jsonObject.result.size()>=1){ def obj = jsonObject.result[0] - row['T'] = obj.id - row['S'] = obj.houseNumber + row['T'] = obj.id + row['S'] = obj.houseNumber } } @@ -172,6 +214,7 @@ class PocTest { } } } + }) } @@ -590,4 +633,34 @@ class PocTest { } ExcelUtils.write(output, rows, "成交案例") } + + def addAuthor(def path){ + def authors = ["丁世菁","王文艳","董彦均","曹玉彦","姚静梦","付贵生","赵灵芝","沈健","许镕杰","徐鹤","穆良书","沈燕芳"] + def personTotal = authors.size() + def avg = Math.ceil(total/personTotal) + + def index = 0 + def count = 0; + ExcelUtils.modify(path, { row -> + if(row['B']){ + if(index < avg){ + row['X'] = authors[count] + } + index++ + if(index >= avg){ + count++ + index = 0 + } + } + }); + } + + def findAvgPrice(def commid){ + def sql = "select year_month,target_avg_price from (select year_month,target_avg_price from avm_evaluation_item_gj where commid='${commid}' order by year_month desc) where rownum<2"; + def avg_price = null + sqlInstance.eachRow(sql, { r -> + avg_price = r.target_avg_price + }); + return avg_price + } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/commData/CommonDatautils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/commData/CommonDatautils.groovy index af552d3d4..b8e3cd5a1 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/commData/CommonDatautils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/commData/CommonDatautils.groovy @@ -3079,18 +3079,26 @@ class CommonDatautils { queryCondition.put("region", region); queryCondition.put("district_name", name); queryCondition.put('weekend', new BasicDBObject('$gte', startDate).append('$lte', endDate)); - DBCursor cur = DIST_STAT_COLL.find(queryCondition).sort(new BasicDBObject().append("weekend", -1)).limit(1) + DBCursor cur = DIST_STAT_COLL.find(queryCondition).sort(new BasicDBObject().append("weekend", -1)) cur.setOptions(Bytes.QUERYOPTION_NOTIMEOUT) DBObject dbo; + def prices = [] + def index = 0 while(cur.hasNext()) { - dbo = cur.next() - def price = dbo.get("avg_price"); - if(price){ - break; + def obj = cur.next() + if(index == 0){ + dbo = obj } + prices << obj.get("avg_price"); + index++ } - return dbo; + if(prices){ + def avg_price = (int)(prices.sum()/prices.size()) + dbo.avg_price = avg_price + return dbo; + } + return null; } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/DistrictPriceExportBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/DistrictPriceExportBatch.groovy index e8cd3476a..bb7b11f46 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/DistrictPriceExportBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/DistrictPriceExportBatch.groovy @@ -6,10 +6,16 @@ import com.fangjia.script.Watcher import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.common.DataHandleUtils import com.fangjia.script.jusfoun.JusfounCommon +import com.fangjia.script.util.DateUtil import com.fangjia.script.util.DateUtils +import com.fangjia.script.util.MongoUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection import org.apache.commons.codec.digest.DigestUtils import org.apache.commons.io.FileUtils +import org.bson.types.ObjectId +import java.text.DecimalFormat import java.util.concurrent.TimeUnit /** @@ -19,8 +25,11 @@ import java.util.concurrent.TimeUnit class DistrictPriceExportBatch extends BaseBatch{ def curDate = Integer.parseInt(DateUtils.addMonth(DateUtils.formatDateByPattern(new Date(), "yyyyMM"), -1, "yyyyMM")); + def lastMonthDate = Integer.parseInt(DateUtils.addMonth(DateUtils.formatDateByPattern(new Date(), "yyyyMM"), -2, "yyyyMM")); def charset = "GBK" + public static final DBCollection FZ_DISTRICT_STAT_COLL = MongoUtils.getCollectionByName("business", "fz_district_stat", "mongo.db.fangjia.com") + static main(args) { runBatch(new DistrictPriceExportBatch(), args) } @@ -32,6 +41,9 @@ class DistrictPriceExportBatch extends BaseBatch{ def ret = createDatas("福州") + saveToDB(ret) + + def fileName = "/fzbank/output/FJW_DISTRICT_STAT_"+curDate+".csv" def dataCodeFileName = "/fzbank/output/FJW_DISTRICT_STAT_"+curDate+".sha512" if(CommonDatautils.isWindow()){ @@ -76,10 +88,10 @@ class DistrictPriceExportBatch extends BaseBatch{ def createDatas(def city){ def districts = CommonDatautils.findAllDistricts(city, "district", null); - - def lastDate = new Date() - def startDate = DateUtils.getFirstDayOfMonth(lastDate, -1) - + def endDateStr = DateUtils.formatDateByPattern(new Date(), "yyyy-MM")+"-10" + def dataStr = DateUtils.add(endDateStr, -30) + def startDate = DateUtils.parseFromTightYYYYMMDD(dataStr) + def lastDate = DateUtils.parseFromTightByPattern(endDateStr, "yyyy-MM-dd") // List list2 = FileUtils.readLines(new File("D:\\数据\\福州\\FJW_DISTRICT_STAT_202111.csv")) // def map2 = [:] // for(def s : list2) { @@ -88,17 +100,34 @@ class DistrictPriceExportBatch extends BaseBatch{ // map2.put(key, row[5]) // } + def lastMonthPriceMap = findFzDistrictStat("福州",lastMonthDate) def result = [] for(def rMap : districts){ + def dbo = CommonDatautils.queryDistrictPriceByDate3(city, rMap.region, rMap.name, startDate, lastDate) if(dbo){ + def lastMonthPrice = lastMonthPriceMap.get(rMap.get("_id").toString()) + def curPrice = dbo.get("avg_price") + if(lastMonthPrice && curPrice){ + def markup = (curPrice - lastMonthPrice)*100/lastMonthPrice + if(Math.abs(markup)>3){ + def randMarkup = nextDouble(0, 3) + if(markup < 0){ + markup = randMarkup*(-1) + }else{ + markup = randMarkup + } + curPrice = (int)(lastMonthPrice*markup/100 + lastMonthPrice) + } + } + def m = [] m << dbo.get("_id").toString()//均价ID m << rMap.get("_id").toString()//楼盘ID m << rMap.city m << rMap.region m << rMap.name - m << dbo.get("avg_price") + m << curPrice // def lastMonthPrice = map2.get(rMap.city + "##" + rMap.region+"##"+rMap.name) // if(lastMonthPrice && dbo.get("avg_price")){ // lastMonthPrice = lastMonthPrice.toInteger() @@ -125,6 +154,19 @@ class DistrictPriceExportBatch extends BaseBatch{ return result } + + def findFzDistrictStat(city,lastMonthDate){ + def q = new BasicDBObject() + q.put("city", city) + q.put("month", lastMonthDate) + def dbcursor = FZ_DISTRICT_STAT_COLL.find(q) + def priceMap = [:] + for(def d : dbcursor){ + priceMap.put(d.comm_id, d.avg_price) + } + return priceMap + } + def export(def fileName, def datas){ def headers = ["id","comm_id","city","district","name","avg_price","year_month"] writeCSV(headers, fileName, datas); @@ -152,5 +194,44 @@ class DistrictPriceExportBatch extends BaseBatch{ file.append(System.getProperty("line.separator")); } } + + //随机浮点数 + public static double nextDouble(final double min, final double max) throws Exception { + + DecimalFormat df = new DecimalFormat("#.00"); + if (max < min) { + throw new Exception("min < max"); + } + if (min == max) { + return min; + } + return Double.parseDouble(df.format(min + ((max - min) * new Random().nextDouble()))); + } + + def saveToDB(rets){ + for(def r : rets){ + def q = new BasicDBObject() + q.put("month", curDate.toInteger()) + q.put("comm_id", r[1]) + def obj = FZ_DISTRICT_STAT_COLL.findOne(q) + if(obj){ + def udata = new BasicDBObject() + udata.put("m_date", new Date()) + udata.put("avg_price", r[5]) + FZ_DISTRICT_STAT_COLL.update(q, new BasicDBObject('$set', udata)) + }else{ + def udata = new BasicDBObject() + def o = new BasicDBObject() + o.put("_id", new ObjectId(r[0])) + o.put("comm_id", r[1]) + o.put("city", r[2]) + o.put("region", r[3]) + o.put("name", r[4]) + o.put("avg_price", r[5].toInteger()) + o.put("month", r[6].toInteger()) + FZ_DISTRICT_STAT_COLL.save(o) + } + } + } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/FzDataResultStat.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/FzDataResultStat.groovy index ba848d886..81c5624d1 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/FzDataResultStat.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/FzDataResultStat.groovy @@ -8,7 +8,9 @@ import com.mongodb.Bytes import com.mongodb.DBCollection import com.mongodb.DBCursor import com.mongodb.DBObject +import com.rabbitmq.client.impl.AMQImpl import org.apache.commons.io.FileUtils +import org.bson.types.ObjectId /** * 福州数据结果统计 @@ -17,16 +19,42 @@ class FzDataResultStat { public static final DBCollection REGION_STAT_COLL = MongoUtils.getCollectionByName("fangjia", "region_stat", "mongo.db.fangjia.com") + public static final DBCollection FZ_DISTRICT_STAT_COLL = MongoUtils.getCollectionByName("business", "fz_district_stat", "mongo.db.fangjia.com") + static main(args) { def task = new FzDataResultStat() task.priceMarkupRun(); task.regionPriceTrendRun() +//// task.margeExcel() +// task.saveCsvData() + } + + def margeExcel(){ + + def list2= ExcelUtils.read("D:\\数据\\福州\\价格比对_202204_新2.xlsx", 0 ,1) + + def map2 = [:] + for(def s : list2){ + def key = s["A"]+"##"+s["B"]+"##"+s["C"] + map2.put(key, s["D"]) + } + + ExcelUtils.multiThreadingModify("D:\\数据\\福州\\价格比对_202204_新3.xlsx",{row-> + if(row["A"]){ + def key = row["A"]+"##"+row["B"]+"##"+row["C"] + def price = map2.get(key) + if(price){ + row['L'] = price + } + } + }) } def priceMarkupRun(){ def curMonth = Integer.parseInt(DateUtils.addMonth(DateUtils.formatDateByPattern(new Date(), "yyyyMM"), -1, "yyyyMM")); def lastMonth = Integer.parseInt(DateUtils.addMonth(DateUtils.formatDateByPattern(new Date(), "yyyyMM"), -2, "yyyyMM")); List list1= FileUtils.readLines(new File("D:\\数据\\福州\\FJW_DISTRICT_STAT_${curMonth}.csv")) + def map1 = [:] for(def s : list1){ def row = s.split("@\\|@") @@ -137,16 +165,13 @@ class FzDataResultStat { queryCondition.put('weekend', new BasicDBObject('$gte', startDate).append('$lte',endDate)); DBCursor cur = REGION_STAT_COLL.find(queryCondition).sort(new BasicDBObject().append("weekend", -1)) cur.setOptions(Bytes.QUERYOPTION_NOTIMEOUT) - def price = 0; + def prices = []; while(cur.hasNext()) { DBObject dbo = cur.next() - price = dbo.get("avg_price"); - if(price){ - break; - } + prices << dbo.get("avg_price"); } - - return price; + def avg_price = (int)(prices.sum()/prices.size()) + return avg_price; } @@ -165,4 +190,45 @@ class FzDataResultStat { weekends = weekends.reverse(); return weekends; } + + + def saveCsvData(){ + def files = getAllFiles("C:\\Users\\gaojuan\\福州数据(1)") + if(files){ + for(def filepath : files){ + List list1= FileUtils.readLines(filepath) + println filepath + for(def s : list1){ + def row = s.split("@\\|@") + def o = new BasicDBObject() + o.put("_id", new ObjectId(row[0])) + o.put("comm_id", row[1]) + o.put("city", row[2]) + o.put("region", row[3]) + o.put("name", row[4]) + o.put("avg_price", row[5].toInteger()) + o.put("month", row[6].toInteger()) + FZ_DISTRICT_STAT_COLL.save(o) + + } + } + } + } + + def static getAllFiles(def path) { + + File file = new File(path); + File[] tempList = file.listFiles(); + + def files = []; + for (int i = 0; i < tempList.length; i++) { + if (tempList[i].isFile()) { + files << tempList[i]; + } + if (tempList[i].isDirectory()) { + System.out.println("文件夹:" + tempList[i]); + } + } + return files; + } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/Test1.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/Test1.groovy index 5a6b21aac..d554c0376 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/Test1.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/Test1.groovy @@ -14,7 +14,7 @@ import com.mongodb.DBCollection //福州第三方均价统计,发送钉钉消息 //def datas = ExcelUtils.read("d:\\数据\\福州\\福州4月2.xlsx",0,1) //def datas = CsvUtils.read("d:\\数据\\福州\\FJW_THIRD_PARTY_AVG_PRICE_202105.csv"); -def datas = readTxt("d:\\数据\\福州\\FJW_THIRD_PARTY_AVG_PRICE_202203.csv") +def datas = readTxt("d:\\数据\\福州\\FJW_THIRD_PARTY_AVG_PRICE_202204.csv") def count0 = 0 def count1 = 0 def count2 = 0 @@ -137,7 +137,7 @@ ExcelUtils.write("d:\\ def s = "第三方均价总量:${total}\n6区总量:${regionCount}\ncount1: "+ count1+"( "+pre1+"% )\ncount2: "+ count2+"( "+pre2+"% )\ncount3: "+count3+"( "+pre3+"% )\ncount4: "+count4+"( "+pre4+"% )\ncount5: "+count5+"( "+pre5+"% )\ncount6: "+count6+"( "+pre6+"% )\ncount7: "+count7+"( "+pre7+"%)\ncount8: "+count8+"( "+pre8+"% )\ncount9: "+count9+" ("+pre9+"% )" println s def access_token = "065f4a05d5f87eb39a9f9e048eeefb80c1f7560446f8926441de80453c160c60" -DingDingMessageUtil.sendTextMessage(access_token, s) +//DingDingMessageUtil.sendTextMessage(access_token, s) ////def districts = CommonDatautils.findAllDistricts("福州", "district", ["city", "region", "name"]); diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/TradeExportBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/TradeExportBatch.groovy index 244497f17..12f241dd6 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/TradeExportBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/fuzhou/TradeExportBatch.groovy @@ -112,22 +112,27 @@ class TradeExportBatch extends BaseBatch{ // q.put("trade_date", new BasicDBObject(QueryOperators.LT, endDate)) def cursor = DEAL_PRICE.find(q).addOption(Bytes.QUERYOPTION_NOTIMEOUT).batchSize(1000); def rets = [] + def urls = [] if (cursor != null) { while (cursor.hasNext()) { DBObject dbo = cursor.next(); def district = districtMap.get(dbo.city + "_" + dbo.region + "_" + dbo.district_name); if(district){ - def ret = []; - ret << dbo._id.toString() - ret << district._id.toString() - ret << dbo.city - ret << dbo.region - ret << dbo.district_name - ret << dbo.avg_price - ret << dbo.area - ret << DateUtils.formatDateByPattern(dbo.trade_date, "yyyy-MM-dd") - ret << dbo.total_price - rets << ret; + if(!urls.contains(dbo.url)){ + urls << dbo.url + + def ret = []; + ret << dbo._id.toString() + ret << district._id.toString() + ret << dbo.city + ret << dbo.region + ret << dbo.district_name + ret << dbo.avg_price + ret << dbo.area + ret << DateUtils.formatDateByPattern(dbo.trade_date, "yyyy-MM-dd") + ret << dbo.total_price + rets << ret; + } } } println "成交总计:"+rets.size() diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeAppCrawl.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeAppCrawl.groovy index 4601c3c60..d55350598 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeAppCrawl.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeAppCrawl.groovy @@ -1,10 +1,13 @@ package com.fangjia.script.gj.crawl import com.fangjia.script.crawl.JQueryUtils +import com.fangjia.script.thirdPriceCrawl.CrawalDBUtil +import com.fangjia.script.thirdPriceCrawl.Utils import com.fangjia.script.util.ABuYunUtil import com.fangjia.script.util.MongoUtils import com.mongodb.BasicDBObject import com.mongodb.DBCollection +import com.rabbitmq.client.impl.AMQImpl import net.sf.json.JSONObject import org.jsoup.Jsoup import org.openqa.selenium.WebDriver @@ -12,16 +15,21 @@ import org.openqa.selenium.chrome.ChromeDriver class AnjukeAppCrawl { + public static final SHORT_DATE = Utils.getLastMonth(); + def static final DBCollection thirdPartyColl = CrawalDBUtil.getThirdPartyCol(); + public static def SOURCE = "安居客"; DBCollection detail = MongoUtils.getCollectionByAuth20190102("fangjia_craw", "app_anjuke_detail") static main(args) { def task = new AnjukeAppCrawl(); - task.run(); +// task.run(); // task.run2() + + task.addThirdPrice() } def run2(){ - def url = "https://m.anjuke.com/fz/community/" + def url = "https://m.anjuke.com/sh/community/" System.setProperty("webdriver.chrome.driver", "C:\\Users\\gaojuan\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe"); System.setProperty("http.nonProxyHosts", "localhost"); WebDriver driver = new ChromeDriver() @@ -95,17 +103,28 @@ class AnjukeAppCrawl { def run(){ + //上海:11,北京:14 //"仓山":4071, - def map = ["晋安":4070,"鼓楼":4068,"闽侯":4073,"台江":4069,"福清":16378,"长乐":15880,"马尾":4072,"连江":16380,"平潭":16387,"罗源":16382,"永泰":16392,"闽清":16384] - map.each{region, area_id-> + // def map = ["晋安":4070,"鼓楼":4068,"闽侯":4073,"台江":4069,"福清":16378,"长乐":15880,"马尾":4072,"连江":16380,"平潭":16387,"罗源":16382,"永泰":16392,"闽清":16384] + // def regionMap = ["浦东":7,"闵行":11, "松江":15,"宝山":13,"嘉定":14,"徐汇":5,"青浦":19,"静安":2,"普陀":10,"杨浦":9,"奉贤":17,"黄浦":4,"虹口":8,"长宁":6,"金山":18,"崇明":20] + def regionMap = [ "朝阳":642,"海淀":601,"昌平":843,"丰台":753,"大兴":865,"通州":818,"房山":802,"顺义":837,"西城":704,"东城":690,"密云":856,"石景山":787,"怀柔":858,"门头沟":815,"延庆":860,"平谷":863,"北京周边":2678] + def cityMap = ["北京":regionMap] + def cityId = 14 + regionMap.each{region, area_id-> for(def i=1;i<40;i++){ def stop = false; def all_stop = false + def error_count=0 while(!stop){//渝北:2359 南岸:2368 沙坪坝:2380 //城口 - def flagMap = getInfo(stop, i, area_id) + def flagMap = getInfo(stop, i, area_id, cityId, "上海") stop = flagMap.stop all_stop = flagMap.all_stop + error_count++ + if(error_count>=20){ + stop = true + all_stop = true + } } if(all_stop){ break; @@ -114,17 +133,17 @@ class AnjukeAppCrawl { } } - def getInfo(def stop, def i, def area_id){ + def getInfo(def stop, def i, def area_id, def cityId, def city){ def map = [:] - def url = "https://m.anjuke.com/esf-ajax/community/list?city_id=35&page_size=100&page=${i}&area_id=${area_id}&is_tw=1" + def url = "https://m.anjuke.com/esf-ajax/community/list?city_id=${cityId}&page_size=100&page=${i}&area_id=${area_id}&is_tw=1" - def header = [:] + def header = [:] header.put("accept","application/json, text/plain, */*") header.put("accept-encoding","gzip, deflate, br") header.put("accept-language","zh-CN,zh;q=0.9") header.put("cookie","aQQ_ajkguid=E9796514-38C0-44D2-8CA3-1C58C3928B29; sessid=765EEB9D-E7A2-4B2C-8151-CA9CD939AB02; id58=CpQB22J8sqMA9stuJfeAAg==; twe=2; 58tj_uuid=bf6eaff8-851c-471a-a914-853242878ddc; als=0; seo_source_type=1; _ga=GA1.2.215255179.1652344695; isp=true; ajk-appVersion=; obtain_by=2; fzq_js_anjuke_ershoufang_m=c2c12b2d1b221734fa20ef752cd6bdc0_1652509223606_27; fzq_h=ef0186eeaba082ecd2a47ede7c7e3e64_1652533612190_a34c026e9c1842a3b35bdd37f3d2aa0b_2015773878; init_refer=https%253A%252F%252Fm.anjuke.com%252Fcq%252Fcommunity%252F; new_uv=8; wmda_uuid=b59ce2efbba070ecfa8fe93d79f30dd4; wmda_new_uuid=1; wmda_session_id_6145577459763=1652535525740-dae51249-3379-d4e7; wmda_visited_projects=%3B6145577459763; new_session=0; xxzl_cid=4601bb59d47e4b42beb192b17946d1dd; xxzl_deviceid=q9XQbdA9hhkHJTj+RgVpwc7jrBzVJp9J1uTlp4hDtRiXtA615K4HS4R0pJ1dgrBa; ctid=20; xxzl_cid=4601bb59d47e4b42beb192b17946d1dd; fzq_js_anjuke_xiaoqu_m=c80eeca4a3301dbf27b3c79b9f18fa3b_1652536277223_27; xzuid=81992155-5990-4a2f-8842-32bcbfbb1117") - header.put("referer","https://m.anjuke.com/fz/community/") + header.put("referer","https://m.anjuke.com/sh/community/") header.put("sec-fetch-dest","empty") header.put("sec-fetch-mode","cors") header.put("sec-fetch-site","same-origin") @@ -134,6 +153,7 @@ class AnjukeAppCrawl { def ret = ABuYunUtil.doGet(url, null, null, "utf-8") def all_stop = false; + def error_count = 0 if (ret) { JSONObject jsonObj = JSONObject.fromObject(ret); if(jsonObj && jsonObj.status=="ok" ){ @@ -143,7 +163,7 @@ class AnjukeAppCrawl { println "【${i}】 "+communities.size() +" "+url if(communities.size()>0){ - save("福州", communities) + save(city, communities) Thread.sleep(10000) stop = true; }else{ @@ -154,6 +174,7 @@ class AnjukeAppCrawl { }else{ stop = false; + error_count ++ println url +" 无数据" } @@ -195,4 +216,42 @@ class AnjukeAppCrawl { q.put("jumpAction",url) return detail.findOne(q); } + + def addThirdPrice(){ + def q = new BasicDBObject() + def dbcursor = detail.find(q) + def index = 0 + for(def d : dbcursor){ + index++ + def city = d.base.cityName + def region = d.base.areaName + def name = d.base.name + def obj = findByParams(city, region, name); + if(!obj){ + def data = new BasicDBObject() + data.put("district_id",d.base.id) + data.put("city", city) + data.put("region", region ) + data.put("name", name) + data.put("address",d.base.address) + data.put("avg_price", d.priceInfo.price) + data.put("source", SOURCE) + data.put("s_date", SHORT_DATE) + data.put("c_date", d.c_date) + thirdPartyColl.save(data) + println index +" "+data + } + } + } + + + def findByParams(city, region, name){ + def q = new BasicDBObject() + q.put("city", city) + q.put("region", region) + q.put("name", name) + q.put("source", SOURCE) + q.put("s_date", SHORT_DATE) + return thirdPartyColl.findOne(q); + } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeToDB.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeToDB.groovy index 1954d135c..85060a709 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeToDB.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/crawl/AnjukeToDB.groovy @@ -22,9 +22,9 @@ class AnjukeToDB { static main(args) { def task = new AnjukeToDB(); -// task.run(); + task.run(); // task.addNoMatch() - task.updateEstateType() +// task.updateEstateType() // task.gaodeRangeData() } @@ -315,16 +315,16 @@ class AnjukeToDB { } } def run(){ - def datas = ExcelUtils.read("D:\\数据\\重庆农商行\\安居客\\安居客重庆小区-芝芝.xlsx",0,1) + def datas = ExcelUtils.read("D:\\数据\\重庆农商行\\安居客\\非人工处理.xlsx",0,1) for(def data : datas){ - if(data['K']=="芝芝"){ +// if(data['K']=="镕杰"){ def flag = data['M'] if(flag && flag=="新增"){ - add(data) +// add(data) }else{ update(data) } - } +// } } } @@ -445,8 +445,6 @@ class AnjukeToDB { } if(!addr_alias.contains(obj.base.address) && obj.base.address.contains("号")){ addr_alias << obj.base.address - } - if(addr_alias!=dist.addr_alias && addr_alias.size()>0){ udata.put("addr_alias", addr_alias) } } @@ -555,8 +553,13 @@ class AnjukeToDB { def findAnjukeDistrictDetail(anjukeId){ def q = new BasicDBObject() - q.put("_id",new ObjectId(anjukeId)) - return detail.findOne(q) + try{ + q.put("_id",new ObjectId(anjukeId)) + return detail.findOne(q) + }catch(Exception e){ + print "[查询出错]anjukeId:"+anjukeId + } + return null } def nameFileter(def region, def name){ diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/district/NameProcess.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/district/NameProcess.groovy index 71657eea3..cbee24228 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/district/NameProcess.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/district/NameProcess.groovy @@ -172,7 +172,8 @@ class NameProcess { if((name.endsWith("村") || name.endsWith("街"))&& name.size()<=3){ return null } - if(name.endsWith("电梯")||name.endsWith("大道")||name.endsWith("厂") || name.endsWith("组") || (name.endsWith("阁") && name.length()<=3) || name.endsWith("条")){ + //|| name.endsWith("组") + if(name.endsWith("电梯")||name.endsWith("大道")||name.endsWith("厂") || name.endsWith("条")){ return null } if(name.contains("、")||name.contains("|")||name.contains(".")){ diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/level/DistrictIndexBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/level/DistrictIndexBatch.groovy index bd387ed77..3a572c7ad 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/level/DistrictIndexBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/level/DistrictIndexBatch.groovy @@ -71,7 +71,8 @@ class DistrictIndexBatch extends BaseBatch{ def run(){ def cityCodeDatas = CcbCommonUtils.findCityCodeValue() - def citys = CommonDatautils.findAllCity(); + def citys = ["昆明","南宁","郑州","长沙","贵阳","乌鲁木齐","中山","湛江","南昌","海口"] + //def citys = CommonDatautils.findAllCity(); for(def city : citys){ def dists = CommonDatautils.findAllDistrictByCity(city, "district", ["city","alias","region","name", "finish_building_date","estate_charge","lat","lng","lng2","lat2","household_count"]) def code = cityCodeDatas.get(city) @@ -86,7 +87,7 @@ class DistrictIndexBatch extends BaseBatch{ city_avg_total_price = 531.2615913 } if(city_avg_total_price){ - // calcute(city, dists, code, city_avg_total_price) + calcute(city, dists, code, city_avg_total_price) calcuteIndex(city, dists, code, city_avg_total_price) } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/meituan/MatchTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/meituan/MatchTest.groovy index 6b4872d19..f42431df6 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/meituan/MatchTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/meituan/MatchTest.groovy @@ -21,10 +21,58 @@ class MatchTest { def task = new MatchTest() // task.run() // task.addNum() - task.dongguang() +// task.dongguang() // task.meituanDel() + + task.addLevel() } + + + def addLevel() { + def citys = ["昆明","南宁","郑州","长沙","贵阳","乌鲁木齐","中山","湛江","南昌","海口"]// + def weekend = DateUtils.getFirstDayOfWeek(new Date()); + def cityLevelMap = [:] + for(def city : citys){ + def dists = CommonDatautils.findAllDistrictByCity(city, "district", ["city", "region","name"]) + def priceMap = CommonDatautils.queryDistrictPrice(city, weekend) + def datas = addPriceData(dists, priceMap); + datas = calcuteLevel(datas); + cityLevelMap.put(city, ["price":priceMap, "level":datas]) + println city +" 楼盘评级同步完成" + } + + + def path = "D:\\数据\\美团\\10城小区明细-结果.xlsx"//美团金融小区测试list-所有数据-评级.xlsx + ExcelUtils.multiThreadingModify(path, { row -> + + def name = row['D'] + def address = row['E'] + def city = RegionData.formatCity(row['A']) + + if(name && !row['O']){ + if(city){ + def map = cityLevelMap.get(city) + def rMap = null + if(map){ + rMap = getArroundDistrictPriceByAddress(city, address, map.level) + } + + if(rMap){ + if(rMap.rank){ + row['Q'] = rMap.rank + } +// if(rMap.level){ +// row['Q'] = rMap.level +// } + } + } + } + + }) + } + + def meituanDel(){ def path = "D:\\数据\\美团\\美团需入库小区合并后.xlsx" def index = 0 diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/BeiKeCrawlByChrome.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/BeiKeCrawlByChrome.groovy index a97cb7669..60ae682b9 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/BeiKeCrawlByChrome.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/BeiKeCrawlByChrome.groovy @@ -193,7 +193,7 @@ public class BeiKeCrawlByChrome { detail.room = roomStr.substring(0, roomStr.indexOf("室")).toInteger() } if (roomStr.indexOf("厅") > 0 && roomStr.indexOf("室") > 0) { - detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")) + detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")).toInteger() } } @@ -215,7 +215,8 @@ public class BeiKeCrawlByChrome { detail.trade_date = DateUtils.parseFromTightByPattern(tradeStr, "yyyy.MM.dd") } detail.source = "贝壳找房" - def dbo = findTrade(detail) + def detailUrl = e.select(".title a").attr("href") + def dbo = findTrade(detailUrl) if (!dbo) { def houseInfo = e.select(".houseInfo").text() def houseInfos = houseInfo.split("\\|") @@ -228,7 +229,7 @@ public class BeiKeCrawlByChrome { detail.height = floorStr.toInteger() } } - detail.url = e.select(".title a").attr("href") + detail.url = detailUrl detail.create_date = new Date() detail.m_date = new Date() println detail @@ -313,8 +314,8 @@ public class BeiKeCrawlByChrome { def roomStr = JQueryUtils.selectText("li:contains(房屋户型)", doc).replace("房屋户型", "") if (roomStr) { detail.room = roomStr.substring(0, roomStr.indexOf("室")).toInteger() - detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")) - detail.toilet = roomStr.substring(roomStr.indexOf("卫") - 1, roomStr.indexOf("卫")) + detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")).toInteger() + detail.toilet = roomStr.substring(roomStr.indexOf("卫") - 1, roomStr.indexOf("卫")).toInteger() } detail.direction = JQueryUtils.selectText("li:contains(房屋朝向)", doc).replace("房屋朝向", "") detail.fitment = JQueryUtils.selectText("li:contains(装修情况)", doc).replace("装修情况", "") @@ -336,13 +337,14 @@ public class BeiKeCrawlByChrome { } - def findTrade(def detail){ + def findTrade(def detailUrl){ def q = new BasicDBObject() q.put("city", detail.city) - q.put("region", detail.region) - q.put("district_name", detail.district_name) - q.put("area", detail.area) - q.put("total_price", detail.total_price) +// q.put("region", detail.region) +// q.put("district_name", detail.district_name) +// q.put("area", detail.area) +// q.put("total_price", detail.total_price) + q.put("url", detailUrl) q.put("trade_date", detail.trade_date) q.put("source", detail.source) def dbo = DEAL_PRICE_COLL.findOne(q) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/LianjiaCrawlByChrome.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/LianjiaCrawlByChrome.groovy index cae68c08d..63ecf3c2a 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/LianjiaCrawlByChrome.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/paimai/LianjiaCrawlByChrome.groovy @@ -34,11 +34,11 @@ public class LianjiaCrawlByChrome { static main(args) { def task = new LianjiaCrawlByChrome(); -// task.run() + task.run() // task.run1() -// task.addDealRegion(); -// task.standardRegion() - task.updadteDealPriceField() + task.addDealRegion(); + task.standardRegion() +// task.updadteDealPriceField() } def updadteDealPriceField(){ @@ -278,7 +278,7 @@ public class LianjiaCrawlByChrome { detail.room = roomStr.substring(0, roomStr.indexOf("室")).toInteger() } if (roomStr.indexOf("厅") > 0 && roomStr.indexOf("室") > 0) { - detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")) + detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")).toInteger() } } @@ -398,8 +398,8 @@ public class LianjiaCrawlByChrome { def roomStr = JQueryUtils.selectText("li:contains(房屋户型)", doc).replace("房屋户型", "") if (roomStr) { detail.room = roomStr.substring(0, roomStr.indexOf("室")).toInteger() - detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")) - detail.toilet = roomStr.substring(roomStr.indexOf("卫") - 1, roomStr.indexOf("卫")) + detail.hall = roomStr.substring(roomStr.indexOf("室") + 1, roomStr.indexOf("厅")).toInteger() + detail.toilet = roomStr.substring(roomStr.indexOf("卫") - 1, roomStr.indexOf("卫")).toInteger() } detail.direction = JQueryUtils.selectText("li:contains(房屋朝向)", doc).replace("房屋朝向", "") detail.fitment = JQueryUtils.selectText("li:contains(装修情况)", doc).replace("装修情况", "") diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/CZDataBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/CZDataBatch.groovy index 8d971ee8a..95bfde522 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/CZDataBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/jiangnanblank/CZDataBatch.groovy @@ -16,9 +16,11 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.bson.types.ObjectId import java.text.DecimalFormat +import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicLong import java.util.regex.Matcher import java.util.regex.Pattern @@ -34,6 +36,9 @@ class CZDataBatch extends BaseBatch{ DBCollection DIST_COLL = MongoUtils.getCollectionByName("business", "jn_bank_district", "mongo.db.fangjia.com") //final def czIdMap = readCZDistrict("d:\\常州数据结果\\原始数据\\常州江南银行住宅编号.xls"); //final def czShopMap = readCZShop("d:\\常州数据结果\\原始数据\\常州江南银行商铺--更新ing(8).xls"); + + public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(40) + static main(args) { runBatch(new CZDataBatch(), args); } @@ -113,25 +118,44 @@ class CZDataBatch extends BaseBatch{ } def districtRun(def districts){ - def total = districts.size(); - def index = 0; - ExecutorService executorService = Executors.newFixedThreadPool(20) - + def totalCount = new AtomicLong() + final CountDownLatch latch = new CountDownLatch(total) for(def i=0;i +// "宁波","佛山","南通","烟台","临沂","呼和浩特","海口","广州", + def citys = ["唐山","泰安","襄阳","台州","镇江","银川","江门","荆州","北京","衡阳","南京","滨州","张家口","商丘","赣州","湖州","安庆","聊城","枣庄","阜阳","西安","芜湖","吉林","遂宁","鞍山","东营","安阳","咸阳"] + for(def city : citys){ + def str = cityList.get(city) for(def i=0;i<1;i++){ - if(citys.contains(city)){ - def districts = CommonDatautils.findAllDistricts(city, "district", ["city", "region", "name"]); - if(districts){ - def arrs = str.split("\\|") - def url = "https://"+arrs[0]+".58.com/xiaoqu/" - distMap.put(city, districts) - - addCrawlKeys(city); - addDetailContent(city, "https://"+arrs[0]+".58.com", arrs[1]); - } + def districts = CommonDatautils.findAllDistricts(city, "district", ["city", "region", "name"]); + if(districts){ + def arrs = str.split("\\|") + def url = "https://"+arrs[0]+".58.com/xiaoqu/" + distMap.put(city, districts) + addCrawlKeys(city); + addDetailContent(city, "https://"+arrs[0]+".58.com", arrs[1]); } } } +// cityList.each{city, str-> +// for(def i=0;i<1;i++){ +// if(citys.contains(city)){ +// def districts = CommonDatautils.findAllDistricts(city, "district", ["city", "region", "name"]); +// if(districts){ +// def arrs = str.split("\\|") +// def url = "https://"+arrs[0]+".58.com/xiaoqu/" +// distMap.put(city, districts) +// +// addCrawlKeys(city); +// addDetailContent(city, "https://"+arrs[0]+".58.com", arrs[1]); +// } +// } +// } +// } + } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy index 1a45be219..f0186187b 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/util/OpenApiClient.groovy @@ -266,7 +266,7 @@ public class OpenApiClient { params.put("unitNumber", unitNum); params.put("roomNumber", roomNum); params.put("token", TOKEN); - String content = new HttpRequest().get("http://open.fangjia.com/property/searchHouseLoudong", params, "utf-8") + String content = new HttpRequest().get("http://localhost:8080/fangjia-open/property/searchHouseLoudong", params, "utf-8") JSONObject result = JSONObject.fromObject(content); while (result == null) { result = HttpRequestUtil.getJsonContent("http://open.fangjia.com/property/searchHouseLoudong", params, "utf-8") @@ -288,6 +288,38 @@ public class OpenApiClient { return null } + + public static JSONObject webankEvaluate(String city, String region, String address, String area){ + try{ + Map params = new HashMap(); + params.put("city", city); + params.put("district", region); + params.put("address", address); + params.put("area", area.toString()); + params.put("token", TOKEN); + String content = new HttpRequest().get("http://open.fangjia.com/webank/evaluate", params, "utf-8") + JSONObject result = JSONObject.fromObject(content); + while (result == null) { + result = HttpRequestUtil.getJsonContent("http://open.fangjia.com/webank/evaluate", params, "utf-8") + println("${city} ${address} 程序调用异常") + Thread.sleep(6000) + } + if(result){ + if (result.getInt("code") == 200) { + return result; + } else if (result.getInt("code") !=0) { + println("${city} ${address} 程序调用异常") + } + } + + } catch (Exception e) { + println("${city} ${address} ${e.getMessage()}") + e.printStackTrace(); + } + return null + } + + public static JSONObject standard2Action(String city, String address) { try { Map params = new HashMap(); @@ -706,7 +738,7 @@ public class OpenApiClient { params.put("startDate", startDate) params.put("limit", "100") try { - String content = new HttpRequest().get("http://localhost:8080/fangjia-open/auction/searchPaimais", params, "utf-8") + String content = new HttpRequest().get("http://open.fangjia.com/auction/searchPaimais", params, "utf-8") JSONObject result = JSONObject.fromObject(content); return result } catch (Exception e) {