package cn.net.caoyao.cpzshandset.service.tools;

import cn.net.caoyao.cpzshandset.bean.City;
import cn.net.caoyao.cpzshandset.common.config.TConfig;
import cn.net.caoyao.cpzshandset.common.util.LogUtil;
import cn.net.caoyao.cpzshandset.common.util.StringUtils;

public class SaleAddressUtil {
	public static String getAddressStrByCity(City city){
		if (city != null) {
			LogUtil.d(TConfig.Echo, "city:" + city.toString());
			if (city.getCityCode() == 0) {
				return city.getProvinceName();
			} else if (isProvinceLevelCity(city.getProvinceName())) {
				if (StringUtils.isEmpty(city.getAreasName())) {
					return city.getCityName();
				} else {
					return city.getCityName() +"·" + city.getAreasName();
				}
			} else {
				if (StringUtils.isEmpty(city.getAreasName()) && StringUtils.isEmpty(city.getCityName())) {
					return city.getProvinceName();
				} else if (StringUtils.isEmpty(city.getAreasName())) {
					return city.getProvinceName() +"·" + city.getCityName();
				} else {
					return city.getProvinceName() +"·" + city.getCityName() +"·" + city.getAreasName();
				}
			}
		} else {
			return "";
		}
	}
	
	/**
     * 判断是否是直辖市
     *
     * @param province
     * @return
     */
    public static boolean isProvinceLevelCity(String province) {
        String citys = "香港,澳门,台湾,北京市,上海市,天津市,重庆市,";
        if (citys.contains(province + ",")) {
            return true;
        }
        return false;
    }

}
