xufenglei
2018-01-30 24b5764532e012274759d71ed02844ad2eb901e4
src/main/java/com/moral/service/impl/AreaServiceImpl.java
@@ -41,4 +41,35 @@
        example.or().andEqualTo("cityCode",cityCode);
        return areaMapper.selectByExample(example);
    }
    /**
     * 通过地区编码获取 中文全程,例如 江苏省 苏州市 昆山市
     * @param code 可以是省 市 区 到地区编码
     * @return
     */
    @Override
    public String selectFullNameByCode(Integer code){
        String codeStr = code.toString();
        String fullName = "";
        // 此时为地区code
        if(!codeStr.endsWith("00")){
            String provinceCode = codeStr.substring(0,2)+"0000";
            Province province = provinceMapper.selectByPrimaryKey(Integer.valueOf(provinceCode));
            String cityCode = codeStr.substring(0,4)+"00";
            City city = cityMapper.selectByPrimaryKey(Integer.valueOf(cityCode));
            Area area = areaMapper.selectByPrimaryKey(code);
            fullName = province.getProvinceName()+city.getCityName()+area.getAreaName();
        }  else if(!codeStr.endsWith("0000")){
            // 此时为 地级市code
            String provinceCode = codeStr.substring(0,2)+"0000";
            Province province = provinceMapper.selectByPrimaryKey(Integer.valueOf(provinceCode));
            City city = cityMapper.selectByPrimaryKey(code);
            fullName = province.getProvinceName()+city.getCityName();
        } else {
            // 此时为 省code
            Province province = provinceMapper.selectByPrimaryKey(code);
            fullName = province.getProvinceName();
        }
        return fullName;
    }
}