| | |
| | | import com.lf.server.mapper.data.DownloadMapper; |
| | | import com.lf.server.service.sys.AttachService; |
| | | 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; |
| | |
| | | return null; |
| | | } |
| | | |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String filePath = pathHelper.getTempPath(tempName) + File.separator + tempName; |
| | | |
| | | File file = new File(filePath); |
| | | if (file.exists() && file.isDirectory()) { |
| | | FileHelper.deleteDir(filePath); |
| | | } |
| | | |
| | | String zipName = tempName + ".zip"; |
| | | String zipName = StringHelper.YMDHMS2_FORMAT.format(new Date()) + ".zip"; |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + zipName; |
| | | |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, null); |
| | | ZipParameters params = Zip4jHelper.getZipParams(); |
| | | addZipFiles(zip, params, file.listFiles()); |
| | | addZipFiles(zip, params, list); |
| | | |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, null); |
| | | int rows = downloadMapper.insert(downloadEntity); |
| | |
| | | /** |
| | | * 添加Zip文件 |
| | | */ |
| | | private void addZipFiles(ZipFile zip, ZipParameters params, File[] files) { |
| | | if (null == files || files.length == 0) { |
| | | return; |
| | | } |
| | | |
| | | for (File f : files) { |
| | | private void addZipFiles(ZipFile zip, ZipParameters params, List<AttachEntity> list) { |
| | | int i = 1; |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | for (AttachEntity ae : list) { |
| | | try { |
| | | zip.addFile(f, params); |
| | | String filePath = uploadPath + File.separator + ae.getPath(); |
| | | |
| | | File file = new File(filePath); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | continue; |
| | | } |
| | | |
| | | zip.addFile(file, params); |
| | | FileHeader header = zip.getFileHeader(file.getName()); |
| | | if (null != header) { |
| | | zip.renameFile(header, i + "_" + ae.getName()); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |