| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.zip.ZipFile; |
| | | |
| | | import static cn.hutool.core.util.ZipUtil.unzip; |
| | | import static com.zbooksoft.gdmis.common.XmlUtil.getDocument; |
| | | |
| | | |
| | |
| | | @RequiresUser |
| | | public Object importXML(@RequestParam(value = "file", required = false) MultipartFile file, String startData, String endData) { |
| | | try { |
| | | Document document = getDocument(file); |
| | | Element rootElement = document.getRootElement(); |
| | | String rootName = rootElement.getName(); |
| | | xmlService.readXml(document, startData, endData); |
| | | ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class); |
| | | String uploadPath = archivesCustomConfig.getOriginalPath(); |
| | | //判断传过来的文件是不是压缩包 |
| | | if (file.getOriginalFilename().endsWith(".zip")) { |
| | | String tempDir = System.getProperty("java.io.tmpdir"); |
| | | String extractPath = tempDir + File.separator + "temp_" + System.currentTimeMillis(); |
| | | File extractDir = new File(extractPath); |
| | | extractDir.mkdirs(); |
| | | String originalFilename = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); |
| | | try { |
| | | // 保存上传的 ZIP 文件到临时位置 |
| | | File zipFile = new File(extractPath + File.separator + file.getOriginalFilename()); |
| | | file.transferTo(zipFile); |
| | | // 解压 ZIP 文件 |
| | | unzip(zipFile.getAbsolutePath(), uploadPath); |
| | | |
| | | String xmlPath = uploadPath + File.separator + originalFilename + File.separator + "管理性文件" + File.separator + "资料文件目录.xml"; |
| | | Document document = getDocument(xmlPath); |
| | | xmlService.readXml(document, startData, endData); |
| | | } finally { |
| | | // 清理临时文件 |
| | | deleteDir(extractDir); |
| | | } |
| | | |
| | | } else { |
| | | Document document = getDocument(file); |
| | | xmlService.readXml(document, startData, endData); |
| | | } |
| | | return new AjaxResponse(true); |
| | | } catch (Exception e) { |
| | | logger.error(e.getMessage(), e); |
| | |
| | | |
| | | File file = new File(yswjPath); |
| | | if (file.exists()) { |
| | | long folderSize = getFolderSize(file); |
| | | long fileSizeMB = folderSize / 1024 / 1024; |
| | | Long folderSize = getFolderSize(file); |
| | | double fileSizeMB = (double) folderSize / 1024 / 1024; |
| | | String fileSizeStr = String.format("%.2f", fileSizeMB); |
| | | catYswjxx.setWjdx(fileSizeStr); |
| | | catYswjxx.setWjlj(yswjPath); |
| | |
| | | System.out.println(folderSize / 1024 / 1024); |
| | | } |
| | | |
| | | public static long getFolderSize(File folder) { |
| | | public static Long getFolderSize(File folder) { |
| | | if (!folder.exists()) { |
| | | return 0; |
| | | return 0L; |
| | | } |
| | | |
| | | if (folder.isFile()) { |
| | | return folder.length(); |
| | | } |
| | | |
| | | long totalSize = 0; |
| | | Long totalSize = 0L; |
| | | File[] files = folder.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | |
| | | } |
| | | return totalSize; |
| | | } |
| | | |
| | | private void deleteDir(File dir) { |
| | | if (dir.isDirectory()) { |
| | | File[] files = dir.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | | deleteDir(file); |
| | | } |
| | | } |
| | | } |
| | | dir.delete(); |
| | | } |
| | | } |
| | | |