| | |
| | | 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; |
| | | |
| | | |
| | | /** |
| | | * @author 15280 |
| | | * @author 15280 secretLedger |
| | | */ |
| | | @Controller |
| | | @RequestMapping("/catAjjxx") |
| | |
| | | ReadXml2017Service readXml2017Service; |
| | | @Autowired |
| | | ReadXml2023Service readXml2023Service; |
| | | @Autowired |
| | | UpdateXml2017Service updateXml2017Service; |
| | | @Autowired |
| | | UpdateXml2023Service updateXml2023Service; |
| | | @Autowired |
| | | XmlService xmlService; |
| | | |
| | |
| | | @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); |
| | |
| | | @RequestMapping(value = "/updateXmlIndex") |
| | | @RequiresUser |
| | | public ModelAndView updateXmlIndex() { |
| | | ModelAndView mv = new ModelAndView("hn/catAjjxx/updateXmlIndex"); |
| | | ModelAndView mv = new ModelAndView("gh/catAjjxx/updateXmlIndex"); |
| | | return mv; |
| | | } |
| | | |
| | |
| | | Element rootElement = document.getRootElement(); |
| | | String rootName = rootElement.getName(); |
| | | if ("AJXX".equals(rootName)) { |
| | | // updateXml2017Service.updateXml(document, checkData, updateId); |
| | | updateXml2017Service.updateXml(document, checkData, updateId); |
| | | } else if ("DZZLXX".equals(rootName)) { |
| | | // updateXml2023Service.updateXml(document, checkData, updateId); |
| | | updateXml2023Service.updateXml(document, checkData, updateId); |
| | | } |
| | | if (checkData != null && !"".equals(checkData)) { |
| | | QueryWrapper<CatCheck> catCheckQueryWrapper = new QueryWrapper<>(); |
| | |
| | | } |
| | | |
| | | File file = new File(yswjPath); |
| | | if (file.exists() && file.isFile()) { |
| | | long fileSize = file.length(); |
| | | double fileSizeMB = fileSize / (1024.0 * 1024.0); |
| | | if (file.exists()) { |
| | | Long folderSize = getFolderSize(file); |
| | | double fileSizeMB = (double) folderSize / 1024 / 1024; |
| | | String fileSizeStr = String.format("%.2f", fileSizeMB); |
| | | catYswjxx.setWjdx(fileSizeStr); |
| | | // catYswjxx.setWjgs("pdf"); |
| | | catYswjxx.setWjlj(yswjPath); |
| | | ysSuccess++; |
| | | } else { |
| | | ysFailed++; |
| | | } |
| | | catYswjxx.setWjm(wjtm); |
| | | catYswjxxService.saveOrUpdate(catYswjxx); |
| | |
| | | return new AjaxResponse(new ErrorInfo(e.getMessage()), false); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | File file = new File("E:\\Desktop\\DD20240091\\DD20240091"); |
| | | long folderSize = getFolderSize(file); |
| | | long l = folderSize / 1024 / 1024; |
| | | long folder = (folderSize / 1024 / 1024); |
| | | System.out.println(folderSize / 1024 / 1024); |
| | | } |
| | | |
| | | public static Long getFolderSize(File folder) { |
| | | if (!folder.exists()) { |
| | | return 0L; |
| | | } |
| | | |
| | | if (folder.isFile()) { |
| | | return folder.length(); |
| | | } |
| | | |
| | | Long totalSize = 0L; |
| | | File[] files = folder.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | | if (file.isFile()) { |
| | | totalSize += file.length(); |
| | | } else if (file.isDirectory()) { |
| | | totalSize += getFolderSize(file); |
| | | } |
| | | } |
| | | } |
| | | 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(); |
| | | } |
| | | } |
| | | |