package com.sinata.shop.modular.system.controller.util;
|
|
import com.sinata.shop.modular.system.model.TCityRegion;
|
import org.springframework.util.StringUtils;
|
|
import java.util.List;
|
|
/**
|
* 数据封装工具类
|
*/
|
public class MapWrapperUtil {
|
|
/**
|
* 封装用户城市
|
*/
|
public static String getWrapperCityCode(List<TCityRegion> cityList, Object cityCode) {
|
// 城市名称
|
String cityName = "";
|
if (cityList != null && cityList.size() > 0 && !StringUtils.isEmpty(cityCode)) {
|
for (TCityRegion cityRegion : cityList) {
|
// 获取当前城市(第3级)
|
if(cityCode.toString().equals(cityRegion.getCode())) {
|
cityName = cityRegion.getName();
|
|
// 获取上级城市(第1/2级)
|
for (int i = 0; i < 2; i++) {
|
for (TCityRegion cityParent : cityList) {
|
if(cityRegion.getParentId().equals(cityParent.getId())) {
|
// 判断上级城市
|
cityRegion = cityParent;
|
cityName = cityParent.getName() + " " + cityName;
|
break;
|
}
|
}
|
}
|
break;
|
}
|
}
|
}
|
return cityName;
|
}
|
|
}
|