From 1b1ecfa770a490869f0331ddd4e08a487f550fcb Mon Sep 17 00:00:00 2001 From: majintao Date: Fri, 29 Nov 2024 17:19:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=B5=B7=E9=93=B6=E8=A1=8C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/AddrSvcController.java | 1193 +++++++++-------- 1 file changed, 626 insertions(+), 567 deletions(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddrSvcController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddrSvcController.java index 9b4164baf..f00d7c267 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddrSvcController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/AddrSvcController.java @@ -718,15 +718,13 @@ public class AddrSvcController { return mav; } - /** - * 涉农识别-新规则-基础版本 + * 涉农识别-新规则-上海银行 * * @param model * @return */ - public Object villageIdentifyAction(AddressModel model) { - + public Object boscVillageIdentifyAction(AddressModel model) { RestfulModelAndView mav = new RestfulModelAndView(); if (StringUtils.isBlank(model.getAddress())) { mav.setModel(BasicModel.buildBadRequestModel("地址不能为空")); @@ -740,40 +738,317 @@ public class AddrSvcController { String address = model.getAddress(); params.put("address", address); String type = StringUtils.isNotBlank(model.getType()) ? model.getType() : null; - String villageType = "2".equals(model.getType()) ? "对公" : "对私"; params.put("type", type); - params.put("showFullValue", "2"); - Pager pager = new Pager(1, 1); - List villageIdentifyList = villageIdentifyService.findByCityAndAddress(villageType, model.getCity(), model.getAddress(), pager); - VillageIdentify villageResult = CollectionUtils.isNotEmpty(villageIdentifyList) ? villageIdentifyList.get(0) : null; - if (villageResult != null && StringUtils.isNotBlank(villageResult.getVerifyFlag())) { - Map resultMap = new HashMap(); - resultMap.put("province", villageResult.getProvince()); - resultMap.put("city", villageResult.getCity1()); - resultMap.put("district", villageResult.getDistrict()); - resultMap.put("town", villageResult.getTown()); - resultMap.put("committee", villageResult.getCommittee()); - resultMap.put("provinceCode", villageResult.getCityCode()); - resultMap.put("cityCode", villageResult.getCityCode()); - resultMap.put("districtCode", villageResult.getDistrictCode()); - resultMap.put("townCode", villageResult.getTownCode()); - resultMap.put("committeeCode", villageResult.getCommitteeCode()); - resultMap.put("typeCode", villageResult.getTypeCode()); - resultMap.put("typeName", villageResult.getTypeName()); - resultMap.put("verifyFlag", villageResult.getVerifyFlag()); - resultMap.put("addrVerify", villageResult.getAddrVerify()); - resultMap.put("countyLevelCity", villageResult.getCountyLevelCity()); - resultMap.put("administrativeTowns", villageResult.getAdministrativeTowns()); - resultMap.put("countyGov", villageResult.getCountyGov()); - resultMap.put("devDistrict", villageResult.getDevDistrict()); - resultMap.put("devDistrictName", villageResult.getDevDistrictName()); - resultMap.put("devLevel", villageResult.getDevLevel()); - resultMap.put("addrArea", villageResult.getAddrArea()); - BasicModel basicModel = new BasicModel(200, "OK"); - basicModel.setResult(resultMap); - mav.setModel(basicModel); - } else { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/shzxVillageIdentify", params, "UTF-8"); + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/shzxVillageIdentify", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + if (json != null) { + if (json.containsKey("result")) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + HashMap map = new HashMap(); + //我们的结果 + JSONObject result = json.getJSONObject("result"); + if (result.containsKey("addrArea")) { + map.put("addrArea", result.getString("addrArea")); + } + if (result.containsKey("devDistrictName")) { + map.put("devDistrictName", result.getString("devDistrictName")); + } + if (result.containsKey("countyGovTown")) { + map.put("countyGovTown", result.getString("countyGovTown")); + } + if (result.containsKey("town")) { + map.put("town", result.getString("town")); + } + basicModel.setResult(map); + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + } + return mav; + } + + /** + * 涉农识别-新规则-基础版本 + * + * @param model + * @return + */ + public Object villageIdentifyAction(AddressModel 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() : null); + String address = model.getAddress(); + params.put("address", address); + String type = StringUtils.isNotBlank(model.getType()) ? model.getType() : null; + String villageType = "2".equals(model.getType()) ? "对公" : "对私"; + params.put("type", type); + params.put("showFullValue", "2"); + Pager pager = new Pager(1, 1); + List villageIdentifyList = villageIdentifyService.findByCityAndAddress(villageType, model.getCity(), model.getAddress(), pager); + VillageIdentify villageResult = CollectionUtils.isNotEmpty(villageIdentifyList) ? villageIdentifyList.get(0) : null; + if (villageResult != null && StringUtils.isNotBlank(villageResult.getVerifyFlag())) { + Map resultMap = new HashMap(); + resultMap.put("province", villageResult.getProvince()); + resultMap.put("city", villageResult.getCity1()); + resultMap.put("district", villageResult.getDistrict()); + resultMap.put("town", villageResult.getTown()); + resultMap.put("committee", villageResult.getCommittee()); + resultMap.put("provinceCode", villageResult.getCityCode()); + resultMap.put("cityCode", villageResult.getCityCode()); + resultMap.put("districtCode", villageResult.getDistrictCode()); + resultMap.put("townCode", villageResult.getTownCode()); + resultMap.put("committeeCode", villageResult.getCommitteeCode()); + resultMap.put("typeCode", villageResult.getTypeCode()); + resultMap.put("typeName", villageResult.getTypeName()); + resultMap.put("verifyFlag", villageResult.getVerifyFlag()); + resultMap.put("addrVerify", villageResult.getAddrVerify()); + resultMap.put("countyLevelCity", villageResult.getCountyLevelCity()); + resultMap.put("administrativeTowns", villageResult.getAdministrativeTowns()); + resultMap.put("countyGov", villageResult.getCountyGov()); + resultMap.put("devDistrict", villageResult.getDevDistrict()); + resultMap.put("devDistrictName", villageResult.getDevDistrictName()); + resultMap.put("devLevel", villageResult.getDevLevel()); + resultMap.put("addrArea", villageResult.getAddrArea()); + BasicModel basicModel = new BasicModel(200, "OK"); + basicModel.setResult(resultMap); + mav.setModel(basicModel); + } else { // params.put("showTestValue", "2"); + Integer radius = model.getRadius(); + params.put("radius", (radius != null && radius != 0) ? radius.toString() : null); + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8"); + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + + if (json != null) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + if (json.containsKey("result")) { + //我们的结果 + JSONObject result = json.getJSONObject("result"); + //我们省级及以上有开发区,直接用我们的结果 + if (result.containsKey("devDistrictName")) { + basicModel.setResult(result); + } else if (!"2".equals(type)) { // 对私的不用齐梁 + basicModel.setResult(result); + } else { + try { + //如果是江苏省或者浙江省 调用齐梁的结果 + if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) { + + //结果比较,如果涉农结果不一致 + //调用齐梁 type :1 对公 0 对私 + //我们 type :1 对私 2 对共 + String qltype = "2".equals(type) ? "1" : "0"; + Map map = senRequest(address, qltype); + // 涉农结果不一样 + if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) { + // 齐梁县政府但是涉农为农,取我们的结果 扬中市三茅街道中华村永固河路1号 + if ("是".equals(map.get("countyGov")) && "农".equals(map.get("verifyFlag"))) { + basicModel.setResult(result); + mav.setModel(basicModel); + return mav; + } + //有市辖建制镇, 或者城市不一样 用我们 + if (result.containsKey("city")) { + if ("是".equals(result.get("administrativeTowns")) || (!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) { + basicModel.setResult(result); + } else { + map.put("addrVerify", "地址有效"); + map.put("addrArea", addrArea(map, type)); + map.put("countyLevelCity", countyLevelCity(map)); + map.put("typeName", areaMap.get(map.get("typeCode"))); + basicModel.setResult(map); + } + } else { + map.put("addrVerify", "地址有效"); + map.put("addrArea", addrArea(map, type)); + map.put("countyLevelCity", countyLevelCity(map)); + map.put("typeName", areaMap.get(map.get("typeCode"))); + basicModel.setResult(map); + } + + } else { + basicModel.setResult(result); + } + + } else { + basicModel.setResult(result); + + } + + } catch (Exception e) { + e.printStackTrace(); + basicModel.setResult(result); + } + + } + + } + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + } + return mav; + } + + private static Map senRequest (String address, String type) throws IOException { + String targetURL = "http://146.56.217.44:9010/uams/farmer/all/v3/sign"; + String proxyHost = "tunnel2.qg.net"; + int proxyPort = 14186; + final String proxyUsername = "113BBC06"; + final String proxyPassword = "3B2FBD05B0AF"; + String jsonData = "{\"address\":\"" + address + "\",\"type\":\"" + type + "\"}"; + String authKey = proxyUsername; + String password = proxyPassword; + String auth = authKey + ":" + password; + String authHeader = "Basic " + new BASE64Encoder().encode(auth.getBytes(Charset.forName("UTF-8"))); + + HttpHost proxy = new HttpHost(proxyHost, proxyPort); + DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); + CloseableHttpClient httpClient = HttpClients.custom() + .setRoutePlanner(routePlanner) + .build(); + HttpPost httpPost = new HttpPost(targetURL); + Authenticator.setDefault(new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray()); + } + }); + httpPost.setHeader("Content-Type", "application/json"); + httpPost.setHeader("Accept", "*/*"); + httpPost.setHeader("Host", "146.56.217.44:9010"); + httpPost.setHeader("Proxy-Authorization", authHeader); + StringEntity stringEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON); + httpPost.setEntity(stringEntity); + + CloseableHttpResponse httpResponse = null; + int retryCount = 2; // 设置重试次数 + int retryDelay = 10; // 设置重试延迟时间(毫秒) + boolean success = false; + for (int i = 0; i < retryCount; i++) { + try { + httpResponse = httpClient.execute(httpPost); + success = true; + break; + } catch (IOException e) { + System.err.println("代理请求失败,进行重试..."); + try { + Thread.sleep(retryDelay); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } + } + + if (success) { + HttpEntity responseEntity = httpResponse.getEntity(); + String responseString = EntityUtils.toString(responseEntity); + + // 使用 Gson 解析 JSON 字符串 + Gson gson = new Gson(); + JsonObject jsonObject = gson.fromJson(responseString, JsonObject.class); + + + // 创建 Map 存储各个值 + Map dataMap = new HashMap(); + + // 获取各个值并放入 Map +// dataMap.put("code", jsonObject.get("code").getAsString()); +// dataMap.put("msg", jsonObject.get("msg").getAsString()); + JsonElement dataElement = jsonObject.get("data"); + if (dataElement != null && !dataElement.isJsonNull() && dataElement.isJsonObject()) { + JsonObject data = dataElement.getAsJsonObject(); + // 在这里继续处理 data 对象 + + if (data != null && !data.isJsonNull()) { + +// dataMap.put("version", data.get("version").getAsString()); + dataMap.put("province", data.get("province").getAsString()); + dataMap.put("city", data.get("city").getAsString()); + dataMap.put("district", data.get("district").getAsString()); + dataMap.put("town", data.get("town").getAsString()); + dataMap.put("committee", data.get("village").getAsString()); + dataMap.put("provinceCode", data.get("provinceCode").getAsString()); + dataMap.put("cityCode", data.get("cityCode").getAsString()); + dataMap.put("districtCode", data.get("districtCode").getAsString()); + dataMap.put("townCode", data.get("townCode").getAsString()); + dataMap.put("committeeCode", data.get("villageCode").getAsString()); + dataMap.put("typeCode", data.get("areaCode").getAsString()); + dataMap.put("verifyFlag", "0".equals(data.get("farmer").getAsString()) ? "非农" : "农"); + dataMap.put("countyGov", "0".equals(data.get("isGovt").getAsString()) ? "否" : "是"); +// dataMap.put("govtAddr", data.get("govtAddr").isJsonNull() ? null : data.get("govtAddr").getAsString()); // 对于可能为 null 的值,需要判断是否为空 + JsonArray indusParkList = data.get("indusParkList").isJsonNull() ? null : data.get("indusParkList").getAsJsonArray(); + + if (indusParkList != null) { + JsonObject jsonObject1 = gson.fromJson(indusParkList.get(0), JsonObject.class); + dataMap.put("devDistrictName", jsonObject1.get("indusParkName").getAsString()); + dataMap.put("devLevel", jsonObject1.get("indusParkLevel").getAsString()); + dataMap.put("devDistrict", "是"); + } + } + } + + httpResponse.close(); + return dataMap; + } else { + System.err.println("重试次数已用完,请求失败。"); + } + + httpClient.close(); + return null; + } + + /** + * 涉农识别-新规则-标准版 + * + * @param model + * @return + */ + public Object villageIdentifyStandardAction (AddressModel 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() : null); + params.put("address", model.getAddress()); + params.put("type", StringUtils.isNotBlank(model.getType()) ? model.getType() : null); + params.put("showFullValue", StringUtils.isNotBlank(model.getShowFullValue()) ? model.getShowFullValue() : null); + params.put("showTestValue", StringUtils.isNotBlank(model.getShowTestValue()) ? model.getShowTestValue() : null); Integer radius = model.getRadius(); params.put("radius", (radius != null && radius != 0) ? radius.toString() : null); try { @@ -786,577 +1061,361 @@ public class AddrSvcController { } } + if (json != null) { + int code = json.getInt("msgCode"); + 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; + } + + + /** + * 地址联想-PRO + * + * @param model + * @return + */ + @Deprecated + public Object addressAssociationAction (AddressModel model){ + + RestfulModelAndView mav = new RestfulModelAndView(); + if (StringUtils.isBlank(model.getKeywords()) && (StringUtils.isBlank(model.getLat()) && StringUtils.isBlank(model.getLng()))) { + 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() : null); + params.put("district", StringUtils.isNotBlank(model.getDistrict()) ? model.getDistrict() : null); + params.put("keywords", StringUtils.isNotBlank(model.getKeywords()) ? model.getKeywords() : null); + if (StringUtils.isNotBlank(model.getLng()) && StringUtils.isNotBlank(model.getLat())) { + params.put("lat", model.getLat()); + params.put("lng", model.getLng()); + } + Integer radius = model.getRadius(); + params.put("radius", (radius != null && radius != 0) ? radius.toString() : null); + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/addressAssociation", params, "UTF-8"); + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/addressAssociation", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); + } + } if (json != null) { int code = json.getInt("msgCode"); String msg = json.getString("msg"); BasicModel basicModel = new BasicModel(code, msg); if (json.containsKey("result")) { - //我们的结果 - JSONObject result = json.getJSONObject("result"); - //我们省级及以上有开发区,直接用我们的结果 - if (result.containsKey("devDistrictName")) { - basicModel.setResult(result); - } else if (!"2".equals(type)) { // 对私的不用齐梁 - basicModel.setResult(result); - } else { - try { - //如果是江苏省或者浙江省 调用齐梁的结果 - if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) { - - //结果比较,如果涉农结果不一致 - //调用齐梁 type :1 对公 0 对私 - //我们 type :1 对私 2 对共 - String qltype = "2".equals(type) ? "1" : "0"; - Map map = senRequest(address, qltype); - // 涉农结果不一样 - if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) { - // 齐梁县政府但是涉农为农,取我们的结果 扬中市三茅街道中华村永固河路1号 - if ("是".equals(map.get("countyGov")) && "农".equals(map.get("verifyFlag"))) { - basicModel.setResult(result); - mav.setModel(basicModel); - return mav; - } - //有市辖建制镇, 或者城市不一样 用我们 - if (result.containsKey("city")) { - if ("是".equals(result.get("administrativeTowns")) || (!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) { - basicModel.setResult(result); - } else { - map.put("addrVerify", "地址有效"); - map.put("addrArea", addrArea(map, type)); - map.put("countyLevelCity", countyLevelCity(map)); - map.put("typeName", areaMap.get(map.get("typeCode"))); - basicModel.setResult(map); - } - } else { - map.put("addrVerify", "地址有效"); - map.put("addrArea", addrArea(map, type)); - map.put("countyLevelCity", countyLevelCity(map)); - map.put("typeName", areaMap.get(map.get("typeCode"))); - basicModel.setResult(map); - } - - } else { - basicModel.setResult(result); - } - - } else { - basicModel.setResult(result); - - } - - } catch (Exception e) { - e.printStackTrace(); - basicModel.setResult(result); - } - - } - + basicModel.setResult(json.get("result")); } mav.setModel(basicModel); } else { mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); } - } - return mav; - } - - private static Map senRequest(String address, String type) throws IOException { - String targetURL = "http://146.56.217.44:9010/uams/farmer/all/v3/sign"; - String proxyHost = "tunnel2.qg.net"; - int proxyPort = 14186; - final String proxyUsername = "113BBC06"; - final String proxyPassword = "3B2FBD05B0AF"; - String jsonData = "{\"address\":\"" + address + "\",\"type\":\"" + type + "\"}"; - String authKey = proxyUsername; - String password = proxyPassword; - String auth = authKey + ":" + password; - String authHeader = "Basic " + new BASE64Encoder().encode(auth.getBytes(Charset.forName("UTF-8"))); - - HttpHost proxy = new HttpHost(proxyHost, proxyPort); - DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); - CloseableHttpClient httpClient = HttpClients.custom() - .setRoutePlanner(routePlanner) - .build(); - HttpPost httpPost = new HttpPost(targetURL); - Authenticator.setDefault(new Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray()); - } - }); - httpPost.setHeader("Content-Type", "application/json"); - httpPost.setHeader("Accept", "*/*"); - httpPost.setHeader("Host", "146.56.217.44:9010"); - httpPost.setHeader("Proxy-Authorization", authHeader); - StringEntity stringEntity = new StringEntity(jsonData, ContentType.APPLICATION_JSON); - httpPost.setEntity(stringEntity); - - CloseableHttpResponse httpResponse = null; - int retryCount = 2; // 设置重试次数 - int retryDelay = 10; // 设置重试延迟时间(毫秒) - boolean success = false; - for (int i = 0; i < retryCount; i++) { - try { - httpResponse = httpClient.execute(httpPost); - success = true; - break; - } catch (IOException e) { - System.err.println("代理请求失败,进行重试..."); - try { - Thread.sleep(retryDelay); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } - } - - if (success) { - HttpEntity responseEntity = httpResponse.getEntity(); - String responseString = EntityUtils.toString(responseEntity); - - // 使用 Gson 解析 JSON 字符串 - Gson gson = new Gson(); - JsonObject jsonObject = gson.fromJson(responseString, JsonObject.class); - - - // 创建 Map 存储各个值 - Map dataMap = new HashMap(); - - // 获取各个值并放入 Map -// dataMap.put("code", jsonObject.get("code").getAsString()); -// dataMap.put("msg", jsonObject.get("msg").getAsString()); - JsonElement dataElement = jsonObject.get("data"); - if (dataElement != null && !dataElement.isJsonNull() && dataElement.isJsonObject()) { - JsonObject data = dataElement.getAsJsonObject(); - // 在这里继续处理 data 对象 - - if (data != null && !data.isJsonNull()) { - -// dataMap.put("version", data.get("version").getAsString()); - dataMap.put("province", data.get("province").getAsString()); - dataMap.put("city", data.get("city").getAsString()); - dataMap.put("district", data.get("district").getAsString()); - dataMap.put("town", data.get("town").getAsString()); - dataMap.put("committee", data.get("village").getAsString()); - dataMap.put("provinceCode", data.get("provinceCode").getAsString()); - dataMap.put("cityCode", data.get("cityCode").getAsString()); - dataMap.put("districtCode", data.get("districtCode").getAsString()); - dataMap.put("townCode", data.get("townCode").getAsString()); - dataMap.put("committeeCode", data.get("villageCode").getAsString()); - dataMap.put("typeCode", data.get("areaCode").getAsString()); - dataMap.put("verifyFlag", "0".equals(data.get("farmer").getAsString()) ? "非农" : "农"); - dataMap.put("countyGov", "0".equals(data.get("isGovt").getAsString()) ? "否" : "是"); -// dataMap.put("govtAddr", data.get("govtAddr").isJsonNull() ? null : data.get("govtAddr").getAsString()); // 对于可能为 null 的值,需要判断是否为空 - JsonArray indusParkList = data.get("indusParkList").isJsonNull() ? null : data.get("indusParkList").getAsJsonArray(); - - if (indusParkList != null) { - JsonObject jsonObject1 = gson.fromJson(indusParkList.get(0), JsonObject.class); - dataMap.put("devDistrictName", jsonObject1.get("indusParkName").getAsString()); - dataMap.put("devLevel", jsonObject1.get("indusParkLevel").getAsString()); - dataMap.put("devDistrict", "是"); - } - } - } - - httpResponse.close(); - return dataMap; - } else { - System.err.println("重试次数已用完,请求失败。"); - } - - httpClient.close(); - return null; - } - - /** - * 涉农识别-新规则-标准版 - * - * @param model - * @return - */ - public Object villageIdentifyStandardAction(AddressModel 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() : null); - params.put("address", model.getAddress()); - params.put("type", StringUtils.isNotBlank(model.getType()) ? model.getType() : null); - params.put("showFullValue", StringUtils.isNotBlank(model.getShowFullValue()) ? model.getShowFullValue() : null); - params.put("showTestValue", StringUtils.isNotBlank(model.getShowTestValue()) ? model.getShowTestValue() : null); - Integer radius = model.getRadius(); - params.put("radius", (radius != null && radius != 0) ? radius.toString() : null); - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (json != null) { - int code = json.getInt("msgCode"); - 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; - } - - - /** - * 地址联想-PRO - * - * @param model - * @return - */ - @Deprecated - public Object addressAssociationAction(AddressModel model) { - - RestfulModelAndView mav = new RestfulModelAndView(); - if (StringUtils.isBlank(model.getKeywords()) && (StringUtils.isBlank(model.getLat()) && StringUtils.isBlank(model.getLng()))) { - 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() : null); - params.put("district", StringUtils.isNotBlank(model.getDistrict()) ? model.getDistrict() : null); - params.put("keywords", StringUtils.isNotBlank(model.getKeywords()) ? model.getKeywords() : null); - if (StringUtils.isNotBlank(model.getLng()) && StringUtils.isNotBlank(model.getLat())) { - params.put("lat", model.getLat()); - params.put("lng", model.getLng()); - } - Integer radius = model.getRadius(); - params.put("radius", (radius != null && radius != 0) ? radius.toString() : null); - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/addressAssociation", params, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/addressAssociation", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (json != null) { - int code = json.getInt("msgCode"); - 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 listCityAction(AddressModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - HttpRequest request = new HttpRequest(); - JSONObject json = null; - Map params = new HashMap(); - params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listCity", params, "UTF-8"); - } catch (Exception e) { + /** + * 市级行政区划查询接口 + * + * @param model + * @return + */ + public Object listCityAction (AddressModel model){ + RestfulModelAndView mav = new RestfulModelAndView(); + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listCity", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (json != null) { - int code = json.getInt("msgCode"); - String msg = json.getString("msg"); - BasicModel basicModel = new BasicModel(code, msg); - List> list = new ArrayList>(); - if (json.containsKey("result")) { - JSONArray jsonArray = json.getJSONArray("result"); - if (jsonArray != null) { - for (Object o : jsonArray) { - JSONObject result = (JSONObject) o; - HashMap map = new HashMap(); - if (result.containsKey("id")) { - map.put("id", result.getString("id")); - } - if (result.containsKey("province")) { - map.put("province", result.getString("province")); - } - if (result.containsKey("tjjProvinceCode")) { - map.put("provinceCode", result.getString("tjjProvinceCode")); - } - if (result.containsKey("city")) { - map.put("city", result.getString("city")); - } - if (result.containsKey("tjjCityCode")) { - map.put("cityCode", result.getString("tjjCityCode")); - } - list.add(map); - } + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listCity", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); } } - basicModel.setResult(list); - mav.setModel(basicModel); - } else { - mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); - } - return mav; - } - /** - * 省级行政区划查询接口 - * - * @param model - * @return - */ - public Object listProvinceAction(AddressModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - HttpRequest request = new HttpRequest(); - JSONObject json = null; - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listProvince", null, "UTF-8"); - } catch (Exception e) { + if (json != null) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + List> list = new ArrayList>(); + if (json.containsKey("result")) { + JSONArray jsonArray = json.getJSONArray("result"); + if (jsonArray != null) { + for (Object o : jsonArray) { + JSONObject result = (JSONObject) o; + HashMap map = new HashMap(); + if (result.containsKey("id")) { + map.put("id", result.getString("id")); + } + if (result.containsKey("province")) { + map.put("province", result.getString("province")); + } + if (result.containsKey("tjjProvinceCode")) { + map.put("provinceCode", result.getString("tjjProvinceCode")); + } + if (result.containsKey("city")) { + map.put("city", result.getString("city")); + } + if (result.containsKey("tjjCityCode")) { + map.put("cityCode", result.getString("tjjCityCode")); + } + list.add(map); + } + } + } + basicModel.setResult(list); + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + + /** + * 省级行政区划查询接口 + * + * @param model + * @return + */ + public Object listProvinceAction (AddressModel model){ + RestfulModelAndView mav = new RestfulModelAndView(); + HttpRequest request = new HttpRequest(); + JSONObject json = null; try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listProvince", null, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (json != null) { - int code = json.getInt("msgCode"); - String msg = json.getString("msg"); - BasicModel basicModel = new BasicModel(code, msg); - List> list = new ArrayList>(); - if (json.containsKey("result")) { - JSONArray jsonArray = json.getJSONArray("result"); - if (jsonArray != null) { - for (Object o : jsonArray) { - JSONObject result = (JSONObject) o; - HashMap map = new HashMap(); - if (result.containsKey("id")) { - map.put("id", result.getString("id")); - } - if (result.containsKey("province")) { - map.put("province", result.getString("province")); - } - if (result.containsKey("tjjProvinceCode")) { - map.put("provinceCode", result.getString("tjjProvinceCode")); - } - list.add(map); - } + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listProvince", null, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); } } - basicModel.setResult(list); - mav.setModel(basicModel); - } else { - mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); - } - return mav; - } - /** - * 区域级行政区划查询接口 - * - * @param model - * @return - */ - public Object listDistrictAction(AddressModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - HttpRequest request = new HttpRequest(); - JSONObject json = null; - Map params = new HashMap(); - params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); - params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null); - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listDistrict", params, "UTF-8"); - } catch (Exception e) { + if (json != null) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + List> list = new ArrayList>(); + if (json.containsKey("result")) { + JSONArray jsonArray = json.getJSONArray("result"); + if (jsonArray != null) { + for (Object o : jsonArray) { + JSONObject result = (JSONObject) o; + HashMap map = new HashMap(); + if (result.containsKey("id")) { + map.put("id", result.getString("id")); + } + if (result.containsKey("province")) { + map.put("province", result.getString("province")); + } + if (result.containsKey("tjjProvinceCode")) { + map.put("provinceCode", result.getString("tjjProvinceCode")); + } + list.add(map); + } + } + } + basicModel.setResult(list); + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + + /** + * 区域级行政区划查询接口 + * + * @param model + * @return + */ + public Object listDistrictAction (AddressModel model){ + RestfulModelAndView mav = new RestfulModelAndView(); + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null); try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listDistrict", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (json != null) { - int code = json.getInt("msgCode"); - String msg = json.getString("msg"); - BasicModel basicModel = new BasicModel(code, msg); - List> list = new ArrayList>(); - if (json.containsKey("result")) { - JSONArray jsonArray = json.getJSONArray("result"); - if (jsonArray != null) { - for (Object o : jsonArray) { - JSONObject result = (JSONObject) o; - HashMap map = new HashMap(); - if (result.containsKey("id")) { - map.put("id", result.getString("id")); - } - if (result.containsKey("province")) { - map.put("province", result.getString("province")); - } - if (result.containsKey("tjjProvinceCode")) { - map.put("provinceCode", result.getString("tjjProvinceCode")); - } - if (result.containsKey("city")) { - map.put("city", result.getString("city")); - } - if (result.containsKey("tjjCityCode")) { - map.put("cityCode", result.getString("tjjCityCode")); - } - if (result.containsKey("district")) { - map.put("district", result.getString("district")); - } - if (result.containsKey("tjjDistrictCode")) { - map.put("districtCode", result.getString("tjjDistrictCode")); - } - list.add(map); - } + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listDistrict", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); } } - basicModel.setResult(list); - mav.setModel(basicModel); - } else { - mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); - } - return mav; - } - public Object listTownshipAction(AddressModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - HttpRequest request = new HttpRequest(); - JSONObject json = null; - Map params = new HashMap(); - params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); - params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null); - params.put("district", StringUtils.isNotBlank(model.getDistrict()) ? model.getDistrict() : null); - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listTownship", params, "UTF-8"); - } catch (Exception e) { + if (json != null) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + List> list = new ArrayList>(); + if (json.containsKey("result")) { + JSONArray jsonArray = json.getJSONArray("result"); + if (jsonArray != null) { + for (Object o : jsonArray) { + JSONObject result = (JSONObject) o; + HashMap map = new HashMap(); + if (result.containsKey("id")) { + map.put("id", result.getString("id")); + } + if (result.containsKey("province")) { + map.put("province", result.getString("province")); + } + if (result.containsKey("tjjProvinceCode")) { + map.put("provinceCode", result.getString("tjjProvinceCode")); + } + if (result.containsKey("city")) { + map.put("city", result.getString("city")); + } + if (result.containsKey("tjjCityCode")) { + map.put("cityCode", result.getString("tjjCityCode")); + } + if (result.containsKey("district")) { + map.put("district", result.getString("district")); + } + if (result.containsKey("tjjDistrictCode")) { + map.put("districtCode", result.getString("tjjDistrictCode")); + } + list.add(map); + } + } + } + basicModel.setResult(list); + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + + public Object listTownshipAction (AddressModel model){ + RestfulModelAndView mav = new RestfulModelAndView(); + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null); + params.put("district", StringUtils.isNotBlank(model.getDistrict()) ? model.getDistrict() : null); try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listTownship", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - if (json != null) { - int code = json.getInt("msgCode"); - String msg = json.getString("msg"); - BasicModel basicModel = new BasicModel(code, msg); - List> list = new ArrayList>(); - if (json.containsKey("result")) { - JSONArray jsonArray = json.getJSONArray("result"); - if (jsonArray != null) { - for (Object o : jsonArray) { - JSONObject result = (JSONObject) o; - HashMap map = new HashMap(); - if (result.containsKey("id")) { - map.put("id", result.getString("id")); - } - if (result.containsKey("province")) { - map.put("province", result.getString("province")); - } - if (result.containsKey("tjjProvinceCode")) { - map.put("provinceCode", result.getString("tjjProvinceCode")); - } - if (result.containsKey("city")) { - map.put("city", result.getString("city")); - } - if (result.containsKey("tjjCityCode")) { - map.put("cityCode", result.getString("tjjCityCode")); - } - if (result.containsKey("district")) { - map.put("district", result.getString("district")); - } - if (result.containsKey("tjjDistrictCode")) { - map.put("districtCode", result.getString("tjjDistrictCode")); - } - if (result.containsKey("street")) { - map.put("street", result.getString("street")); - } - if (result.containsKey("tjjStreetCode")) { - map.put("streetCode", result.getString("tjjStreetCode")); - } - list.add(map); - } + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listTownship", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); } } - basicModel.setResult(list); - mav.setModel(basicModel); - } else { - mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); - } - return mav; - } - public Object levelAction(AddressModel model) { - RestfulModelAndView mav = new RestfulModelAndView(); - HttpRequest request = new HttpRequest(); - JSONObject json = null; - Map params = new HashMap(); - params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); - params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null); - params.put("address", StringUtils.isNotBlank(model.getAddress()) ? model.getAddress() : null); - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/addrLevel", params, "UTF-8"); - } catch (Exception e) { + if (json != null) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + List> list = new ArrayList>(); + if (json.containsKey("result")) { + JSONArray jsonArray = json.getJSONArray("result"); + if (jsonArray != null) { + for (Object o : jsonArray) { + JSONObject result = (JSONObject) o; + HashMap map = new HashMap(); + if (result.containsKey("id")) { + map.put("id", result.getString("id")); + } + if (result.containsKey("province")) { + map.put("province", result.getString("province")); + } + if (result.containsKey("tjjProvinceCode")) { + map.put("provinceCode", result.getString("tjjProvinceCode")); + } + if (result.containsKey("city")) { + map.put("city", result.getString("city")); + } + if (result.containsKey("tjjCityCode")) { + map.put("cityCode", result.getString("tjjCityCode")); + } + if (result.containsKey("district")) { + map.put("district", result.getString("district")); + } + if (result.containsKey("tjjDistrictCode")) { + map.put("districtCode", result.getString("tjjDistrictCode")); + } + if (result.containsKey("street")) { + map.put("street", result.getString("street")); + } + if (result.containsKey("tjjStreetCode")) { + map.put("streetCode", result.getString("tjjStreetCode")); + } + list.add(map); + } + } + } + basicModel.setResult(list); + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; + } + + public Object levelAction (AddressModel model){ + RestfulModelAndView mav = new RestfulModelAndView(); + HttpRequest request = new HttpRequest(); + JSONObject json = null; + Map params = new HashMap(); + params.put("province", StringUtils.isNotBlank(model.getProvince()) ? model.getProvince() : null); + params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null); + params.put("address", StringUtils.isNotBlank(model.getAddress()) ? model.getAddress() : null); try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/addrLevel", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); + } catch (Exception e) { + try { + json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/addrLevel", params, "UTF-8"); + } catch (Exception ex) { + ex.printStackTrace(); + } } + + if (json != null) { + int code = json.getInt("msgCode"); + String msg = json.getString("msg"); + BasicModel basicModel = new BasicModel(code, msg); + if (json.containsKey("result")) { + JSONObject result = json.getJSONObject("result"); + basicModel.setResult(result); + } + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + return mav; } - if (json != null) { - int code = json.getInt("msgCode"); - String msg = json.getString("msg"); - BasicModel basicModel = new BasicModel(code, msg); - if (json.containsKey("result")) { - JSONObject result = json.getJSONObject("result"); - basicModel.setResult(result); - } - mav.setModel(basicModel); - } else { - mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + public void setDistrictStatService (DistrictStatService districtStatService){ + this.districtStatService = districtStatService; } - return mav; - } - public void setDistrictStatService(DistrictStatService districtStatService) { - this.districtStatService = districtStatService; - } + public void setDistrictService (DistrictService districtService){ + this.districtService = districtService; + } - public void setDistrictService(DistrictService districtService) { - this.districtService = districtService; + public void setVillageIdentifyService (VillageIdentifyService villageIdentifyService){ + this.villageIdentifyService = villageIdentifyService; + } } - - public void setVillageIdentifyService(VillageIdentifyService villageIdentifyService) { - this.villageIdentifyService = villageIdentifyService; - } -}