cloudroam
3 天以前 3a819e4f668c15e8b77b188b322470da12bb7a43
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.mzl.flower.service.system;
 
import com.alibaba.fastjson.JSON;
import com.mzl.flower.base.cache.StringCacheClient;
import com.mzl.flower.dto.response.system.AreaDTO;
import com.mzl.flower.service.BaseService;
import com.mzl.flower.utils.LocalUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
@Service
@Transactional
public class ProvinceService extends BaseService {
 
    @Autowired
    private StringCacheClient stringCacheClient;
 
    public String getChineseArea() {
        String result = stringCacheClient.get("CHINA_AREA_DATA");
        if (StringUtils.isNotBlank(result)) {
            return result;
        } else {
            return refreshChineseData();
        }
    }
 
    public String refreshChineseData(){
        LocalUtil lu = LocalUtil.getNewInstance();
        String country = "中国";
        List<String> provinces = lu.getProvinces(country);
        List<AreaDTO> pLs = new ArrayList<>();
        for (String province : provinces) {
            AreaDTO p = new AreaDTO();
            pLs.add(p);
            p.setCode(province);
            p.setName(province);
            List<String> cities = lu.getCities(country, province);
            List<AreaDTO> cLs = new ArrayList<>();
            p.setChildren(cLs);
            for (String city : cities) {
                AreaDTO c = new AreaDTO();
                cLs.add(c);
                c.setCode(city);
                c.setName(city);
                List<String> regions = lu.getDistrict(country, province, city);
                List<AreaDTO> rLs = new ArrayList<>();
                c.setChildren(rLs);
                for (String region : regions) {
                    AreaDTO r = new AreaDTO();
                    rLs.add(r);
                    r.setCode(region);
                    r.setName(region);
                }
            }
        }
        String jj = JSON.toJSONString(pLs);
        stringCacheClient.set("CHINA_AREA_DATA", jj);
        return jj;
    }
}