From b2a92c6bf2cb67bd022f83e60ba9bd1ea9737d3b Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Tue, 8 Mar 2022 11:05:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=A0=87=E5=87=86=E5=8C=96=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/AddressController.java | 134 ++++++++++++++++++ .../src/main/resources/urlrewrite2.0.xml | 5 + 2 files changed, 139 insertions(+) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java index 907212d5f..07d121e77 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java @@ -106,6 +106,7 @@ public class AddressController { private HouseLoudongService houseLoudongService; private FjtEvaluationService fjtEvaluationService; private AddressMatchProxyService addressMatchProxyService; + private final static String AK = OpenConfig.getConfig().getBaiduAk(); private final static Logger LOGGER = LoggerFactory.getLogger(AddressController.class); @@ -1705,6 +1706,139 @@ public class AddressController { return mav; } + /** + * 地址标准化接口V2 + * + * @param model + * @return + */ + public Object standardV2Action(AddesssMatchModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + if (StringUtils.isBlank(model.getAddress())) { + mav.setModel(BasicModel.buildBadRequestModel("地址不能为空")); + return mav; + } + + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : "重庆市"); + params.put("address", model.getAddress()); + try{ + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/structure", params, "UTF-8"); + } catch(Exception e){ + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/structure", params, "UTF-8"); + } catch(Exception ex){ + ex.printStackTrace(); + } + } + + if (json != null) { + int code = json.getInt("status"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + if(json.containsKey("result")){ + basicModel.setResult(json.get("result")); + } + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + + /** + * 五级地址标准化接口 + * + * @param model + * @return + */ + public Object fiveDivisionStructureAction(AddesssMatchModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + if (StringUtils.isBlank(model.getAddress())) { + mav.setModel(BasicModel.buildBadRequestModel("地址不能为空")); + return mav; + } + + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : "重庆市"); + params.put("address", model.getAddress()); + // 地址验证无效也输出标准化结果 + params.put("flag", "true"); + try{ + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/fiveDivisionStructure", params, "UTF-8"); + } catch(Exception e){ + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/fiveDivisionStructure", params, "UTF-8"); + } catch(Exception ex){ + ex.printStackTrace(); + } + } + + if (json != null) { + int code = json.getInt("status"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + if(json.containsKey("result")){ + basicModel.setResult(json.get("result")); + } + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + + /** + * 详细地址标准化接口 + * + * @param model + * @return + */ + public Object divisionStructureAction(AddesssMatchModel model) { + + RestfulModelAndView mav = new RestfulModelAndView(); + if (StringUtils.isBlank(model.getAddress())) { + mav.setModel(BasicModel.buildBadRequestModel("地址不能为空")); + return mav; + } + + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : "重庆市"); + params.put("address", model.getAddress()); + // 地址验证无效也输出标准化结果 + params.put("flag", "true"); + try{ + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/divisionStructure", params, "UTF-8"); + } catch(Exception e){ + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/divisionStructure", params, "UTF-8"); + } catch(Exception ex){ + ex.printStackTrace(); + } + } + + if (json != null) { + int code = json.getInt("status"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + if(json.containsKey("result")){ + basicModel.setResult(json.get("result")); + } + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + public Object similarityAction(AddesssMatchModel model) { RestfulModelAndView mav = new RestfulModelAndView(); if (StringUtils.isBlank(model.getAddress_1()) || StringUtils.isBlank(model.getAddress_2())) { diff --git a/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml b/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml index fb8d631db..0e434c5a4 100644 --- a/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml +++ b/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml @@ -33,5 +33,10 @@ /property/avgPrice + + + /address/standardV2 + + \ No newline at end of file From 73cc32931b8ba44a967b098d61bf60eb987aee07 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Tue, 8 Mar 2022 13:44:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=A0=87=E5=87=86=E5=8C=96=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fangjia/open/OpenConfig.java | 5 +++++ .../com/fangjia/open/controllers/AddressController.java | 9 ++++++--- .../src/main/resources/fangjia-open.properties | 3 ++- .../fangjia-open/src/main/resources/urlrewrite2.0.xml | 8 ++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/OpenConfig.java b/projects/fangjia-open/src/main/java/com/fangjia/open/OpenConfig.java index e1064e8cd..c13a28b36 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/OpenConfig.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/OpenConfig.java @@ -38,6 +38,7 @@ public class OpenConfig extends Configuration { private final String ipdatfile; private final String baiduAk; + private final String defaultCity; private final boolean isOpenAllAuthority; @@ -54,6 +55,7 @@ public class OpenConfig extends Configuration { baiduAk = configuration.get("fangjia.baidu.ak"); isOpenAllAuthority = configuration.getBoolean("fangjia.isOpenAllAuthority", false); enabledAddressMatch = configuration.getBoolean("fangjia.addressMatch.enabled",false); + defaultCity = configuration.get("fangjia.default.city"); } public static OpenConfig getConfig() { @@ -134,4 +136,7 @@ public class OpenConfig extends Configuration { return enabledAddressMatch; } + public String getDefaultCity() { + return defaultCity; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java index 07d121e77..d11473fcc 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddressController.java @@ -89,6 +89,7 @@ import com.fangjia.service.mongo.fangjia.ServerAreaService; import com.fangjia.service.open.WaitCrawlKeywordsService; import com.fangjia.service.sql.FjtEvaluationService; import com.fangjia.service.web.AddressService; +import org.sothis.web.mvc.annotation.Param; @Authority(role = Role.USER) public class AddressController { @@ -118,6 +119,8 @@ public class AddressController { private static final String GRADE_NATION = "全国评分"; private static final String GRADE_CONSUME = "消费评分"; + public final static OpenConfig CONFIG = OpenConfig.getConfig(); + /** * @deprecated see parse2Action * @param model @@ -1712,7 +1715,7 @@ public class AddressController { * @param model * @return */ - public Object standardV2Action(AddesssMatchModel model) { + public Object standard2Action(AddesssMatchModel model) { RestfulModelAndView mav = new RestfulModelAndView(); if (StringUtils.isBlank(model.getAddress())) { @@ -1723,7 +1726,7 @@ public class AddressController { HttpRequest request = new HttpRequest(); JSONObject json = null; Map params = new HashMap(); - params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : "重庆市"); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : CONFIG.getDefaultCity()); params.put("address", model.getAddress()); try{ json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/structure", params, "UTF-8"); @@ -1766,7 +1769,7 @@ public class AddressController { HttpRequest request = new HttpRequest(); JSONObject json = null; Map params = new HashMap(); - params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : "重庆市"); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : CONFIG.getDefaultCity()); params.put("address", model.getAddress()); // 地址验证无效也输出标准化结果 params.put("flag", "true"); diff --git a/projects/fangjia-open/src/main/resources/fangjia-open.properties b/projects/fangjia-open/src/main/resources/fangjia-open.properties index aaf6af5ca..c7d4d526c 100644 --- a/projects/fangjia-open/src/main/resources/fangjia-open.properties +++ b/projects/fangjia-open/src/main/resources/fangjia-open.properties @@ -100,4 +100,5 @@ fangjia.jms.email.queue=email.queue fangjia.redis_nodes=192.168.0.79:6379,192.168.0.79:6380,192.168.0.79:6381,192.168.0.81:6382,192.168.0.81:6383,192.168.0.81:6384 -fangjia.fangjiatong.url = http://user.fangjia.com/fangjiatong2 \ No newline at end of file +fangjia.fangjiatong.url = http://user.fangjia.com/fangjiatong2 +fangjia.default.city = \u91CD\u5E86\u5E02 \ No newline at end of file diff --git a/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml b/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml index 0e434c5a4..ba0a21b49 100644 --- a/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml +++ b/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml @@ -1,8 +1,8 @@ - - + + @@ -33,9 +33,9 @@ /property/avgPrice - + - /address/standardV2 + /address/standard