From 3408c978f758f0a463d2f143398d66ed6aaf3c21 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 12 一月 2023 20:47:55 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/data/DownloadService.java | 77 ++++++++++++++++++++++++++++++++++---- 1 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/lf/server/service/data/DownloadService.java b/src/main/java/com/lf/server/service/data/DownloadService.java index 685ddb2..2f17e20 100644 --- a/src/main/java/com/lf/server/service/data/DownloadService.java +++ b/src/main/java/com/lf/server/service/data/DownloadService.java @@ -1,5 +1,6 @@ package com.lf.server.service.data; +import com.lf.server.entity.all.StaticData; import com.lf.server.entity.ctrl.DownloadReqEntity; import com.lf.server.entity.data.DownloadEntity; import com.lf.server.entity.data.MetaEntity; @@ -225,18 +226,34 @@ * 娣诲姞鍏冩暟鎹枃浠惰嚦Zip鍖� */ private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) { - String uploadPath = pathHelper.getConfig().getUploadPath(); - int i = 1; - for (MetaEntity entity : list) { + String uploadPath = pathHelper.getConfig().getUploadPath(); + for (MetaEntity mf : list) { try { - File file = new File(uploadPath + File.separator + entity.getPath()); - zip.addFile(file, params); - - FileHeader header = zip.getFileHeader(entity.getGuid()); - if (null != header) { - zip.renameFile(header, i++ + "_" + entity.getName()); + switch ("." + mf.getType()) { + case StaticData.MPT: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.MPT_EXT); + break; + case StaticData.IMG: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.IMG_EXT); + break; + case StaticData.TIF: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.TIF_EXT); + break; + case StaticData.TIFF: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.TIFF_EXT); + break; + case StaticData.SHP: + addMultiFile(i++, uploadPath, mf, zip, params, StaticData.SHP_EXT); + break; + case StaticData.GDB: + addFolderFile(i++, uploadPath, mf, zip, params); + break; + default: + addSingleFile(i++, uploadPath, mf, zip, params); + break; } + } catch (Exception ex) { log.error(ex.getMessage(), ex); } @@ -244,6 +261,48 @@ } /** + * 娣诲姞鐩綍鏂囦欢 + */ + private void addFolderFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { + + } + + /** + * 娣诲姞澶氭枃浠� + */ + private void addMultiFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params, List<String> extList) throws Exception { + addSingleFile(i, uploadPath, mf, zip, params); + + for (String ext : extList) { + File file = new File(uploadPath + File.separator + mf.getPath().replace("." + mf.getType(), ext)); + if (!file.exists() || !file.isDirectory()) { + continue; + } + zip.addFile(file, params); + + String fileName = FileHelper.getFileName(file.getPath()); + FileHeader header = zip.getFileHeader(fileName); + if (null != header) { + zip.renameFile(header, i + "_" + mf.getName().replace("." + mf.getType(), ext)); + } + } + } + + /** + * 娣诲姞鍗曟枃浠� + */ + private void addSingleFile(int i, String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { + File file = new File(uploadPath + File.separator + mf.getPath()); + zip.addFile(file, params); + + String fileName = FileHelper.getFileName(file.getPath()); + FileHeader header = zip.getFileHeader(fileName); + if (null != header) { + zip.renameFile(header, i + "_" + mf.getName()); + } + } + + /** * 鑾峰彇涓嬭浇瀹炰綋绫� */ private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception { -- Gitblit v1.9.3