Merge branch 'open_gj' into 'master'

浙商风险识别优化

See merge request !650
This commit is contained in:
2023-05-29 11:22:57 +08:00
@@ -985,6 +985,14 @@ public class AddressController {
return term;
}
private JSONObject addMatchPhrase(String name, String value){
JSONObject term = new JSONObject();
JSONObject match = new JSONObject();
match.put(name, value);
term.put("match_phrase", match);
return term;
}
/***
* 获取自然村
* @param city
@@ -3322,20 +3330,26 @@ public class AddressController {
searchKey.append(searchAddress.getString("streetNumber"));
}
if (StringUtils.isNotBlank(searchKey.toString()) && searchAddress.has("city") && StringUtils.isNotBlank(searchAddress.getString("city"))) {
JSONObject jsonObject = addressMatchProxyService.searchByAmap(searchAddress.getString("city"), model.getAddress());
JSONArray poisData = jsonObject.getJSONArray("pois");
for (int i = 0; i < poisData.size(); i++) {
String address = poisData.getJSONObject(i).getString("address");
if (address.contains(searchKey.toString())) {
resultMap.put("riskLevel", "A");
resultModel.setResult(resultMap);
mav.setModel(resultModel);
return mav;
} else {
continue;
}
// JSONObject jsonObject = addressMatchProxyService.searchByAmap(searchAddress.getString("city"), model.getAddress());
// JSONArray poisData = jsonObject.getJSONArray("pois");
// for (int i = 0; i < poisData.size(); i++) {
// String address = poisData.getJSONObject(i).getString("address");
// if (address.contains(searchKey.toString())) {
// resultMap.put("riskLevel", "A");
// resultModel.setResult(resultMap);
// mav.setModel(resultModel);
// return mav;
// } else {
// continue;
// }
// }
String city = searchAddress.getString("city");
List<JSONObject> poiList = this.findPois(city, searchKey.toString());
if (CollectionUtils.isNotEmpty(poiList)) {
resultMap.put("riskLevel", "A");
} else {
resultMap.put("riskLevel", "B");
}
resultMap.put("riskLevel", "B");
resultModel.setResult(resultMap);
mav.setModel(resultModel);
return mav;
@@ -3352,6 +3366,44 @@ public class AddressController {
return mav;
}
private List<JSONObject> findPois(String city, String address) {
JSONObject reqBody = new JSONObject();
reqBody.put("from", 0);
reqBody.put("size", 1);
JSONObject query = new JSONObject();
JSONObject bool = new JSONObject();
JSONArray must = new JSONArray();
must.add(addTerm("city", city));
must.add(addMatchPhrase("address", address));
bool.put("must", must);
query.put("bool", bool);
reqBody.put("query", query);
Base64 token = new Base64();
String authenticationEncoding = token.encodeAsString((""+ES_USER+":"+ES_PASSWORD+"").getBytes());
HttpRequest request = new HttpRequest();
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Basic "+authenticationEncoding+"");
try {
String response = request.postWithBody("http://192.168.0.45:9200/association/_search", reqBody, headers, "UTF-8");
JSONObject json = JSONObject.fromObject(response);
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")){
return Collections.emptyList();
}
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
List<JSONObject> results = new ArrayList<JSONObject>();
for(int i=0 ;i < hits.size(); i++){
JSONObject jsonObject = hits.getJSONObject(i);
results.add(jsonObject);
}
return results;
} catch (HttpRequestException e) {
e.printStackTrace();
}
return Collections.emptyList();
}
public void setAddressService(AddressService addressService) {
this.addressService = addressService;
}