改造realMatchAll
This commit is contained in:
+81
-12
@@ -108,6 +108,55 @@ public class AddressMatchProxyServiceImpl extends AbstractHttpApiService impleme
|
||||
return baseModel.toString();
|
||||
}
|
||||
|
||||
public String realMatchAll(Map<String, Object> paramsMap) {
|
||||
String address = paramsMap.get("address").toString();;
|
||||
address = address.replaceAll("@@", "#");// 框架无法处理参数带有#的Buge 用@@代替
|
||||
BuildingType buildingType = null;
|
||||
if (paramsMap.containsKey("category")) {
|
||||
if ("property".equals(paramsMap.get("category"))) {
|
||||
paramsMap.put("category", "district");
|
||||
}
|
||||
try {
|
||||
buildingType = BuildingType.valueOf(((String)paramsMap.get("category")).toUpperCase());
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
PreciseLevel preciseLevel = PreciseLevel.FUZZY;
|
||||
if ("strict".equals(paramsMap.get("preciseLevel"))) {
|
||||
preciseLevel = PreciseLevel.STRICT;
|
||||
}
|
||||
MatchParams params = new MatchParams();
|
||||
if (paramsMap.containsKey("city")) {
|
||||
params.setCity(paramsMap.get("city").toString());
|
||||
}
|
||||
if (paramsMap.containsKey("suggestDistrict")) {
|
||||
params.setSuggestDistrict(paramsMap.get("suggestDistrict").toString());
|
||||
}
|
||||
if (paramsMap.containsKey("suggestName")) {
|
||||
params.setSuggestName(paramsMap.get("suggestName").toString());
|
||||
}
|
||||
|
||||
params.setAddress(address);
|
||||
params.setBuildingType(buildingType);
|
||||
params.setPreciseLevel(preciseLevel);
|
||||
|
||||
if (paramsMap.containsKey("province")) {
|
||||
params.setProvince(paramsMap.get("province").toString());
|
||||
}
|
||||
AddressParseResult addressParseResult = addressParserService.parserAll(params);
|
||||
List<Building> buildings = addressParseResult.getBuildings();
|
||||
List<Map<String, Object>> buildingObjs = new ArrayList<Map<String, Object>>(buildings.size());
|
||||
for (Building building : buildings) {
|
||||
buildingObjs.add(convertBuildingToMap(building));
|
||||
}
|
||||
JSONObject baseModel = new JSONObject();
|
||||
baseModel.put("code", 200);
|
||||
baseModel.put("msg", "ok");
|
||||
baseModel.put("result", buildingObjs);
|
||||
return baseModel.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parser(Map<String, Object> params) {
|
||||
params.put("token", TOKEN);
|
||||
@@ -129,7 +178,7 @@ public class AddressMatchProxyServiceImpl extends AbstractHttpApiService impleme
|
||||
public String parserAll(Map<String, Object> params) {
|
||||
params.put("token", TOKEN);
|
||||
try {
|
||||
String result = this.invoke("address/realMatchAll", params, "UTF-8");
|
||||
String result = realMatchAll(params);
|
||||
return result;
|
||||
} catch (JSONException e) {
|
||||
LOGGER.error("", e);
|
||||
@@ -508,29 +557,49 @@ public class AddressMatchProxyServiceImpl extends AbstractHttpApiService impleme
|
||||
Map<String, Object> convertBuildingToMap(Building building) {
|
||||
Map<String, Object> result = new LinkedHashMap<String, Object>();
|
||||
if (building != null) {
|
||||
result.put("id", building.getId());
|
||||
if (StringUtils.isNotBlank(building.getId())) {
|
||||
result.put("id", building.getId());
|
||||
}
|
||||
result.put("credit", building.getCredit());
|
||||
result.put("precise", building.getPrecise());
|
||||
result.put("province", building.getProvince());
|
||||
result.put("city", building.getCity());
|
||||
result.put("district", building.getDistrict());
|
||||
result.put("name", building.getName());
|
||||
result.put("suggestName", building.getSuggestName());
|
||||
result.put("map", building.getMap());
|
||||
if (StringUtils.isNotBlank(building.getSuggestName())) {
|
||||
result.put("suggestName", building.getSuggestName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(building.getMap())) {
|
||||
result.put("map", building.getMap());
|
||||
}
|
||||
result.put("propertyType", building.getPropertyType());
|
||||
result.put("township", building.getTownship());
|
||||
result.put("suggestAddress", building.getSuggestAddress());
|
||||
if (StringUtils.isNotBlank(building.getTownship())) {
|
||||
result.put("township", building.getTownship());
|
||||
}
|
||||
if (StringUtils.isNotBlank(building.getSuggestAddress())) {
|
||||
result.put("suggestAddress", building.getSuggestAddress());
|
||||
}
|
||||
if ("district".equals(building.getCategory())) {
|
||||
result.put("category", "property");
|
||||
} else {
|
||||
result.put("category", building.getCategory());
|
||||
}
|
||||
result.put("address", building.getAddress());
|
||||
result.put("block", building.getBlock());
|
||||
result.put("lng", building.getLng());
|
||||
result.put("lat", building.getLat());
|
||||
result.put("alias", building.getAlias());
|
||||
result.put("searchAddress", building.getSearchAddress());
|
||||
if (StringUtils.isNotBlank(building.getAddress())) {
|
||||
result.put("address", building.getAddress());
|
||||
}
|
||||
if (StringUtils.isNotBlank(building.getBlock())) {
|
||||
result.put("block", building.getBlock());
|
||||
}
|
||||
if (building.getLng() != null && building.getLat() != null) {
|
||||
result.put("lng", building.getLng());
|
||||
result.put("lat", building.getLat());
|
||||
}
|
||||
if (building.getAlias() != null) {
|
||||
result.put("alias", building.getAlias());
|
||||
}
|
||||
if (building.getSearchAddress() != null) {
|
||||
result.put("searchAddress", building.getSearchAddress());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user