| | |
| | | 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.MetaFileEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.show.PipelineEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | |
| | | * @param pwd 密码 |
| | | * @return 下载文件GUID |
| | | */ |
| | | public String zipFiles(UserEntity ue, List<MetaFileEntity> list, String pwd) throws Exception { |
| | | public String zipFiles(UserEntity ue, List<MetaEntity> list, String pwd) throws Exception { |
| | | rmRepeatMetaFiles(list); |
| | | |
| | | String downloadPath = pathHelper.getDownloadFullPath(); |
| | |
| | | /** |
| | | * 移除重复的元数据文件 |
| | | */ |
| | | private void rmRepeatMetaFiles(List<MetaFileEntity> list) { |
| | | private void rmRepeatMetaFiles(List<MetaEntity> list) { |
| | | List<String> guidList = new ArrayList<>(); |
| | | |
| | | int i = 0; |
| | | while (i < list.size()) { |
| | | MetaFileEntity entity = list.get(i); |
| | | MetaEntity entity = list.get(i); |
| | | if (guidList.contains(entity.getGuid())) { |
| | | list.remove(i); |
| | | continue; |
| | |
| | | /** |
| | | * 添加元数据文件至Zip包 |
| | | */ |
| | | private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaFileEntity> list) { |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | |
| | | private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) { |
| | | int i = 1; |
| | | for (MetaFileEntity 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); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 添加目录文件 |
| | | */ |
| | | 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 { |