puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
    }
 
}