|
@@ -1,16 +1,17 @@
|
|
|
package org.springblade.evisa.utils;
|
|
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.pdmodel.PDPage;
|
|
|
import org.apache.pdfbox.text.PDFTextStripper;
|
|
|
import org.springblade.business.vo.TaskSignInfoVO;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -23,7 +24,9 @@ public class PDFUtils {
|
|
|
PDFTextStripper stripper = new PDFTextStripper();
|
|
|
String text = stripper.getText(document);
|
|
|
String[] lines = text.split("[ \\n]+");
|
|
|
- String regex = "^\\d{4}年\\d{2}月\\d{2}日$";
|
|
|
+ String lastDate = getPdfFirstPageLastDate(document);
|
|
|
+ taskApp.setPdfDate(lastDate);
|
|
|
+ Pattern pattern = Pattern.compile("(\\d{4}[年-]\\d{2}[月-]\\d{2}日?)");
|
|
|
|
|
|
for(int k=0;k<lines.length;k++){
|
|
|
String textStr = lines[k];
|
|
@@ -41,10 +44,11 @@ public class PDFUtils {
|
|
|
if (txt.length() >= 15 && Func.isNumeric(txt)||(Func.isNumeric(txt)&&txt.length()==8&&txt.startsWith("123"))) {
|
|
|
eVisaConfigList.add(txt);
|
|
|
}
|
|
|
-
|
|
|
- Pattern pattern = Pattern.compile(regex);
|
|
|
- if(pattern.matcher(txt).matches()){
|
|
|
- taskApp.setPdfDate(txt);
|
|
|
+ if (taskApp.getPdfDate() == null || taskApp.getPdfDate().isEmpty()) {
|
|
|
+ Matcher matcher = pattern.matcher(txt);
|
|
|
+ if(matcher.matches()){
|
|
|
+ taskApp.setPdfDate(matcher.group(1));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -123,4 +127,26 @@ public class PDFUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static String getPdfFirstPageLastDate(PDDocument document) throws IOException {
|
|
|
+ PDFTextStripper stripper = new PDFTextStripper();
|
|
|
+ stripper.setStartPage(1);
|
|
|
+ stripper.setEndPage(1);
|
|
|
+ String text = stripper.getText(document);
|
|
|
+ Pattern pattern = Pattern.compile("(\\d{4}[-年.]\r?\n?\\d{2}[-月.]\r?\n?\\d{2}日?)");
|
|
|
+ Matcher matcher = pattern.matcher(text);
|
|
|
+ List<String> dates = new ArrayList<>();
|
|
|
+ while (matcher.find()) {
|
|
|
+ dates.add(matcher.group(1));
|
|
|
+ }
|
|
|
+ if (!dates.isEmpty()) {
|
|
|
+ Optional<String> max = dates.stream().map(item -> {
|
|
|
+ String replace = item.replace("年", "-").replace("月", "-").replace("日", "").replaceAll("\\.", "-");
|
|
|
+ return replace.replaceAll("[\r\n]", "");
|
|
|
+ }).max(String::compareTo);
|
|
|
+ return max.get();
|
|
|
+ } else {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|