| | |
| | | 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; |
| | |
| | | |
| | | import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM; |
| | | import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE; |
| | | import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | |
| | | /** |
| | | * 【文件材料综合信息】Controller |
| | |
| | | |
| | | @Autowired |
| | | private IArchiveRecordsService iArchiveRecordsService; |
| | | |
| | | /** |
| | | * 文件分隔符 |
| | | */ |
| | | private static final String FILE_DELIMETER = ","; |
| | | /** |
| | | * 判断PageNumber是否连续 |
| | | */ |
| | |
| | | list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials); |
| | | |
| | | } |
| | | |
| | | |
| | | ExcelUtil<DocumentMaterials> util = new ExcelUtil<DocumentMaterials>(DocumentMaterials.class); |
| | | util.exportExcel(response, list, "电子文件目录"); |
| | | } |
| | |
| | | @PostMapping("/exportDir") |
| | | public void exportDir(HttpServletResponse response, DocumentMaterials documentMaterials, @RequestParam(value = "ids", required = false) Long[] ids) |
| | | { |
| | | List<DocumentMaterials> list; |
| | | System.out.println(ids); |
| | | // 如果提供了ids参数,则根据ids导出指定记录 |
| | | if (ids != null && ids.length > 0) { |
| | | list = documentMaterialsService.selectDocumentMaterialsByIds(ids); |
| | | } else { |
| | | list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials); |
| | | ArchiveRecords archiveRecords = iArchiveRecordsService.selectArchiveRecordsById(documentMaterials.getRecordId()); |
| | | List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(documentMaterials.getRecordId().toString(), archiveRecords.getPageCount()); |
| | | |
| | | } |
| | | // 根据visible字段筛选,只保留visible为1的记录 |
| | | List<DocumentMaterials> filteredList = list.stream() |
| | | .filter(doc -> doc.getVisible() != null && doc.getVisible() == 1 && !Objects.equals(doc.getFileStyle(), "其他材料")) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 使用AtomicLong实现序号的递增 |
| | | AtomicLong nm = new AtomicLong(1L); |
| | | // 将筛选后的DocumentMaterials转换为DocumentMaterialsVo |
| | | List<DocumentMaterialsVoSmall> list1 = filteredList.stream().map(doc -> { |
| | | DocumentMaterialsVoSmall vo = new DocumentMaterialsVoSmall(); |
| | | // 手动映射字段,使用getAndIncrement()方法获取当前值并递增 |
| | | vo.setNum(nm.getAndIncrement()); |
| | | 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()); |
| | | |
| | | vo.setDocumentNumber(doc.getDocumentNumber()); |
| | | vo.setCreator(doc.getCreator()); |
| | | vo.setTitle(doc.getTitle()); |
| | | vo.setDate(doc.getDate()); |
| | | vo.setPageNumberFormatted(doc.getPageNumber().toString()); |
| | | vo.setRemarks(doc.getRemarks()); |
| | | // vo.setRecordId(doc.getRecordId() != null ? doc.getRecordId().toString() : null); |
| | | // vo.setPublicity(doc.getPublicity()); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | // List<DocumentMaterials> list; |
| | | // System.out.println(ids); |
| | | // // 如果提供了ids参数,则根据ids导出指定记录 |
| | | // if (ids != null && ids.length > 0) { |
| | | // list = documentMaterialsService.selectDocumentMaterialsByIds(ids); |
| | | // } else { |
| | | // list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials); |
| | | // |
| | | // } |
| | | // // 根据visible字段筛选,只保留visible为1的记录 |
| | | // List<DocumentMaterials> filteredList = list.stream() |
| | | // .filter(doc -> doc.getVisible() != null && doc.getVisible() == 1 && !Objects.equals(doc.getFileStyle(), "其他材料")) |
| | | // .collect(Collectors.toList()); |
| | | // |
| | | // // 使用AtomicLong实现序号的递增 |
| | | // AtomicLong nm = new AtomicLong(1L); |
| | | // // 将筛选后的DocumentMaterials转换为DocumentMaterialsVo |
| | | // List<DocumentMaterialsVoSmall> list1 = filteredList.stream().map(doc -> { |
| | | // DocumentMaterialsVoSmall vo = new DocumentMaterialsVoSmall(); |
| | | // // 手动映射字段,使用getAndIncrement()方法获取当前值并递增 |
| | | // vo.setNum(nm.getAndIncrement()); |
| | | // |
| | | // vo.setDocumentNumber(doc.getDocumentNumber()); |
| | | // vo.setCreator(doc.getCreator()); |
| | | // vo.setTitle(doc.getTitle()); |
| | | // vo.setDate(doc.getDate()); |
| | | // vo.setPageNumberFormatted(doc.getPageNumber().toString()); |
| | | // vo.setRemarks(doc.getRemarks()); |
| | | //// vo.setRecordId(doc.getRecordId() != null ? doc.getRecordId().toString() : null); |
| | | //// vo.setPublicity(doc.getPublicity()); |
| | | // return vo; |
| | | // }).collect(Collectors.toList()); |
| | | |
| | | ExcelUtil<DocumentMaterialsVoSmall> util = new ExcelUtil<DocumentMaterialsVoSmall>(DocumentMaterialsVoSmall.class); |
| | | util.exportExcel(response, list1, "卷内目录"); |
| | | util.exportExcel(response, list2, "卷内目录"); |
| | | } |
| | | |
| | | // List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString()); |
| | |
| | | |
| | | 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"; |
| | |
| | | String compName = "广州盈家档案管理有限公司"; |
| | | String li_person = "仇翀"; |
| | | String sh_person = "曾瑞莹"; |
| | | |
| | | ArchiveRecords archiveRecords = iArchiveRecordsService.selectArchiveRecordsById(id); |
| | | if(!StringUtils.isEmpty(archiveRecords.getLiPerson())) |
| | | li_person = archiveRecords.getLiPerson(); |
| | | String note_remark = ""; |
| | | if(!StringUtils.isEmpty(archiveRecords.getNoteRemark())) |
| | | note_remark = ","+archiveRecords.getNoteRemark(); |
| | | System.out.println(note_remark+"{{{{"); |
| | | ArchiveProjectName tmp = new ArchiveProjectName(); |
| | | tmp.setName(archiveRecords.getProjectName()); |
| | | List<ArchiveProjectName> projectName = iArchiveProjectNameService.selectArchiveProjectNameList(tmp); |
| | |
| | | hs.put("company", compName); |
| | | hs.put("liPerson", li_person); |
| | | hs.put("shPerson", sh_person); |
| | | hs.put("noteRemark", note_remark); |
| | | hs.put("time", cdt); |
| | | |
| | | if (!getLicense()) { |
| | |
| | | @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(), |
| | |
| | | |
| | | } |
| | | |
| | | @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<>(); |
| | | 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("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()); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |