diff --git a/config.ini b/config.ini index 0a81d99..d6ab3ea 100644 --- a/config.ini +++ b/config.ini @@ -1,10 +1,13 @@ file.mode=图片 file.read.url=C:\jiahsi-saomiao\缩微\ddd_0001\ -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 +a3.length=300 +a0.length=200 +a4.width=200 +a4.length=200 +plate33.size=300 +a0.width=200 diff --git a/src/main/java/com/docus/sw/fenpan/Document.java b/src/main/java/com/docus/sw/fenpan/Document.java index b406d51..e423f4a 100644 --- a/src/main/java/com/docus/sw/fenpan/Document.java +++ b/src/main/java/com/docus/sw/fenpan/Document.java @@ -5,7 +5,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; @Getter -@AllArgsConstructor public class Document { /** @@ -23,15 +22,26 @@ public class Document { private String name; + private String rollModel; + //写一个方法判断是 A3 还是 A4 public Boolean isA3() { - if (width / dpi > Integer.parseInt(Config.getParam("a4.width")) - || longTh / dpi > Integer.parseInt(Config.getParam("a4.length"))) { - return true; + if(rollModel.equals("16mm规格")){ + if (width / dpi > Integer.parseInt(Config.getParam("a4.width")) + || longTh / dpi > Integer.parseInt(Config.getParam("a4.length"))) { + return true; + } + return false; + }else{ + if (width / dpi > Integer.parseInt(Config.getParam("a0.width")) + || longTh / dpi > Integer.parseInt(Config.getParam("a0.length"))) { + return true; + } + return false; } - return false; + } @@ -60,4 +70,16 @@ public class Document { } } + + public Document(Integer width, Integer longTh, Integer dpi, String name,String rollModel) { + this.width = width; + this.longTh = longTh; + this.dpi = dpi; + this.name = name; + + if(this.dpi==-1){ + this.dpi = 300; + } + this.rollModel = rollModel; + } } diff --git a/src/main/java/com/docus/sw/fenpan/FenpanService.java b/src/main/java/com/docus/sw/fenpan/FenpanService.java index 9904247..f3ba6ce 100644 --- a/src/main/java/com/docus/sw/fenpan/FenpanService.java +++ b/src/main/java/com/docus/sw/fenpan/FenpanService.java @@ -24,10 +24,27 @@ import java.util.concurrent.*; @Slf4j public class FenpanService { + + + private Integer plateSize; + + private String rollModel; + + private String zongPrefix; + + public FenpanService(String rollModel,String zongPrefix){ + if(rollModel.equals("16mm规格")){ + plateSize = Integer.parseInt(Config.getParam("plate.size")); + }else{ + plateSize = Integer.parseInt(Config.getParam("plate33.size")); + } + this.rollModel = rollModel; + this.zongPrefix = zongPrefix; + } + public void fenpan(String saveUrl, String readUrl) { try { - FenpanService main = new FenpanService(); - Map zongMap = main.readFile(readUrl); + Map zongMap = this.readFile(readUrl); Map> zongListMap = new HashMap<>(); //读取需要转宗的文件夹 @@ -36,13 +53,13 @@ public class FenpanService { List plateList = new ArrayList<>(); Zong zong = zongMap.get(key); List rollList = zong.getRollList(); - Plate plate = new Plate(Integer.parseInt(Config.getParam("plate.size")), String.format("%04d", i++)); + Plate plate = new Plate(plateSize, String.format("%04d", i++)); for (Roll roll : rollList) { Boolean put = plate.put(roll); if (!put) { //磁盘放不进去了 plateList.add(plate); - plate = new Plate(Integer.parseInt(Config.getParam("plate.size")), String.format("%04d", i++)); + plate = new Plate(plateSize, String.format("%04d", i++)); plate.put(roll); } } @@ -87,14 +104,7 @@ public class FenpanService { } } - public static void main(String[] args) throws IOException { - //读取配置文件。 - Config.loadConfig(); - String saveUrl = Config.getParam("file.save.url"); - String readUrl = Config.getParam("file.read.url"); - new FenpanService().fenpan(saveUrl, readUrl); - } public List getDocument(Pieces piece) { return null; @@ -209,6 +219,7 @@ public class FenpanService { // 处理图片 } + piece.put(documentList); executorService.shutdown(); } @@ -241,7 +252,7 @@ public class FenpanService { String zongName = parentFile.getParentFile().getName(); Zong zong = zongMap.get(zongName); if (zong == null) { - zong = new Zong(parentFile.getParentFile().getAbsolutePath(), parentFile.getParentFile().getName()); + zong = new Zong(parentFile.getParentFile().getAbsolutePath(), parentFile.getParentFile().getName(),this.zongPrefix); } zongMap.put(zongName, zong); } @@ -282,7 +293,7 @@ public class FenpanService { } - private static void getDocumentList(List documentList, File file) { + private void getDocumentList(List documentList, File file) { //非图片模式,跳过。 if (!(file.getName().endsWith(".jpg") || file.getName().endsWith(".png") || file.getName().endsWith(".jpeg") || file.getName().endsWith(".tif") || file.getName().endsWith(".tiff")) || file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm") || file.getName().endsWith(".gif")) { return; @@ -295,7 +306,7 @@ public class FenpanService { BufferedImage image = ImageIO.read(file); int height = image.getHeight(); int width = image.getWidth(); - Document document = new Document(width, height, 300,file.getName()); + Document document = new Document(width, height, 300,file.getName(),this.rollModel); documentList.add(document); } catch (IOException e) { throw new RuntimeException(e); @@ -307,7 +318,7 @@ public class FenpanService { int height = imageInfo.getHeight(); int width = imageInfo.getWidth(); int physicalHeightDpi = imageInfo.getPhysicalHeightDpi(); - Document document = new Document(width, height, physicalHeightDpi,file.getName()); + Document document = new Document(width, height, physicalHeightDpi,file.getName(),this.rollModel); documentList.add(document); } catch (IOException e) { FileUtils.delete(file); @@ -322,7 +333,7 @@ public class FenpanService { } - private static Document getDocumentList(File file) { + private Document getDocumentList(File file) { //非图片模式,跳过。 if (!(file.getName().endsWith(".jpg") || file.getName().endsWith(".png") || file.getName().endsWith(".jpeg") || file.getName().endsWith(".tif") || file.getName().endsWith(".tiff")) || file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm") || file.getName().endsWith(".gif")) { return null; @@ -335,7 +346,7 @@ public class FenpanService { BufferedImage image = ImageIO.read(file); int height = image.getHeight(); int width = image.getWidth(); - Document document = new Document(width, height, 300,file.getName()); + Document document = new Document(width, height, 300,file.getName(),this.rollModel); return document; } catch (IOException e) { throw new RuntimeException(e); @@ -347,7 +358,7 @@ public class FenpanService { int height = imageInfo.getHeight(); int width = imageInfo.getWidth(); int physicalHeightDpi = imageInfo.getPhysicalHeightDpi(); - Document document = new Document(width, height, physicalHeightDpi,file.getName()); + Document document = new Document(width, height, physicalHeightDpi,file.getName(),this.rollModel); return document; } catch (IOException e) { FileUtils.delete(file); diff --git a/src/main/java/com/docus/sw/fenpan/MyApplication.java b/src/main/java/com/docus/sw/fenpan/MyApplication.java index 138aa27..87e4937 100644 --- a/src/main/java/com/docus/sw/fenpan/MyApplication.java +++ b/src/main/java/com/docus/sw/fenpan/MyApplication.java @@ -15,6 +15,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; public class MyApplication { public static void main(String[] args) throws IOException { @@ -61,14 +62,19 @@ public class MyApplication { GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(5, 5, 5, 5); + JPanel sizePanel3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + sizePanel3.add(new JLabel("A0大小尺寸(英寸) 长:")); + JTextField a0LongJtf = new JTextField(5); + sizePanel3.add(a0LongJtf); + sizePanel3.add(new JLabel("宽:")); + JTextField a0WidthJt = new JTextField(5); + sizePanel3.add(a0WidthJt); + gbc.gridx = 0; gbc.gridy = 0; + gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.WEST; - paramPanel.add(new JLabel("宗前缀名:"), gbc); - gbc.gridx = 1; - gbc.anchor = GridBagConstraints.CENTER; - JTextField zongPreJtf = new JTextField(20); - paramPanel.add(zongPreJtf, gbc); + paramPanel.add(sizePanel3, gbc); JPanel sizePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); sizePanel.add(new JLabel("A4大小尺寸(英寸) 长:")); @@ -104,26 +110,24 @@ public class MyApplication { gbc.gridy = 3; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.WEST; - paramPanel.add(new JLabel("盘大小:"), gbc); + paramPanel.add(new JLabel("16mm规格盘大小:"), gbc); gbc.gridx = 1; gbc.anchor = GridBagConstraints.CENTER; JTextField plateSizeJtf = new JTextField(20); paramPanel.add(plateSizeJtf, gbc); - JPanel modePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - modePanel.add(new JLabel("模式选择:")); - String[] modes = {"图片", "word", "pdf"}; - JComboBox modeComboBox = new JComboBox<>(modes); - modePanel.add(modeComboBox); - - - gbc.gridx = 0; gbc.gridy = 4; - gbc.gridwidth = 2; + gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.WEST; - paramPanel.add(modePanel, gbc); + paramPanel.add(new JLabel("33mm规格盘大小:"), gbc); + gbc.gridx = 1; + gbc.anchor = GridBagConstraints.CENTER; + JTextField plateSizeJtf33 = new JTextField(20); + paramPanel.add(plateSizeJtf33, gbc); + + gbc.gridx = 0; gbc.gridy = 5; @@ -136,11 +140,6 @@ public class MyApplication { //添加事件 jButton.addActionListener(e -> { //宗名 - System.out.println(zongPreJtf.getText()); - - //模式 - String selectedValue = (String) modeComboBox.getSelectedItem(); - System.out.println(selectedValue); //a3 图片大小 System.out.println(a4LongJtf.getText()); @@ -152,13 +151,14 @@ public class MyApplication { Map keyvalue = new HashMap<>(); - keyvalue.put("zong.name.prefix",zongPreJtf.getText()); - keyvalue.put("file.mode",selectedValue); + keyvalue.put("a0.length",a0LongJtf.getText()); keyvalue.put("a3.length",a3LongJtf2.getText()); keyvalue.put("a4.length",a4LongJtf.getText()); + keyvalue.put("a0.width",a0WidthJt.getText()); keyvalue.put("a3.width",a3WidthJtf2.getText()); keyvalue.put("a4.width",a4WidthJtf.getText()); keyvalue.put("plate.size",plateSizeJtf.getText()); + keyvalue.put("plate33.size",plateSizeJtf33.getText()); try { Config.updateConfig(keyvalue); } catch (IOException ex) { @@ -172,8 +172,18 @@ public class MyApplication { GridBagConstraints leftGbc = new GridBagConstraints(); leftGbc.insets = new Insets(5, 5, 5, 5); + leftGbc.gridx = 0; leftGbc.gridy = 0; + leftPanel.add(new JLabel("模式选择:")); + String[] rollmodes = {"16mm规格", "35mm规格"}; + JComboBox rollmodeComboBox = new JComboBox<>(rollmodes); + leftGbc.gridx = 1; + leftGbc.gridwidth = 1; + leftPanel.add(rollmodeComboBox); + + leftGbc.gridx = 0; + leftGbc.gridy = 1; leftPanel.add(new JLabel("分盘目录:"), leftGbc); JTextField folderField = new JTextField(20); leftGbc.gridx = 1; @@ -198,12 +208,16 @@ public class MyApplication { leftPanel.add(folderChooserButton, leftGbc); leftGbc.gridx = 0; - leftGbc.gridy = 1; + leftGbc.gridy = 2; leftPanel.add(new JLabel("保存路径:"), leftGbc); JTextField savePathField = new JTextField(20); leftGbc.gridx = 1; leftPanel.add(savePathField, leftGbc); + + + + JButton savePathChooserButton = new JButton("选择文件夹"); savePathChooserButton.addActionListener(new ActionListener() { @Override @@ -222,7 +236,14 @@ public class MyApplication { leftPanel.add(savePathChooserButton, leftGbc); leftGbc.gridx = 0; - leftGbc.gridy = 2; + leftGbc.gridy = 3; + leftPanel.add(new JLabel("宗前缀名:"), leftGbc); + JTextField zongFiled = new JTextField(20); + leftGbc.gridx = 1; + leftPanel.add(zongFiled, leftGbc); + + leftGbc.gridx = 0; + leftGbc.gridy = 4; leftGbc.gridwidth = 2; leftGbc.anchor = GridBagConstraints.CENTER; JButton fenpanJbtn = new JButton("开始分盘"); @@ -248,6 +269,7 @@ public class MyApplication { public void run() { logTextArea.append(df.format(new Date())+": 开始分盘。。。"+ "\n"); + logTextArea.append(df.format(new Date())+": 分盘中。。。"+ "\n"); } }); // 启动一个异步任务 @@ -258,7 +280,9 @@ public class MyApplication { // 模拟耗时操作 String saveUrl = savePathField.getText()+"/"; String readUrl = folderField.getText(); - new FenpanService().fenpan(saveUrl,readUrl); + String s = Objects.requireNonNull(rollmodeComboBox.getSelectedItem()).toString(); + System.out.println(s); + new FenpanService(s,zongFiled.getText()).fenpan(saveUrl,readUrl); SwingUtilities.invokeLater(new Runnable() { @Override @@ -291,12 +315,14 @@ public class MyApplication { //加载数据 - zongPreJtf.setText(Config.getParam("zong.name.prefix")); a4LongJtf.setText(Config.getParam("a4.length")); + a0LongJtf.setText(Config.getParam("a0.length")); a3LongJtf2.setText(Config.getParam("a3.length")); a4WidthJtf.setText(Config.getParam("a4.width")); + a0WidthJt.setText(Config.getParam("a0.width")); a3WidthJtf2.setText(Config.getParam("a3.width")); plateSizeJtf.setText(Config.getParam("plate.size")); + plateSizeJtf33.setText(Config.getParam("plate33.size")); } @@ -317,7 +343,7 @@ public class MyApplication { leftGbc.gridwidth = 1; leftPanel.add(filePathField, leftGbc); - JButton fileChooserButton = new JButton("选择文件"); + JButton fileChooserButton = new JButton("选择文件夹"); leftGbc.gridx = 2; leftPanel.add(fileChooserButton, leftGbc); @@ -326,6 +352,7 @@ public class MyApplication { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); @@ -393,6 +420,7 @@ public class MyApplication { public void run() { logTextArea.append(df.format(new Date())+": 检查开始。。。"+ "\n"); + logTextArea.append(df.format(new Date())+": 检查中。。。"+ "\n"); } }); // 启动一个异步任务 @@ -497,6 +525,7 @@ public class MyApplication { public void run() { indexLogTextArea.append(df.format(new Date())+": 索引开始。。。"+ "\n"); + indexLogTextArea.append(df.format(new Date())+": 索引中。。。"+ "\n"); } }); // 启动一个异步任务 diff --git a/src/main/java/com/docus/sw/fenpan/Zong.java b/src/main/java/com/docus/sw/fenpan/Zong.java index b541caa..cf52118 100644 --- a/src/main/java/com/docus/sw/fenpan/Zong.java +++ b/src/main/java/com/docus/sw/fenpan/Zong.java @@ -16,8 +16,8 @@ public class Zong { private String absolutePath; - public Zong(String absolutePath,String name){ - this.name = Config.getParam("zong.name.prefix")+name; + public Zong(String absolutePath,String name,String zongPrefix){ + this.name = zongPrefix+name; this.absolutePath = absolutePath; rollList = new ArrayList<>(); } diff --git a/src/main/java/com/docus/sw/souyin/CheckService.java b/src/main/java/com/docus/sw/souyin/CheckService.java index 85a9dbc..3b8bfc4 100644 --- a/src/main/java/com/docus/sw/souyin/CheckService.java +++ b/src/main/java/com/docus/sw/souyin/CheckService.java @@ -187,7 +187,7 @@ public class CheckService { BufferedImage image = ImageIO.read(docfile); int height = image.getHeight(); int width = image.getWidth(); - Document document = new Document(width, height, 300, docfile.getName()); + Document document = new Document(width, height, 300, docfile.getName(),null); documentList.add(document); } catch (IOException e) { throw new RuntimeException(e); @@ -199,7 +199,7 @@ public class CheckService { int height = imageInfo.getHeight(); int width = imageInfo.getWidth(); int physicalHeightDpi = imageInfo.getPhysicalHeightDpi(); - Document document = new Document(width, height, physicalHeightDpi, docfile.getName()); + Document document = new Document(width, height, physicalHeightDpi, docfile.getName(),null); documentList.add(document); } catch (IOException e) { throw new RuntimeException("非图片格式", e); diff --git a/src/main/java/com/docus/sw/souyin/SuoyinService.java b/src/main/java/com/docus/sw/souyin/SuoyinService.java index 4d5778b..a8ef12f 100644 --- a/src/main/java/com/docus/sw/souyin/SuoyinService.java +++ b/src/main/java/com/docus/sw/souyin/SuoyinService.java @@ -34,11 +34,6 @@ public class SuoyinService { //统计出需要使用的 胶片量 - public static void main(String[] args) throws IOException { - Config.loadConfig(); - String path = "C:\\Users\\zhanghai\\Desktop\\桌面\\test\\ppp\\ppp"; - new SuoyinService().index(path); - } public void index(String path) throws IOException { Map map = new HashMap<>(); @@ -279,7 +274,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()); + Document document = new Document(width, height, 300, docfile.getName(),null); documentList.add(document); } catch (IOException e) { throw new RuntimeException(e); @@ -291,7 +286,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()); + Document document = new Document(width, height, physicalHeightDpi, docfile.getName(),null); documentList.add(document); } catch (IOException e) { throw new RuntimeException("非图片格式", e); diff --git a/src/test/java/JpmTest.java b/src/test/java/JpmTest.java index 7a50af7..c679873 100644 --- a/src/test/java/JpmTest.java +++ b/src/test/java/JpmTest.java @@ -35,7 +35,7 @@ public class JpmTest { Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL); } public static void main(String[] args) throws ImageProcessingException, IOException, ImageReadException { - File file = new File("C:\\Users\\zhanghai\\Documents\\WeChat Files\\wxid_wexo4ubjorso22\\FileStorage\\File\\2023-11\\GIF\\新建文件夹 - 副本 - 副本/0000007.gif"); + File file = new File("C:\\Users\\zhanghai\\Downloads\\微信图片_20231203095721.jpg"); ImageInfo imageInfo = Imaging.getImageInfo(file); int height = imageInfo.getHeight(); int width = imageInfo.getWidth();