添加三层目录支持

master
zhanghai 2 years ago
parent 9e1924ff06
commit a27faaf96c

@ -34,7 +34,9 @@ public class FenpanService {
private Integer num;
public FenpanService(String rollModel,String zongPrefix,Integer num){
private LevelType levelType;
public FenpanService(String rollModel,String zongPrefix,Integer num,LevelType levelType){
if(rollModel.equals("16mm规格")){
plateSize = Integer.parseInt(Config.getParam("plate.size"));
}else{
@ -43,6 +45,7 @@ public class FenpanService {
this.rollModel = rollModel;
this.zongPrefix = zongPrefix;
this.num = num;
this.levelType = levelType;
}
public void fenpan(String saveUrl, String readUrl) {
@ -192,6 +195,7 @@ public class FenpanService {
//删除对应的temp 文件
// FileUtils.delete(file);
} else {
//是图片,直接从图片提取
List<Document> documentList = new ArrayList<>();
File sourceFile = new File(piece.getAbsolutePath());
@ -272,16 +276,16 @@ public class FenpanService {
@Override
public int compare(File file1, File file2) {
// 使用正则表达式提取数字部分
int num1 = extractNumber(file1.getName());
int num2 = extractNumber(file2.getName());
long num1 = extractNumber(file1.getName());
long num2 = extractNumber(file2.getName());
// 比较提取的数字部分
return Integer.compare(num1, num2);
return Long.compare(num1, num2);
}
private int extractNumber(String fileName) {
private long extractNumber(String fileName) {
String numberPart = fileName.replaceAll("[^0-9]", "");
return numberPart.isEmpty() ? 0 : Integer.parseInt(numberPart);
return numberPart.isEmpty() ? 0 : Long.parseLong(numberPart);
}
};
@ -388,17 +392,23 @@ public class FenpanService {
if (o.isFile()) {
//判断是word,pdf,pic
if (o.getName().endsWith(".pdf")) {
Pieces pieces = new Pieces(FileTypeEnum.PDF, o.getAbsolutePath(), o.getName());
Pieces pieces = new Pieces(FileTypeEnum.PDF, o.getAbsolutePath(), o.getName(), LevelType.THREE);
allDirectory.add(pieces);
} else if (o.getName().endsWith(".docx")) {
Pieces pieces = new Pieces(FileTypeEnum.DOCX, o.getAbsolutePath(), o.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOCX, o.getAbsolutePath(), o.getName(), LevelType.THREE);
allDirectory.add(pieces);
} else if (o.getName().endsWith(".doc")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, o.getAbsolutePath(), o.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOC, o.getAbsolutePath(), o.getName(), LevelType.THREE);
allDirectory.add(pieces);
} else if (o.getName().endsWith(".jpg") || o.getName().endsWith(".png") || o.getName().endsWith(".jpeg") || o.getName().endsWith(".tif") || o.getName().endsWith(".tiff")) {
Pieces pieces = new Pieces(FileTypeEnum.JPG, o.getParentFile().getAbsolutePath(), o.getParentFile().getName());
allDirectory.add(pieces);
if(levelType==LevelType.THREE){
//如果是三层目录。则自己就是件
Pieces pieces = new Pieces(FileTypeEnum.JPG, o.getAbsolutePath(), o.getName(), LevelType.THREE);
allDirectory.add(pieces);
}else{
Pieces pieces = new Pieces(FileTypeEnum.JPG, o.getParentFile().getAbsolutePath(), o.getParentFile().getName(), LevelType.FOUR);
allDirectory.add(pieces);
}
break;
} else {

@ -0,0 +1,15 @@
package com.docus.sw.fenpan;
public enum LevelType {
THREE,
FOUR;
public static LevelType value(String level){
if(level.equals("3层")){
return LevelType.THREE;
}else{
return LevelType.FOUR;
}
}
}

@ -175,6 +175,16 @@ public class MyApplication {
leftGbc.gridx = 0;
leftGbc.gridy = 0;
leftPanel.add(new JLabel("层级目录:"));
String[] levels = {"4层", "3层"};
JComboBox<String> levelComboBox = new JComboBox<>(levels);
leftGbc.gridx = 1;
leftGbc.gridwidth = 1;
leftPanel.add(levelComboBox);
leftGbc.gridx = 0;
leftGbc.gridy = 1;
leftPanel.add(new JLabel("规格选择:"));
String[] rollmodes = {"16mm规格", "35mm规格"};
JComboBox<String> rollmodeComboBox = new JComboBox<>(rollmodes);
@ -183,7 +193,7 @@ public class MyApplication {
leftPanel.add(rollmodeComboBox);
leftGbc.gridx = 0;
leftGbc.gridy = 1;
leftGbc.gridy = 2;
leftPanel.add(new JLabel("分盘目录:"), leftGbc);
JTextField folderField = new JTextField(20);
leftGbc.gridx = 1;
@ -208,7 +218,7 @@ public class MyApplication {
leftPanel.add(folderChooserButton, leftGbc);
leftGbc.gridx = 0;
leftGbc.gridy = 2;
leftGbc.gridy = 3;
leftPanel.add(new JLabel("保存路径:"), leftGbc);
JTextField savePathField = new JTextField(20);
leftGbc.gridx = 1;
@ -236,7 +246,7 @@ public class MyApplication {
leftPanel.add(savePathChooserButton, leftGbc);
leftGbc.gridx = 0;
leftGbc.gridy = 3;
leftGbc.gridy = 4;
leftPanel.add(new JLabel("宗前缀名:"), leftGbc);
JTextField zongFiled = new JTextField(20);
leftGbc.gridx = 1;
@ -244,7 +254,7 @@ public class MyApplication {
leftGbc.gridx = 0;
leftGbc.gridy = 4;
leftGbc.gridy = 5;
leftPanel.add(new JLabel("起始分盘号:"), leftGbc);
JTextField spiltNum = new JTextField(20);
leftGbc.gridx = 1;
@ -253,7 +263,7 @@ public class MyApplication {
leftGbc.gridx = 0;
leftGbc.gridy = 5;
leftGbc.gridy = 6;
leftGbc.gridwidth = 2;
leftGbc.anchor = GridBagConstraints.CENTER;
JButton fenpanJbtn = new JButton("开始分盘");
@ -292,7 +302,7 @@ public class MyApplication {
String readUrl = folderField.getText();
String s = Objects.requireNonNull(rollmodeComboBox.getSelectedItem()).toString();
System.out.println(s);
new FenpanService(s,zongFiled.getText(),Integer.parseInt(spiltNum.getText())).fenpan(saveUrl,readUrl);
new FenpanService(s,zongFiled.getText(),Integer.parseInt(spiltNum.getText()),LevelType.value(levelComboBox.getSelectedItem().toString())).fenpan(saveUrl,readUrl);
SwingUtilities.invokeLater(new Runnable() {
@Override
@ -345,9 +355,18 @@ public class MyApplication {
leftGbc.gridx = 0;
leftGbc.gridy = 0;
leftPanel.add(new JLabel("层级目录:"));
String[] levels = {"4层", "3层"};
JComboBox<String> levelComboBox = new JComboBox<>(levels);
leftGbc.gridx = 1;
leftGbc.gridwidth = 1;
leftPanel.add(levelComboBox);
leftGbc.gridx = 0;
leftGbc.gridy = 1;
leftGbc.anchor = GridBagConstraints.WEST;
leftPanel.add(new JLabel("文件路径选择:"), leftGbc);
JTextField filePathField = new JTextField(20);
@ -363,7 +382,7 @@ public class MyApplication {
leftGbc.gridx = 0;
leftGbc.gridy = 1;
leftGbc.gridy = 2;
leftGbc.anchor = GridBagConstraints.WEST;
leftPanel.add(new JLabel("保存路径选择:"), leftGbc);
JTextField savefilePathField = new JTextField(20);
@ -443,7 +462,7 @@ public class MyApplication {
// 模拟耗时操作
try {
new CheckService().index(filePathField.getText(),savefilePathField.getText());
new CheckService().index(filePathField.getText(),savefilePathField.getText(),LevelType.value(levelComboBox.getSelectedItem().toString()));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
@ -475,6 +494,15 @@ public class MyApplication {
leftIndexGbc.gridx = 0;
leftIndexGbc.gridy = 0;
leftIndexPanel.add(new JLabel("层级目录:"));
String[] levels = {"4层", "3层"};
JComboBox<String> levelComboBox = new JComboBox<>(levels);
leftIndexGbc.gridx = 1;
leftIndexGbc.gridwidth = 1;
leftIndexPanel.add(levelComboBox);
leftIndexGbc.gridx = 0;
leftIndexGbc.gridy = 1;
leftIndexPanel.add(new JLabel("索引模式:"));
String[] rollmodes = {"详细索引", "简略索引"};
JComboBox<String> rollmodeComboBox = new JComboBox<>(rollmodes);
@ -483,7 +511,7 @@ public class MyApplication {
leftIndexPanel.add(rollmodeComboBox);
leftIndexGbc.gridx = 0;
leftIndexGbc.gridy = 1;
leftIndexGbc.gridy = 2;
leftIndexGbc.anchor = GridBagConstraints.WEST;
leftIndexPanel.add(new JLabel("文件路径选择:"), leftIndexGbc);
JTextField filePathField = new JTextField(20);
@ -559,7 +587,7 @@ public class MyApplication {
// 模拟耗时操作
try {
new SuoyinService().index(filePathField.getText(),rollmodeComboBox.getSelectedItem().toString());
new SuoyinService().index(filePathField.getText(),rollmodeComboBox.getSelectedItem().toString(),LevelType.value(levelComboBox.getSelectedItem().toString()));
} catch (IOException ex) {
throw new RuntimeException(ex);
}

@ -26,11 +26,14 @@ public class Pieces {
List<Document> documentList;
private LevelType levelType;
public Pieces(FileTypeEnum fileTypeEnum, String absolutePath, String name) {
public Pieces(FileTypeEnum fileTypeEnum, String absolutePath, String name,LevelType levelType) {
this.fileTypeEnum = fileTypeEnum;
this.absolutePath = absolutePath;
this.name = name;
this.levelType = levelType;
}

@ -3,10 +3,7 @@ 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.fenpan.*;
import com.docus.sw.word.GetPicsDocx;
import com.docus.sw.word.PdfBoxUtils;
import com.docus.sw.word.ReadImgDoc;
@ -38,7 +35,7 @@ public class CheckService {
// new CheckService().index(path);
}
public void index(String path,String savepath) throws IOException {
public void index(String path,String savepath, LevelType levelType) throws IOException {
Map<String, IndexPlate> map = new HashMap<>();
findAllDir(path, map);
@ -61,7 +58,7 @@ public class CheckService {
Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath());
List<Pieces> pieceList = new ArrayList<>();
File[] piecesFile = rollFile.listFiles();
Pieces pieces = new Pieces(FileTypeEnum.JPG, roll.getAbsolutePath(), roll.getName());
Pieces pieces = new Pieces(FileTypeEnum.JPG, roll.getAbsolutePath(), roll.getName(), LevelType.THREE);
genPieces(pieces, piecesFile, FileTypeEnum.JPG);
pieceList.add(pieces);
roll.putAll(pieceList);
@ -71,7 +68,7 @@ public class CheckService {
Roll roll = new Roll(rollFile.getName(), rollFile.getAbsolutePath());
List<Pieces> pieceList = new ArrayList<>();
File[] piecesFile = rollFile.listFiles();
Pieces pieces = new Pieces(FileTypeEnum.JPG, roll.getAbsolutePath(), roll.getName());
Pieces pieces = new Pieces(FileTypeEnum.JPG, roll.getAbsolutePath(), roll.getName(), LevelType.THREE);
genPieces(pieces, piecesFile, FileTypeEnum.JPG);
pieceList.add(pieces);
roll.putAll(pieceList);
@ -86,7 +83,7 @@ public class CheckService {
//区分word和pdf
if (piece.getName().endsWith(".doc")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName(), LevelType.THREE);
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
@ -102,7 +99,7 @@ public class CheckService {
//删除对应的temp 文件
FileUtils.delete(temp);
} else if (piece.getName().endsWith(".docx")) {
Pieces pieces = new Pieces(FileTypeEnum.DOCX, piece.getAbsolutePath(), piece.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOCX, piece.getAbsolutePath(), piece.getName(), LevelType.THREE);
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
@ -117,7 +114,7 @@ public class CheckService {
//删除对应的temp 文件
FileUtils.delete(temp);
} else if (piece.getName().endsWith(".pdf")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName(), LevelType.THREE);
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
@ -138,10 +135,19 @@ public class CheckService {
// 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);
if(levelType==LevelType.THREE){
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName(),LevelType.THREE);
File[] listFiles = piece.getParentFile().listFiles(); //就是自己本身
genPieces(pieces, listFiles, FileTypeEnum.JPG);
pieceList.add(pieces);
}else{
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName(),LevelType.FOUR);
File[] listFiles = piece.listFiles();
genPieces(pieces, listFiles, FileTypeEnum.JPG);
pieceList.add(pieces);
}
}
}
@ -187,16 +193,16 @@ public class CheckService {
@Override
public int compare(CheckPageRow file1, CheckPageRow file2) {
// 使用正则表达式提取数字部分
int num1 = extractNumber(file1.getPhNum());
int num2 = extractNumber(file2.getPhNum());
long num1 = extractNumber(file1.getPhNum());
long num2 = extractNumber(file2.getPhNum());
// 比较提取的数字部分
return Integer.compare(num1, num2);
return Long.compare(num1, num2);
}
private int extractNumber(String fileName) {
private long extractNumber(String fileName) {
String numberPart = fileName.replaceAll("[^0-9]", "");
return numberPart.isEmpty() ? 0 : Integer.parseInt(numberPart);
return numberPart.isEmpty() ? 0 : Long.parseLong(numberPart);
}
};
Collections.sort(checkPageRows,fileComparator);

@ -3,10 +3,7 @@ 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.fenpan.*;
import com.docus.sw.word.GetPicsDocx;
import com.docus.sw.word.PdfBoxUtils;
import com.docus.sw.word.ReadImgDoc;
@ -34,7 +31,7 @@ public class SuoyinService {
//统计出需要使用的 胶片量
public void index(String path, String indexType) throws IOException {
public void index(String path, String indexType,LevelType levelType) throws IOException {
Map<String, IndexPlate> map = new HashMap<>();
findAllDir(path, map);
@ -67,7 +64,7 @@ public class SuoyinService {
//区分word和pdf
if (piece.getName().endsWith(".doc")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName(), LevelType.THREE);
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
@ -83,7 +80,7 @@ public class SuoyinService {
//删除对应的temp 文件
FileUtils.delete(temp);
} else if (piece.getName().endsWith(".docx")) {
Pieces pieces = new Pieces(FileTypeEnum.DOCX, piece.getAbsolutePath(), piece.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOCX, piece.getAbsolutePath(), piece.getName(), LevelType.THREE);
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
@ -98,7 +95,7 @@ public class SuoyinService {
//删除对应的temp 文件
FileUtils.delete(temp);
} else if (piece.getName().endsWith(".pdf")) {
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName(), LevelType.THREE);
String teamName = "tempIndex/" + UUID.randomUUID();
File temp = new File(teamName);
@ -119,10 +116,19 @@ public class SuoyinService {
// 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);
int level =3;
if(levelType==LevelType.THREE){
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName(),LevelType.THREE);
File[] listFiles = piece.getParentFile().listFiles();
genPieces(pieces, listFiles, FileTypeEnum.JPG);
pieceList.add(pieces);
}else{
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName(),LevelType.FOUR);
File[] listFiles = piece.listFiles();
genPieces(pieces, listFiles, FileTypeEnum.JPG);
pieceList.add(pieces);
}
}
}

@ -187,7 +187,7 @@ public class PdfBoxUtils {
}
public static void main(String[] args) throws Exception {
pdf2image("C:\\Users\\zhanghai\\Desktop\\桌面\\test\\a.pdf", "C:\\Users\\zhanghai\\Desktop\\桌面\\test\\");
pdf2image("C:\\Users\\zhanghai\\Desktop\\桌面\\test3\\287a51df-ca56-4fbe-9c86-8b8d35bb3a0d~1.pdf", "C:\\Users\\zhanghai\\Desktop\\桌面\\test\\");
// long a1 = System.currentTimeMillis();

Loading…
Cancel
Save