diff --git a/backend/src/main/java/io/dataease/config/WebMvcConfig.java b/backend/src/main/java/io/dataease/config/WebMvcConfig.java index bca35898fb..8a1de3000b 100644 --- a/backend/src/main/java/io/dataease/config/WebMvcConfig.java +++ b/backend/src/main/java/io/dataease/config/WebMvcConfig.java @@ -9,7 +9,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebMvcConfig implements WebMvcConfigurer { - @Value("${geo.rootpath:file:/opt/dataease/data/feature/}") + @Value("${geo.custom.rootpath:file:/opt/dataease/data/custom/}") private String geoPath; @Override 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 e4d395eee7..e131df7210 100644 --- a/backend/src/main/java/io/dataease/map/service/MapService.java +++ b/backend/src/main/java/io/dataease/map/service/MapService.java @@ -11,6 +11,7 @@ import io.dataease.map.utils.MapUtils; import io.dataease.plugins.common.base.domain.AreaMappingGlobal; import io.dataease.plugins.common.base.domain.AreaMappingGlobalExample; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,7 +27,9 @@ import java.util.stream.Collectors; @Service public class MapService { - private static final String dirPath = "/opt/dataease/data/feature/"; + @Value("${geo.custom.rootpath:/opt/dataease/data/custom/}") + private String rootGeoPath; + @Cacheable("sys_map_areas") public List areaEntities() { @@ -93,7 +96,7 @@ public class MapService { Set sets = nodes.stream().flatMap(node -> codesByNode(node, pLevel).stream()).collect(Collectors.toSet()); sets.forEach(code -> { String countryCode = code.substring(0, 3); - String path = dirPath + "/full/" + countryCode + "/" + code +"_full.json"; + String path = rootGeoPath + "/full/" + countryCode + "/" + code +"_full.json"; if (FileUtil.exist(path)) { FileUtil.del(path); } @@ -194,7 +197,7 @@ public class MapService { private void validateFile(MultipartFile file) { long size = file.getSize(); - String name = file.getName(); + String name = file.getOriginalFilename(); if (size / 1024 / 1024 > 30) { DEException.throwException("large file that exceed 30M is not supported"); } @@ -318,13 +321,15 @@ public class MapService { } public void uploadMapFile(MultipartFile file, String areaCode) throws Exception{ - String dir = dirPath + "full/"; + + String countryCode = areaCode.substring(0, 3); + String dir = rootGeoPath + "full/" + countryCode + "/"; File fileDir = new File(dir); if (!fileDir.exists()) { fileDir.mkdirs(); } - String countryCode = areaCode.substring(0, 3); - String targetPath = dir + countryCode + "/" + areaCode+"_full.json"; + + String targetPath = dir + areaCode+"_full.json"; File target = new File(targetPath); file.transferTo(target); } diff --git a/backend/src/main/java/io/dataease/map/service/MapTransferService.java b/backend/src/main/java/io/dataease/map/service/MapTransferService.java index 7c3b857be9..34a4becd44 100644 --- a/backend/src/main/java/io/dataease/map/service/MapTransferService.java +++ b/backend/src/main/java/io/dataease/map/service/MapTransferService.java @@ -1,6 +1,7 @@ package io.dataease.map.service; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ArrayUtil; import com.google.gson.Gson; import io.dataease.plugins.common.base.domain.ChartView; @@ -24,6 +25,10 @@ public class MapTransferService { @Value("${geo.rootpath:/opt/dataease/data/feature/}") private String geoPath; + + @Value("${geo.custom.rootpath:/opt/dataease/data/custom/}") + private String customGeoPath; + private static final List MATCH_TYPES = new ArrayList<>(); private static final Gson gson = new Gson(); private static final String AREA_CODE_KEY = "areaCode"; @@ -65,23 +70,45 @@ public class MapTransferService { String chinaRootPath = geoPath + FULL_KEY + FILE_SEPARATOR; File chinaRootDir = new File(chinaRootPath); File[] files = chinaRootDir.listFiles(); + if(ArrayUtil.isEmpty(files)) return; Map> listMap = Arrays.stream(files).filter(FileUtil::isFile).collect(Collectors.groupingBy(this::fileType)); if (ObjectUtils.isEmpty(listMap)) return; moveFiles(listMap, BORDER_KEY); moveFiles(listMap, FULL_KEY); + moveGlobalFile(); + } private void moveFiles(Map> listMap, String fileType) { - String dirPath = geoPath + fileType + FILE_SEPARATOR; + String dirPath = customGeoPath + fileType + FILE_SEPARATOR; Optional.ofNullable(listMap.get(fileType)).ifPresent(files -> { files.forEach(file -> { String fileName = file.getName(); String newFilePath = dirPath + GLOBAL_CHINA_PREFIX + FILE_SEPARATOR + GLOBAL_CHINA_PREFIX + fileName; - FileUtil.move(file, new File(newFilePath), true); + FileUtil.move(file, new File(newFilePath), false); }); }); } + private void moveGlobalFile() { + String fileName = "000000000" + FULL_FILE_SUFFIX; + String sourcePath = geoPath + FULL_KEY + FILE_SEPARATOR + "000" + FILE_SEPARATOR + fileName; + File sourceFile = new File(sourcePath); + if (!sourceFile.exists()) return; + + String targetDirPath = customGeoPath + FULL_KEY + FILE_SEPARATOR + "000" + FILE_SEPARATOR; + File targetDir = new File(targetDirPath); + if (!targetDir.exists()) { + targetDir.mkdirs(); + } + String targetPath = targetDirPath + fileName; + + File targetFile = new File(targetPath); + + FileUtil.move(sourceFile, targetFile, false); + + } + private String fileType(File file) { return file.getName().endsWith(FULL_FILE_SUFFIX) ? FULL_KEY : BORDER_KEY; } diff --git a/frontend/src/views/system/SysParam/MapSetting/index.vue b/frontend/src/views/system/SysParam/MapSetting/index.vue index 4c6124f08b..f671307aec 100644 --- a/frontend/src/views/system/SysParam/MapSetting/index.vue +++ b/frontend/src/views/system/SysParam/MapSetting/index.vue @@ -1,11 +1,11 @@