国信所需接口封装

This commit is contained in:
majintao
2024-08-30 15:06:33 +08:00
parent 47faa451d0
commit a9b8e954ca
2 changed files with 290 additions and 32 deletions
@@ -20,6 +20,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
@@ -42,6 +43,7 @@ import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -78,14 +80,17 @@ public class AddrSvcController {
Map<String, String> params = new HashMap<String, String>();
params.put("city", model.getCity());
params.put("address", model.getAddress());
params.put("addressAssessment","true");
try {
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/structure/v2", params, "UTF-8");
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/formatNinelevel", params, "UTF-8");
if (json != null) {
int code = json.getInt("status");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) {
basicModel.setResult(CommonDtoUtils.transformV(StructureDto.class, json.get("result")));
JSONObject result = json.getJSONObject("result");
result.remove("formatAddress");
basicModel.setResult(result);
}
mav.setModel(basicModel);
} else {
@@ -118,13 +123,27 @@ public class AddrSvcController {
params.put("city", model.getCity());
params.put("address", model.getAddress());
try {
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/fiveDivisionStructure/v2", params, "UTF-8");
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8");
if (json != null) {
int code = json.getInt("status");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) {
basicModel.setResult(CommonDtoUtils.transformV(DistrictIdentifyDto.class, json.get("result")));
DistrictIdentifyDto districtIdentifyDto = CommonDtoUtils.transformV(DistrictIdentifyDto.class, json.get("result"));
JSONObject result = json.getJSONObject("result");
if (result.containsKey("town")) {
districtIdentifyDto.setTownship(result.getString("town"));
}
if (result.containsKey("townCode")) {
districtIdentifyDto.setTownshipCode(result.getString("townCode"));
}
if (result.containsKey("committee")) {
districtIdentifyDto.setCommunity(result.getString("committee"));
}
if (result.containsKey("committeeCode")) {
districtIdentifyDto.setCommunityCode(result.getString("committeeCode"));
}
basicModel.setResult(districtIdentifyDto);
}
mav.setModel(basicModel);
} else {
@@ -268,17 +287,17 @@ public class AddrSvcController {
params.put("region", model.getRegion());
params.put("keywords", model.getKeywords());
params.put("page", "0");
params.put("size", String.valueOf(model.getMax() == 0 ? 20 : (model.getMax() > 100 ? 100 : model.getMax())));
params.put("offset", String.valueOf(model.getMax() == 0 ? 10 : (model.getMax() > 100 ? 100 : model.getMax())));
try {
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/addressAssociation2", params, "UTF-8");
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/v2/addressAssociation", params, "UTF-8");
if (json != null) {
int code = json.getInt("status");
int code = json.getInt("msgCode");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) {
JSONObject result = (JSONObject.fromObject(json.get("result")));
if (result.getInt("totalElements") > 0) {
basicModel.setResult(CommonDtoUtils.transformListV(DistrictDto.class, result.getJSONArray("content")));
JSONArray jsonArray = json.getJSONArray("result");
if (jsonArray.size() > 0) {
basicModel.setResult(CommonDtoUtils.transformListV(DistrictDto.class,jsonArray));
}
}
mav.setModel(basicModel);
@@ -513,7 +532,7 @@ public class AddrSvcController {
if (map.get("city").endsWith("区")) {
return "否";
}
if (map.get("city").equals("东莞市") || map.get("city").equals("嘉峪关市") || map.get("city").equals("中山市") || map.get("city").equals("儋州市") ) {
if (map.get("city").equals("东莞市") || map.get("city").equals("嘉峪关市") || map.get("city").equals("中山市") || map.get("city").equals("儋州市")) {
return "否";
}
return "是";
@@ -526,7 +545,7 @@ public class AddrSvcController {
* @return
*/
public String addrArea(Map<String, String> map, String type) {
if (map.get("verifyFlag") == null ) {
if (map.get("verifyFlag") == null) {
return "";
}
if (map.get("verifyFlag").equals("非农")) {
@@ -675,27 +694,27 @@ public class AddrSvcController {
VillageIdentify villageResult = CollectionUtils.isNotEmpty(villageIdentifyList) ? villageIdentifyList.get(0) : null;
if (villageResult != null && StringUtils.isNotBlank(villageResult.getVerifyFlag())) {
Map<String, String> resultMap = new HashMap<String, String>();
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("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());
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);
@@ -994,6 +1013,236 @@ public class AddrSvcController {
return mav;
}
/**
* 市级行政区划查询接口
*
* @param model
* @return
*/
public Object listCityAction(AddressModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
HttpRequest request = new HttpRequest();
JSONObject json = null;
Map<String, String> params = new HashMap<String, String>();
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 ex) {
ex.printStackTrace();
}
}
if (json != null) {
int code = json.getInt("msgCode");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
if (json.containsKey("result")) {
JSONArray jsonArray = json.getJSONArray("result");
if (jsonArray != null) {
for (Object o : jsonArray) {
JSONObject result = (JSONObject) o;
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", result.getString("id"));
map.put("province", result.getString("province"));
map.put("provinceCode", result.getString("tjjProvinceCode"));
map.put("city", result.getString("city"));
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 ex) {
ex.printStackTrace();
}
}
if (json != null) {
int code = json.getInt("msgCode");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
if (json.containsKey("result")) {
JSONArray jsonArray = json.getJSONArray("result");
if (jsonArray != null) {
for (Object o : jsonArray) {
JSONObject result = (JSONObject) o;
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", result.getString("id"));
map.put("province", result.getString("province"));
map.put("provinceCode", result.getString("mzbProvinceCode"));
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<String, String> params = new HashMap<String, String>();
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 ex) {
ex.printStackTrace();
}
}
if (json != null) {
int code = json.getInt("msgCode");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
if (json.containsKey("result")) {
JSONArray jsonArray = json.getJSONArray("result");
if (jsonArray != null) {
for (Object o : jsonArray) {
JSONObject result = (JSONObject) o;
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", result.getString("id"));
map.put("province", result.getString("province"));
map.put("provinceCode", result.getString("tjjProvinceCode"));
map.put("city", result.getString("city"));
map.put("cityCode", result.getString("tjjCityCode"));
map.put("district", result.getString("district"));
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<String, String> params = new HashMap<String, String>();
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 ex) {
ex.printStackTrace();
}
}
if (json != null) {
int code = json.getInt("msgCode");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
if (json.containsKey("result")) {
JSONArray jsonArray = json.getJSONArray("result");
if (jsonArray != null) {
for (Object o : jsonArray) {
JSONObject result = (JSONObject) o;
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", result.getString("id"));
map.put("province", result.getString("province"));
map.put("provinceCode", result.getString("tjjProvinceCode"));
map.put("city", result.getString("city"));
map.put("cityCode", result.getString("tjjCityCode"));
map.put("district", result.getString("district"));
map.put("districtCode", result.getString("tjjDistrictCode"));
map.put("street", result.getString("street"));
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<String, String> params = new HashMap<String, String>();
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 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;
}
public void setDistrictStatService(DistrictStatService districtStatService) {
this.districtStatService = districtStatService;
}
@@ -7,6 +7,7 @@ public class DistrictDto {
private String region;
private String name;
private String address;
private String district;
public String getProvince() {
return province;
@@ -47,4 +48,12 @@ public class DistrictDto {
public void setAddress(String address) {
this.address = address;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
}