From b5d3a7a52656e6d86d9dc9c102ef91a809d7f718 Mon Sep 17 00:00:00 2001 From: zhanghai <120228220@qq.com> Date: Sat, 2 Dec 2023 14:50:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=AE=8C=E6=95=B4=E7=9A=84?= =?UTF-8?q?=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.ini | 2 + .../com/docus/sw/fenpan/MyApplication.java | 48 ++- .../com/docus/sw/souyin/CheckService.java | 330 ++++++++++++++++++ 3 files changed, 366 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/docus/sw/souyin/CheckService.java diff --git a/config.ini b/config.ini index d901f1a..0a81d99 100644 --- a/config.ini +++ b/config.ini @@ -4,5 +4,7 @@ a3.length=300 plate.size=200 a3.width=300 file.save.url=C:\jiahsi-saomiao\缩微\分盘结果\档案图\ +a4.width=200 zong.name.prefix=南方医院 +a4.length=200 Split.mode=copy/cut diff --git a/src/main/java/com/docus/sw/fenpan/MyApplication.java b/src/main/java/com/docus/sw/fenpan/MyApplication.java index 8e51ada..23dd8d5 100644 --- a/src/main/java/com/docus/sw/fenpan/MyApplication.java +++ b/src/main/java/com/docus/sw/fenpan/MyApplication.java @@ -49,7 +49,7 @@ public class MyApplication { } private static void createAndShowGUI() { - JFrame frame = new JFrame("分盘索引工具"); + JFrame frame = new JFrame("数转模前处理软件 V2.1"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 400); @@ -70,12 +70,21 @@ public class MyApplication { paramPanel.add(zongPreJtf, gbc); JPanel sizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - sizePanel.add(new JLabel("A3大小尺寸(英寸) 长:")); - JTextField a3LongJtf = new JTextField(5); - sizePanel.add(a3LongJtf); + sizePanel.add(new JLabel("A4大小尺寸(英寸) 长:")); + JTextField a4LongJtf = new JTextField(5); + sizePanel.add(a4LongJtf); sizePanel.add(new JLabel("宽:")); - JTextField a3WidthJtf = new JTextField(5); - sizePanel.add(a3WidthJtf); + JTextField a4WidthJtf = new JTextField(5); + sizePanel.add(a4WidthJtf); + + + JPanel sizePanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + sizePanel2.add(new JLabel("A3大小尺寸(英寸) 长:")); + JTextField a3LongJtf2 = new JTextField(5); + sizePanel2.add(a3LongJtf2); + sizePanel2.add(new JLabel("宽:")); + JTextField a3WidthJtf2 = new JTextField(5); + sizePanel2.add(a3WidthJtf2); gbc.gridx = 0; gbc.gridy = 1; @@ -83,8 +92,15 @@ public class MyApplication { gbc.anchor = GridBagConstraints.WEST; paramPanel.add(sizePanel, gbc); + gbc.gridx = 0; gbc.gridy = 2; + gbc.gridwidth = 2; + gbc.anchor = GridBagConstraints.WEST; + paramPanel.add(sizePanel2, gbc); + + gbc.gridx = 0; + gbc.gridy = 3; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.WEST; paramPanel.add(new JLabel("盘大小:"), gbc); @@ -103,13 +119,13 @@ public class MyApplication { gbc.gridx = 0; - gbc.gridy = 3; + gbc.gridy = 4; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.WEST; paramPanel.add(modePanel, gbc); gbc.gridx = 0; - gbc.gridy = 4; + gbc.gridy = 5; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; JButton jButton = new JButton("保存设置"); @@ -126,8 +142,8 @@ public class MyApplication { System.out.println(selectedValue); //a3 图片大小 - System.out.println(a3LongJtf.getText()); - System.out.println(a3WidthJtf.getText()); + System.out.println(a4LongJtf.getText()); + System.out.println(a4WidthJtf.getText()); //盘大小 String text = plateSizeJtf.getText(); @@ -137,8 +153,10 @@ public class MyApplication { Map keyvalue = new HashMap<>(); keyvalue.put("zong.name.prefix",zongPreJtf.getText()); keyvalue.put("file.mode",selectedValue); - keyvalue.put("a3.length",a3LongJtf.getText()); - keyvalue.put("a3.width",a3WidthJtf.getText()); + keyvalue.put("a3.length",a3LongJtf2.getText()); + keyvalue.put("a4.length",a4LongJtf.getText()); + keyvalue.put("a3.width",a3WidthJtf2.getText()); + keyvalue.put("a4.width",a4WidthJtf.getText()); keyvalue.put("plate.size",plateSizeJtf.getText()); try { Config.updateConfig(keyvalue); @@ -269,8 +287,10 @@ public class MyApplication { //加载数据 zongPreJtf.setText(Config.getParam("zong.name.prefix")); - a3LongJtf.setText(Config.getParam("a3.length")); - a3WidthJtf.setText(Config.getParam("a3.width")); + a4LongJtf.setText(Config.getParam("a4.length")); + a3LongJtf2.setText(Config.getParam("a3.length")); + a4WidthJtf.setText(Config.getParam("a4.width")); + a3WidthJtf2.setText(Config.getParam("a3.width")); plateSizeJtf.setText(Config.getParam("plate.size")); } diff --git a/src/main/java/com/docus/sw/souyin/CheckService.java b/src/main/java/com/docus/sw/souyin/CheckService.java new file mode 100644 index 0000000..820034e --- /dev/null +++ b/src/main/java/com/docus/sw/souyin/CheckService.java @@ -0,0 +1,330 @@ +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.Roll; +import com.docus.sw.word.GetPicsDocx; +import com.docus.sw.word.PdfBoxUtils; +import com.docus.sw.word.ReadImgDoc; +import com.google.gson.Gson; +import org.apache.commons.imaging.ImageInfo; +import org.apache.commons.imaging.ImageReadException; +import org.apache.commons.imaging.Imaging; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.*; + +public class CheckService { + + //读取分盘后的结果。 + //宗,盘,卷,件 + //输出目录文件 + //生成片头,片尾 + //统计出需要使用的 胶片量 + + + public static void main(String[] args) throws IOException { + Config.loadConfig(); + String path = "C:\\Users\\zhanghai\\Desktop\\桌面\\test\\ppp\\ppp"; + new CheckService().index(path); + } + + public void index(String path) throws IOException { + 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) { + + //区分word和pdf + if (piece.getName().endsWith(".doc")) { + Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName()); + + String teamName = "tempIndex/" + UUID.randomUUID(); + File temp = new File(teamName); + if (!temp.exists()) { + temp.mkdirs(); + } + + ReadImgDoc.readPicture(piece.getAbsolutePath(), temp.getAbsolutePath()); + File[] listFiles = temp.listFiles(); + genPieces(pieces, listFiles, FileTypeEnum.DOC); + pieceList.add(pieces); + + //删除对应的temp 文件 + FileUtils.delete(temp); + } else if (piece.getName().endsWith(".docx")) { + Pieces pieces = new Pieces(FileTypeEnum.DOCX, piece.getAbsolutePath(), piece.getName()); + + String teamName = "tempIndex/" + UUID.randomUUID(); + File temp = new File(teamName); + if (!temp.exists()) { + temp.mkdirs(); + } + + GetPicsDocx.getPics(piece.getAbsolutePath(), temp.getAbsolutePath()); + File[] listFiles = temp.listFiles(); + genPieces(pieces, listFiles, FileTypeEnum.DOCX); + pieceList.add(pieces); + //删除对应的temp 文件 + FileUtils.delete(temp); + } else if (piece.getName().endsWith(".pdf")) { + Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName()); + + String teamName = "tempIndex/" + UUID.randomUUID(); + File temp = new File(teamName); + if (!temp.exists()) { + temp.mkdirs(); + } + + try { + PdfBoxUtils.pdf2image(piece.getAbsolutePath(), temp.getAbsolutePath()); + File[] listFiles = temp.listFiles(); + genPieces(pieces, listFiles, FileTypeEnum.DOC); + pieceList.add(pieces); + + } catch (IOException e) { + + } + //删除对应的temp 文件 +// temp.delete(); + FileUtils.delete(temp); + } else { + Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName()); + File[] listFiles = piece.listFiles(); + genPieces(pieces, listFiles, FileTypeEnum.JPG); + pieceList.add(pieces); + } + + } + //填充卷 + Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath()); + roll.putAll(pieceList); + rollList.add(roll); + + } + + + } + indexPlate.putAll(rollList); + + } + + FileUtils.delete(new File("tempIndex")); + + //生成索引目录 + for (IndexPlate indexPlate : map.values()) { + List rollList = indexPlate.getRollList(); + for(Roll roll:rollList){ + List piecesList = roll.getPiecesList(); + for(Pieces pieces:piecesList){ + List documentList = pieces.getDocumentList(); + for(Document document:documentList){ + + } + } + } + } + + + } + + private static void genPieces(Pieces pieces, File[] listFiles, FileTypeEnum fileTypeEnum) { + List documentList = new ArrayList<>(); + + for (File docfile : listFiles) { + //非图片模式,跳过。 + if (!(docfile.getName().endsWith(".jpg") || docfile.getName().endsWith(".png") + || docfile.getName().endsWith(".jpeg") || docfile.getName().endsWith(".tif") + || docfile.getName().endsWith(".tiff") || docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm")) || docfile.getName().endsWith(".gif")) { + continue; + } + if (docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm")) { + // 读取 JPEG 2000 图像文件 + + try { + BufferedImage image = ImageIO.read(docfile); + int height = image.getHeight(); + int width = image.getWidth(); + Document document = new Document(width, height, 300, docfile.getName()); + documentList.add(document); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } else { + 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, docfile.getName()); + documentList.add(document); + } catch (IOException e) { + throw new RuntimeException("非图片格式", e); + } catch (ImageReadException e) { + throw new RuntimeException(e); + } catch (IllegalArgumentException e) { + throw new RuntimeException(e); + } + } + pieces.put(documentList); + + } + + + } + + 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) { + + + File sourceFile = new File(absolutePath); + File[] files = sourceFile.listFiles(); + for (File o : files) { + if (o.isDirectory()) { + findAllDir(o.getAbsolutePath(), map); + } + + if (o.isFile()) { + //判断是word,pdf,pic + if (o.getName().endsWith(".pdf")) { + + File rofile = o.getParentFile().getParentFile(); +// new Plate() + if (map.get(rofile.getAbsolutePath()) == null) { + IndexPlate indexPlate = new IndexPlate(rofile.getAbsolutePath(), rofile.getName(), rofile.getParentFile().getName()); + map.put(rofile.getAbsolutePath(), indexPlate); + } + + } else if (o.getName().endsWith(".docx") || o.getName().endsWith(".doc")) { + File rofile = o.getParentFile().getParentFile(); +// new Plate() + if (map.get(rofile.getAbsolutePath()) == null) { + IndexPlate indexPlate = new IndexPlate(rofile.getAbsolutePath(), rofile.getName(), rofile.getParentFile().getName()); + map.put(rofile.getAbsolutePath(), indexPlate); + } + } 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(); + + if (map.get(parentFile.getAbsolutePath()) == null) { + IndexPlate indexPlate = new IndexPlate(parentFile.getAbsolutePath(), parentFile.getName(), parentFile.getParentFile().getName()); + map.put(parentFile.getAbsolutePath(), indexPlate); + } + + } else { + + System.out.println("请删除无效的文件:" + o.getAbsolutePath()); + + } + break; + } + } + } +}