mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.panzhihua.service_community.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ProvinceCityReturnVO;
import com.panzhihua.service_community.entity.BcRegion;
import com.panzhihua.service_community.dao.BcRegionDao;
import com.panzhihua.service_community.service.BcRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * 行政区划表(BcRegion)表服务实现类
 * projectName 成都呐喊信息技术有限公司-智慧社区项目
 * description: 行政区划表相关功能
 *
 * @author zzj
 * @since 2022-04-20 14:26:14
 */
@Slf4j
@Service
public class BcRegionServiceImpl extends ServiceImpl<BcRegionDao, BcRegion> implements BcRegionService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
 
    @Override
    public R pageList(String province, String city, String country,String town) {
        return R.ok(this.baseMapper.selectByName(province,city,country,town));
    }
 
    @Override
    public R selectCommunityCodeByName( String city, String country,String town,String villagetr) {
        return R.ok(this.baseMapper.selectCommunityCodeByName(city,country,town,villagetr));
    }
 
    @Override
    public R levelList(Integer level,String code) {
        if(level==1){
            List<ProvinceCityReturnVO> firstLevel=this.baseMapper.selectFirst();
            return R.ok(firstLevel);
        }
        if(level==2){
            List<ProvinceCityReturnVO> secondLevel=this.baseMapper.selectSecond(code);
            return R.ok(secondLevel);
        }
        if(level==3){
            List<ProvinceCityReturnVO> thirdLevel=this.baseMapper.selectThird(code);
            return R.ok(thirdLevel);
        }
        if(level==4){
            List<ProvinceCityReturnVO> fourthLevel=this.baseMapper.selectFourth(code);
            return R.ok(fourthLevel);
        }
        return R.fail("参数错误");
//        if(stringRedisTemplate.hasKey("levelList")){
//            return R.ok(stringRedisTemplate.opsForValue().get("levelList"));
//        }
//        else {
//            List<ProvinceCityReturnVO> firstLevel=this.baseMapper.selectFirst();
//            firstLevel.forEach(provinceCityReturnVO -> {
//                List<ProvinceCityReturnVO> secondLevel=this.baseMapper.selectSecond(provinceCityReturnVO.getCode());
//                secondLevel.forEach(provinceCityReturnVO1 -> {
//                    List<ProvinceCityReturnVO> thirdLevel=this.baseMapper.selectThird(provinceCityReturnVO1.getCode());
//                    thirdLevel.forEach(provinceCityReturnVO2 -> {
//                        List<ProvinceCityReturnVO> fourthLevel=this.baseMapper.selectFourth(provinceCityReturnVO2.getCode());
//                        provinceCityReturnVO2.setProvinceCityReturnVOList(fourthLevel);
//                    });
//                    provinceCityReturnVO1.setProvinceCityReturnVOList(thirdLevel);
//                });
//                provinceCityReturnVO.setProvinceCityReturnVOList(secondLevel);
//            });
//            stringRedisTemplate.opsForValue().set("levelList", JSON.toJSONString(firstLevel));
//            return R.ok(firstLevel);
//        }
    }
 
    @Override
    public R levelListBackstage() {
        if(stringRedisTemplate.hasKey("levelList")){
            return R.ok(stringRedisTemplate.opsForValue().get("levelList"));
        }
        else {
            List<ProvinceCityReturnVO> firstLevel=this.baseMapper.selectFirst();
            firstLevel.forEach(provinceCityReturnVO -> {
                List<ProvinceCityReturnVO> secondLevel=this.baseMapper.selectSecond(provinceCityReturnVO.getCode());
                secondLevel.forEach(provinceCityReturnVO1 -> {
                    List<ProvinceCityReturnVO> thirdLevel=this.baseMapper.selectThird(provinceCityReturnVO1.getCode());
                    thirdLevel.forEach(provinceCityReturnVO2 -> {
                        List<ProvinceCityReturnVO> fourthLevel=this.baseMapper.selectFourth(provinceCityReturnVO2.getCode());
                        provinceCityReturnVO2.setProvinceCityReturnVOList(fourthLevel);
                    });
                    provinceCityReturnVO1.setProvinceCityReturnVOList(thirdLevel);
                });
                provinceCityReturnVO.setProvinceCityReturnVOList(secondLevel);
            });
            stringRedisTemplate.opsForValue().set("levelList", JSON.toJSONString(firstLevel));
            return R.ok(firstLevel);
        }
    }
}