Merge branch 'open_gj' into 'master'

地址标准化新接口包装

See merge request !270
This commit is contained in:
2022-03-08 12:51:32 +08:00
4 changed files with 151 additions and 3 deletions
@@ -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;
}
}
@@ -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 {
@@ -106,6 +107,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);
@@ -117,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
@@ -1705,6 +1709,139 @@ public class AddressController {
return mav;
}
/**
* 地址标准化接口V2
*
* @param model
* @return
*/
public Object standard2Action(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<String, String> params = new HashMap<String, String>();
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");
} 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<String, String> params = new HashMap<String, String>();
params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : CONFIG.getDefaultCity());
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<String, String> params = new HashMap<String, String>();
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())) {
@@ -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
fangjia.fangjiatong.url = http://user.fangjia.com/fangjiatong2
fangjia.default.city = \u91CD\u5E86\u5E02
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlrewrite>
<global-params>
<param value="st" name="sort" type="attach"/>
<param value="pn" name="pager.currentPage" type="attach"/>
<!-- <param value="st" name="sort" type="attach"/>-->
<!-- <param value="pn" name="pager.currentPage" type="attach"/>-->
</global-params>
<rules>
<rule controller="city" action="condition2" channel="v2">
@@ -33,5 +33,10 @@
<ladder>/property/avgPrice</ladder>
</ladders>
</rule>
<rule controller="address" action="standard2" channel="v2">
<ladders>
<ladder>/address/standard</ladder>
</ladders>
</rule>
</rules>
</urlrewrite>