IceDistrictClient.java 3.1 KB
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;
    }


}