From 9a557da1836147d6acb0549bc3190287bec41ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Wed, 11 Mar 2026 18:35:26 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=98=93=E6=96=B9?= =?UTF-8?q?=E8=BE=BE=E6=8E=A5=E5=8F=A3=E4=BB=A5=E5=8F=8A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?claude=E6=8A=80=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 4 +- .../script/opentest/EfundInterfaceTest.groovy | 3 +- projects/fangjia-service/pom.xml | 5 + .../district/DistrictStatServiceImpl.java | 1 + .../service/efund/EfundMatchServiceImpl.java | 161 ++++++++++++++---- 5 files changed, 142 insertions(+), 32 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 795b2c552..1fa130129 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -5,7 +5,9 @@ "Bash(pandoc:*)", "Bash(python ooxml/scripts/unpack.py:*)", "Bash(npm install:*)", - "Bash(node generate_doc.js:*)" + "Bash(node generate_doc.js:*)", + "Bash(xargs grep:*)", + "Bash(node:*)" ] } } diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy index 538b1cd1e..a538bed6c 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy @@ -45,7 +45,7 @@ try { // 3. 修改表头,添加结果列 allData[0] = ["序号", "城市", "地址", "返回城市", "返回区域", "返回街道","返回道路","返回门牌号", "小区名称", "物业类型", "匹配级别", "匹配置信度", - "参考价格", "典型总价", "更新时间", "耗时(ms)", "异常信息"] + "参考价格", "典型总价", "更新时间", "耗时(ms)", "异常信息", "周边一公里住宅均价"] // 4. 为每一行数据添加空的结果列 for (int i = 1; i < allData.size(); i++) { @@ -103,6 +103,7 @@ try { row[14] = result.optString("update_time", "") row[15] = duration row[16] = "" // 无异常 + row[17] = result.optString("typical_total_price", "") } else { // 接口返回异常 row[15] = duration diff --git a/projects/fangjia-service/pom.xml b/projects/fangjia-service/pom.xml index 1b688ac2d..b1f53895d 100644 --- a/projects/fangjia-service/pom.xml +++ b/projects/fangjia-service/pom.xml @@ -239,5 +239,10 @@ kafka_2.13 3.4.0 + + com.aliyun + aliyun-java-sdk-address-purification + 1.0.1 + 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 27089094c..f249b5ba0 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 @@ -1858,6 +1858,7 @@ public class DistrictStatServiceImpl implements DistrictStatService { if (StringUtils.isNotBlank(name)) { params.add(new QueryParam("districtName", name)); } + params.add(new QueryParam("estateType", QueryParam.IN_OPERATOR, Arrays.asList("小区", "别墅"))); if (null != weekend) { params.add(new QueryParam("weekend", DateUtil.getThisSunday(weekend))); } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java index 62a489d63..031487c08 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java @@ -1,12 +1,22 @@ package com.fangjia.service.efund; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.address_purification.model.v20191118.GetAddressGeocodeRequest; +import com.aliyuncs.address_purification.model.v20191118.GetAddressGeocodeResponse; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.profile.DefaultProfile; import com.fangjia.core.ProvinceData; import com.fangjia.core.RegionData; import com.fangjia.core.util.DateUtil; import com.fangjia.core.util.HttpRequest; import com.fangjia.core.util.HttpRequestException; +import com.fangjia.dal.QueryParam; +import com.fangjia.dal.SortParam; import com.fangjia.dal.common.DistrictKey; +import com.fangjia.dal.mongo.dao.office.OfficeSellStatDao; import com.fangjia.dal.mongo.model.DistrictStat; +import com.fangjia.dal.mongo.model.OfficeSellStat; import com.fangjia.dal.mongo.model.RegionSellStat; import com.fangjia.dal.mongo.model.bkoff.DealPrice; import com.fangjia.dal.seaweed.model.District; @@ -18,13 +28,9 @@ import com.fangjia.service.mongo.fangjia.DealPriceService; import com.fangjia.service.mongo.fangjia.RegionSellStatService; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; - -import java.math.BigDecimal; +import org.apache.log4j.Logger; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * E基金地址匹配服务实现 @@ -32,11 +38,16 @@ import java.util.Map; */ public class EfundMatchServiceImpl implements EfundMatchService { + private static final Logger logger = Logger.getLogger(EfundMatchServiceImpl.class); private AddressMatchProxyService addressMatchProxyService; private DistrictStatService districtStatService; private DealPriceService dealPriceService; private DistrictService districtService; private RegionSellStatService regionSellStatService; + private OfficeSellStatDao officeSellStatDao; + + private static final DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIdaj4eSO79gzz", "xw6EsvqydZ9HC6zAvIB3ruQqVHynxf"); + private static final IAcsClient client = new DefaultAcsClient(profile); @Override public UniversalDto matchAddress(String address, String city) { @@ -92,7 +103,7 @@ public class EfundMatchServiceImpl implements EfundMatchService { result.append("property_type", "住宅"); result.append("match_level", "小区级"); // 查询小区房价和数据更新时间 - DistrictStat latestStat = districtStatService.findOneDistrictStatsSort(districtCity, districtRegion, districtName, null); + DistrictStat latestStat = districtStatService.findOneDistrictStatsSort(districtCity, districtRegion, districtName, DateUtil.getFirstDayOfWeek(new Date())); if (latestStat != null) { // 优先使用avg_price_2b,如果为空再使用avgPrice Integer avgPrice = null; @@ -120,16 +131,18 @@ public class EfundMatchServiceImpl implements EfundMatchService { } } }else if(district != null && district.getCategory().equals("office")){ - // 写字楼,不输出房价 + // 写字楼,查询最新月份单价 result.append("property_type", "写字楼"); result.append("match_level", "建筑级"); - }else { - result.append("match_level", "建筑级"); - result.append("property_type", category); - if(category.contains("住宅")){ - result.append("match_level", "小区级"); - result.append("property_type", "住宅"); - String location = matchResult.getString("lng") + "," + matchResult.getString("lat"); + OfficeSellStat officeStat = findLatestOfficeSellStat(district.getCity(),district.getRegion(), district.getName()); + if (officeStat != null && officeStat.getAvgPrice() != null && officeStat.getAvgPrice() > 0) { + result.append("reference_price", officeStat.getAvgPrice()); + if (officeStat.getDate() != null) { + result.append("update_time", DateUtil.formatByPattern(DateUtil.parseDate(officeStat.getDate().toString(), "yyyyMM"), "yyyy-MM-dd")); + } + } + if(!result.containsKey("reference_price")){ + String location = district.getLng()/100000000000.0 + "," + district.getLat()/100000000000.0; HttpRequest httpRequest = new HttpRequest(); JSONObject json = null; Map param = new HashMap(); @@ -138,17 +151,74 @@ public class EfundMatchServiceImpl implements EfundMatchService { try { json = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8"); if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { - result.put("reference_price", json.getInt("unitPrice")); + result.put("residential 1km _price", json.getInt("unitPrice")); result.append("update_time", DateUtil.formatByPattern(DateUtil.getFirstDayOfWeek(new Date()), "yyyy-MM-dd")); } } catch (HttpRequestException e) { throw new RuntimeException(e); } } + + }else { + result.append("match_level", "建筑级"); + result.append("property_type", category); + String location = matchResult.getString("lng") + "," + matchResult.getString("lat"); + HttpRequest httpRequest = new HttpRequest(); + JSONObject json = null; + Map param = new HashMap(); + param.put("location", location); + param.put("area", "100"); + try { + json = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8"); + if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { + result.put("residential_1km_price", json.getInt("unitPrice")); + result.append("update_time", DateUtil.formatByPattern(DateUtil.getFirstDayOfWeek(new Date()), "yyyy-MM-dd")); + } + } catch (HttpRequestException e) { + throw new RuntimeException(e); + } + if(category.contains("住宅")){ + result.append("match_level", "小区级"); + result.append("property_type", "住宅"); + if(result.containsKey("residential_1km_price")){ + result.put("reference_price", result.get("residential_1km_price")); + result.remove("residential_1km_price"); + } + } } return result; } + /** + * 获取经纬度工具类 + * { + * "wgs84":"120.02099798073618,30.281364166381348", + * "level":"roadno", + * "gcj02":"120.025746,30.278984" + * } + * @param city 城市 + * @param address 地址 + * @return + */ + public static com.alibaba.fastjson.JSONObject getAddressGeocode(String city, String address) { + GetAddressGeocodeRequest request = new GetAddressGeocodeRequest(); + request.setAppKey("68czunztrb1o"); + request.setServiceCode("addrp"); + request.setText(address); + request.setDefaultCity(city); + GetAddressGeocodeResponse response = null; + try { + response = client.getAcsResponse(request); + com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response.getData()); + if(jsonObject.containsKey("offline_geocode")){ + return jsonObject.getJSONObject("offline_geocode"); + } + } catch (ClientException e) { + logger.error("通用经纬度查询异常:", e); + } + return null; + } + /** * 查找典型总价:成交单价最接近参考均价的成交记录的总价 * @param districtKey 小区Key @@ -261,23 +331,22 @@ public class EfundMatchServiceImpl implements EfundMatchService { }else if(StringUtils.isNotBlank(structCity)){ result.append("match_level", "城市级"); } - // 格式化城市和区域为简称 - String formattedCity = RegionData.formatCity(structCity); - String formattedRegion = RegionData.formatRegion(formattedCity, structDistrict); - - // 查询区域价格 - if (StringUtils.isNotBlank(formattedCity) && StringUtils.isNotBlank(formattedRegion)) { - RegionSellStat regionSellStat = regionSellStatService.findNewestRegionPrice(formattedCity, formattedRegion); - if (regionSellStat != null && regionSellStat.getAvgPrice() != null && regionSellStat.getAvgPrice() > 0) { - result.append("reference_price", regionSellStat.getAvgPrice()); - - // 数据更新时间 - if (regionSellStat.getUpdateDate() != null) { - result.append("update_time", DateUtil.formatByPattern(DateUtil.parseDate(regionSellStat.getDate().toString(),"yyyyMM"), "yyyy-MM-dd")); + com.alibaba.fastjson.JSONObject json = getAddressGeocode(city, address); + if(json != null && json.containsKey("gcj02")){ + HttpRequest httpRequest = new HttpRequest(); + Map param = new HashMap(); + param.put("location", json.getString("gcj02")); + param.put("area", "100"); + try { + JSONObject avmJson = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8"); + if (avmJson.containsKey("msg") && "成功".equals(avmJson.getString("msg"))) { + result.put("residential_1km_price", avmJson.getInt("unitPrice")); + result.append("update_time", DateUtil.formatByPattern(DateUtil.getFirstDayOfWeek(new Date()), "yyyy-MM-dd")); } + } catch (HttpRequestException e) { + throw new RuntimeException(e); } } - return result; } catch (Exception e) { @@ -305,4 +374,36 @@ public class EfundMatchServiceImpl implements EfundMatchService { public void setRegionSellStatService(RegionSellStatService regionSellStatService) { this.regionSellStatService = regionSellStatService; } + + public void setOfficeSellStatDao(OfficeSellStatDao officeSellStatDao) { + this.officeSellStatDao = officeSellStatDao; + } + + /** + * 查询写字楼最新月份的统计单价 + * @param city 城市 + * @param district 区域 + * @param name 写字楼名称 + * @return 最新月份的OfficeSellStat,未找到时返回null + */ + private OfficeSellStat findLatestOfficeSellStat(String city, String district, String name) { + if (officeSellStatDao == null || StringUtils.isBlank(city) || StringUtils.isBlank(name)) { + return null; + } + try { + List params = new ArrayList(); + params.add(new QueryParam("city", city)); + params.add(new QueryParam("district", district)); + params.add(new QueryParam("name", name)); + List sortParams = new ArrayList(); + sortParams.add(new SortParam("date", false)); + List stats = officeSellStatDao.findAllByParams(params, sortParams, 1); + if (stats != null && !stats.isEmpty()) { + return stats.get(0); + } + } catch (Exception e) { + // 查询失败不影响主流程 + } + return null; + } } From c6297614e08e64e85b8f21439ad990a95724b079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Wed, 11 Mar 2026 18:56:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=93=E6=96=B9?= =?UTF-8?q?=E8=BE=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fangjia/script/opentest/EfundInterfaceTest.groovy | 4 ++-- .../java/com/fangjia/service/efund/EfundMatchServiceImpl.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy index a538bed6c..638906510 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy @@ -61,7 +61,7 @@ try { // 6. 使用 ExcelUtils.multiThreadingModify 多线程调用接口 println "\n开始多线程测试接口..." - println "接口地址:http://localhost:9180/efund/match" + println "接口地址:http://open.fangjia.com/efund/match" println "线程数:CPU核心数 × 4 = ${Runtime.getRuntime().availableProcessors() * 4}" ExcelUtils.multiThreadingModify(outputFile, { List row -> @@ -79,7 +79,7 @@ try { params.put("city", city) } - String response = request.get("http://localhost:9180/efund/match", params, "UTF-8") + String response = request.get("http://open.fangjia.com/efund/match", params, "UTF-8") long duration = System.currentTimeMillis() - startTime // 解析响应 diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java index 031487c08..7648af4a5 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java @@ -392,6 +392,7 @@ public class EfundMatchServiceImpl implements EfundMatchService { } try { List params = new ArrayList(); + params.add(new QueryParam("cat", "office")); params.add(new QueryParam("city", city)); params.add(new QueryParam("district", district)); params.add(new QueryParam("name", name)); From 06758af3273850a8324c493a4505a84d95d4b4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Wed, 11 Mar 2026 20:08:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=93=E6=96=B9?= =?UTF-8?q?=E8=BE=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fangjia/script/opentest/EfundInterfaceTest.groovy | 10 +++++----- .../fangjia/service/efund/EfundMatchServiceImpl.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy index 638906510..5504860ff 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/opentest/EfundInterfaceTest.groovy @@ -64,7 +64,7 @@ try { println "接口地址:http://open.fangjia.com/efund/match" println "线程数:CPU核心数 × 4 = ${Runtime.getRuntime().availableProcessors() * 4}" - ExcelUtils.multiThreadingModify(outputFile, { List row -> + ExcelUtils.modify(outputFile, { List row -> HttpRequest request = new HttpRequest() long startTime = System.currentTimeMillis() @@ -103,7 +103,7 @@ try { row[14] = result.optString("update_time", "") row[15] = duration row[16] = "" // 无异常 - row[17] = result.optString("typical_total_price", "") + row[17] = result.optString("residential_1km_price", "") } else { // 接口返回异常 row[15] = duration @@ -139,13 +139,13 @@ try { List row = finalData[i] // 统计成功/失败 - String errorMsg = row[14]?.toString() ?: "" + String errorMsg = row[16]?.toString() ?: "" if (errorMsg == "") { successCount++ // 统计耗时 - if (row[13] instanceof Number) { - int duration = ((Number)row[13]).intValue() + if (row[15] instanceof Number) { + int duration = ((Number)row[15]).intValue() totalTime += duration // 耗时分布 diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java index 7648af4a5..eb99d8d5a 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java @@ -142,7 +142,7 @@ public class EfundMatchServiceImpl implements EfundMatchService { } } if(!result.containsKey("reference_price")){ - String location = district.getLng()/100000000000.0 + "," + district.getLat()/100000000000.0; + String location = district.getLng()/10000000000.0 + "," + district.getLat()/10000000000.0; HttpRequest httpRequest = new HttpRequest(); JSONObject json = null; Map param = new HashMap(); From 11476065171a05e83770524033caf28600100ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Thu, 12 Mar 2026 13:46:46 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=93=E6=96=B9?= =?UTF-8?q?=E8=BE=BE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fangjia/service/efund/EfundMatchServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java index eb99d8d5a..b3626ef72 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/efund/EfundMatchServiceImpl.java @@ -138,7 +138,7 @@ public class EfundMatchServiceImpl implements EfundMatchService { if (officeStat != null && officeStat.getAvgPrice() != null && officeStat.getAvgPrice() > 0) { result.append("reference_price", officeStat.getAvgPrice()); if (officeStat.getDate() != null) { - result.append("update_time", DateUtil.formatByPattern(DateUtil.parseDate(officeStat.getDate().toString(), "yyyyMM"), "yyyy-MM-dd")); + result.append("update_time", DateUtil.formatByPattern(DateUtil.getFirstDayOfWeek(new Date()), "yyyy-MM-dd")); } } if(!result.containsKey("reference_price")){