| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String tempPath = pathHelper.getTempPath(tempName); |
| | | String gdbPath = tempPath + File.separator + "tabs.gdb"; |
| | | String annexPath = tempPath + File.separator + "annex"; |
| | | |
| | | File gdbFile = new File(gdbPath); |
| | | if (gdbFile.exists() && gdbFile.isDirectory()) { |
| | |
| | | } |
| | | GdbHelper.createGdb(gdbPath, dataMap); |
| | | |
| | | File annexFile = new File(annexPath); |
| | | if (!annexFile.exists() || !annexFile.isDirectory()) { |
| | | annexFile.mkdirs(); |
| | | } |
| | | createAnnex(annexPath, annexMap); |
| | | |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".gdb.zip"; |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, dr.getPwd()); |
| | | ZipParameters params = Zip4jHelper.getZipParams(true); |
| | | zip.addFolder(new File(gdbPath), params); |
| | | zip.addFolder(new File(annexPath), params); |
| | | // zip.addFolder(new File(annexPath), params) |
| | | addAnnex(zip, params, annexMap); |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); |
| | | DownloadEntity downloadEntity = getDownloadEntity(ue, zipFile, dbPwd); |
| | |
| | | } |
| | | |
| | | if (!annexMap.containsKey(entity)) { |
| | | annexMap.put(entity, annex); |
| | | annexMap.put(tab.replace(".", "_"), annex); |
| | | } else { |
| | | annexMap.get(entity).addAll(annex); |
| | | annexMap.get(tab.replace(".", "_")).addAll(annex); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 创建附件 |
| | | * 创建附件 * |
| | | */ |
| | | private void createAnnex(String annexPath, Map<String, List<AttachEntity>> annexMap) { |
| | | if (annexMap.size() == 0) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 添加附件 |
| | | */ |
| | | private void addAnnex(ZipFile zip, ZipParameters params, Map<String, List<AttachEntity>> annexMap) { |
| | | List<String> files = new ArrayList<>(); |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | | for (String key : annexMap.keySet()) { |
| | | for (AttachEntity ae : annexMap.get(key)) { |
| | | try { |
| | | File srcFile = new File(uploadPath + File.separator + ae.getPath()); |
| | | if (!srcFile.exists() || srcFile.isDirectory()) { |
| | | continue; |
| | | } |
| | | if (files.contains(srcFile.getPath())) { |
| | | continue; |
| | | } |
| | | |
| | | files.add(srcFile.getPath()); |
| | | params.setFileNameInZip(key + File.separator + ae.getName()); |
| | | zip.addStream(new FileInputStream(srcFile), params); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { |