From ef317a67e4fe34fc5f5b5792f1bb0adf4f7fbaca Mon Sep 17 00:00:00 2001 From: zhanghai <120228220@qq.com> Date: Tue, 19 Dec 2023 15:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=A9=E7=95=A5=EF=BC=8C?= =?UTF-8?q?=E8=AF=A6=E7=BB=86=E7=B4=A2=E5=BC=95=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/docus/sw/fenpan/MyApplication.java | 19 +++- .../com/docus/sw/souyin/CheckPageRow.java | 3 +- .../com/docus/sw/souyin/CheckService.java | 68 ++---------- .../com/docus/sw/souyin/SuoyinService.java | 105 +++++++++--------- 4 files changed, 80 insertions(+), 115 deletions(-) diff --git a/src/main/java/com/docus/sw/fenpan/MyApplication.java b/src/main/java/com/docus/sw/fenpan/MyApplication.java index 6b01283..1e28df8 100644 --- a/src/main/java/com/docus/sw/fenpan/MyApplication.java +++ b/src/main/java/com/docus/sw/fenpan/MyApplication.java @@ -317,8 +317,8 @@ public class MyApplication { tabbedPane.addTab("参数设置", paramPanel); tabbedPane.addTab("分盘工具", splitPanel); - tabbedPane.addTab("索引工具", createIndexPanel()); tabbedPane.addTab("检查工具", checkPanel()); + tabbedPane.addTab("索引工具", createIndexPanel()); frame.add(tabbedPane); frame.setVisible(true); @@ -344,6 +344,8 @@ public class MyApplication { leftGbc.insets = new Insets(5, 5, 5, 5); + + leftGbc.gridx = 0; leftGbc.gridy = 0; leftGbc.anchor = GridBagConstraints.WEST; @@ -470,8 +472,18 @@ public class MyApplication { GridBagConstraints leftIndexGbc = new GridBagConstraints(); leftIndexGbc.insets = new Insets(5, 5, 5, 5); + leftIndexGbc.gridx = 0; leftIndexGbc.gridy = 0; + leftIndexPanel.add(new JLabel("索引模式:")); + String[] rollmodes = {"详细索引", "简略索引"}; + JComboBox rollmodeComboBox = new JComboBox<>(rollmodes); + leftIndexGbc.gridx = 1; + leftIndexGbc.gridwidth = 1; + leftIndexPanel.add(rollmodeComboBox); + + leftIndexGbc.gridx = 0; + leftIndexGbc.gridy = 1; leftIndexGbc.anchor = GridBagConstraints.WEST; leftIndexPanel.add(new JLabel("文件路径选择:"), leftIndexGbc); JTextField filePathField = new JTextField(20); @@ -508,7 +520,7 @@ public class MyApplication { // ... 其他标签左对齐,与前面的代码相同 ... leftIndexGbc.gridx = 0; - leftIndexGbc.gridy = 2; + leftIndexGbc.gridy = 3; leftIndexGbc.gridwidth = 2; leftIndexGbc.anchor = GridBagConstraints.CENTER; JButton jButton = new JButton("开始生成索引"); @@ -529,6 +541,7 @@ public class MyApplication { 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() { @@ -546,7 +559,7 @@ public class MyApplication { // 模拟耗时操作 try { - new SuoyinService().index(filePathField.getText()); + new SuoyinService().index(filePathField.getText(),rollmodeComboBox.getSelectedItem().toString()); } catch (IOException ex) { throw new RuntimeException(ex); } diff --git a/src/main/java/com/docus/sw/souyin/CheckPageRow.java b/src/main/java/com/docus/sw/souyin/CheckPageRow.java index 4458bb6..a5e9b86 100644 --- a/src/main/java/com/docus/sw/souyin/CheckPageRow.java +++ b/src/main/java/com/docus/sw/souyin/CheckPageRow.java @@ -21,5 +21,6 @@ public class CheckPageRow { @ExcelProperty("胶片用量(厘米)") private Double useStore; - + @ExcelProperty("画幅幅面") + private String sizeString; } diff --git a/src/main/java/com/docus/sw/souyin/CheckService.java b/src/main/java/com/docus/sw/souyin/CheckService.java index f8536fc..cc6017c 100644 --- a/src/main/java/com/docus/sw/souyin/CheckService.java +++ b/src/main/java/com/docus/sw/souyin/CheckService.java @@ -152,6 +152,7 @@ public class CheckService { List checkPageRows = new ArrayList<>(); //生成索引目录 + Double longth = 0d; for (IndexPlate indexPlate : map.values()) { List rollList = indexPlate.getRollList(); for(Roll roll:rollList){ @@ -159,13 +160,18 @@ public class CheckService { for(Pieces pieces:piecesList){ List documentList = pieces.getDocumentList(); for(Document document:documentList){ - CheckPageRow checkPageRow = new CheckPageRow(indexPlate.getName(), document.getName(), document.getDpi(), document.useStore()); + CheckPageRow checkPageRow = new CheckPageRow(indexPlate.getName(), document.getName(), document.getDpi(), document.useStore(),document.toSize()); checkPageRows.add(checkPageRow); + longth+=checkPageRow.getUseStore(); } } } } + //加上统计 + CheckPageRow checkPageRow = new CheckPageRow("", "总计长度:", null, longth,""); + checkPageRows.add(checkPageRow); + EasyExcel.write(savepath+"/check" + ".xls", CheckPageRow.class).sheet("test").doWrite(checkPageRows); } @@ -216,66 +222,6 @@ public class CheckService { } - 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) { diff --git a/src/main/java/com/docus/sw/souyin/SuoyinService.java b/src/main/java/com/docus/sw/souyin/SuoyinService.java index a8ef12f..f4c6bc1 100644 --- a/src/main/java/com/docus/sw/souyin/SuoyinService.java +++ b/src/main/java/com/docus/sw/souyin/SuoyinService.java @@ -34,8 +34,7 @@ public class SuoyinService { //统计出需要使用的 胶片量 - - public void index(String path) throws IOException { + public void index(String path, String indexType) throws IOException { Map map = new HashMap<>(); findAllDir(path, map); @@ -176,76 +175,82 @@ public class SuoyinService { } } + if (indexType.equals("简略索引")) { + List indexPageRows = indexGen(indexPlate, rollList, pianPageNum, totalSize); + //修正数据 + System.out.println(new Gson().toJson(indexPageRows)); - 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)); + } - //生成excel - List mesEasyExcels = new ArrayList<>(); - for (IndexPageRow indexPageRowTemp : indexPageRows) { - mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp)); - } + EasyExcel.write(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels); - EasyExcel.write(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels); + ExcelUtil.toPdf(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); - ExcelUtil.toPdf(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); + Integer page = PdfUtil.getPage(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); - Integer page = PdfUtil.getPage(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); + indexPageRows = indexGen(indexPlate, rollList, page, totalSize); + //修正数据 + System.out.println(new Gson().toJson(indexPageRows)); - 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)); + } - //生成excel - mesEasyExcels = new ArrayList<>(); - for (IndexPageRow indexPageRowTemp : indexPageRows) { - mesEasyExcels.add(MesEasyExcel.create(indexPageRowTemp)); - } + EasyExcel.write(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels); + + ExcelUtil.toPdf(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); - EasyExcel.write(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", MesEasyExcel.class).sheet("test").doWrite(mesEasyExcels); + //写入文件夹。 + PdfToPic.toPic(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf", indexPlate.getAbsolutePath() + "/片头", "01", "jpg"); - ExcelUtil.toPdf(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls", indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); - //写入文件夹。 - PdfToPic.toPic(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf", indexPlate.getAbsolutePath() + "/片头", "01", "jpg"); + PdfToPic.toPicDesc(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf", indexPlate.getAbsolutePath() + "/片尾", "00", "jpg"); + File pdf = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); + //再重算一次索引,以及将文件进行替换。 + File parentFile = pdf.getParentFile().getParentFile(); + File file = new File(parentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); + Files.move(pdf.toPath(), file.toPath(), StandardCopyOption.ATOMIC_MOVE); - PdfToPic.toPicDesc(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf", indexPlate.getAbsolutePath() + "/片尾", "00", "jpg"); + File xls = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls"); + //再重算一次索引,以及将文件进行替换。 + File xlsParentFile = xls.getParentFile().getParentFile(); + File file2 = new File(xlsParentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".xls"); + Files.move(xls.toPath(), file2.toPath()); + } - File pdf = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); - //再重算一次索引,以及将文件进行替换。 - File parentFile = pdf.getParentFile().getParentFile(); - File file = new File(parentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); - Files.move(pdf.toPath(), file.toPath(), StandardCopyOption.ATOMIC_MOVE); - File xls = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls"); - //再重算一次索引,以及将文件进行替换。 - File xlsParentFile = xls.getParentFile().getParentFile(); - File file2 = new File(xlsParentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".xls"); - Files.move(xls.toPath(), file2.toPath()); //计算完整索引 - List fullIndexPageRows = new ArrayList<>(); - int i = 1; - for (Roll roll : rollList) { - List piecesList = roll.getPiecesList(); - for (Pieces pieces : piecesList) { - List documentList = pieces.getDocumentList(); - for (Document document : documentList) { - FullIndexPageRow fullIndexPageRow = new FullIndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), pieces.getName(), document.getName(), document.isA3() ? "A3" : "A4", i); - fullIndexPageRows.add(fullIndexPageRow); - i++; + if (indexType.equals("详细索引")) { + List fullIndexPageRows = new ArrayList<>(); + int i = 1; + for (Roll roll : rollList) { + List piecesList = roll.getPiecesList(); + for (Pieces pieces : piecesList) { + List documentList = pieces.getDocumentList(); + for (Document document : documentList) { + FullIndexPageRow fullIndexPageRow = new FullIndexPageRow(indexPlate.getZongName(), indexPlate.getName(), roll.getName(), pieces.getName(), document.getName(), document.isA3() ? "A3" : "A4", i); + fullIndexPageRows.add(fullIndexPageRow); + i++; + } } } + + File file1 = new File(indexPlate.getAbsolutePath()); + EasyExcel.write(file1.getParentFile().getAbsolutePath() + "/full-index-" + indexPlate.getName() + ".xls", FullIndexPageRow.class).sheet("test").doWrite(fullIndexPageRows); } - File file1 = new File(indexPlate.getAbsolutePath()); - EasyExcel.write(file1.getParentFile().getAbsolutePath() + "/full-index-" + indexPlate.getName() + ".xls", FullIndexPageRow.class).sheet("test").doWrite(fullIndexPageRows); } @@ -274,7 +279,7 @@ public class SuoyinService { BufferedImage image = ImageIO.read(docfile); int height = image.getHeight(); int width = image.getWidth(); - Document document = new Document(width, height, 300, docfile.getName(),null); + Document document = new Document(width, height, 300, docfile.getName(), null); documentList.add(document); } catch (IOException e) { throw new RuntimeException(e); @@ -286,7 +291,7 @@ public class SuoyinService { int height = imageInfo.getHeight(); int width = imageInfo.getWidth(); int physicalHeightDpi = imageInfo.getPhysicalHeightDpi(); - Document document = new Document(width, height, physicalHeightDpi, docfile.getName(),null); + Document document = new Document(width, height, physicalHeightDpi, docfile.getName(), null); documentList.add(document); } catch (IOException e) { throw new RuntimeException("非图片格式", e);