archiveManager/src/main/java/com/ruoyi/domain/DocumentMaterials.java
@@ -159,6 +159,8 @@ private Integer visible; /** $column.columnComment */ private Date updatedAt; @Excel(name = "文件类型", headerColor = IndexedColors.BLACK) private String fileStyle; public String getUrl() { archiveManager/src/main/java/com/ruoyi/domain/vo/ArchiveInfoVo.java
@@ -50,6 +50,8 @@ private Long pageCount; } archiveManager/src/main/java/com/ruoyi/mapper/ArchiveRecordsMapper.java
@@ -45,7 +45,7 @@ @Select("UPDATE `archivesys`.`archive_records` SET `inquiry_number` = '', `case_title` = NULL, `public_attribute` = NULL, `preparation_unit` = NULL, `preparation_date` = NULL, `retention_period` = NULL, `security_classification` = NULL, `page_count` = NULL, `filing_number` = NULL, `construction_unit` = NULL, `construction_address` = NULL, `project_name` = '', `project_number` = NULL, `scanning_company` = NULL, `archive_room_number` = NULL, `microfilm_number` = NULL, `remarks` = NULL, `historical_reference_number` = NULL, `record_status` = '待修改', `every_project_name` = NULL WHERE `id` = #{id}") Long updateAllInfoById(@Param("id") Long id); @Select("select record_id,archive_room_number,microfilm_number,inquiry_number,case_title,preparation_date,preparation_unit,retention_period,security_classification from archive_records where id=#{id}") @Select("select record_id,page_count,archive_room_number,microfilm_number,inquiry_number,case_title,preparation_date,preparation_unit,retention_period,security_classification from archive_records where id=#{id}") ArchiveInfoVo findByRecordId(@Param("id") Long id); @Select("SELECT every_project_name, count(*) as cnt, (select count(*) from archive_records as ac where ac.every_project_name=ar.every_project_name and record_status='未录入') as unfinished,\n" + archiveManager/src/main/java/com/ruoyi/service/IArchiveRecordsService.java
@@ -92,7 +92,7 @@ List<AnalysisResult> statisticAya(); public int updateArchiveById(String status, Long id); public int updateArchiveById(String status, Long id, String operator); public int updateStatusByIds(Long [] ids); public List<ArchiveRecordSmall> findByIds(ArchiveRecords archiveRecords); archiveManager/src/main/java/com/ruoyi/service/IDocumentMaterialsService.java
@@ -40,7 +40,7 @@ public List<DocumentMaterialsVoLarge> selectDocumentMaterialsAllByRecordId(Long id); public List<DocumentMaterials> SelectAllRecordsByPageNumbersToList(Long recordId, Long maxPageNumber); public List<DocumentMaterialsFileList> selectDocumentMaterialsFileList(Long id); /** * 新增【请填写功能名称】 @@ -76,7 +76,7 @@ public int deleteDocumentMaterialsByMaterialId(String materialId); public Long getFiNum(Long pageNumber, Long recordId); public int updateByPageNumber(Long pageNumber,String sizeType, Long fileNumber, int wid, int hei, int wdpi, int hdpi, double sz,String url,String format, Long recordId); public List<DocumentMaterialsVo> findArchMInfo(String recordId); public List<DocumentMaterialsVo> findArchMInfo(String recordId, long pageCount); public List<DocumentMaterialFileStyle> findFileStyleInfo(@Param("recordId") int recordId); archiveManager/src/main/java/com/ruoyi/service/impl/ArchiveRecordsServiceImpl.java
@@ -403,14 +403,15 @@ } @Override public int updateArchiveById(String status, Long id) { public int updateArchiveById(String status, Long id, String operator) { LocalDateTime time = LocalDateTime.now(); Date date = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()); // 获取当前用户ID Long userId = SecurityUtils.getUserId(); // 可以在这里使用userId进行授权操作 archiverecordstouserService.deleteArchiverecordstouserByRecordId(id, userId); if(operator.equals("退回管理员")) archiverecordstouserService.deleteArchiverecordstouserByRecordId(id, userId); this.baseMapper.updateStatusById(status, id, date); return 0; } archiveManager/src/main/java/com/ruoyi/service/impl/DocumentMaterialsServiceImpl.java
@@ -302,12 +302,13 @@ } @Override public List<DocumentMaterialsVo> findArchMInfo(String recordId) { public List<DocumentMaterialsVo> findArchMInfo(String recordId, long pageCount) { // 获取原始数据列表 List<DocumentMaterialsVo> dataList = this.baseMapper.getArchiveMatInfo(Integer.parseInt(recordId)); // 获取该案卷的最大页号(总页数) Long totalPages = this.baseMapper.getMaxPageNumber(Integer.parseInt(recordId)); Long totalPages = (long) pageCount; //this.baseMapper.getMaxPageNumber(Integer.parseInt(recordId)); // 如果数据列表不为空 if (dataList != null && !dataList.isEmpty() && totalPages != null) { @@ -416,7 +417,114 @@ public int getFileCount(Integer recordId) { return this.baseMapper.getCount(recordId); } public List<DocumentMaterials> SelectAllRecordsByPageNumbersToList(Long recordId, Long maxPageNumber) { // 获取指定recordId下的所有记录,按页号升序排列 LambdaQueryWrapper<DocumentMaterials> lqw = new LambdaQueryWrapper<>(); lqw.eq(DocumentMaterials::getRecordId, recordId); lqw.ne(DocumentMaterials::getFileStyle, "其他材料"); lqw.orderByAsc(DocumentMaterials::getPageNumber); List<DocumentMaterials> records = this.list(lqw); if (records == null || records.isEmpty()) { // return AjaxResult.success("没有找到指定记录"); return null; } List<DocumentMaterials> middleRecords = new ArrayList<>(); int startFileNumber = 1; // 遍历记录,找出需要添加中间页号的位置 for (int i = 0; i < records.size() - 1; i++) { // startFileNumber = 1; int pageOrderNumber = 1; DocumentMaterials currentRecord = records.get(i); DocumentMaterials nextRecord = records.get(i + 1); currentRecord.setFileNumber((long) startFileNumber); currentRecord.setPageOrder((long) pageOrderNumber++); middleRecords.add(currentRecord); long currentPage = currentRecord.getPageNumber(); long nextPage = nextRecord.getPageNumber(); // 如果当前页号和下一页号之间有间隔 if (nextPage - currentPage > 1) { // 添加中间页号的记录,信息与当前记录保持一致 for (long page = currentPage + 1; page < nextPage; page++) { DocumentMaterials newRecord = new DocumentMaterials(); // 复制当前记录的所有属性 BeanUtils.copyBeanProp(newRecord, currentRecord); // 设置新的页号 newRecord.setPageNumber(page); // 清除ID,确保是新记录 newRecord.setMaterialId(null); // 设置创建时间 newRecord.setCreatedAt(new Date()); // 重置文件材料序号为null,让系统自动生成 newRecord.setFileNumber((long) startFileNumber); // 重置页次为null,让系统自动生成 newRecord.setPageOrder((long) pageOrderNumber++); // 重置图像相关字段,以便上传文件时更新 newRecord.setSizeType(null); newRecord.setWidth(null); newRecord.setHeight(null); newRecord.setHorizontalResolution(null); newRecord.setVerticalResolution(null); newRecord.setFileSize(null); newRecord.setFormat(null); newRecord.setUrl(null); //不在前端显示 newRecord.setVisible(0); // 添加到中间记录列表 middleRecords.add(newRecord); } } //下一次加1 startFileNumber++; } // 处理最后一条记录到maxPageNumber之间的间隔 // int startLastFileNumber = 1; DocumentMaterials lastRecord = records.get(records.size() - 1); lastRecord.setFileNumber((long) startFileNumber); int lastpageordernumber = 1; lastRecord.setPageOrder((long) lastpageordernumber); long lastPage = lastRecord.getPageNumber(); middleRecords.add(lastRecord); if (maxPageNumber > lastPage) { // 添加从lastPage+1到maxPageNumber之间的中间记录 for (long page = lastPage + 1; page <= maxPageNumber; page++) { DocumentMaterials newRecord = new DocumentMaterials(); // 复制最后一条记录的所有属性 BeanUtils.copyBeanProp(newRecord, lastRecord); // 设置新的页号 newRecord.setPageNumber(page); // 清除ID,确保是新记录 newRecord.setMaterialId(null); // 设置创建时间 newRecord.setCreatedAt(new Date()); // 重置文件材料序号为null,让系统自动生成 newRecord.setFileNumber((long) startFileNumber); // 重置页次为null,让系统自动生成 newRecord.setPageOrder((long) lastpageordernumber++); // 重置图像相关字段,以便上传文件时更新 newRecord.setSizeType(null); newRecord.setWidth(null); newRecord.setHeight(null); newRecord.setHorizontalResolution(null); newRecord.setVerticalResolution(null); newRecord.setFileSize(null); newRecord.setFormat(null); newRecord.setUrl(null); newRecord.setVisible(0); // 添加到中间记录列表 middleRecords.add(newRecord); } } return middleRecords; } @Override public AjaxResult addMiddleRecordsByPageNumbers(Long recordId, Long maxPageNumber) { try { ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java
@@ -193,9 +193,9 @@ @PreAuthorize("@ss.hasPermi('system:records:edit')") @Log(title = "修改状态", businessType = BusinessType.IMPORT) @GetMapping(value = "/updateStatusById/{status}/{id}") public AjaxResult updateStatusById(@PathVariable("status") String status, @PathVariable("id") String id) { return new AjaxResult(200, archiveRecordsService.updateArchiveById(status, Long.parseLong(id)) + ""); @GetMapping(value = "/updateStatusById/{status}/{id}/{operator}") public AjaxResult updateStatusById(@PathVariable("status") String status, @PathVariable("id") String id, @PathVariable("operator") String operator) { return new AjaxResult(200, archiveRecordsService.updateArchiveById(status, Long.parseLong(id), operator)+""); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
@@ -15,6 +15,7 @@ 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; @@ -187,8 +188,8 @@ @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()); @@ -282,13 +283,13 @@ 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"; @@ -596,7 +597,9 @@ @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(), @@ -675,127 +678,207 @@ } @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(List<MultipartFile> files, @PathVariable Long recordId) throws Exception { 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("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); // } // } // } 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)); return ajax; } catch (Exception e) { log.error("批量上传文件失败", e); return AjaxResult.error(e.getMessage()); ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
@@ -4,11 +4,16 @@ import cn.hutool.core.date.DateUtil; import com.aspose.cells.PdfCompliance; import com.aspose.words.License; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.deepoove.poi.XWPFTemplate; import com.itextpdf.text.*; import com.itextpdf.text.Image; import com.itextpdf.text.pdf.PdfPCell; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.poi.*; import com.ruoyi.domain.ArchiveProjectName; @@ -21,18 +26,29 @@ import com.ruoyi.service.impl.BarcodeService; import com.ruoyi.service.impl.pdfGenerateService; import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.Imaging; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.awt.*; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -40,6 +56,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -499,7 +516,7 @@ for(int i = 0; i < ids.length; i++) { System.out.println(ids[i]); ArchiveRecords archiveRecords1 = iArchiveRecordsService.selectArchiveRecordsById(ids[i]); // 获取文件的保存位置,读取数据库, DocumentMaterials documentMaterials = new DocumentMaterials(); documentMaterials.setRecordId(ids[i]); @@ -508,7 +525,7 @@ //.selectDocumentMaterialsList(documentMaterials); List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(ids[i].toString()); List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(ids[i].toString(), archiveRecords1.getPageCount()); ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(ids[i]); System.out.println(aIV.getInquiryNumber()); System.out.println(aIV.getRecordId()); @@ -604,7 +621,7 @@ String compName = "广州盈家档案管理有限公司"; String li_person = "仇翀"; String sh_person = "曾瑞莹"; ArchiveRecords archiveRecords1 = iArchiveRecordsService.selectArchiveRecordsById(ids[i]); if(!StringUtils.isEmpty(archiveRecords1.getLiPerson())) li_person = archiveRecords1.getLiPerson(); ArchiveProjectName tmp = new ArchiveProjectName(); @@ -992,8 +1009,6 @@ /** * 打包下载 * @param response @@ -1002,20 +1017,174 @@ @PostMapping("/export/{id}") public void packDownload(HttpServletResponse response, @PathVariable Long id) throws Exception { // 获取文件的保存位置,读取数据库, DocumentMaterials documentMaterials = new DocumentMaterials(); documentMaterials.setRecordId(id); List<DocumentMaterialsVoLarge> docs = documentMaterialsService.selectDocumentMaterialsAllByRecordId(id); System.out.println(docs.size()+"----009"); // List<DocumentMaterialsVoLarge> docs = documentMaterialsService.selectDocumentMaterialsAllByRecordId(id); //根据id拿到pageNumber ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(id); System.out.println(aIV.getPageCount()+"++++++++++++++++=="); //生成新的记录,不保存再数据库 List<DocumentMaterials> docAllInfo = documentMaterialsService.SelectAllRecordsByPageNumbersToList(id, aIV.getPageCount()); //把DocumentMaterils转到docs List<DocumentMaterialsVoLarge> docs = new ArrayList<>(); int nstar = 1; for (DocumentMaterials mater : docAllInfo) { // physcialService.mySave(physcial); DocumentMaterialsVoLarge docum = new DocumentMaterialsVoLarge(); BeanUtils.copyProperties(mater, docum); docum.setRecordId(aIV.getRecordId()); docum.setNum(nstar++); docs.add(docum); } System.out.println(docs.size()+"----009"); //.selectDocumentMaterialsList(documentMaterials); List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString()); if(dsvs==null||dsvs.isEmpty()) //把附件和记录一一对应 String fileSysPath = RuoYiConfig.getUploadPath(); AjaxResult ajax = AjaxResult.success(); String path = fileSysPath + File.separator + id; File desc = new File(fileSysPath + File.separator + id); System.out.println("44444444444444456666666666666666"); if (!desc.exists()) { throw new RuntimeException("电子文件信息没有上传,请补充!"); } ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(id); 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 )); } List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString(), aIV.getPageCount()); //重新封装一下docs,和附件绑定再一起 for (int i = 0; i < docs.size(); i++) { DocumentMaterialsVoLarge dc = docs.get(i); if (dc.getSecurityLevel() != null && (dc.getSecurityLevel().equals("该页另存") || dc.getSecurityLevel().equals("秘密") || dc.getSecurityLevel().equals("内部用途") || dc.getSecurityLevel().equals("内部用图"))) { // 替换为了准备好的图像 String fp = fileSysPath + "\\glc.jpg"; Path path1 = Paths.get(fp); // 拿到图像属性 BufferedImage bufferedImage = ImageIO.read(Files.newInputStream(path1)); int wid = bufferedImage.getWidth(); int hei = bufferedImage.getHeight(); double sz = Double.parseDouble(String.format("%.2f", Files.size(path1) * 1.0 / 1024)); // 拿到图像的dpi信息 ImageInfo info = Imaging.getImageInfo(Files.readAllBytes(path1)); 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 java.awt.Font("宋体", Font.BOLD, 80)); // 设置字体样式和大小 g2d.setColor(Color.black); String pageNumber = dc.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 ost = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "jpg", ost); InputStream input = new ByteArrayInputStream(ost.toByteArray()); multipartFile = new MockMultipartFile(pageNumber, pageNumber + ".jpg", "text/plain", input); // 上传并返回新文件名称 String fileName1 = FileUploadUtils.upload(fileSysPath, multipartFile); // filePath = fileName1; dc.setWidth((long) wid); dc.setHeight((long) hei); dc.setFileSize(sz); dc.setFormat(".jpg"); dc.setHorizontalResolution((long) wdpi); dc.setVerticalResolution((long) hdpi); dc.setSizeType(sizeType); fileMap.put(dc.getPageNumber()+"", fp); // dc.set // 更新数据库 // 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]; // ajax.put("url", url); //拿到图像属性 System.out.println(dc.getPageNumber()); String fip = fileMap.get(dc.getPageNumber().toString()); // 创建 File 对象 File file = new File(fip); // 使用 ImageIO 读取图片 BufferedImage image = ImageIO.read(file); BufferedImage bufferedImage = ImageIO.read(file); int wid = bufferedImage.getWidth(); int hei = bufferedImage.getHeight(); double sz = Double.parseDouble(String.format("%.2f", file.length()*1.0/1024)); System.out.println(wid+":"+hei+":"+sz); //拿到图像的dpi信息 byte[] bytesArray = new byte[(int) file.length()]; FileInputStream fis = new FileInputStream(file); fis.read(bytesArray); //read file into bytes[] ImageInfo info = Imaging.getImageInfo(bytesArray); int wdpi = info.getPhysicalWidthDpi() ; int hdpi = info.getPhysicalHeightDpi(); // System.out.println("DPI: " + info.getPhysicalWidthDpi()+nam+"dds"); fis.close(); //计算fileNumber // Long fileNumber = documentMaterialsService.getFiNum(dc.getPageNumber(), id); //计算sizeType String sizeType = getPageSize(wid*hei); dc.setWidth((long) wid); dc.setHeight((long) hei); dc.setFileSize(sz); dc.setFormat(".jpg"); dc.setHorizontalResolution((long) wdpi); dc.setVerticalResolution((long) hdpi); dc.setSizeType(sizeType); } } System.out.println(dsvs.size()); List<String> paths = new ArrayList<>(); // System.out.println(docs); @@ -1036,7 +1205,8 @@ String datumName = "user"; //压缩文件 List<String> filePathList = paths; File file = compressedFileToZip(docs, dsvs, aIV, id); //把docmentMaterial转为 File file = compressedFileToZip(docs, dsvs, aIV, id, fileMap); System.out.println(file.getName()); String fileName =aIV.getRecordId()+".zip"; @@ -1130,7 +1300,7 @@ // 压缩文件 private File compressedFileToZip(List<DocumentMaterialsVoLarge> docs, List<DocumentMaterialsVo> dsvs, ArchiveInfoVo aIV, Long id) throws Exception { private File compressedFileToZip(List<DocumentMaterialsVoLarge> docs, List<DocumentMaterialsVo> dsvs, ArchiveInfoVo aIV, Long id, Map<String, String> fileMap) throws Exception { //压缩包具体名称(拼接时间戳防止重名) String datumName = ""; String zipFileName =dsvs.get(0).getDocumentNumber()+aIV.getRecordId()+ ".zip"; @@ -1510,14 +1680,45 @@ byte[] buf = new byte[1024]; for (DocumentMaterialsVoLarge dc : docs) { String filePath = dc.getUrl(); String filePath = fileMap.get(dc.getPageNumber().toString()); if(filePath==null) continue; filePath = filePath.replace("/profile/", RuoYiConfig.getProfile() + "/"); System.out.println(filePath); // 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); // } // File tempFile = new File(filePath); System.out.println(filePath); System.out.println(tempFile.length()); //在压缩包中添加文件夹 if(res) { zos.putNextEntry(new ZipEntry("01-申请材料/")); @@ -1530,9 +1731,15 @@ } //得到文件名frontCompWithZore(4, dc.get)+ String fname = ""; if(dc.getFileNumber()!=null&&dc.getPageNumber()!=null) { fname = frontCompWithZore(4, dc.getFileNumber().intValue()) + "-" + dc.getTitle() + "-" + frontCompWithZore(4, dc.getPageNumber().intValue()) + "." + dc.getUrl().split("\\.")[1]; // if(dc.getFileNumber()!=null&&dc.getPageNumber()!=null) { if(dc.getPageNumber()!=null) { // fname = frontCompWithZore(4, dc.getFileNumber().intValue()) + "-" + dc.getTitle() + "-" + frontCompWithZore(4, dc.getPageNumber().intValue()) + "." // + filePath.split("\\.")[1]; fname = "-" + dc.getTitle() + "-" + frontCompWithZore(4, dc.getPageNumber().intValue()) + "." + filePath.split("\\.")[1]; System.out.println(fname); if (dc.getStage().equals("01-申请材料")) zos.putNextEntry(new ZipEntry("01-申请材料/" + fname)); else if (dc.getStage().equals("02-办案过程材料")) @@ -1584,7 +1791,19 @@ } return file; } public String getPageSize(double du) { if(du <= 8699840 * 1.5) return "A4"; else if(du <= 17403188 * 1.5) return "A3"; else if(du <= 34811347 * 1.5) return "A2"; else if(du <= 69622674 * 1.5) return "A1"; else return "A0"; } } ruoyi-admin/src/main/resources/application-druid.yml
@@ -20,7 +20,7 @@ # 最小连接池数量 minIdle: 10 # 最大连接池数量 maxActive: 200 maxActive: 600 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置连接超时时间 ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
@@ -86,7 +86,34 @@ throw new IOException(e.getMessage(), e); } } public static final String uploadImg(String baseDir, MultipartFile file) throws IOException { try { int fileNameLength = Objects.requireNonNull(file.getOriginalFilename()).length(); if (fileNameLength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) { throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH); } assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); String fileName = StringUtils.format("{}.{}", FilenameUtils.getBaseName(file.getOriginalFilename()), getExtension(file)); String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); System.out.println(absPath+"[[[[[[[[[[[[[[[[["); file.transferTo(Paths.get(absPath)); return getPathFileName(baseDir, fileName); // return upload(baseDir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION, true); } catch (Exception e) { throw new IOException(e.getMessage(), e); } } /** * 文件上传 * ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
@@ -419,6 +419,8 @@ System.out.println(declaredFields.length); int i = 0; for (Field field : declaredFields) { if(i==8) break; // 设置字段的访问权限,以便于访问私有字段 field.setAccessible(true); @@ -556,7 +558,7 @@ // 条形码居中且不超出第二个格子 // 调整结束列索引和位置参数 // 增加dx1值,使条形码整体向右移动 ClientAnchor anchor1 = new HSSFClientAnchor(660, 0, 900, 60, (short) 0, 9, (short) 1, 10); ClientAnchor anchor1 = new HSSFClientAnchor(537, 0, 788, 245, (short) 0, 9, (short) 1, 9); // 设置图片位置和大小 anchor1.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);