国信所需接口封装

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.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
@@ -42,6 +43,7 @@ import java.net.InetSocketAddress;
import java.net.PasswordAuthentication; import java.net.PasswordAuthentication;
import java.net.Proxy; import java.net.Proxy;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -78,14 +80,17 @@ public class AddrSvcController {
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
params.put("city", model.getCity()); params.put("city", model.getCity());
params.put("address", model.getAddress()); params.put("address", model.getAddress());
params.put("addressAssessment","true");
try { 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) { if (json != null) {
int code = json.getInt("status"); int code = json.getInt("status");
String msg = json.getString("msg"); String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg); BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) { 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); mav.setModel(basicModel);
} else { } else {
@@ -118,13 +123,27 @@ public class AddrSvcController {
params.put("city", model.getCity()); params.put("city", model.getCity());
params.put("address", model.getAddress()); params.put("address", model.getAddress());
try { 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) { if (json != null) {
int code = json.getInt("status"); int code = json.getInt("status");
String msg = json.getString("msg"); String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg); BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) { 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); mav.setModel(basicModel);
} else { } else {
@@ -268,17 +287,17 @@ public class AddrSvcController {
params.put("region", model.getRegion()); params.put("region", model.getRegion());
params.put("keywords", model.getKeywords()); params.put("keywords", model.getKeywords());
params.put("page", "0"); 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 { 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) { if (json != null) {
int code = json.getInt("status"); int code = json.getInt("msgCode");
String msg = json.getString("msg"); String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg); BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) { if (json.containsKey("result")) {
JSONObject result = (JSONObject.fromObject(json.get("result"))); JSONArray jsonArray = json.getJSONArray("result");
if (result.getInt("totalElements") > 0) { if (jsonArray.size() > 0) {
basicModel.setResult(CommonDtoUtils.transformListV(DistrictDto.class, result.getJSONArray("content"))); basicModel.setResult(CommonDtoUtils.transformListV(DistrictDto.class,jsonArray));
} }
} }
mav.setModel(basicModel); mav.setModel(basicModel);
@@ -994,6 +1013,236 @@ public class AddrSvcController {
return mav; 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) { public void setDistrictStatService(DistrictStatService districtStatService) {
this.districtStatService = districtStatService; this.districtStatService = districtStatService;
} }
@@ -7,6 +7,7 @@ public class DistrictDto {
private String region; private String region;
private String name; private String name;
private String address; private String address;
private String district;
public String getProvince() { public String getProvince() {
return province; return province;
@@ -47,4 +48,12 @@ public class DistrictDto {
public void setAddress(String address) { public void setAddress(String address) {
this.address = address; this.address = address;
} }
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
} }