| | |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | import java.util.zip.ZipEntry; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | @PostMapping("/exportDir") |
| | | public void exportDir(HttpServletResponse response, DocumentMaterials documentMaterials, @RequestParam(value = "ids", required = false) Long[] ids) |
| | | { |
| | | |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(documentMaterials.getRecordId().toString()); |
| | | ArchiveRecords archiveRecords = iArchiveRecordsService.selectArchiveRecordsById(documentMaterials.getRecordId()); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(documentMaterials.getRecordId().toString(), archiveRecords.getPageCount()); |
| | | |
| | | List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(), |
| | | res1.getTitle(), res1.getDate(), res1.getPageNumberFormatted(), res1.getRemarks())).collect(Collectors.toList()); |
| | |
| | | |
| | | public String getPageSize(double du) |
| | | { |
| | | if(du <= 8699840) |
| | | if(du <= 8699840 * 1.5) |
| | | return "A4"; |
| | | else if(du <= 17403188) |
| | | else if(du <= 17403188 * 1.5) |
| | | return "A3"; |
| | | else if(du <= 34811347) |
| | | else if(du <= 34811347 * 1.5) |
| | | return "A2"; |
| | | else if(du <= 69622674) |
| | | else if(du <= 69622674 * 1.5) |
| | | return "A1"; |
| | | else |
| | | return "A0"; |
| | |
| | | @PostMapping("/exportJuan/{id}") |
| | | |
| | | public void exportJuanInfo(HttpServletResponse response, @PathVariable Long id) throws IOException { |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString()); |
| | | |
| | | ArchiveRecords archiveRecords = iArchiveRecordsService.selectArchiveRecordsById(id); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString(), archiveRecords.getPageCount()); |
| | | |
| | | //拿到卷内目录的excel |
| | | List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(), |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/uploads/{recordId}") |
| | | public AjaxResult uploadFiles(List<MultipartFile> files, @PathVariable Long recordId) throws Exception { |
| | | try { |
| | | @PreAuthorize("@ss.hasPermi('system:materials:list')") |
| | | @GetMapping("/getFileCounts/{recordId}") |
| | | public AjaxResult getFileCounts(@PathVariable("recordId") Integer recordId) throws IOException { |
| | | //上传的时候判断最多只能上传多少个 |
| | | // 上传文件路径 |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | String path = filePath + File.separator + recordId; |
| | | File desc = new File(filePath + File.separator + recordId); |
| | | System.out.println("44444444444444456666666666666666"); |
| | | if (!desc.exists()) |
| | | { |
| | | ajax.put("length", 0); |
| | | // ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); |
| | | // ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); |
| | | // ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); |
| | | return ajax; |
| | | } |
| | | |
| | | |
| | | Map<String, String> fileMap = new HashMap<>(); |
| | | try (Stream<Path> paths = Files.walk(Paths.get(path))) { |
| | | fileMap = paths |
| | | .filter(Files::isRegularFile) |
| | | .collect(Collectors.toMap( |
| | | // Key: 文件名前缀(不带扩展名) |
| | | Path -> { |
| | | String fileNam = Path.getFileName().toString(); |
| | | int dotIndex = fileNam.lastIndexOf('.'); |
| | | return dotIndex > 0 ? fileNam.substring(0, dotIndex) : fileNam; |
| | | }, |
| | | // Value: 文件全路径 |
| | | Path::toString, |
| | | // 处理重复键的情况(如果有相同前缀的文件) |
| | | (existing, replacement) -> existing |
| | | )); |
| | | System.out.println(fileMap); |
| | | |
| | | ajax.put("length", fileMap.size()); |
| | | // ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); |
| | | // ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); |
| | | // ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); |
| | | return ajax; |
| | | } |
| | | } |
| | | @PostMapping("/uploads/{recordId}") |
| | | public AjaxResult uploadFiles(MultipartFile file, @PathVariable Long recordId) throws Exception { |
| | | try { |
| | | |
| | | //上传的时候判断最多只能上传多少个 |
| | | // 上传文件路径 |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | |
| | | String path = filePath + File.separator + recordId; |
| | | File desc = new File(filePath + File.separator + recordId); |
| | | System.out.println("44444444444444456666666666666666"); |
| | | if (!desc.exists()) |
| | | { |
| | | System.out.println("4444444444444445688888666666666666666"); |
| | | System.out.println(desc.getParentFile().exists()); |
| | | if (!desc.exists()) |
| | | { |
| | | desc.mkdirs(); |
| | | } |
| | | } |
| | | |
| | | String fileName = FileUploadUtils.uploadImg(filePath + File.separator + recordId, file); |
| | | List<String> urls = new ArrayList<>(); |
| | | List<String> fileNames = new ArrayList<>(); |
| | | List<String> newFileNames = new ArrayList<>(); |
| | | List<String> originalFilenames = new ArrayList<>(); |
| | | |
| | | // 批量处理文件上传 |
| | | for (MultipartFile file : files) { |
| | | // 根据文件名称,然后修改对应数据的url |
| | | String fname = file.getOriginalFilename(); |
| | | if (StringUtils.isBlank(fname)) { |
| | | continue; |
| | | } |
| | | |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | |
| | | // 分割文件名 |
| | | String[] nams = fname.split("\\."); |
| | | if (nams.length < 2) { |
| | | continue; |
| | | } |
| | | |
| | | Long nam = Long.parseLong(nams[0]); |
| | | |
| | | // 根据页号拿到案卷的详细信息 |
| | | DocumentMaterials doc = documentMaterialsService.selectByPageNumber(nam, Math.toIntExact(recordId)); |
| | | if (doc != null) { |
| | | if (doc.getSecurityLevel() != null && (doc.getSecurityLevel().equals("该页另存")|| |
| | | doc.getSecurityLevel().equals("秘密")||doc.getSecurityLevel().equals("内部用途")|| |
| | | doc.getSecurityLevel().equals("内部用图"))) { |
| | | // 替换为了准备好的图像 |
| | | String fp = filePath + "\\glc.jpg"; |
| | | Path path = Paths.get(fp); |
| | | // 拿到图像属性 |
| | | BufferedImage bufferedImage = ImageIO.read(Files.newInputStream(path)); |
| | | int wid = bufferedImage.getWidth(); |
| | | int hei = bufferedImage.getHeight(); |
| | | double sz = Double.parseDouble(String.format("%.2f", Files.size(path) * 1.0 / 1024)); |
| | | |
| | | // 拿到图像的dpi信息 |
| | | ImageInfo info = Imaging.getImageInfo(Files.readAllBytes(path)); |
| | | int wdpi = info.getPhysicalWidthDpi(); |
| | | int hdpi = info.getPhysicalHeightDpi(); |
| | | |
| | | // 计算fileNumber |
| | | Long fileNumber = documentMaterialsService.getFiNum(nam, recordId); |
| | | // 计算sizeType |
| | | String sizeType = getPageSize(wid * hei); |
| | | |
| | | Graphics2D g2d = bufferedImage.createGraphics(); |
| | | g2d.setFont(new Font("Arial", Font.BOLD, 80)); |
| | | g2d.setColor(Color.black); |
| | | String pageNumber = doc.getPageNumber() + ""; |
| | | int fontHeight = g2d.getFontMetrics().getHeight(); |
| | | int x = bufferedImage.getWidth() - g2d.getFontMetrics().stringWidth(pageNumber) - 80; |
| | | int y = bufferedImage.getHeight() - fontHeight / 2 - 100; |
| | | g2d.drawString(pageNumber, x, y); |
| | | g2d.dispose(); |
| | | |
| | | // 将BufferedImage转换为MultipartFile |
| | | MultipartFile multipartFile = null; |
| | | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| | | ImageIO.write(bufferedImage, "jpg", os); |
| | | InputStream input = new ByteArrayInputStream(os.toByteArray()); |
| | | multipartFile = new MockMultipartFile(pageNumber, pageNumber + ".jpg", "text/plain", input); |
| | | |
| | | // 上传并返回新文件名称 |
| | | String fileName1 = FileUploadUtils.upload(filePath, multipartFile); |
| | | |
| | | // 更新数据库 |
| | | documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName1, "jpg", recordId); |
| | | |
| | | urls.add(serverConfig.getUrl() + fileName1); |
| | | fileNames.add(fileName1); |
| | | newFileNames.add(FileUtils.getName(fileName1)); |
| | | originalFilenames.add(pageNumber + ".jpg"); |
| | | } else { |
| | | // 文件名称 |
| | | String pname = nams[1]; |
| | | |
| | | // 拿到图像属性 |
| | | BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); |
| | | int wid = bufferedImage.getWidth(); |
| | | int hei = bufferedImage.getHeight(); |
| | | double sz = Double.parseDouble(String.format("%.2f", file.getSize() * 1.0 / 1024)); |
| | | |
| | | // 拿到图像的dpi信息 |
| | | ImageInfo info = Imaging.getImageInfo(file.getBytes()); |
| | | int wdpi = info.getPhysicalWidthDpi(); |
| | | int hdpi = info.getPhysicalHeightDpi(); |
| | | |
| | | // 计算fileNumber |
| | | Long fileNumber = documentMaterialsService.getFiNum(nam, recordId); |
| | | // 计算sizeType |
| | | String sizeType = getPageSize(wid * hei); |
| | | |
| | | // 更新数据库 |
| | | documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName, pname, recordId); |
| | | |
| | | urls.add(url); |
| | | fileNames.add(fileName); |
| | | newFileNames.add(FileUtils.getName(fileName)); |
| | | originalFilenames.add(fname); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Map<String, String> fileMap = new HashMap<>(); |
| | | try (Stream<Path> paths = Files.walk(Paths.get(path))) { |
| | | fileMap = paths |
| | | .filter(Files::isRegularFile) |
| | | .collect(Collectors.toMap( |
| | | // Key: 文件名前缀(不带扩展名) |
| | | Path -> { |
| | | String fileNam = Path.getFileName().toString(); |
| | | int dotIndex = fileNam.lastIndexOf('.'); |
| | | return dotIndex > 0 ? fileNam.substring(0, dotIndex) : fileNam; |
| | | }, |
| | | // Value: 文件全路径 |
| | | Path::toString, |
| | | // 处理重复键的情况(如果有相同前缀的文件) |
| | | (existing, replacement) -> existing |
| | | )); |
| | | System.out.println(fileMap); |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); |
| | | ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); |
| | | ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); |
| | | ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); |
| | | ajax.put("length", file.getSize()); |
| | | // ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); |
| | | // ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); |
| | | // ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); |
| | | return ajax; |
| | | } |
| | | //读取 |
| | | // |
| | | // |
| | | // // 批量处理文件上传 |
| | | // for (MultipartFile file : files) { |
| | | // // 根据文件名称,然后修改对应数据的url |
| | | // String fname = file.getOriginalFilename(); |
| | | // if (StringUtils.isBlank(fname)) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // // 上传并返回新文件名称 |
| | | // String fileName = FileUploadUtils.upload(filePath, file); |
| | | // String url = serverConfig.getUrl() + fileName; |
| | | // |
| | | // // 分割文件名 |
| | | // String[] nams = fname.split("\\."); |
| | | // if (nams.length < 2) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // Long nam = Long.parseLong(nams[0]); |
| | | // |
| | | // // 根据页号拿到案卷的详细信息 |
| | | // DocumentMaterials doc = documentMaterialsService.selectByPageNumber(nam, Math.toIntExact(recordId)); |
| | | // if (doc != null) { |
| | | // if (doc.getSecurityLevel() != null && (doc.getSecurityLevel().equals("该页另存")|| |
| | | // doc.getSecurityLevel().equals("秘密")||doc.getSecurityLevel().equals("内部用途")|| |
| | | // doc.getSecurityLevel().equals("内部用图"))) { |
| | | // // 替换为了准备好的图像 |
| | | // String fp = filePath + "\\glc.jpg"; |
| | | // Path path = Paths.get(fp); |
| | | // // 拿到图像属性 |
| | | // BufferedImage bufferedImage = ImageIO.read(Files.newInputStream(path)); |
| | | // int wid = bufferedImage.getWidth(); |
| | | // int hei = bufferedImage.getHeight(); |
| | | // double sz = Double.parseDouble(String.format("%.2f", Files.size(path) * 1.0 / 1024)); |
| | | // |
| | | // // 拿到图像的dpi信息 |
| | | // ImageInfo info = Imaging.getImageInfo(Files.readAllBytes(path)); |
| | | // int wdpi = info.getPhysicalWidthDpi(); |
| | | // int hdpi = info.getPhysicalHeightDpi(); |
| | | // |
| | | // // 计算fileNumber |
| | | // Long fileNumber = documentMaterialsService.getFiNum(nam, recordId); |
| | | // // 计算sizeType |
| | | // String sizeType = getPageSize(wid * hei); |
| | | // |
| | | // Graphics2D g2d = bufferedImage.createGraphics(); |
| | | // g2d.setFont(new Font("Arial", Font.BOLD, 80)); |
| | | // g2d.setColor(Color.black); |
| | | // String pageNumber = doc.getPageNumber() + ""; |
| | | // int fontHeight = g2d.getFontMetrics().getHeight(); |
| | | // int x = bufferedImage.getWidth() - g2d.getFontMetrics().stringWidth(pageNumber) - 80; |
| | | // int y = bufferedImage.getHeight() - fontHeight / 2 - 100; |
| | | // g2d.drawString(pageNumber, x, y); |
| | | // g2d.dispose(); |
| | | // |
| | | // // 将BufferedImage转换为MultipartFile |
| | | // MultipartFile multipartFile = null; |
| | | // ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| | | // ImageIO.write(bufferedImage, "jpg", os); |
| | | // InputStream input = new ByteArrayInputStream(os.toByteArray()); |
| | | // multipartFile = new MockMultipartFile(pageNumber, pageNumber + ".jpg", "text/plain", input); |
| | | // |
| | | // // 上传并返回新文件名称 |
| | | // String fileName1 = FileUploadUtils.upload(filePath, multipartFile); |
| | | // |
| | | // // 更新数据库 |
| | | // documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName1, "jpg", recordId); |
| | | // |
| | | // urls.add(serverConfig.getUrl() + fileName1); |
| | | // fileNames.add(fileName1); |
| | | // newFileNames.add(FileUtils.getName(fileName1)); |
| | | // originalFilenames.add(pageNumber + ".jpg"); |
| | | // } else { |
| | | // // 文件名称 |
| | | // String pname = nams[1]; |
| | | // |
| | | // // 拿到图像属性 |
| | | // BufferedImage bufferedImage = ImageIO.read(file.getInputStream()); |
| | | // int wid = bufferedImage.getWidth(); |
| | | // int hei = bufferedImage.getHeight(); |
| | | // double sz = Double.parseDouble(String.format("%.2f", file.getSize() * 1.0 / 1024)); |
| | | // |
| | | // // 拿到图像的dpi信息 |
| | | // ImageInfo info = Imaging.getImageInfo(file.getBytes()); |
| | | // int wdpi = info.getPhysicalWidthDpi(); |
| | | // int hdpi = info.getPhysicalHeightDpi(); |
| | | // // 计算fileNumber |
| | | // Long fileNumber = documentMaterialsService.getFiNum(nam, recordId); |
| | | // // 计算sizeType |
| | | // String sizeType = getPageSize(wid * hei); |
| | | // |
| | | // // 更新数据库 |
| | | // documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName, pname, recordId); |
| | | // |
| | | // urls.add(url); |
| | | // fileNames.add(fileName); |
| | | // newFileNames.add(FileUtils.getName(fileName)); |
| | | // originalFilenames.add(fname); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | log.error("批量上传文件失败", e); |
| | | return AjaxResult.error(e.getMessage()); |