From 3af5e8f2335b3d5cd4528f9ee9f326eef5fe2f9a Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 10 一月 2023 10:43:01 +0800 Subject: [PATCH] 3 --- src/main/java/com/lf/server/service/all/BaseUploadService.java | 116 +++++++++++++++++++++------------------------------------ 1 files changed, 43 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/lf/server/service/all/BaseUploadService.java b/src/main/java/com/lf/server/service/all/BaseUploadService.java index 9c978af..62fb8d6 100644 --- a/src/main/java/com/lf/server/service/all/BaseUploadService.java +++ b/src/main/java/com/lf/server/service/all/BaseUploadService.java @@ -259,7 +259,7 @@ boolean isShp = StaticData.SHP.equals(extName); if (isGdb) { - // + String md5 = getGdbMd5(f.getPath()); continue; } @@ -270,7 +270,7 @@ mf.setPath(f.getPath().substring(subPath.length())); if (isShp) { mf.setTab(fileName); - // + mf.setGuid(getShpMd5(f.getPath())); } else { mf.setGuid(FileHelper.getFileMd5(f.getPath())); } @@ -295,89 +295,59 @@ return mf; } - /*private List<TabMapperEntity> getMappers(String zipPath, File[] files) { - String temp = pathHelper.getConfig().getTempPath(); + /** + * 鑾峰彇SHP鏂囦欢鐨凪D5鐮� + */ + private String getShpMd5(String shpPath) { + List<String> files = new ArrayList<>(); + files.add(shpPath); - List<TabMapperEntity> list = new ArrayList<>(); - for (File f : files) { - String fileName = FileHelper.getFileName(f.getPath()); - if (fileName.contains(XLS)) { - String path = f.getPath().replace(temp + File.separator, ""); - list.add(new TabMapperEntity(fileName, "xls", null, path)); - continue; - } - if (fileName.contains(MDB)) { - String path = f.getPath().replace(temp + File.separator, ""); - List<String> tabs = MdbHelper.getTabNames(f.getPath()); - for (String tab : tabs) { - list.add(new TabMapperEntity(fileName, "mdb", tab, path)); - } - continue; - } - if (fileName.contains(SHP_ZIP)) { - String subPath = zipPath + File.separator + f.getName().toLowerCase().replace(".zip", ""); - ZipHelper.unzip(f.getPath(), subPath); - getShpFiles(f.getName(), subPath, list); - continue; - } - if (fileName.contains(GDB_ZIP)) { - String subPath = zipPath + File.separator + f.getName().toLowerCase().replace(".zip", ""); - ZipHelper.unzip(f.getPath(), subPath); - getGdbFiles(f.getName(), subPath, list); - continue; - } - if (fileName.contains(ZIP)) { - // 鏆傛椂涓嶅疄鐜� + for (int i = 1, c = StaticData.SHP_EXTENSION.size(); i < c; i++) { + String path = shpPath.replace(".shp", StaticData.SHP_EXTENSION.get(i)); + + File f = new File(path); + if (f.exists() && !f.isDirectory()) { + files.add(path); } } - return list; + return getFilesMd5(files); } - private void getShpFiles(String sourceName, String subPath, List<TabMapperEntity> list) { - List<String> files = new ArrayList<>(); - getShpFiles(subPath, files); - - String root = pathHelper.getConfig().getTempPath() + File.separator; - for (String file : files) { - String name = FileHelper.getFileName(file); - String path = file.replace(root, ""); - list.add(new TabMapperEntity(sourceName, "shp", name, path)); - } - } - - private void getGdbFiles(String sourceName, String subPath, List<TabMapperEntity> list) { - List<String> files = new ArrayList<>(); - getGdbFiles(subPath, files); - - String root = pathHelper.getConfig().getTempPath() + File.separator; - for (String file : files) { - String path = file.replace(root, ""); - List<String> tabs = GdbHelper.getTabNames(file); - for (String tab : tabs) { - list.add(new TabMapperEntity(sourceName, "gdb", tab, path)); - } - } - }*/ - - private void getShpFiles(String shpPath, List<String> list) { - File file = new File(shpPath); - - File[] files = file.listFiles(); + /** + * 鑾峰彇GDB鏂囦欢鐨凪D5鐮� + */ + private String getGdbMd5(String path) { + File[] files = new File(path).listFiles(); if (null == files || files.length == 0) { - return; + return StringHelper.getGuid(); } + List<String> list = new ArrayList<>(); for (File f : files) { - if (f.isDirectory()) { - getShpFiles(f.getPath(), list); - continue; - } + list.add(f.getPath()); + } - if (f.getName().toLowerCase().endsWith(".shp")) { - list.add(f.getPath()); + return getFilesMd5(list); + } + + /** + * 鑾峰彇澶氭枃浠剁殑MD5 + */ + private String getFilesMd5(List<String> list) { + StringBuilder sb = new StringBuilder(); + for (String str : list) { + String md5 = FileHelper.getFileMd5(str); + if (null != md5) { + sb.append(sb + ","); } } + + if (sb.length() > 0) { + return FileHelper.getStringMd5(sb.toString()); + } + + return StringHelper.getGuid(); } private void getGdbFiles(String shpPath, List<String> list) { @@ -423,7 +393,7 @@ } /** - * 鑾峰彇鍙傛暟 + * 鑾峰彇鍙傛暟 * * Enumeration<String> headers = req.getHeaderNames(); * Enumeration<String> attributes = req.getAttributeNames(); */ -- Gitblit v1.9.3