优化匹配接口
This commit is contained in:
+11
-3
@@ -228,6 +228,10 @@ public class ComprehensiveQueryController {
|
||||
String cityStr = model.getCity();
|
||||
if (StringUtils.isNotBlank(cityStr) && cityStr.matches("\\d+")) {
|
||||
AdministrativeDivision administrativeDivision = administrativeDivisionService.findcityByCode(cityStr);
|
||||
if(administrativeDivision == null){
|
||||
mav.setModel(BasicModel.buildBadRequestModel("城市代码错误"));
|
||||
return mav;
|
||||
}
|
||||
String city = administrativeDivision.getCityShort();
|
||||
if (StringUtils.isBlank(city)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("城市代码错误"));
|
||||
@@ -242,7 +246,7 @@ public class ComprehensiveQueryController {
|
||||
communityAvgPriceParams.put("city", model.getCity());
|
||||
communityAvgPriceParams.put("address", model.getAddress());
|
||||
communityAvgPriceParams.put("category", model.getCategory());
|
||||
// communityAvgPriceParams.put("useMap", String.valueOf(model.isUseMap()));
|
||||
communityAvgPriceParams.put("useMap", "true");
|
||||
communityAvgPriceParams.put("suggestName", String.valueOf(model.getName()));
|
||||
communityAvgPriceParams.put("preciseLevel", "strict");
|
||||
communityAvgPriceParams.put("propertyType", model.getPropertyType());
|
||||
@@ -284,13 +288,17 @@ public class ComprehensiveQueryController {
|
||||
// }
|
||||
// return mav;
|
||||
// }
|
||||
String id = matchResponse.getJSONObject("result").getString("id");
|
||||
JSONObject result = matchResponse.getJSONObject("result");
|
||||
if(!result.containsKey("id")){
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
return mav;
|
||||
}
|
||||
String id = matchResponse.getJSONObject("result") .getString("id");
|
||||
District district = districtService.findById(id);
|
||||
if (district == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
MatchedBuildingDto dto = CommonDtoUtils.transformV(MatchedBuildingDto.class, matchResponse.getJSONObject("result"));
|
||||
DistrictStatBo statBo = districtStatService.findCurrentDistrictStat(new DistrictKey(district));
|
||||
if (null != statBo) {
|
||||
|
||||
+1
@@ -1606,6 +1606,7 @@ public class PropertyController {
|
||||
params.put("suggestName", model.getName());
|
||||
}
|
||||
params.put("category", "district");
|
||||
params.put("propertyType", model.getPropertyType());
|
||||
String result = addressMatchProxyService.parser(params);
|
||||
if (result != null) {
|
||||
JSONObject json = JSONObject.fromObject(result);
|
||||
|
||||
+1
-116
@@ -165,127 +165,12 @@ public class AddressParserServiceImpl implements AddressParserService {
|
||||
return building;
|
||||
}
|
||||
Building matchedBuilding;
|
||||
//调用CRF算法切分数据
|
||||
/*JSONObject jsonObj = null;
|
||||
if(params.isUseCrf() && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
|
||||
jsonObj = getDataFromCRF(addr.getOrgAddress());
|
||||
if(jsonObj != null){
|
||||
String poi = (jsonObj.containsKey("community_model") ? jsonObj.getString("community_model") : "") +
|
||||
(jsonObj.containsKey("poi_model") ? jsonObj.getString("poi_model") : "") +
|
||||
(jsonObj.containsKey("subpoi_model") ? jsonObj.getString("subpoi_model") : "");
|
||||
if(StringUtils.isNotBlank(poi)){
|
||||
if(addr.getKeywords()==null || !addr.getKeywords().contains(poi)){
|
||||
addr.setKeywords(poi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//keywords使用aliyun接口返回的poi
|
||||
AliyunBo aliyunBo = null;
|
||||
if(params.isUseAliyunApi() && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
|
||||
aliyunBo = aliyunService.addressStand(params.getAddress(), params.getCity());
|
||||
if(aliyunBo != null){
|
||||
String poi = ((aliyunBo.getPoi() == null ? "":aliyunBo.getPoi()) + (aliyunBo.getSubpoi() == null ? "":aliyunBo.getSubpoi())).replaceAll("\\s*", "");
|
||||
if(StringUtils.isNotBlank(poi)){
|
||||
if(addr.getKeywords()==null || !addr.getKeywords().contains(poi)){
|
||||
addr.setKeywords(poi);
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(aliyunBo.getCity())){
|
||||
addr.setCity(RegionData.formatCity(aliyunBo.getCity()));
|
||||
}
|
||||
if(StringUtils.isNotBlank(addr.getKeywords()) && addr.getOrgAddress().indexOf(addr.getKeywords())>-1){
|
||||
String str = AddressParserUtil.match(Pattern.compile(".*村(.*(组|队))?\\d+(号)?$"), addr.getOrgAddress().substring(addr.getOrgAddress().indexOf(addr.getKeywords()),addr.getOrgAddress().length()));
|
||||
if(StringUtils.isNotBlank(str)){
|
||||
String newKeywords = AddressParserUtil.match(Pattern.compile(".*村(.*(组|队))?"), str);
|
||||
if(StringUtils.isNotBlank(newKeywords)){
|
||||
addr.setKeywords(newKeywords);
|
||||
addr.setParsedPropertyName(newKeywords);
|
||||
aliyunBo.setRoomno(str.replace(newKeywords,""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
addr.addKeyword(addr.getOrgAddress());
|
||||
if(params.isUseMap()){
|
||||
matchedBuilding = findMatchedBuilding(addr, params.getBuildingType(), MetaDataType.MAP);
|
||||
}else{
|
||||
matchedBuilding = findMatchedBuilding(addr, params.getBuildingType(), MetaDataType.CPDB);
|
||||
}
|
||||
|
||||
/*if(jsonObj != null){
|
||||
//乡镇优化
|
||||
String township = jsonObj.containsKey("town") ? jsonObj.getString("town") : "";
|
||||
if(StringUtils.isBlank(addr.getTownship()) && StringUtils.isNotBlank(township)){
|
||||
String town = AddressParserUtil.match(AddressParserPatterns.TOWN, township);
|
||||
if(StringUtils.isNotBlank(town)){
|
||||
addr.setTownship(town);
|
||||
}
|
||||
}
|
||||
//道路优化(两边均去掉乡镇)
|
||||
String street = addr.getStreet();
|
||||
String streetNumber = addr.getStreetNumber();
|
||||
String streetCrf = jsonObj.containsKey("road") ? jsonObj.getString("road") : "";
|
||||
String streetNumberCrf = jsonObj.containsKey("roadno") ? jsonObj.getString("roadno") : "";
|
||||
//去掉路名中含有乡镇名的
|
||||
if(StringUtils.isNotBlank(addr.getTownship())){
|
||||
street = StringUtils.isNotBlank(street) ? street.replace(addr.getTownship(),"") : street;
|
||||
streetCrf = StringUtils.isNotBlank(streetCrf) ? streetCrf.replace(addr.getTownship(),"") : streetCrf;
|
||||
}
|
||||
|
||||
//crf解析出的路名为空、与Java解析出路名一致或不满足正则则不处理
|
||||
if(StringUtils.isNotBlank(streetCrf) && !streetCrf.equals(street) && StringUtils.isNotBlank(AddressParserUtil.match(AddressParserPatterns.STREET, streetCrf))){
|
||||
//Java解析出路名为空
|
||||
if(StringUtils.isBlank(street)){
|
||||
street = streetCrf;
|
||||
if(StringUtils.isNotBlank(streetNumberCrf)){
|
||||
streetNumber = streetNumberCrf;
|
||||
}
|
||||
}else{
|
||||
//CRF包含java解析出的路名或Java解析出的路名包含CRF解析出的路名并且多余部分也满足路名正则
|
||||
if(streetCrf.contains(street) || (street.contains(streetCrf) && StringUtils.isBlank(AddressParserUtil.match(AddressParserPatterns.STREET, street.replace(streetCrf,""))))){
|
||||
street = streetCrf;
|
||||
}
|
||||
}
|
||||
addr.setStreet(street);
|
||||
addr.setStreetNumber(streetNumber);
|
||||
}
|
||||
//poi处理
|
||||
//没有匹配上库中小区时
|
||||
if(StringUtils.isBlank(matchedBuilding.getId())){
|
||||
String poi = (jsonObj.containsKey("community") ? jsonObj.getString("community") : "") +
|
||||
(jsonObj.containsKey("poi") ? jsonObj.getString("poi") : "") +
|
||||
(jsonObj.containsKey("subpoi") ? jsonObj.getString("subpoi") : "");
|
||||
//去掉路名中含有乡镇名和路名 getParsedPropertyName
|
||||
if(StringUtils.isNotBlank(addr.getTownship())){
|
||||
poi = poi.replace(addr.getTownship(),"");
|
||||
}
|
||||
if(StringUtils.isNotBlank(addr.getStreet())){
|
||||
poi = poi.replace(addr.getStreet(),"");
|
||||
}
|
||||
addr.setParsedPropertyName(poi);
|
||||
}
|
||||
//楼栋、单元、室号
|
||||
String houseNo = (jsonObj.containsKey("houseno") ? jsonObj.getString("houseno") : "").replaceAll("[\u4E00-\u9FA5]", "");
|
||||
String cellNo = (jsonObj.containsKey("cellno") ? jsonObj.getString("cellno") : "").replaceAll("[\u4E00-\u9FA5]", "");
|
||||
String floorNo = (jsonObj.containsKey("floorno") ? jsonObj.getString("floorno") : "").replaceAll("[\u4E00-\u9FA5]", "");
|
||||
String roomNo = (jsonObj.containsKey("roomno") ? jsonObj.getString("roomno") : "").replaceAll("[\u4E00-\u9FA5]", "");
|
||||
addr.setOrgBuildingNumber(houseNo);
|
||||
addr.setBuildingNumber(houseNo);
|
||||
addr.setOrgUnitNumber(cellNo);
|
||||
addr.setUnitNumber(cellNo);
|
||||
addr.setFloor(floorNo);
|
||||
addr.setOrgRoomNumber(roomNo);
|
||||
addr.setRoomNumber(roomNo);
|
||||
}*/
|
||||
matchedBuilding = findMatchedBuilding(addr, params.getBuildingType(), MetaDataType.CPDB);
|
||||
matchedBuilding.setProvince(addr.getProvince());
|
||||
matchedBuilding.setSearchAddress(addr);
|
||||
matchedBuilding.setSuggestName(getSuggestName(matchedBuilding));
|
||||
matchedBuilding.setSuggestAddress(getSuggestAddress(matchedBuilding));
|
||||
if(params.isUseAliyunApi() && aliyunBo != null && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
|
||||
completBuildingField(matchedBuilding, aliyunBo, params);
|
||||
}
|
||||
Address tempAddr = matchedBuilding.getSearchAddress();
|
||||
if((StringUtils.isBlank(tempAddr.getStreet()) || StringUtils.isBlank(tempAddr.getStreetNumber())) && AddressParserGoal.Match.equals(addr.getAddressParserGoal())){
|
||||
AddressMatchMetaData meta = getMapMeta(addr);
|
||||
|
||||
+15
-9
@@ -19,7 +19,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class GeoProcessor extends AbstractAddressProcessor {
|
||||
|
||||
private static final String KEY = "4ccfe3c898a9489884bd2bcb1ef6dcde";
|
||||
private static final String KEY = "94d4f0e7d11745e84419a68104c06315";
|
||||
private static final Logger logger = Logger.getLogger(GeoProcessor.class);
|
||||
List<String> POI_LEVELS = Arrays.asList("村庄", "热点商圈", "兴趣点", "门牌号", "单元号", "道路交叉路口", "门牌号");
|
||||
|
||||
@@ -31,10 +31,7 @@ public class GeoProcessor extends AbstractAddressProcessor {
|
||||
if(!address.isUseMap()){
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
String addr = address.getEffectiveAddress();
|
||||
if(addr == null || addr.length() < 3){
|
||||
addr = address.getOrgAddress();
|
||||
}
|
||||
String addr = address.getOrgAddress();
|
||||
HttpRequest request = new HttpRequest();
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("address", addr);
|
||||
@@ -46,8 +43,17 @@ public class GeoProcessor extends AbstractAddressProcessor {
|
||||
logger.info("高德API:" + response.toString());
|
||||
if (response.getInt("status") == 1) {
|
||||
JSONArray geocodes = response.getJSONArray("geocodes");
|
||||
JSONObject json = null;
|
||||
if(geocodes.size() > 0){
|
||||
JSONObject json = geocodes.getJSONObject(0);
|
||||
for(int i=0; i < geocodes.size(); i++){
|
||||
if(POI_LEVELS.contains(geocodes.getJSONObject(i).getString("level"))){
|
||||
json = geocodes.getJSONObject(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(json == null){
|
||||
return RepeatStatus.NEXT;
|
||||
}
|
||||
if(json.get("district") instanceof String){
|
||||
String city = address.getCity();
|
||||
if(city == null){
|
||||
@@ -66,15 +72,15 @@ public class GeoProcessor extends AbstractAddressProcessor {
|
||||
String location = json.getString("location");
|
||||
address.setLng(Double.valueOf(location.split(",")[0]));
|
||||
address.setLat(Double.valueOf(location.split(",")[1]));
|
||||
String tmp = "{ \"_source\": [\"seaweed_id\"], \"query\": {\"geo_shape\": {\"shape\": {\"shape\": {\"type\": \"Point\",\"coordinates\":[location]},\"relation\": \"CONTAINS\"}}}}";
|
||||
String tmp = "{ \"_source\": [\"comm_id\"], \"query\": {\"geo_shape\": {\"shape\": {\"shape\": {\"type\": \"Point\",\"coordinates\":[location]},\"relation\": \"CONTAINS\"}}}}";
|
||||
tmp = tmp.replace("location", location);
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("Authorization","Basic ZGV2ZWxvcGVyOjVlOGVkZDg1MWQyZmRmYmQ3NDE1MjMyYzY3MzY3Y2Mz");
|
||||
JSONObject resp = JSONObject.fromObject(request.postWithBody("http://192.168.0.206:9200/seaweed_polygon/_search", JSONObject.fromObject(tmp),headers,"UTF-8"));
|
||||
JSONObject resp = JSONObject.fromObject(request.postWithBody("http://192.168.0.89:9200/seaweed_fence/_search", JSONObject.fromObject(tmp),headers,"UTF-8"));
|
||||
if(resp.containsKey("hits") && resp.getJSONObject("hits").containsKey("hits")){
|
||||
JSONArray hits = resp.getJSONObject("hits").getJSONArray("hits");
|
||||
if(hits.size() > 0){
|
||||
String seaweedId = hits.getJSONObject(0).getJSONObject("_source").getString("seaweed_id");
|
||||
String seaweedId = hits.getJSONObject(0).getJSONObject("_source").getString("comm_id");
|
||||
address.setPolygonSeaweedId(seaweedId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user