| | |
| | | * @date 2023/6/12 15:18 |
| | | */ |
| | | @Override |
| | | public List<RegionVo> listCityVo() { |
| | | if (redisService.hasKey(SecurityConstant.CITY_LIST)) { |
| | | // 如果存在,则直接从缓存中获取并返回 |
| | | List<RegionVo> result = redisService.getCacheList(SecurityConstant.CITY_LIST); |
| | | return result; |
| | | } else { |
| | | // 如果不存在,则从数据库中查询并进行处理 |
| | | List<RegionVo> regionVoList = regionMapper.listRegionVo(); |
| | | List<RegionVo> regionVoList1 = new ArrayList<>(); |
| | | List<RegionVo> regionVoList2 = new ArrayList<>(); |
| | | // 将地区按照级别分别存放到不同的列表中 |
| | | for (RegionVo regionVo : regionVoList) { |
| | | if (regionVo.getLevel() == 1) { |
| | | regionVoList1.add(regionVo); |
| | | } |
| | | if (regionVo.getLevel() == 2) { |
| | | regionVoList2.add(regionVo); |
| | | } |
| | | } |
| | | RegionVo children; |
| | | Iterator<RegionVo> regionVoIterator2; |
| | | // 将第二级地区挂到第一级地区下面 |
| | | for (RegionVo regionVo : regionVoList1) { |
| | | if (null == regionVo.getChildren()) { |
| | | regionVo.setChildren(new ArrayList<>()); |
| | | } |
| | | regionVoIterator2 = regionVoList2.iterator(); |
| | | while (regionVoIterator2.hasNext()) { |
| | | children = regionVoIterator2.next(); |
| | | if (regionVo.getId().equals(children.getParentId())) { |
| | | regionVo.getChildren().add(children); |
| | | regionVoIterator2.remove(); |
| | | } |
| | | } |
| | | } |
| | | // 将处理后的地区列表存入缓存中 |
| | | redisService.setCacheList(SecurityConstant.CITY_LIST, regionVoList1); |
| | | // 返回处理后的地区列表 |
| | | return regionVoList1; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @return List<RegionVo> |
| | | * @description |
| | | * @author jqs |
| | | * @date 2023/6/12 15:18 |
| | | */ |
| | | @Override |
| | | public List<RegionVo> listRegionVo() { |
| | | if (redisService.hasKey(SecurityConstant.REGION_LIST)) { |
| | | // 如果存在,则直接从缓存中获取并返回 |