mitao
2024-07-08 022a7ff7abf82cd2546e18071ade5228b4e2339f
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
66
67
68
package com.sinata.modular.system.service.impl;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sinata.modular.system.dao.TCityRegionMapper;
import com.sinata.modular.system.model.TCityRegion;
import com.sinata.modular.system.service.ITCityRegionService;
import org.springframework.stereotype.Service;
 
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 省市区三级联动 服务实现类
 * </p>
 *
 * @author goku
 * @since 2023-03-27
 */
@Service
public class TCityRegionServiceImpl extends ServiceImpl<TCityRegionMapper, TCityRegion> implements ITCityRegionService {
 
    @Override
    public String[] getProvinceCityCountyName(String countyCode) {
        return this.selectObjs(
                new EntityWrapper<TCityRegion>()
                        .setSqlSelect("name")
                        .in("code", Arrays.asList(
                                StrUtil.sub(countyCode, 0, 2) + "0000",
                                StrUtil.sub(countyCode, 0, 4) + "00",
                                countyCode
                        ))
                        .orderBy("code", true)
 
        ).stream().toArray(String[]::new);
    }
 
    @Override
    public List<TCityRegion> getProvinceCityCountyNameByAll(List<TCityRegion> cityAll, String countyCode) {
        String province = StrUtil.sub(countyCode, 0, 2) + "0000";
        String city = StrUtil.sub(countyCode, 0, 4) + "00";
 
        if (cityAll == null) {
            cityAll = this.selectList(new EntityWrapper<>());
        }
 
        return cityAll.stream()
                .filter(o -> {
                    if (o.getCode().equals(province) || o.getCode().equals(city) || o.getCode().equals(countyCode)) {
                        return true;
                    }
                    return false;
                })
                .collect(Collectors.toList());
    }
 
    @Override
    public List<TCityRegion> getCityNameCodeAll() {
        return this.selectList(
                new EntityWrapper<TCityRegion>()
                        .setSqlSelect("name, code")
                        .orderBy("code", true)
        );
    }
}