|
|
|
@ -23,7 +23,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import javafx.scene.effect.SepiaTone; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
@ -40,9 +39,20 @@ import org.springblade.system.vo.RegionVO;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import static org.springblade.system.cache.RegionCache.*; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.CITY_LEVEL; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.DISTRICT_LEVEL; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.MAIN_CODE; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.PROVINCE_LEVEL; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.TOWN_LEVEL; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.VILLAGE_LEVEL; |
|
|
|
|
import static org.springblade.system.cache.RegionCache.getByCode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -121,44 +131,44 @@ public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> impleme
|
|
|
|
|
public List<RegionAllVO> lazyListAll() { |
|
|
|
|
List<RegionAllVO> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
Map<String,List<RegionVO>> listMap = new HashMap<>(); |
|
|
|
|
Map<String, List<RegionVO>> listMap = new HashMap<>(); |
|
|
|
|
List<RegionVO> regionVOS = baseMapper.lazyListAll(); |
|
|
|
|
//处理省
|
|
|
|
|
for (RegionVO regionVO : regionVOS) { |
|
|
|
|
if(listMap.size() < 1){ |
|
|
|
|
if (listMap.size() < 1) { |
|
|
|
|
//没有数据
|
|
|
|
|
List<RegionVO> list1 = new ArrayList<>(); |
|
|
|
|
list1.add(regionVO); |
|
|
|
|
listMap.put(regionVO.getProvinceCode(),list1); |
|
|
|
|
}else{ |
|
|
|
|
listMap.put(regionVO.getProvinceCode(), list1); |
|
|
|
|
} else { |
|
|
|
|
//有数据
|
|
|
|
|
List<RegionVO> regionVOS2 = listMap.get(regionVO.getProvinceCode()); |
|
|
|
|
if(ObjectUtils.isNotNull(regionVOS2)){ |
|
|
|
|
if (ObjectUtils.isNotNull(regionVOS2)) { |
|
|
|
|
//有一样的数据
|
|
|
|
|
List<RegionVO> regionVOS1 = listMap.get(regionVO.getProvinceCode()); |
|
|
|
|
regionVOS1.add(regionVO); |
|
|
|
|
listMap.put(regionVO.getProvinceCode(),regionVOS1); |
|
|
|
|
}else{ |
|
|
|
|
listMap.put(regionVO.getProvinceCode(), regionVOS1); |
|
|
|
|
} else { |
|
|
|
|
//没有
|
|
|
|
|
List<RegionVO> list1 = new ArrayList<>(); |
|
|
|
|
list1.add(regionVO); |
|
|
|
|
listMap.put(regionVO.getProvinceCode(),list1); |
|
|
|
|
listMap.put(regionVO.getProvinceCode(), list1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Map<String, RegionVO> collect = regionVOS.stream().collect(Collectors.toMap(RegionVO::getProvinceCode, Function.identity(), (key1, key2) -> key2));
|
|
|
|
|
Map<String,List<RegionAllVO>> m = new HashMap<>(); //市,区数据
|
|
|
|
|
Map<String, List<RegionAllVO>> m = new HashMap<>(); //市,区数据
|
|
|
|
|
//处理区
|
|
|
|
|
listMap.forEach((k,v) ->{ |
|
|
|
|
listMap.forEach((k, v) -> { |
|
|
|
|
RegionAllVO sheng = new RegionAllVO(); |
|
|
|
|
|
|
|
|
|
sheng.setValue(v.get(0).getProvinceCode()); |
|
|
|
|
sheng.setLabel(v.get(0).getProvinceName()); |
|
|
|
|
|
|
|
|
|
Set<RegionAllVO> lis = new HashSet<>(); |
|
|
|
|
v.forEach(it ->{ |
|
|
|
|
if(ObjectUtils.isNotNull(it.getCityCode())){ |
|
|
|
|
v.forEach(it -> { |
|
|
|
|
if (ObjectUtils.isNotNull(it.getCityCode())) { |
|
|
|
|
RegionAllVO shi = new RegionAllVO(); |
|
|
|
|
shi.setValue(it.getCityCode()); |
|
|
|
|
shi.setLabel(it.getCityName()); |
|
|
|
@ -168,34 +178,34 @@ public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> impleme
|
|
|
|
|
qu.setValue(it.getDistrictCode()); |
|
|
|
|
qu.setLabel(it.getDistrictName()); |
|
|
|
|
voList.add(qu); |
|
|
|
|
if(m.size() < 1){ |
|
|
|
|
if (m.size() < 1) { |
|
|
|
|
//没有数据 添加市 区数据
|
|
|
|
|
|
|
|
|
|
m.put(it.getCityCode(),voList); |
|
|
|
|
}else{ |
|
|
|
|
m.put(it.getCityCode(), voList); |
|
|
|
|
} else { |
|
|
|
|
//有数据 判断是不是同一个市
|
|
|
|
|
List<RegionAllVO> voList2 = m.get(it.getCityCode()); |
|
|
|
|
if(ObjectUtils.isNotNull(voList2)){ |
|
|
|
|
if (ObjectUtils.isNotNull(voList2)) { |
|
|
|
|
//有一样的数据
|
|
|
|
|
List<RegionAllVO> voList1 = m.get(it.getCityCode()); |
|
|
|
|
voList1.add(qu); |
|
|
|
|
m.put(it.getCityCode(),voList1); |
|
|
|
|
}else{ |
|
|
|
|
m.put(it.getCityCode(), voList1); |
|
|
|
|
} else { |
|
|
|
|
//没有
|
|
|
|
|
shi.setValue(it.getCityCode()); |
|
|
|
|
shi.setLabel(it.getCityName()); |
|
|
|
|
m.put(it.getCityCode(),voList); |
|
|
|
|
m.put(it.getCityCode(), voList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
//有市对区的数据
|
|
|
|
|
lis.forEach(i ->{ |
|
|
|
|
lis.forEach(i -> { |
|
|
|
|
List<RegionAllVO> voLis = m.get(i.getValue()); |
|
|
|
|
i.setChildren(voLis); |
|
|
|
|
}); |
|
|
|
|
sheng.setChildren( new ArrayList<>(lis) ); |
|
|
|
|
sheng.setChildren(new ArrayList<>(lis)); |
|
|
|
|
list.add(sheng); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -206,47 +216,50 @@ public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> impleme
|
|
|
|
|
public String selectAllStr() { |
|
|
|
|
String key = "REGION:ALL:ROW:DATA"; |
|
|
|
|
String str = bladeRedis.get(key); |
|
|
|
|
if(StringUtil.isBlank(str)){ |
|
|
|
|
if (StringUtil.isBlank(str)) { |
|
|
|
|
QueryWrapper<Region> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("parent_code","00"); |
|
|
|
|
queryWrapper.eq("parent_code", "00"); |
|
|
|
|
List<Region> regions = baseMapper.selectList(queryWrapper); |
|
|
|
|
JSONArray jsonArray = new JSONArray(); |
|
|
|
|
for (Region region : regions) { |
|
|
|
|
String code = region.getCode(); |
|
|
|
|
JSONObject provinceObject = new JSONObject(); |
|
|
|
|
provinceObject.put("value",code); |
|
|
|
|
provinceObject.put("label",region.getName()); |
|
|
|
|
queryWrapper.eq("parent_code",code); |
|
|
|
|
provinceObject.put("value", code); |
|
|
|
|
provinceObject.put("label", region.getName()); |
|
|
|
|
queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("parent_code", code); |
|
|
|
|
List<Region> cityRegions = baseMapper.selectList(queryWrapper); |
|
|
|
|
JSONArray cityArray = new JSONArray(); |
|
|
|
|
for (Region cityRegion : cityRegions) { |
|
|
|
|
String cityCode = cityRegion.getCode(); |
|
|
|
|
JSONObject cityObject = new JSONObject(); |
|
|
|
|
cityObject.put("value",cityCode); |
|
|
|
|
cityObject.put("label",cityRegion.getName()); |
|
|
|
|
queryWrapper.eq("parent_code",cityCode); |
|
|
|
|
cityObject.put("value", cityCode); |
|
|
|
|
cityObject.put("label", cityRegion.getName()); |
|
|
|
|
queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("parent_code", cityCode); |
|
|
|
|
List<Region> areaRegions = baseMapper.selectList(queryWrapper); |
|
|
|
|
JSONArray areaArray = new JSONArray(); |
|
|
|
|
for (Region areaRegion : areaRegions){ |
|
|
|
|
for (Region areaRegion : areaRegions) { |
|
|
|
|
String areaCode = areaRegion.getCode(); |
|
|
|
|
String areaName = areaRegion.getName(); |
|
|
|
|
JSONObject areaObject = new JSONObject(); |
|
|
|
|
cityObject.put("value",areaCode); |
|
|
|
|
cityObject.put("label",areaName); |
|
|
|
|
cityObject.put("value", areaCode); |
|
|
|
|
cityObject.put("label", areaName); |
|
|
|
|
areaArray.add(cityObject); |
|
|
|
|
} |
|
|
|
|
if(areaArray.size() > 0){ |
|
|
|
|
cityObject.put("children",areaArray); |
|
|
|
|
if (areaArray.size() > 0) { |
|
|
|
|
cityObject.put("children", areaArray); |
|
|
|
|
} |
|
|
|
|
cityArray.add(cityObject); |
|
|
|
|
} |
|
|
|
|
if(cityArray.size() > 0){ |
|
|
|
|
provinceObject.put("children",cityArray); |
|
|
|
|
if (cityArray.size() > 0) { |
|
|
|
|
provinceObject.put("children", cityArray); |
|
|
|
|
} |
|
|
|
|
jsonArray.add(provinceObject); |
|
|
|
|
} |
|
|
|
|
str = jsonArray.toJSONString(); |
|
|
|
|
} |
|
|
|
|
bladeRedis.setEx(key, str, 60L * 60L); |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|