From 56362224e2e89946942e2242713e89cd3d08710c Mon Sep 17 00:00:00 2001 From: zhanghai <120228220@qq.com> Date: Sat, 11 Nov 2023 17:03:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 + .../com/docus/sw/fenpan/MyApplication.java | 43 ++- src/main/java/com/docus/sw/fenpan/Roll.java | 4 + .../java/com/docus/sw/souyin/ExcelUtil.java | 82 ++++-- .../com/docus/sw/souyin/IndexPageRow.java | 2 +- .../java/com/docus/sw/souyin/IndexPlate.java | 21 +- .../com/docus/sw/souyin/MesEasyExcel.java | 17 +- .../java/com/docus/sw/souyin/PdfToPic.java | 26 ++ .../java/com/docus/sw/souyin/PdfUtil.java | 84 +++++- .../com/docus/sw/souyin/SuoyinService.java | 255 ++++++++++++++++-- 10 files changed, 496 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index bbc2f02..9f1d6a9 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,11 @@ 2.0.23 bundle + + com.google.code.gson + gson + 2.10 + diff --git a/src/main/java/com/docus/sw/fenpan/MyApplication.java b/src/main/java/com/docus/sw/fenpan/MyApplication.java index 1fe8080..a3522c3 100644 --- a/src/main/java/com/docus/sw/fenpan/MyApplication.java +++ b/src/main/java/com/docus/sw/fenpan/MyApplication.java @@ -1,6 +1,7 @@ package com.docus.sw.fenpan; import com.docus.sw.Config; +import com.docus.sw.souyin.SuoyinService; import javax.swing.*; import java.awt.*; @@ -308,7 +309,9 @@ public class MyApplication { leftIndexGbc.gridy = 2; leftIndexGbc.gridwidth = 2; leftIndexGbc.anchor = GridBagConstraints.CENTER; - leftIndexPanel.add(new JButton("开始生成索引"), leftIndexGbc); + JButton jButton = new JButton("开始生成索引"); + leftIndexPanel.add(jButton, leftIndexGbc); + JTextArea indexLogTextArea = new JTextArea(); JScrollPane indexLogScrollPane = new JScrollPane(indexLogTextArea); @@ -319,6 +322,44 @@ public class MyApplication { indexPanel.add(leftIndexPanel, BorderLayout.WEST); indexPanel.add(rightIndexPanel, BorderLayout.CENTER); + + + jButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 在EDT上执行更新操作 + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + + indexLogTextArea.append(df.format(new Date())+": 索引开始。。。"+ "\n"); + } + }); + // 启动一个异步任务 + + Thread workerThread = new Thread(() -> { + // 执行长时间运行的业务操作 + + // 模拟耗时操作 + new SuoyinService().index(filePathField.getText()); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + // 在EDT上更新UI + indexLogTextArea.append(df.format(new Date())+": 索引结束。。。"+ "\n"); + } + }); + }); + + workerThread.start(); // 启动线程 + + } + + }); + + return indexPanel; } } diff --git a/src/main/java/com/docus/sw/fenpan/Roll.java b/src/main/java/com/docus/sw/fenpan/Roll.java index 2d82660..ec0d442 100644 --- a/src/main/java/com/docus/sw/fenpan/Roll.java +++ b/src/main/java/com/docus/sw/fenpan/Roll.java @@ -38,6 +38,10 @@ public class Roll { piecesList.add(pieces); } + public void putAll(List piecesList){ + this.piecesList.addAll(piecesList); + } + } diff --git a/src/main/java/com/docus/sw/souyin/ExcelUtil.java b/src/main/java/com/docus/sw/souyin/ExcelUtil.java index 1bf0f22..c6147f4 100644 --- a/src/main/java/com/docus/sw/souyin/ExcelUtil.java +++ b/src/main/java/com/docus/sw/souyin/ExcelUtil.java @@ -2,16 +2,19 @@ package com.docus.sw.souyin; import com.alibaba.excel.EasyExcel; +import com.itextpdf.text.*; +import com.itextpdf.text.Font; +import com.itextpdf.text.pdf.BaseFont; +import com.itextpdf.text.pdf.PdfPCell; +import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.*; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -29,35 +32,70 @@ public class ExcelUtil { } catch (Exception e) { System.out.println(e.getMessage()); } - ; + ExcelUtil.toPdf(fileName,"C:\\jiahsi-saomiao\\缩微\\test\\output.pdf"); - try { - FileInputStream excelFile = new FileInputStream(new File(fileName)); - Workbook workbook = new HSSFWorkbook(excelFile); - // 选择要转换的工作表(这里假设你选择第一个工作表) + } + + + + public static void toPdf(String filename,String outName){ + try (Workbook workbook = WorkbookFactory.create(new File(filename)); + FileOutputStream fos = new FileOutputStream(outName)) { + // 获取第一个工作表 Sheet sheet = workbook.getSheetAt(0); - // 创建一个输出流,用于将Excel内容写入PDF文件 - FileOutputStream pdfOutput = new FileOutputStream("C:\\jiahsi-saomiao\\缩微\\test\\output.pdf"); + // 创建PDF文档对象 + Document document = new Document(PageSize.A4, 50, 50, 50, 50); + + // 创建PDF输出流 + PdfWriter writer = PdfWriter.getInstance(document, fos); - // 使用iText库创建一个PDF文档 - com.itextpdf.text.Document pdfDocument = new com.itextpdf.text.Document(); - PdfWriter.getInstance(pdfDocument, pdfOutput); - pdfDocument.open(); + // 打开PDF文档 + document.open(); - // 读取Excel单元格内容并将其写入PDF + // 创建PDF表格对象 + PdfPTable table = new PdfPTable(sheet.getRow(0).getLastCellNum()); + + // 设置表格宽度 + table.setWidthPercentage(100); + + // 设置表格标题 + com.itextpdf.text.Font font = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED,10f, com.itextpdf.text.Font.NORMAL, BaseColor.BLACK); + Paragraph title = new Paragraph("",font); + title.setAlignment(Element.ALIGN_CENTER); + document.add(title); + + // 添加表格内容 for (Row row : sheet) { for (Cell cell : row) { - pdfDocument.add(new com.itextpdf.text.Paragraph(cell.toString())); + + int columnIndex = cell.getColumnIndex(); + + if(columnIndex==4&&row.getRowNum()!=0){ + PdfPCell pdfCell = new PdfPCell(new Paragraph(String.valueOf((int)cell.getNumericCellValue()), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12))); + pdfCell.setBorderWidth(1f); + pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER); + pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE); + table.addCell(pdfCell); + }else{ + PdfPCell pdfCell = new PdfPCell(new Paragraph(cell.getStringCellValue(), new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12))); + pdfCell.setBorderWidth(1f); + pdfCell.setHorizontalAlignment(Element.ALIGN_CENTER); + pdfCell.setVerticalAlignment(Element.ALIGN_MIDDLE); + table.addCell(pdfCell); + } + } } - pdfDocument.close(); - pdfOutput.close(); + // 添加表格到PDF文档 + document.add(table); - System.out.println("Excel文件已成功转换为PDF文件。"); - } catch (Exception e) { + // 关闭PDF文档 + document.close(); + writer.close(); + } catch (IOException | DocumentException e) { e.printStackTrace(); } } @@ -71,7 +109,7 @@ public class ExcelUtil { m.setPlateName("盘2"); m.setRollName("卷名"); m.setPieces("档号"); - m.setNums("80"); + m.setNums(80); m.setStartNum("28"); list.add(m); } diff --git a/src/main/java/com/docus/sw/souyin/IndexPageRow.java b/src/main/java/com/docus/sw/souyin/IndexPageRow.java index be5b025..cebdcb9 100644 --- a/src/main/java/com/docus/sw/souyin/IndexPageRow.java +++ b/src/main/java/com/docus/sw/souyin/IndexPageRow.java @@ -16,7 +16,7 @@ public class IndexPageRow { private String piecesName; - private String nums; + private Integer nums; private Integer start; diff --git a/src/main/java/com/docus/sw/souyin/IndexPlate.java b/src/main/java/com/docus/sw/souyin/IndexPlate.java index 28e8717..5b0d762 100644 --- a/src/main/java/com/docus/sw/souyin/IndexPlate.java +++ b/src/main/java/com/docus/sw/souyin/IndexPlate.java @@ -1,9 +1,12 @@ package com.docus.sw.souyin; +import com.docus.sw.fenpan.Roll; import lombok.AllArgsConstructor; import lombok.Data; -@AllArgsConstructor +import java.util.ArrayList; +import java.util.List; + @Data public class IndexPlate { @@ -11,4 +14,20 @@ public class IndexPlate { private String name; + private List rollList; + + private String zongName; + + + public IndexPlate(String absolutePath, String name,String zongName) { + this.absolutePath = absolutePath; + this.name = name; + this.zongName = zongName; + rollList = new ArrayList<>(); + } + + public void putAll(List rollList){ + this.rollList.addAll(rollList); + } + } diff --git a/src/main/java/com/docus/sw/souyin/MesEasyExcel.java b/src/main/java/com/docus/sw/souyin/MesEasyExcel.java index 6ce38d4..1483b94 100644 --- a/src/main/java/com/docus/sw/souyin/MesEasyExcel.java +++ b/src/main/java/com/docus/sw/souyin/MesEasyExcel.java @@ -1,12 +1,16 @@ package com.docus.sw.souyin; import com.alibaba.excel.annotation.ExcelProperty; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * @author 未来码匠 */ @Data +@AllArgsConstructor +@NoArgsConstructor public class MesEasyExcel { @ExcelProperty("全宗名") @@ -22,9 +26,20 @@ public class MesEasyExcel { private String pieces; @ExcelProperty("数量") - private String nums; + private Integer nums; @ExcelProperty("起始缩微号") private String startNum; + + public static MesEasyExcel create(IndexPageRow indexPageRow){ + + String startNum = ""; + Integer start = indexPageRow.getStart(); + if(start!=null){ + startNum = start.toString(); + } + return new MesEasyExcel(indexPageRow.getZongName(),indexPageRow.getPhNum(),indexPageRow.getRollName(),indexPageRow.getPiecesName(),indexPageRow.getNums(),startNum); + } + } diff --git a/src/main/java/com/docus/sw/souyin/PdfToPic.java b/src/main/java/com/docus/sw/souyin/PdfToPic.java index 96154b3..5f3b8f2 100644 --- a/src/main/java/com/docus/sw/souyin/PdfToPic.java +++ b/src/main/java/com/docus/sw/souyin/PdfToPic.java @@ -31,4 +31,30 @@ public class PdfToPic { } } + + public static void toPic(String source, String desFilePath, String desFileName, String imageType){ + Pair pair = PdfUtil.pdfToImage(source, desFilePath, desFileName, imageType); + System.out.println("PDF文档转化为图片结果:" + pair.getLeft()); + if (!pair.getLeft()) { + System.out.println("" + pair.getRight()); + } else { + List fileList = (List) pair.getRight(); + System.out.println("转化的文件的内容:"); + fileList.forEach(System.out::println); + } + } + + + public static void toPicDesc(String source, String desFilePath, String desFileName, String imageType){ + Pair pair = PdfUtil.pdfToImageDesc(source, desFilePath, desFileName, imageType); + System.out.println("PDF文档转化为图片结果:" + pair.getLeft()); + if (!pair.getLeft()) { + System.out.println("" + pair.getRight()); + } else { + List fileList = (List) pair.getRight(); + System.out.println("转化的文件的内容:"); + fileList.forEach(System.out::println); + } + } + } diff --git a/src/main/java/com/docus/sw/souyin/PdfUtil.java b/src/main/java/com/docus/sw/souyin/PdfUtil.java index d49c9c6..aee30f9 100644 --- a/src/main/java/com/docus/sw/souyin/PdfUtil.java +++ b/src/main/java/com/docus/sw/souyin/PdfUtil.java @@ -14,6 +14,34 @@ import java.util.List; public class PdfUtil { + + public static Integer getPage(String source) { + File file = new File(source); + + + PDDocument doc = null; + try { + //加载PDF文件 + doc = PDDocument.load(file); + PDFRenderer renderer = new PDFRenderer(doc); + //获取PDF文档的页数 + int pageCount = doc.getNumberOfPages(); + return pageCount; + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } finally { + try { + if (doc != null) { + doc.close(); + } + } catch (IOException e) { + System.out.println("关闭文档失败"); + e.printStackTrace(); + } + } + } + /** * @param source 原文件 * @param desFilePath 生成图片的路径 @@ -44,9 +72,9 @@ public class PdfUtil { List fileList = new ArrayList<>(); for (int i = 0; i < pageCount; i++) { //只有一页的时候文件名为传入的文件名,大于一页的文件名为:文件名_自增加数字(从1开始) - String realFileName = pageCount > 1 ? desFileName + "_" + (i + 1) : desFileName; + String realFileName = pageCount > 1 ? desFileName + "" + (i + 1) : desFileName; //每一页通过分辨率和颜色值进行转化 - BufferedImage bufferedImage = renderer.renderImageWithDPI(i, 96 * 2, ImageType.RGB); + BufferedImage bufferedImage = renderer.renderImageWithDPI(i, 150 * 2, ImageType.RGB); String filePath = desFilePath + File.separator + realFileName + "." + imageType; //写入文件 ImageIO.write(bufferedImage, imageType, new File(filePath)); @@ -68,6 +96,58 @@ public class PdfUtil { } } } + + + public static Pair pdfToImageDesc(String source, String desFilePath, String desFileName, String imageType) { + //通过给定的源路径名字符串创建一个File实例 + File file = new File(source); + if (!file.exists()) { + return Pair.of(false, "文件不存在,无法转化"); + } + //目录不存在则创建目录 + File destination = new File(desFilePath); + if (!destination.exists()) { + boolean flag = destination.mkdirs(); + System.out.println("创建文件夹结果:" + flag); + } + PDDocument doc = null; + try { + //加载PDF文件 + doc = PDDocument.load(file); + PDFRenderer renderer = new PDFRenderer(doc); + //获取PDF文档的页数 + int pageCount = doc.getNumberOfPages(); + System.out.println("文档一共" + pageCount + "页"); + List fileList = new ArrayList<>(); + int j = 1; + for (int i = pageCount-1; i >= 0; i--) { + //只有一页的时候文件名为传入的文件名,大于一页的文件名为:文件名_自增加数字(从1开始) + String realFileName = pageCount > 1 ? desFileName + "" + j : desFileName; + //每一页通过分辨率和颜色值进行转化 + BufferedImage bufferedImage = renderer.renderImageWithDPI(i, 150 * 2, ImageType.RGB); + String filePath = desFilePath + File.separator + realFileName + "." + imageType; + //写入文件 + ImageIO.write(bufferedImage, imageType, new File(filePath)); + //文件名存入list + fileList.add(filePath); + j++; + + } + return Pair.of(true, fileList); + } catch (IOException e) { + e.printStackTrace(); + return Pair.of(false, "PDF转化图片异常"); + } finally { + try { + if (doc != null) { + doc.close(); + } + } catch (IOException e) { + System.out.println("关闭文档失败"); + e.printStackTrace(); + } + } + } } diff --git a/src/main/java/com/docus/sw/souyin/SuoyinService.java b/src/main/java/com/docus/sw/souyin/SuoyinService.java index cc845ed..6e7f17d 100644 --- a/src/main/java/com/docus/sw/souyin/SuoyinService.java +++ b/src/main/java/com/docus/sw/souyin/SuoyinService.java @@ -1,13 +1,23 @@ package com.docus.sw.souyin; +import com.alibaba.excel.EasyExcel; import com.alibaba.excel.util.FileUtils; +import com.docus.sw.Config; +import com.docus.sw.fenpan.Document; import com.docus.sw.fenpan.FileTypeEnum; import com.docus.sw.fenpan.Pieces; -import com.docus.sw.fenpan.Plate; +import com.docus.sw.fenpan.Roll; +import com.google.gson.Gson; +import org.apache.commons.imaging.ImageInfo; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.Imaging; import java.io.File; +import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SuoyinService { @@ -18,33 +28,238 @@ public class SuoyinService { //统计出需要使用的 胶片量 - public static void main(String[] args) { - + public static void main(String[] args) throws IOException { + Config.loadConfig(); + String path = "C:\\jiahsi-saomiao\\0001"; + new SuoyinService().index(path); } - public void test(){ - ArrayList indexPlates = new ArrayList<>(); - findAllDir("",indexPlates); + public void index(String path) { +// ArrayList indexPlates = new ArrayList<>(); + Map map = new HashMap<>(); + findAllDir(path, map); //计算出宗 //计算出每个盘的目录。 + for (IndexPlate indexPlate : map.values()) { + String absolutePath = indexPlate.getAbsolutePath(); + File file = new File(absolutePath); + File[] files = file.listFiles(); + + List rollList = new ArrayList<>(); + //卷 + for (File rollFile : files) { + if (rollFile.getName().equals("片头")) { +//填充卷 + Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath()); + + rollList.add(roll); + } else if (rollFile.getName().equals("片尾")) { +//填充卷 + Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath()); + + rollList.add(roll); + } else { + // + List pieceList = new ArrayList<>(); + File[] piecesFile = rollFile.listFiles(); + for(File piece:piecesFile){ + List documentList = new ArrayList<>(); + Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName()); + for (File docfile : piece.listFiles()) { + try { + ImageInfo imageInfo = Imaging.getImageInfo(docfile); + int height = imageInfo.getHeight(); + int width = imageInfo.getWidth(); + int physicalHeightDpi = imageInfo.getPhysicalHeightDpi(); + Document document = new Document(width, height, physicalHeightDpi); + documentList.add(document); + } catch (IOException e) { +// FileUtils.delete(file); + throw new RuntimeException("非图片格式", e); + } catch (ImageReadException e) { +// FileUtils.delete(file); + throw new RuntimeException(e); + } catch (IllegalArgumentException e) { +// FileUtils.delete(file); + } + } + pieces.put(documentList); + pieceList.add(pieces); + + } + + //填充卷 + Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath()); + roll.putAll(pieceList); + rollList.add(roll); + } + + + } + indexPlate.putAll(rollList); + + } + + + + //生成索引目录 + for(IndexPlate indexPlate : map.values()){ + + + List rollList = indexPlate.getRollList(); + + + //计算出总size + Double totalPage = 0d; + for(Roll roll:rollList){ + List piecesList = roll.getPiecesList(); + totalPage+=piecesList.size(); + } + + Integer pianPageNum = 0; + + + Integer totalSize = 0; + for(Roll roll:rollList){ + //跳过片头 + if(roll.getName().equals("片头")){ + continue; + } + //跳过片尾 + if(roll.getName().equals("片尾")){ + continue; + } + List piecesList = roll.getPiecesList(); + for(Pieces pieces:piecesList){ + Integer size = pieces.getDocumentList().size(); + totalSize+=size; + } + } + + + List indexPageRows= indexGen(indexPlate, rollList, pianPageNum, totalSize); + //修正数据 + System.out.println(new Gson().toJson(indexPageRows)); + + + //生成excel + List mesEasyExcels = new ArrayList<>(); + for(IndexPageRow indexPageRowTemp:indexPageRows){ + mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp)); + } + + EasyExcel.write(indexPlate.getAbsolutePath()+"\\index.xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels); + + ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"\\index.xls",indexPlate.getAbsolutePath()+"\\index.pdf"); + + Integer page = PdfUtil.getPage(indexPlate.getAbsolutePath() + "\\index.pdf"); + + + + indexPageRows= indexGen(indexPlate, rollList, page, totalSize); + //修正数据 + System.out.println(new Gson().toJson(indexPageRows)); + + + //生成excel + mesEasyExcels = new ArrayList<>(); + for(IndexPageRow indexPageRowTemp:indexPageRows){ + mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp)); + } + + EasyExcel.write(indexPlate.getAbsolutePath()+"\\index.xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels); + + ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"\\index.xls",indexPlate.getAbsolutePath()+"\\index.pdf"); + + //写入文件夹。 + PdfToPic.toPic(indexPlate.getAbsolutePath()+"\\index.pdf",indexPlate.getAbsolutePath()+"/片头","0000","jpg"); + + + PdfToPic.toPicDesc(indexPlate.getAbsolutePath()+"\\index.pdf",indexPlate.getAbsolutePath()+"/片尾","0010","jpg"); + + //再重算一次索引,以及将文件进行替换。 + + } //读取片头 //读取片尾 //生成excel //生成图片 + // } + private List indexGen(IndexPlate indexPlate, List rollList, Integer pianPageNum, Integer totalSize) { + List indexPageRows = new ArrayList<>(); + int start = 1; + //添加片头 + for(Roll roll: rollList){ + + //跳过片头 + if(roll.getName().equals("片头")){ + File file = new File(roll.getAbsolutePath()); + int fileasize = file.listFiles().length; + fileasize+=pianPageNum; + IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), "", fileasize, start); + start+=fileasize; + indexPageRows.add(indexPageRow); + start+=1; + } + } + + //处理偏中 + for(Roll roll: rollList){ + + //跳过片头 + if(roll.getName().equals("片头")){ + continue; + } + //跳过片尾 + if(roll.getName().equals("片尾")){ + continue; + } + List piecesList = roll.getPiecesList(); + for(Pieces pieces:piecesList){ + IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), pieces.getName(), pieces.getDocumentList().size(), start); + start+=pieces.getDocumentList().size(); + indexPageRows.add(indexPageRow); + } + start+=1; + } + + //添加片尾 + for(Roll roll: rollList){ + + //跳过片头 + if(roll.getName().equals("片尾")){ + File file = new File(roll.getAbsolutePath()); + int fileasize = file.listFiles().length; + fileasize+=pianPageNum; + IndexPageRow indexPageRow = new IndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), "", fileasize, start); + start+=fileasize; + indexPageRows.add(indexPageRow); + start+=1; + } + } + + //加上统计 + IndexPageRow indexPageRow = new IndexPageRow("", "", "", "有效画幅数", totalSize, null); + indexPageRows.add(indexPageRow); + + return indexPageRows; + } + + + private void findAllDir(String absolutePath, Map map) { - private void findAllDir(String absolutePath, List allDirectory) { File sourceFile = new File(absolutePath); File[] files = sourceFile.listFiles(); for (File o : files) { if (o.isDirectory()) { - findAllDir(o.getAbsolutePath(), allDirectory); + findAllDir(o.getAbsolutePath(), map); } if (o.isFile()) { @@ -58,14 +273,24 @@ public class SuoyinService { } else if (o.getName().endsWith(".jpg") || o.getName().endsWith(".png") || o.getName().endsWith(".jpeg") || o.getName().endsWith(".tif") || o.getName().endsWith(".tiff")) { - //件 + + if(o.getParentFile().getName().equals("片头")||o.getParentFile().getName().equals("片尾")){ + continue; + } + + + //件 File parentFile = o.getParentFile() - //卷 - .getParentFile() - //盘 - .getParentFile(); - IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName()); - allDirectory.add(indexPlate); + //卷 + .getParentFile() + //盘 + .getParentFile(); + + if(map.get(parentFile.getAbsolutePath())==null){ + IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName(),parentFile.getParentFile().getName()); + map.put(parentFile.getAbsolutePath(),indexPlate); + } + } else { FileUtils.delete(new File(o.getAbsolutePath())); System.out.println("请删除无效的文件:" + o.getAbsolutePath());