|
|
@@ -69,10 +69,11 @@ public class App extends Application {
|
|
|
*/
|
|
|
private List<OutputModel> outputModelList;
|
|
|
/**
|
|
|
- * IMEI码与PDF文件映射
|
|
|
+ * IMEI码与工单文件映射
|
|
|
+ * 文件类型可能是PDF或者JPG
|
|
|
* @see Map<String, File>
|
|
|
*/
|
|
|
- private Map<String,File> pdfFileMap;
|
|
|
+ private Map<String,File> workOrderFileMap;
|
|
|
/**
|
|
|
* 进度条控件
|
|
|
* @see ProgressBar
|
|
|
@@ -282,7 +283,7 @@ public class App extends Application {
|
|
|
|
|
|
inputModelList = new ArrayList<>();
|
|
|
outputModelList = new ArrayList<>();
|
|
|
- pdfFileMap = new HashMap<>();
|
|
|
+ workOrderFileMap = new HashMap<>();
|
|
|
List<OutputErrorModel> errorImeiList = new ArrayList<>();
|
|
|
|
|
|
// 读取excel
|
|
|
@@ -321,7 +322,7 @@ public class App extends Application {
|
|
|
//资源清理
|
|
|
inputModelList = null;
|
|
|
outputModelList = null;
|
|
|
- pdfFileMap = null;
|
|
|
+ workOrderFileMap = null;
|
|
|
}
|
|
|
}).start();
|
|
|
}
|
|
|
@@ -338,29 +339,35 @@ public class App extends Application {
|
|
|
}
|
|
|
|
|
|
private void handler(List<OutputErrorModel> errorImeiList) {
|
|
|
- int totalPDFs = inputModelList.size();
|
|
|
- int processedPDFs = 0;
|
|
|
+ int totalWorkOrders = inputModelList.size();
|
|
|
+ int processedWorkOrders = 0;
|
|
|
|
|
|
for (InputModel inputModel : inputModelList) {
|
|
|
OutputModel outputModel = new OutputModel(inputModel);
|
|
|
String imei = inputModel.getImei();
|
|
|
- //找到对应pdf的文件路径
|
|
|
- File pdfFile = pdfFileMap.getOrDefault(imei, null);
|
|
|
- if (Objects.isNull(pdfFile)) {
|
|
|
+ //找到对应工单文件的路径
|
|
|
+ File workOrderFile = workOrderFileMap.getOrDefault(imei, null);
|
|
|
+ if (Objects.isNull(workOrderFile)) {
|
|
|
errorImeiList.add(new OutputErrorModel(imei));
|
|
|
- processedPDFs++;
|
|
|
- double progress = 0.5 + (0.4 * processedPDFs / totalPDFs);
|
|
|
- updateProgress("解析PDF文件: " + processedPDFs + "/" + totalPDFs + " (IMEI未找到: " + imei + ")", progress);
|
|
|
+ processedWorkOrders++;
|
|
|
+ double progress = 0.5 + (0.4 * processedWorkOrders / totalWorkOrders);
|
|
|
+ updateProgress("解析工单文件: " + processedWorkOrders + "/" + totalWorkOrders + " (IMEI未找到: " + imei + ")", progress);
|
|
|
continue;
|
|
|
}
|
|
|
+ //解析工单文件
|
|
|
+ String text = null;
|
|
|
+ if (workOrderFile.getName().endsWith(".pdf")) {
|
|
|
+ //pdf
|
|
|
+ text = pdfHandler(workOrderFile);
|
|
|
+ }else if (workOrderFile.getName().endsWith(".jpg") || workOrderFile.getName().endsWith(".png") || workOrderFile.getName().endsWith(".jpeg")) {
|
|
|
+ //图片
|
|
|
+ text = imageHandler(workOrderFile);
|
|
|
+ }
|
|
|
//解析pdf
|
|
|
- String text = "";
|
|
|
- try (PDDocument pdDocument = Loader.loadPDF(pdfFile)) {
|
|
|
- PDFTextStripper textStripper = new PDFTextStripper();
|
|
|
- //提取文本
|
|
|
- text = textStripper.getText(pdDocument);
|
|
|
- //System.out.println("text = " + text);
|
|
|
- //解析金额
|
|
|
+ if (Objects.isNull(text)) {
|
|
|
+ //没有文本
|
|
|
+ errorImeiList.add(new OutputErrorModel(imei));
|
|
|
+ }else{
|
|
|
Matcher matcher = pattern.matcher(text);
|
|
|
if (matcher.find()) {
|
|
|
String money = matcher.group("money"); // 获取命名分组 "money"
|
|
|
@@ -373,23 +380,57 @@ public class App extends Application {
|
|
|
//System.out.println("未匹配到金额");
|
|
|
errorImeiList.add(new OutputErrorModel(imei));
|
|
|
}
|
|
|
- } catch (IOException | NumberFormatException e) {
|
|
|
- e.printStackTrace();
|
|
|
- errorImeiList.add(new OutputErrorModel(imei));
|
|
|
}
|
|
|
+
|
|
|
outputModelList.add(outputModel);
|
|
|
|
|
|
- processedPDFs++;
|
|
|
- double progress = 0.5 + (0.4 * processedPDFs / totalPDFs);
|
|
|
- updateProgress("解析PDF文件: " + processedPDFs + "/" + totalPDFs, progress);
|
|
|
+ processedWorkOrders++;
|
|
|
+ double progress = 0.5 + (0.4 * processedWorkOrders / totalWorkOrders);
|
|
|
+ updateProgress("解析工单文件: " + processedWorkOrders + "/" + totalWorkOrders, progress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图片转文本,通过OCR实现
|
|
|
+ * @param workOrderFile
|
|
|
+ * @return {@code String }
|
|
|
+ * @description:
|
|
|
+ * @author: 杨逸
|
|
|
+ * @data:2025/12/09 14:25:00
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+ private String imageHandler(File workOrderFile) {
|
|
|
+ String text = null;
|
|
|
+ //todo:OCR识别
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PDF转文本
|
|
|
+ * @param workOrderFile 文件对象
|
|
|
+ * @return {@code String }
|
|
|
+ * @description:
|
|
|
+ * @author: 杨逸
|
|
|
+ * @data:2025/12/09 14:24:17
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+ private String pdfHandler(File workOrderFile) {
|
|
|
+ String text = null;
|
|
|
+ try (PDDocument pdDocument = Loader.loadPDF(workOrderFile)) {
|
|
|
+ PDFTextStripper textStripper = new PDFTextStripper();
|
|
|
+ //提取文本
|
|
|
+ text = textStripper.getText(pdDocument);
|
|
|
+ }catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ return text;
|
|
|
}
|
|
|
|
|
|
private void readFolder(String folderPath) {
|
|
|
File folder = new File(folderPath);
|
|
|
File[] files = folder.listFiles();
|
|
|
|
|
|
- // 扫描文件夹并建立IMEI-PDF映射
|
|
|
+ // 扫描文件夹并建立IMEI-工单文件映射
|
|
|
int totalFolders = files.length;
|
|
|
int processedFolders = 0;
|
|
|
|
|
|
@@ -399,10 +440,10 @@ public class App extends Application {
|
|
|
}
|
|
|
File[] listFiles = file.listFiles();
|
|
|
String imei = file.getName().split("-")[2];
|
|
|
- //拿到文件夹里的pdf
|
|
|
- for (File pdfFile : listFiles) {
|
|
|
- if (pdfFile.getName().endsWith(".pdf")) {
|
|
|
- if (pdfFileMap.containsKey(imei)) {
|
|
|
+ //拿到文件夹里的工单文件(文件类型可能是PDF或JPG)
|
|
|
+ for (File workOrderFile : listFiles) {
|
|
|
+ if (workOrderFile.getName().contains("工单照片")) {
|
|
|
+ if (workOrderFileMap.containsKey(imei)) {
|
|
|
//出现重复的imei
|
|
|
Platform.runLater(()->{
|
|
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
|
|
@@ -412,7 +453,7 @@ public class App extends Application {
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
- pdfFileMap.put(imei, pdfFile);
|
|
|
+ workOrderFileMap.put(imei, workOrderFile);
|
|
|
break;
|
|
|
}
|
|
|
}
|