IceDistrictClient.java
3.22 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
package com.glsx.ice.iceClient;
import com.glsx.config.SystemProperty;
import com.glsx.ice.DISTRICT.IDistrictFinderPrx;
import com.glsx.ice.DISTRICT.IDistrictFinderPrxHelper;
import com.glsx.model.DTO.DistDetilDto;
import com.glsx.model.DTO.DistInfoDto;
import lombok.extern.slf4j.Slf4j;
@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 DistInfoDto 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);
DistInfoDto infoDto = null;
if (res) {
int dist_code = distCode.value;
String dist_name = strDistName.value;
infoDto = new DistInfoDto();
infoDto.setDist_code(dist_code);
infoDto.setDist_name(dist_name);
log.info("success===getDistInfoByPos:" + distCode + "==" + strDistName);
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 DistDetilDto 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);
DistDetilDto detilDto = null;
if (res) {
String provName = strProvName.value;
String cityName = strCityName.value;
String countyName = strCountyName.value;
detilDto = new DistDetilDto();
detilDto.setProv_name(provName);
detilDto.setCity_name(cityName);
detilDto.setCounty_name(countyName);
log.info("success===getDistDetailByPos:" + provName + "==" + cityName + "==" + 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;
}
}