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 3ed1c5b08..118cf497c 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 @@ -44,10 +44,7 @@ import java.io.IOException; import java.net.Authenticator; import java.net.PasswordAuthentication; import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 地址治理 @@ -752,9 +749,89 @@ public class AddrSvcController { int code = json.getInt("msgCode"); String msg = json.getString("msg"); BasicModel basicModel = new BasicModel(code, msg); - HashMap map = new HashMap(); + HashMap map = new LinkedHashMap(); //我们的结果 +// "province": "江苏省", +// "city": "苏州市", +// "district": "昆山市", +// "town": "玉山镇", +// "committee": "南星渎村委会", +// "provinceCode": "320000000000", +// "cityCode": "320500000000", +// "districtCode": "320583000000", +// "townCode": "320583100000", +// "committeeCode": "320583100222", +// "typeCode": "220", +// "typeName": "村庄", +// "verifyFlag": "非农", +// "addrVerify": "地址有效", +// "countyLevelCity": "是", +// "administrativeTowns": "否", +// "countyGov": "否", +// "devDistrict": "是", +// "devDistrictName": "昆山高新技术产业开发区", +// "devLevel": "国家级", +// "addrArea": "开发区", +// "countyGovTown": "昆山开发区" JSONObject result = json.getJSONObject("result"); + if (result.containsKey("province")) { + map.put("province", result.getString("province")); + } + if (result.containsKey("city")) { + map.put("city", result.getString("city")); + } + if (result.containsKey("district")) { + map.put("district", result.getString("district")); + } + if (result.containsKey("town")) { + map.put("town", result.getString("town")); + } + if (result.containsKey("committee")) { + map.put("committee", result.getString("committee")); + } + if (result.containsKey("provinceCode")) { + map.put("provinceCode", result.getString("provinceCode")); + } + if (result.containsKey("cityCode")) { + map.put("cityCode", result.getString("cityCode")); + } + if (result.containsKey("districtCode")) { + map.put("districtCode", result.getString("districtCode")); + } + if (result.containsKey("townCode")) { + map.put("townCode", result.getString("townCode")); + } + if (result.containsKey("committeeCode")) { + map.put("committeeCode", result.getString("committeeCode")); + } + if (result.containsKey("typeCode")) { + map.put("typeCode", result.getString("typeCode")); + } + if (result.containsKey("typeName")) { + map.put("typeName", result.getString("typeName")); + } + if (result.containsKey("verifyFlag")) { + map.put("verifyFlag", result.getString("verifyFlag")); + } + if (result.containsKey("addrVerify")) { + map.put("addrVerify", result.getString("addrVerify")); + } + if (result.containsKey("countyLevelCity")) { + map.put("countyLevelCity", result.getString("countyLevelCity")); + } + if (result.containsKey("administrativeTowns")) { + map.put("administrativeTowns", result.getString("administrativeTowns")); + } + if (result.containsKey("countyGov")) { + map.put("countyGov", result.getString("countyGov")); + } + if (result.containsKey("devDistrict")) { + map.put("devDistrict", result.getString("devDistrict")); + } + if (result.containsKey("devLevel")) { + map.put("devLevel", result.getString("devLevel")); + } + if (result.containsKey("addrArea")) { map.put("addrArea", result.getString("addrArea")); } @@ -764,9 +841,6 @@ public class AddrSvcController { 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 { @@ -999,276 +1073,60 @@ public class AddrSvcController { } /** - * 涉农识别-新规则-基础版本 - * - * @param model - * @return - */ - public Object villageIdentifyAction(AddressModel model){ + * 涉农识别-新规则-基础版本 + * + * @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("服务升级中...")); - } - } + RestfulModelAndView mav = new RestfulModelAndView(); + if (StringUtils.isBlank(model.getAddress())) { + mav.setModel(BasicModel.buildBadRequestModel("地址不能为空")); 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); + 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 { @@ -1281,361 +1139,577 @@ 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")); + //我们的结果 + 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; } - - /** - * 地址联想-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("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(); } + } - 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()); + 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")); } - Integer radius = model.getRadius(); - params.put("radius", (radius != null && radius != 0) ? radius.toString() : null); + 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 e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/addressAssociation", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } + } 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); + 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) { try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listCity", params, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listCity", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } + } 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); - } - } - } - 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; + 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 e) { try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listProvince", null, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listProvince", null, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } + } 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); - } - } - } - 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); + 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 e) { try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listDistrict", params, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listDistrict", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } + } 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); - } - } - } - 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); + 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 e) { try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listTownship", params, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/listTownship", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } + } 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); + 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; + 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); + 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) { try { json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/addrLevel", params, "UTF-8"); - } catch (Exception e) { - try { - json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/addrLevel", params, "UTF-8"); - } catch (Exception ex) { - ex.printStackTrace(); - } + } 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("服务升级中...")); + 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); } - return mav; - } - - public void setDistrictStatService (DistrictStatService districtStatService){ - this.districtStatService = districtStatService; - } - - public void setDistrictService (DistrictService districtService){ - this.districtService = districtService; - } - - public void setVillageIdentifyService (VillageIdentifyService villageIdentifyService){ - this.villageIdentifyService = villageIdentifyService; + mav.setModel(basicModel); + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); } + return mav; } + + public void setDistrictStatService(DistrictStatService districtStatService) { + this.districtStatService = districtStatService; + } + + public void setDistrictService(DistrictService districtService) { + this.districtService = districtService; + } + + public void setVillageIdentifyService(VillageIdentifyService villageIdentifyService) { + this.villageIdentifyService = villageIdentifyService; + } +}