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
44
package com.sinata.rest.modular.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sinata.rest.modular.system.dao.CityRegionMapper;
import com.sinata.rest.modular.system.model.CityRegion;
import com.sinata.rest.modular.system.service.ICityRegionService;
import org.springframework.stereotype.Service;
 
/**
 * <p>
 * 省市区三级联动 服务实现类
 * </p>
 *
 * @author goku
 * @since 2023-03-23
 */
@Service
public class CityRegionServiceImpl extends ServiceImpl<CityRegionMapper, CityRegion> implements ICityRegionService {
 
    @Override
    public String getFullName(String code) {
        LambdaQueryWrapper<CityRegion> wrapper = new LambdaQueryWrapper();
        wrapper.eq(CityRegion::getCode, code);
        CityRegion r = getOne(wrapper);
        if (r == null) {
            return "城市码错误";
        }
        if (r.getParentId() == 0) {
            return r.getName();
        }
        CityRegion c = baseMapper.selectById(r.getParentId());
        if (c != null) {
            if (c.getParentId() != 0) {
                CityRegion p = baseMapper.selectById(c.getParentId());
                if (p != null) {
                    return p.getName() + " " + c.getName() + " " + r.getName();
                }
            }
            return c.getName() + " " + r.getName();
        }
        return "";
    }
}