| | |
| | | package com.ruoyi.system.service.impl.config; |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.system.api.constant.SecurityConstant; |
| | | import com.ruoyi.system.domain.pojo.config.Region; |
| | |
| | | import com.ruoyi.system.mapper.config.RegionMapper; |
| | | import com.ruoyi.system.service.config.RegionService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.system.util.HttpUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | /** |
| | | * @param |
| | | * @return List<RegionVo> |
| | | * @description |
| | | * @author jqs |
| | | * @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<>(); |
| | | List<RegionVo> regionVoList3 = new ArrayList<>(); |
| | | // 将地区按照级别分别存放到不同的列表中 |
| | | for (RegionVo regionVo : regionVoList) { |
| | | if (regionVo.getLevel() == 1) { |
| | | regionVoList1.add(regionVo); |
| | | } |
| | | if (regionVo.getLevel() == 2) { |
| | | regionVoList2.add(regionVo); |
| | | } |
| | | if (regionVo.getLevel() == 3) { |
| | | regionVoList3.add(regionVo); |
| | | } |
| | | } |
| | | RegionVo children; |
| | | Iterator<RegionVo> regionVoIterator2; |
| | | |
| | | for (RegionVo regionVo : regionVoList2) { |
| | | if (null == regionVo.getChildren()) { |
| | | regionVo.setChildren(new ArrayList<>()); |
| | | } |
| | | regionVoIterator2 = regionVoList3.iterator(); |
| | | while (regionVoIterator2.hasNext()) { |
| | | children = regionVoIterator2.next(); |
| | | if (regionVo.getId().equals(children.getParentId())) { |
| | | regionVo.getChildren().add(children); |
| | | regionVoIterator2.remove(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 将第二级地区挂到第一级地区下面 |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<RegionVo> listRegions(Long pid) { |
| | | return regionMapper.listRegions(pid); |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @return List<RegionVo> |
| | |
| | | return regionVoList1; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // public R renewalRegion(){ |
| | | // HttpUtils.doPost() |
| | | // } |
| | | } |