新增易方达接口以及添加claude技能
This commit is contained in:
+1
-1
@@ -599,7 +599,7 @@ public class AddressMatchProxyServiceImpl extends AbstractHttpApiService impleme
|
||||
params.put("city", city);
|
||||
params.put("address", address);
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/structure", params, "UTF-8");
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/formatNinelevel", params, "UTF-8");
|
||||
if (json != null && json.containsKey("msgCode") && json.getInt("msgCode") == 200) {
|
||||
if (json.containsKey("result")) {
|
||||
return (JSONObject) json.get("result");
|
||||
|
||||
+4
-2
@@ -1096,7 +1096,7 @@ public class DistrictStatServiceImpl implements DistrictStatService {
|
||||
if (StringUtils.isNotBlank(city) && StringUtils.isNotBlank(region) && StringUtils.isNotBlank(name)) {
|
||||
DistrictStatBo districtStatBo = this.districtStatService.findDistrictStat(new DistrictKey(city, region, name));
|
||||
if (districtStatBo.getDefaultDistrictStat() != null) {
|
||||
return districtStatBo.getDefaultDistrictStat().getAvgPrice();
|
||||
return districtStatBo.getDefaultDistrictStat().getAvg_price_2b() != null ? districtStatBo.getDefaultDistrictStat().getAvg_price_2b() : districtStatBo.getDefaultDistrictStat().getAvgPrice();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1861,7 +1861,9 @@ public class DistrictStatServiceImpl implements DistrictStatService {
|
||||
if (null != weekend) {
|
||||
params.add(new QueryParam("weekend", DateUtil.getThisSunday(weekend)));
|
||||
}
|
||||
DistrictStat dss = districtStatDao.findFirstByParams(params);
|
||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||
sortParams.add(new SortParam("weekend", false));
|
||||
DistrictStat dss = districtStatDao.findFirstByParams(params, sortParams);
|
||||
return dss;
|
||||
}
|
||||
});
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.fangjia.service.efund;
|
||||
|
||||
import com.fangjia.service.dto.UniversalDto;
|
||||
|
||||
/**
|
||||
* E基金地址匹配服务
|
||||
* @author wenyan
|
||||
*/
|
||||
public interface EfundMatchService {
|
||||
|
||||
/**
|
||||
* 根据地址进行匹配,返回房价信息和地址类型标签
|
||||
*
|
||||
* @param address 地址字符串
|
||||
* @param city 城市名称(可选)
|
||||
* @return 匹配结果,包含小区信息、房价、地址类型等
|
||||
*/
|
||||
UniversalDto matchAddress(String address, String city);
|
||||
}
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
package com.fangjia.service.efund;
|
||||
|
||||
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.common.DistrictKey;
|
||||
import com.fangjia.dal.mongo.model.DistrictStat;
|
||||
import com.fangjia.dal.mongo.model.RegionSellStat;
|
||||
import com.fangjia.dal.mongo.model.bkoff.DealPrice;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.service.api.AddressMatchProxyService;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.district.DistrictStatService;
|
||||
import com.fangjia.service.dto.UniversalDto;
|
||||
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 java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* E基金地址匹配服务实现
|
||||
* @author wenyan
|
||||
*/
|
||||
public class EfundMatchServiceImpl implements EfundMatchService {
|
||||
|
||||
private AddressMatchProxyService addressMatchProxyService;
|
||||
private DistrictStatService districtStatService;
|
||||
private DealPriceService dealPriceService;
|
||||
private DistrictService districtService;
|
||||
private RegionSellStatService regionSellStatService;
|
||||
|
||||
@Override
|
||||
public UniversalDto matchAddress(String address, String city) {
|
||||
if (StringUtils.isBlank(address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 调用地址匹配服务
|
||||
JSONObject matchResult = addressMatchProxyService.newMatch(city, address, null, true);
|
||||
|
||||
// 检查是否匹配到POI(有id字段),没有id算匹配失败
|
||||
String id = (matchResult != null) ? matchResult.optString("id") : null;
|
||||
if (StringUtils.isBlank(id)) {
|
||||
// 匹配失败,调用标准化拆分接口
|
||||
return handleAddressStructure(city, address);
|
||||
}
|
||||
// 从匹配结果获取展示用的城市、区域、街道
|
||||
String matchCity = matchResult.optString("city");
|
||||
String matchDistrict = matchResult.optString("district");
|
||||
String matchName = matchResult.optString("name");
|
||||
String street = matchResult.optString("street");
|
||||
String township = matchResult.optString("township");
|
||||
String category = matchResult.optString("category");
|
||||
if(category.contains("写字楼")){
|
||||
category = "写字楼";
|
||||
}
|
||||
Double credit = matchResult.optDouble("credit", 0.0);
|
||||
UniversalDto result = UniversalDto.newDto();
|
||||
// 输出基本信息
|
||||
if(StringUtils.isNotBlank(matchCity)){
|
||||
result.append("city", matchCity);
|
||||
}
|
||||
if(StringUtils.isNotBlank(matchDistrict)){
|
||||
result.append("district", matchDistrict);
|
||||
}
|
||||
if(StringUtils.isNotBlank(township)){
|
||||
result.append("street", township);
|
||||
}
|
||||
if(StringUtils.isNotBlank(township)){
|
||||
result.append("community_name", matchName);
|
||||
}
|
||||
result.append("match_confidence", credit);
|
||||
result.append("property_type", category);
|
||||
result.append("validation", "地址有效");
|
||||
// 有id,匹配到POI,使用id查询权威的小区信息
|
||||
District district = districtService.findById(id);
|
||||
if (district != null && district.getCategory().equals("district")) {
|
||||
// 从District获取权威的城市、区域、名称(用于查询价格和成交数据)
|
||||
String districtCity = district.getCity();
|
||||
String districtRegion = district.getRegion();
|
||||
String districtName = district.getName();
|
||||
// 小区,输出房价
|
||||
result.append("property_type", "住宅");
|
||||
result.append("match_level", "小区级");
|
||||
// 查询小区房价和数据更新时间
|
||||
DistrictStat latestStat = districtStatService.findOneDistrictStatsSort(districtCity, districtRegion, districtName, null);
|
||||
if (latestStat != null) {
|
||||
// 优先使用avg_price_2b,如果为空再使用avgPrice
|
||||
Integer avgPrice = null;
|
||||
if (latestStat.getAvg_price_2b() != null && latestStat.getAvg_price_2b() > 0) {
|
||||
avgPrice = latestStat.getAvg_price_2b();
|
||||
} else if (latestStat.getAvgPrice() > 0) {
|
||||
avgPrice = latestStat.getAvgPrice();
|
||||
}
|
||||
|
||||
if (avgPrice != null && avgPrice > 0) {
|
||||
result.append("reference_price", avgPrice);
|
||||
|
||||
// 数据更新时间
|
||||
if (latestStat.getWeekend() != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
result.append("update_time", sdf.format(latestStat.getWeekend()));
|
||||
}
|
||||
|
||||
// 查询典型总价:成交单价最接近参考均价的成交记录的总价
|
||||
DistrictKey districtKey = new DistrictKey(districtCity, districtRegion, districtName);
|
||||
Integer typicalTotalPrice = findTypicalTotalPrice(districtKey, avgPrice);
|
||||
if (typicalTotalPrice != null) {
|
||||
result.append("typical_total_price", typicalTotalPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
}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");
|
||||
HttpRequest httpRequest = new HttpRequest();
|
||||
JSONObject json = null;
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
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("reference_price", json.getInt("unitPrice"));
|
||||
result.append("update_time", DateUtil.formatByPattern(DateUtil.getFirstDayOfWeek(new Date()), "yyyy-MM-dd"));
|
||||
}
|
||||
} catch (HttpRequestException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找典型总价:成交单价最接近参考均价的成交记录的总价
|
||||
* @param districtKey 小区Key
|
||||
* @param referencePrice 参考均价
|
||||
* @return 典型总价(万元)
|
||||
*/
|
||||
private Integer findTypicalTotalPrice(DistrictKey districtKey, Integer referencePrice) {
|
||||
if (referencePrice == null || referencePrice <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 计算半年前的日期和当前日期
|
||||
Date halfYearAgo = new Date(System.currentTimeMillis() - 180L * 24 * 60 * 60 * 1000);
|
||||
Date now = new Date();
|
||||
|
||||
// 查询近半年的成交记录
|
||||
List<DealPrice> dealPrices = dealPriceService.findDealPriceList(
|
||||
districtKey.getCity(),
|
||||
districtKey.getRegion(),
|
||||
districtKey.getName(),
|
||||
halfYearAgo,
|
||||
now
|
||||
);
|
||||
|
||||
if (dealPrices == null || dealPrices.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 找到单价最接近参考均价的成交记录
|
||||
DealPrice closestDeal = null;
|
||||
int minDiff = Integer.MAX_VALUE;
|
||||
|
||||
for (DealPrice deal : dealPrices) {
|
||||
if (deal.getAvgPrice() != null && deal.getTotalPrice() != null) {
|
||||
int diff = Math.abs(deal.getAvgPrice() - referencePrice);
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff;
|
||||
closestDeal = deal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (closestDeal != null && closestDeal.getTotalPrice() != null) {
|
||||
// 检查价格差异是否超过10%
|
||||
double diffPercent = Math.abs(closestDeal.getAvgPrice() - referencePrice) * 1.0 / referencePrice;
|
||||
if (diffPercent > 0.1) {
|
||||
return null;
|
||||
}
|
||||
return closestDeal.getTotalPrice()/10000;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 查询失败时不影响主流程,仅记录日志
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理地址标准化拆分并返回区域价格
|
||||
* @param city 城市
|
||||
* @param address 地址
|
||||
* @return 包含区域价格的结果
|
||||
*/
|
||||
private UniversalDto handleAddressStructure(String city, String address) {
|
||||
try {
|
||||
// 调用地址标准化拆分
|
||||
JSONObject structureResult = addressMatchProxyService.addressStructure(city, address);
|
||||
if (structureResult == null || structureResult.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UniversalDto result = UniversalDto.newDto();
|
||||
|
||||
// 提取拆分的城市、区域、街道信息
|
||||
String province = structureResult.optString("province", null);
|
||||
String cityField = structureResult.optString("city", null);
|
||||
String structDistrict = structureResult.optString("district", null);
|
||||
String structTownship = structureResult.optString("township", null);
|
||||
String structRoad = structureResult.optString("street", null);
|
||||
String structRoadNumber = structureResult.optString("streetNumber", null);
|
||||
String msg = null;
|
||||
if(structureResult.containsKey("addressAssessment")){
|
||||
JSONObject addressAssessment = structureResult.getJSONObject("addressAssessment");
|
||||
msg = addressAssessment.optString("msg");
|
||||
}
|
||||
// 处理直辖市:如果是直辖市,城市名在province字段中
|
||||
String structCity;
|
||||
if (ProvinceData.isGovernmentCity(province)) {
|
||||
structCity = province;
|
||||
} else {
|
||||
structCity = cityField;
|
||||
}
|
||||
// 输出基本信息
|
||||
result.append("city", structCity);
|
||||
result.append("district", structDistrict);
|
||||
result.append("street", structTownship);
|
||||
result.append("road", structRoad);
|
||||
result.append("road_number", structRoadNumber);
|
||||
result.append("validation", msg);
|
||||
if(StringUtils.isNotBlank(structRoadNumber)){
|
||||
result.append("match_level", "门牌级");
|
||||
}else if(StringUtils.isNotBlank(structRoad)){
|
||||
result.append("match_level", "道路级");
|
||||
}else if(StringUtils.isNotBlank(structTownship)){
|
||||
result.append("match_level", "街道级");
|
||||
}else if(StringUtils.isNotBlank(structDistrict)){
|
||||
result.append("match_level", "区域级");
|
||||
}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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
// 处理失败时返回null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) {
|
||||
this.addressMatchProxyService = addressMatchProxyService;
|
||||
}
|
||||
|
||||
public void setDistrictStatService(DistrictStatService districtStatService) {
|
||||
this.districtStatService = districtStatService;
|
||||
}
|
||||
|
||||
public void setDealPriceService(DealPriceService dealPriceService) {
|
||||
this.dealPriceService = dealPriceService;
|
||||
}
|
||||
|
||||
public void setDistrictService(DistrictService districtService) {
|
||||
this.districtService = districtService;
|
||||
}
|
||||
|
||||
public void setRegionSellStatService(RegionSellStatService regionSellStatService) {
|
||||
this.regionSellStatService = regionSellStatService;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user