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


}