| | |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.data.DownloadMapper; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.FileHeader; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | |
| | | * @param pwd 密码 |
| | | * @return 下载文件GUID |
| | | */ |
| | | public String zipFiles(UserEntity ue, List<MetaFileEntity> list, String pwd) { |
| | | public String zipFiles(UserEntity ue, List<MetaFileEntity> list, String pwd) throws Exception { |
| | | rmRepeatMetaFiles(list); |
| | | |
| | | String downloadPath = pathHelper.getDownloadFullPath(); |
| | |
| | | |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, pwd); |
| | | ZipParameters params = Zip4jHelper.getZipParams(); |
| | | |
| | | addMetaFiles(zip, params, list); |
| | | |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, pwd); |
| | | |
| | | return null; |
| | | } |
| | |
| | | private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaFileEntity> list) { |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | for (MetaFileEntity entity : list) { |
| | | String filePath = uploadPath + File.separator + entity.getPath(); |
| | | File file = new File(filePath); |
| | | File newFile = new File(filePath.replace(entity.getGuid(), entity.getName())); |
| | | |
| | | try { |
| | | file.renameTo(newFile); |
| | | zip.addFile(newFile, params); |
| | | 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, entity.getName()); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } finally { |
| | | newFile.renameTo(file); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) throws Exception { |
| | | DownloadEntity de = new DownloadEntity(); |
| | | de.setName(FileHelper.getFileName(file)); |
| | | // 1-Shp文件,2-专题图,3-元数据 |
| | | de.setType(3); |
| | | de.setSizes(FileHelper.sizeToMb(new File(file).length())); |
| | | de.setDepid(ue.getDepid()); |
| | | de.setDcount(0); |
| | | // de.setPwd(null) |
| | | de.setUrl(FileHelper.getRelativePath(file)); |
| | | de.setDescr("元数据文件"); |
| | | de.setGuid(FileHelper.getFileMd5(file)); |
| | | de.setCreateUser(ue.getId()); |
| | | // de.setGeom(null) |
| | | |
| | | return de; |
| | | } |
| | | } |