diff --git a/backend/src/main/java/io/dataease/map/api/MapApi.java b/backend/src/main/java/io/dataease/map/api/MapApi.java index 7c47924083..88e179ddbf 100644 --- a/backend/src/main/java/io/dataease/map/api/MapApi.java +++ b/backend/src/main/java/io/dataease/map/api/MapApi.java @@ -18,4 +18,13 @@ public interface MapApi { @GetMapping("/areaEntitys/{pcode}") List areaEntitys(@PathVariable String pcode); + + + /** + * 由于api有限流机制 + * 请求失败后 调用重试方法 + * @param areaCode + */ + @GetMapping("/retry/{areaCode}") + void retry(@PathVariable String areaCode); } diff --git a/backend/src/main/java/io/dataease/map/server/MapServer.java b/backend/src/main/java/io/dataease/map/server/MapServer.java index 1d51b943cc..10dab5d7c8 100644 --- a/backend/src/main/java/io/dataease/map/server/MapServer.java +++ b/backend/src/main/java/io/dataease/map/server/MapServer.java @@ -8,6 +8,7 @@ import io.dataease.map.utils.MapUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; @RestController @@ -41,10 +42,14 @@ public class MapServer implements MapApi { List areaEntities = mapService.areaEntities(); return mapService.entitysByPid(areaEntities, pcode); + } - /*return areaEntities.stream().filter(item -> StringUtils.equals(item.getPcode(), pcode)).map(item -> { - item.setChildren(null); - return item; - }).collect(Collectors.toList());*/ + @Override + public void retry(@PathVariable String areaCode) { + List areaEntities = mapService.areaEntities(); + AreaEntity areaEntity = MapUtils.nodeByCode(areaEntities, areaCode); + List targets = new ArrayList<>(); + targets.add(areaEntity); + MapUtils.recursionWriteFull(targets); } } diff --git a/backend/src/main/java/io/dataease/map/service/MapService.java b/backend/src/main/java/io/dataease/map/service/MapService.java index b27da8b05f..d159cac3cb 100644 --- a/backend/src/main/java/io/dataease/map/service/MapService.java +++ b/backend/src/main/java/io/dataease/map/service/MapService.java @@ -48,4 +48,6 @@ public class MapService { } + + } diff --git a/backend/src/main/java/io/dataease/map/utils/MapUtils.java b/backend/src/main/java/io/dataease/map/utils/MapUtils.java index 0cc7edcc39..99dc7b6f7b 100644 --- a/backend/src/main/java/io/dataease/map/utils/MapUtils.java +++ b/backend/src/main/java/io/dataease/map/utils/MapUtils.java @@ -7,6 +7,7 @@ import cn.hutool.json.JSONUtil; import io.dataease.base.domain.AreaMapping; import io.dataease.base.domain.AreaMappingExample; import io.dataease.base.mapper.AreaMappingMapper; +import io.dataease.commons.utils.LogUtil; import io.dataease.map.dto.entity.*; import io.dataease.map.dto.entity.Properties; import io.dataease.map.dto.response.MapResponse; @@ -68,7 +69,7 @@ public class MapUtils { AreaEntity china = root(); maps.parallelStream().forEach(map -> { - // maps.stream().forEach(map -> { + // maps.stream().forEach(map -> { String province_code = map.get(Constants.PROVINCE_CODE).toString(); String city_code = map.get(Constants.CITY_CODE).toString(); String county_code = map.get(Constants.COUNTY_CODE).toString(); @@ -77,6 +78,10 @@ public class MapUtils { city_code = formatCode(city_code); county_code = formatCode(county_code); + // 是否是跨级直辖 + Boolean isCrossLevel = StrUtil.equals(province_code, city_code) && !StrUtil.equals(province_code, "710000"); + + if (!provinceMap.containsKey(province_code)) { String province_name = map.get(Constants.PROVINCE_NAME).toString(); AreaEntity child = AreaEntity.builder().code(province_code).name(province_name).pcode(china.getCode()).build(); @@ -86,20 +91,26 @@ public class MapUtils { //当前省 AreaEntity currentProvince = provinceMap.get(province_code); + + String city_name = map.get(Constants.CITY_NAME).toString(); + if (isCrossLevel) { + city_code = county_code; + city_name = map.get(Constants.COUNTY_NAME).toString(); + } if (!cityMap.containsKey(city_code)) { - String city_name = map.get(Constants.CITY_NAME).toString(); AreaEntity child = AreaEntity.builder().code(city_code).name(city_name).pcode(currentProvince.getCode()).build(); cityMap.put(city_code, child); currentProvince.addChild(child); } - - //当前市 - AreaEntity currentCity = cityMap.get(city_code); - if (!countyMap.containsKey(county_code)) { - String county_name = map.get(Constants.COUNTY_NAME).toString(); - AreaEntity child = AreaEntity.builder().code(county_code).name(county_name).pcode(currentCity.getCode()).build(); - countyMap.put(county_code, child); - currentCity.addChild(child); + if (!isCrossLevel) { + //当前市 + AreaEntity currentCity = cityMap.get(city_code); + if (!countyMap.containsKey(county_code)) { + String county_name = map.get(Constants.COUNTY_NAME).toString(); + AreaEntity child = AreaEntity.builder().code(county_code).name(county_name).pcode(currentCity.getCode()).build(); + countyMap.put(county_code, child); + currentCity.addChild(child); + } } }); // List treeNodes = provinceMap.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); @@ -156,8 +167,11 @@ public class MapUtils { List kidFeatures = districts.stream().map(district -> buildFeature(district, child)).collect(Collectors.toList()); features.addAll(kidFeatures); } + }else { + LogUtil.error("请求节点错误 请手动补偿: " + areaEntity.getName() +" -> "+child.getName()); } }); + if (CollectionUtil.isNotEmpty(features)) { MapResultDto mapResultDto = buildGeometry(features); writeFeatureFileFull(mapResultDto, areaEntity.getCode() + "_full"); @@ -249,4 +263,20 @@ public class MapUtils { String content = JSONUtil.toJsonStr(mapResultDto); fileWriter.write(content); } + + public static AreaEntity nodeByCode(List areaEntities, String code) { + for (int i = 0; i < areaEntities.size(); i++) { + AreaEntity areaEntity = areaEntities.get(i); + if (StrUtil.equals(areaEntity.getCode(), code)) { + return areaEntity; + } + if (CollectionUtil.isNotEmpty(areaEntity.getChildren())) { + AreaEntity temp = nodeByCode(areaEntity.getChildren(), code); + if (null != temp){ + return temp; + } + } + } + return null; + } } diff --git a/frontend/src/views/panel/filter/filterDialog.vue b/frontend/src/views/panel/filter/filterDialog.vue index f693b71943..68b5befd6a 100644 --- a/frontend/src/views/panel/filter/filterDialog.vue +++ b/frontend/src/views/panel/filter/filterDialog.vue @@ -182,7 +182,7 @@
- + 显示标题 - - + + {{ $t('panel.custom_scope') }} - +