IceDistrictClient.java
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.glsx.ice.iceClient;
import com.glsx.config.SystemProperty;
import com.glsx.ice.DISTRICT.IDistrictFinderPrx;
import com.glsx.ice.DISTRICT.IDistrictFinderPrxHelper;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class IceDistrictClient {
static String url = SystemProperty.getProperty("ice.districUrl");
static Ice.Communicator ic = Ice.Util.initialize();
static Ice.ObjectPrx base = ic.stringToProxy(url).ice_timeout(Integer.parseInt(SystemProperty.getProperty("ice.connectTimeout")));
static IDistrictFinderPrx prx = IDistrictFinderPrxHelper.checkedCast(base);
/**
* 通过经纬度查询所属行政区域
*
* @return
*/
public static Map<String, Object> getDistInfoByPos(float lng, float lat) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
Ice.IntHolder distCode = new Ice.IntHolder();
Ice.StringHolder strDistName = new Ice.StringHolder();
boolean res = prx.get_distinfo_by_pos(lng, lat, distCode, strDistName);
Map<String,Object> infoDto = null;
if (res) {
infoDto = new HashMap<>();
//行政编码
infoDto.put("dist_code",distCode.value);
//行政区域名称
infoDto.put("dist_name",strDistName.value);
return infoDto;
}
} catch (Ice.LocalException e) {
log.error("===getDistInfoByPos_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getDistInfoByPos_EXCEP:" + e.getMessage(), e);
}
return null;
}
/**
* 通过经纬度查询所属省份城市区域
*
* @return
*/
public static Map<String, Object> getDistDetailByPos(float lng, float lat) {
try {
if (prx == null) {
throw new Exception("Invalid proxy");
}
Ice.StringHolder strProvName = new Ice.StringHolder();
Ice.StringHolder strCityName = new Ice.StringHolder();
Ice.StringHolder strCountyName = new Ice.StringHolder();
boolean res = prx.get_distdetail_by_pos(lng, lat, strProvName, strCityName, strCountyName);
Map<String,Object> detilDto = null;
if (res) {
String provName = strProvName.value;
String cityName = strCityName.value;
String countyName = strCountyName.value;
detilDto = new HashMap<>();
//所属省份
detilDto.put("prov_name",provName);
//所属城市
detilDto.put("city_name",cityName);
//所属县城
detilDto.put("county_name",countyName);
return detilDto;
}
} catch (Ice.LocalException e) {
log.error("===getDistDetailByPos_ICE_EXCEP:" + e.getMessage(), e);
} catch (Exception e) {
log.error("===getDistDetailByPos_EXCEP:" + e.getMessage(), e);
}
return null;
}
}