From 1a4817c33896b2e7595301179e1a02e23519b49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Fri, 3 Jan 2025 17:40:28 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A6=86=E7=9B=96BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/ComprehensiveQueryController.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java index 4800e992c..bc9ada616 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/ComprehensiveQueryController.java @@ -747,11 +747,8 @@ public class ComprehensiveQueryController { districtPriceMap.put("city", district.getCity()); districtPriceMap.put("district", district.getRegion()); districtPriceMap.put("name", district.getName()); - if (evaluation.getAvgPrice2b() != null && evaluation.getAvgPrice2b() != 0) { - districtPriceMap.put("avgPrice", evaluation.getAvgPrice2b()); - } else { - districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); - } + // 估值中已经取过评估2B价格,且经过系数调整,不能在覆盖 + districtPriceMap.put("avgPrice", evaluation.getAvgPrice()); Long totalPrice = new BigDecimal((Integer)districtPriceMap.get("avgPrice")).multiply(new BigDecimal(evaluation.getArea())).longValue(); districtPriceMap.put("totalPrice", totalPrice); From 761f6221c15c3416cc5eefc684ea806de6d1a32f Mon Sep 17 00:00:00 2001 From: gaojuan1 Date: Mon, 6 Jan 2025 07:56:47 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=88=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dealPrice/SynchDealPriceToEs.groovy | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy new file mode 100644 index 000000000..7d06921dc --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy @@ -0,0 +1,83 @@ +package com.fangjia.script.dealPrice + +import com.fangjia.core.util.MongoUtils +import com.fangjia.script.gj.xiamen.ElasticUtils89 +import com.fangjia.script.util.ElasticUtils +import com.mongodb.BasicDBObject +import com.mongodb.DBCollection +import org.elasticsearch.action.bulk.BulkRequest +import org.elasticsearch.action.bulk.BulkResponse +import org.elasticsearch.action.index.IndexRequest +import org.elasticsearch.action.support.WriteRequest +import org.elasticsearch.client.RequestOptions +import org.elasticsearch.common.xcontent.XContentType + +class SynchDealPriceToEs { + static DBCollection dealPriceConn = MongoUtils.getCollectionByName("fangjia", "deal_price", "192.168.0.43",28017) + + static main(args) { + def task = new SynchDealPriceToEs() + task.run() + } + + def run(){ + def batchsize = 1000 + def dbcursor = dealPriceConn.find(new BasicDBObject()).batchSize(batchsize) + def ret = [] + def index = 0 + for(def d : dbcursor){ + ret << d + if(ret.size()>=2000){ + save(ret) + ret.clear() + index ++ + println index + } + } + + } + + + def save(rows){ + BulkRequest request = new BulkRequest(); + int batchSize = 500; + int processedCount = 0; + def client = ElasticUtils.getClient("192.168.0.206") + + for(def map : rows){ +// def map = rows.get(key) + def data_id = map._id.toString() + map.remove("_id") + request.add(new IndexRequest("deal_price", "_doc", data_id).source(map, XContentType.JSON)); + + // 批量提交数据 + if (request.numberOfActions() >= batchSize) { + request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); + if (bulkResponse.hasFailures()) { + // 处理错误 + print "Bulk request has failures: " + bulkResponse.buildFailureMessage() + } else { + processedCount += request.numberOfActions(); + println "Processed " + processedCount + " documents "+new Date().format("yyyy-MM-dd HH:mm:ss") + } + + request = new BulkRequest(); + } + } + + if (request.numberOfActions() > 0) { + request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + BulkResponse bulkResponse = client.bulk(request, RequestOptions.DEFAULT); + if (bulkResponse.hasFailures()) { + // 处理错误 + println "Bulk request has failures: " + bulkResponse.buildFailureMessage() + } else { + processedCount += request.numberOfActions(); + println "Processed " + processedCount + " documents" + } + } + + } + +} From 920b3969b98d0becd0d58b2ac2e28a53eafb5752 Mon Sep 17 00:00:00 2001 From: gaojuan1 Date: Mon, 6 Jan 2025 10:21:32 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=9F=8E=E5=B8=82?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fangjia/script/gj/data_handle/NewGaoDePoiBatch.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/NewGaoDePoiBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/NewGaoDePoiBatch.groovy index fd631c5e0..a87c0b154 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/NewGaoDePoiBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/NewGaoDePoiBatch.groovy @@ -360,7 +360,7 @@ class NewGaoDePoiBatch extends BaseBatch{ def index = 0 for(def cityObj : cityList){ index ++ - if(index <140){ + if(index <291){ continue } def fileName = "/home/goojia/gj/poi/old_poi/merge_poi/${cityObj.city}.csv" From 96e13d215ff1ef5d6a2fd891ebd37f272d88bd21 Mon Sep 17 00:00:00 2001 From: gaojuan1 Date: Mon, 6 Jan 2025 13:29:30 +0800 Subject: [PATCH 4/8] update --- .../dealPrice/SynchDealPriceToEs.groovy | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy index 7d06921dc..13ea5e3de 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/dealPrice/SynchDealPriceToEs.groovy @@ -3,8 +3,10 @@ package com.fangjia.script.dealPrice import com.fangjia.core.util.MongoUtils import com.fangjia.script.gj.xiamen.ElasticUtils89 import com.fangjia.script.util.ElasticUtils +import com.mongodb.AggregationOutput import com.mongodb.BasicDBObject import com.mongodb.DBCollection +import com.mongodb.DBObject import org.elasticsearch.action.bulk.BulkRequest import org.elasticsearch.action.bulk.BulkResponse import org.elasticsearch.action.index.IndexRequest @@ -21,23 +23,57 @@ class SynchDealPriceToEs { } def run(){ - def batchsize = 1000 - def dbcursor = dealPriceConn.find(new BasicDBObject()).batchSize(batchsize) - def ret = [] - def index = 0 - for(def d : dbcursor){ - ret << d - if(ret.size()>=2000){ - save(ret) - ret.clear() - index ++ - println index + def batchsize = 2000 + def citys = getCityCount() + citys.each{city,count-> + def dbcursor = dealPriceConn.find(new BasicDBObject("city", city)).batchSize(batchsize) + def ret = [] + for(def o : dbcursor){ + ret << o + } + save(ret) +// def index = 0 +// for(def d : dbcursor){ +// ret << d +// if(ret.size()>=2000){ +// save(ret) +// ret.clear() +// index ++ +// println index +// } +// } + } + } + + + def getCityCount(){ + + BasicDBObject match = null; + // 定义聚合管道,按 city 字段分组,并计算每个城市的数量 + DBObject groupFields = new BasicDBObject(); + +// match = new BasicDBObject('$match', new BasicDBObject("level", "城市")); + groupFields.put("_id", new BasicDBObject("city",'$city')) + + groupFields.put("count", new BasicDBObject('$sum', 1)); + DBObject group = new BasicDBObject('$group', groupFields); + + // 执行聚合查询 + AggregationOutput output = dealPriceConn.aggregate(Arrays.asList(group)); + def map = [:] + // 遍历结果 + for (DBObject result : output.results()) { + def obj = (DBObject ) result.get("_id"); + if(obj.get("city")) { + int count = (Integer) result.get("count"); + map.put(obj.get("city"), count) } } - + return map; } + def save(rows){ BulkRequest request = new BulkRequest(); int batchSize = 500; From a1243552838406daee482bdc7f2b42ef91ca6d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Mon, 6 Jan 2025 13:54:38 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=B0=8F=E5=8C=BA=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=B9=E4=B8=BA2B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/PropertyController.java | 4 +- .../service/district/DistrictStatService.java | 11 +++++ .../district/DistrictStatServiceImpl.java | 46 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java index 45f930632..fcee9783d 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java @@ -752,7 +752,9 @@ public class PropertyController { districtInfoDto.setDistrict(district.getRegion()); districtInfoDto.setName(district.getName()); districtInfoDto.setAddress(district.getAddress()); - int avgPrice = districtStatService.findLatestDistrictAvgPrice(new DistrictKey(district), null); + //int avgPrice = districtStatService.findLatestDistrictAvgPrice(new DistrictKey(district), null); + // 返回2B价格,小程序用,其他也改为2B + int avgPrice = districtStatService.findLatestDistrictAvgPrice2B(new DistrictKey(district), null); if (avgPrice != 0) { districtInfoDto.setAvgPrice(avgPrice); } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatService.java b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatService.java index a308e1a67..623a779b0 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatService.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatService.java @@ -295,6 +295,17 @@ public interface DistrictStatService { * @return */ public int findLatestDistrictAvgPrice(DistrictKey districtKey,Date weekend); + + /** + * 获得指定时间的小区均价2B + * + * @param districtKey + * @param weekend + * @return + */ + int findLatestDistrictAvgPrice2B(DistrictKey districtKey,Date weekend); + + /** diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java index 242aac83e..9d7d57f50 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java @@ -1524,6 +1524,52 @@ public class DistrictStatServiceImpl implements DistrictStatService { return value; } + @Override + public int findLatestDistrictAvgPrice2B(DistrictKey districtKey, Date weekend) { + if (weekend == null) { + weekend = DateUtil.getFirstDayOfWeek(new Date()); + } + String cacheKey = districtKey.getCity() + "_" + districtKey.getRegion() + "_" + districtKey.getName() + "_" + DateUtil.formatToYYMMDD(weekend); + Object obj = CacheUtils.getValue(this.getClass(), cacheKey); + if (obj != null) { + return (Integer)obj; + } + Integer value = doFindLatestDistrictAvgPrice2B(districtKey, weekend); + CacheUtils.putValue(CachePolicyEnum.LONG, this.getClass(), cacheKey, value); + return value; + } + + public Integer doFindLatestDistrictAvgPrice2B(DistrictKey districtKey, Date weekend){ + + DistrictStatBo statBo = districtStatService.findDistrictStat(districtKey); + if (statBo != null && statBo.getDefaultDistrictStat() != null) { + if (statBo.getDefaultDistrictStat().getAvg_price_2b() > 0) { + return statBo.getDefaultDistrictStat().getAvg_price_2b(); + } + if (statBo.getDefaultDistrictStat().getAvgPrice() > 0) { + return statBo.getDefaultDistrictStat().getAvgPrice(); + } + } + + double r = AveragerUtil.getFloatingRate(districtKey, weekend); + if (StringUtils.isNotBlank(districtKey.getCity()) && StringUtils.isNotBlank(districtKey.getRegion())) { + RegionStat regionStat = regionStatService.findRegionStat(districtKey.getCity(), districtKey.getRegion(), null); + if (regionStat != null) { + return (int) (regionStat.getAvgPrice() * r); + } + } + + if (StringUtils.isNotBlank(districtKey.getCity())) { + RegionStat regionStat = regionStatService.findRegionStat(districtKey.getCity(), null, null); + if (regionStat != null) { + return (int) (regionStat.getAvgPrice() * r); + } + } + + return 0; + + } + public Integer doFindLatestDistrictAvgPrice(DistrictKey districtKey, Date weekend){ DistrictStatBo statBo = districtStatService.findDistrictStat(districtKey); From ad5b9535d7839cf3187049b35dc26d7d18f8cc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Mon, 6 Jan 2025 14:05:56 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=93=E5=AD=98key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fangjia/service/district/DistrictStatServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java index 9d7d57f50..9d2259bd7 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/district/DistrictStatServiceImpl.java @@ -1529,7 +1529,7 @@ public class DistrictStatServiceImpl implements DistrictStatService { if (weekend == null) { weekend = DateUtil.getFirstDayOfWeek(new Date()); } - String cacheKey = districtKey.getCity() + "_" + districtKey.getRegion() + "_" + districtKey.getName() + "_" + DateUtil.formatToYYMMDD(weekend); + String cacheKey = districtKey.getCity() + "_" + districtKey.getRegion() + "_" + districtKey.getName() + "_2B_" + DateUtil.formatToYYMMDD(weekend); Object obj = CacheUtils.getValue(this.getClass(), cacheKey); if (obj != null) { return (Integer)obj; From 423e22f54ba6d8d9c582b5b1f7a21f54195fc4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Mon, 6 Jan 2025 14:22:50 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=B0=8F=E5=8C=BA=E5=9D=87=E4=BB=B7?= =?UTF-8?q?=E8=B5=B0=E5=8A=BF=E6=94=B9=E4=B8=BA2B=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/weixin/DistrictTrendController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/DistrictTrendController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/DistrictTrendController.java index 3005fcf82..18c8f0bbe 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/DistrictTrendController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/DistrictTrendController.java @@ -559,7 +559,7 @@ public class DistrictTrendController { DistrictStat ds = districtStatMap.get(key); JSONArray ja = new JSONArray(); ja.put(DateUtil.getBeforeDay(ds.getWeekend(), -1).getTime()); - ja.put(ds.getAvgPrice()); + ja.put(ds.getAvg_price_2b()); districtJa.put(ja); } @@ -567,7 +567,7 @@ public class DistrictTrendController { DistrictStat ds = villaDistrictStatMap.get(key); JSONArray ja = new JSONArray(); ja.put(DateUtil.getBeforeDay(ds.getWeekend(), -1).getTime()); - ja.put(ds.getAvgPrice()); + ja.put(ds.getAvg_price_2b()); villaJa.put(ja); } From 9f5f3812c3413128762f1f29e5eceea0b7f067f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Mon, 6 Jan 2025 14:43:17 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=B0=8F=E5=8C=BA=E5=9D=87=E4=BB=B7?= =?UTF-8?q?=E8=B5=B0=E5=8A=BF=E6=94=B9=E4=B8=BA2B=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fangjia/open/controllers/PropertyController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java index fcee9783d..89ee1cfcf 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java @@ -2429,7 +2429,7 @@ public class PropertyController { item.put("city", districtStat.getCity()); item.put("district", districtStat.getRegion()); item.put("name", districtStat.getDistrictName()); - item.put("avgPrice", districtStat.getAvgPrice()); + item.put("avgPrice", districtStat.getAvg_price_2b()); if ("monthly".equals(model.getPeriodType())) { item.put("date", DateUtil.formatByPattern(districtStat.getWeekend(), "yyyy-MM")); } else {