zoukankan      html  css  js  c++  java
  • 查询全国城市行政区

    @PostMapping("/allAddressInfo")
    @ApiOperation(consumes = MediaType.APPLICATION_JSON_VALUE, value = "查询城市区域信息")
    public R getProvinceCityInfo() {
    List<Province> provinceList = addressInfoService.getAllCityInfo();
    return R.ok(provinceList);
    }

    @Override
    public List<Province> getAllCityInfo() {
    String key = ADDRESS_PREFIX + "allCityInfo";
    ValueOperations<String, List<Province>> operations = redisTemplate.opsForValue();
    // 缓存存在
    boolean hasKey = redisTemplate.hasKey(key);
    if (hasKey) {
    List<Province> provinces = operations.get(key);
    LOGGER.info("getProvinces >>>> 从缓存查询到全国城市信息");
    return provinces;
    }
    List<ProvinceCityArea> provinceCityAreas = provinceCityAreaMapper
    .selectList(new QueryWrapper<ProvinceCityArea>().eq("pid", 0));
    List<Province> provinces = new ArrayList<>();
    provinceCityAreas.forEach(p -> {
    Province province = new Province();
    province.setName(p.getName());
    province.setCode(String.valueOf(p.getId()));
    List<City> cityList = new ArrayList<>();

    List<ProvinceCityArea> cities = provinceCityAreaMapper
    .selectList(new QueryWrapper<ProvinceCityArea>().eq("pid", p.getId()));
    cities.forEach(c -> {
    List<Area> areas = new ArrayList<>();
    List<ProvinceCityArea> cityAreas = provinceCityAreaMapper
    .selectList(new QueryWrapper<ProvinceCityArea>().eq("pid", c.getId()));
    cityAreas.forEach(a -> {
    Area area = new Area();
    area.setCode(String.valueOf(a.getId()));
    area.setName(a.getName());
    areas.add(area);
    });
    City city = new City();
    city.setName(c.getName());
    city.setCode(String.valueOf(c.getId()));
    city.setChildren(areas);
    cityList.add(city);
    });
    province.setChildren(cityList);
    provinces.add(province);
    });
    operations.set(key, provinces);
    return provinces;
    }

    —————————————————————————————————————————
    @PostMapping("/provinceCity")
    @ApiOperation(consumes = MediaType.APPLICATION_JSON_VALUE, value = "查询省市信息")
    public R getProvinceCity() {
    List<Province> provinceList = addressInfoService.provinceCityes();
    return R.ok(provinceList);
    }

    @Override
    public List<Province> provinceCityes() {
    String key = ADDRESS_PREFIX + "provinceCityInfo";
    ValueOperations<String, List<Province>> operations = redisTemplate.opsForValue();
    // 缓存存在
    boolean hasKey = redisTemplate.hasKey(key);
    if (hasKey) {
    List<Province> provinces = operations.get(key);
    LOGGER.info("getProvinces >>>> 从缓存查询到全国城市信息");
    return provinces;
    }
    List<ProvinceCityArea> provinceCityAreas = provinceCityAreaMapper
    .selectList(new QueryWrapper<ProvinceCityArea>().eq("pid", 0));
    List<Province> provinces = new ArrayList<>();
    provinceCityAreas.forEach(p -> {
    Province province = new Province();
    province.setName(p.getName());
    province.setCode(String.valueOf(p.getId()));
    List<City> cityList = new ArrayList<>();

    List<ProvinceCityArea> cities = provinceCityAreaMapper
    .selectList(new QueryWrapper<ProvinceCityArea>().eq("pid", p.getId()));
    cities.forEach(c -> {

    City city = new City();
    city.setName(c.getName());
    city.setCode(String.valueOf(c.getId()));
    cityList.add(city);
    });
    province.setChildren(cityList);
    provinces.add(province);
    });
    operations.set(key, provinces);
    return provinces;
    }

    —————————————————————————————————————————
    20195月中华人民共和国县以上行政区划代码
    http://www.mca.gov.cn/article/sj/xzqh/2019/201901-06/201906211421.html
  • 相关阅读:
    Linux更新时,出现无法更新锁
    Linux显示su:认证失败
    08 redis的缓存预热,雪崩,击穿,穿透问题以及常用的监控参数
    06 redis的哨兵系统的工作流程
    05 redis的主从复制机制的工作流程以及相关基础知识
    03 redis的事务以及锁、过期数据的删除策略、逐出算法、配置文件的核心配置参数
    02 jedis以及redis的持久化
    01 redis的5种基本数据类型的介绍,使用以及应用场景
    M1 MySQL事务知识点的总结
    02 Java文件读写通道的使用以及文件的基本操作方法
  • 原文地址:https://www.cnblogs.com/pxzbky/p/12172050.html
Copyright © 2011-2022 走看看