Browse Source

电签时获取pdf第一页最大时间

lvy 2 months ago
parent
commit
aa3f98aa29

+ 1 - 1
blade-service/blade-e-visa/src/main/java/org/springblade/evisa/service/impl/EVDataServiceImpl.java

@@ -335,7 +335,7 @@ public class EVDataServiceImpl implements EVDataService {
                     if (taskApp.getSigType() == 2) {
                         this.jdbcTemplate.execute("update u_entrust_info set sample_status=2,status=" + (taskApp.getSigType() + 1) + ",entrust_e_pdf='" + taskApp.getLastFilePdfUrl() + "' where id=(SELECT wbs_id from u_information_query where id='" + taskApp.getFormDataId() + "')");
                     }
-                    updateSql = "update u_information_query set e_visa_pdf_url='" + taskApp.getLastFilePdfUrl() + "',status=" + taskApp.getSigType() + " where id='" + taskApp.getFormDataId() + "'";
+                    updateSql = "update u_information_query set e_visa_pdf_url='" + taskApp.getLastFilePdfUrl() + "',status=" + taskApp.getSigType() + ",business_time='" + taskApp.getPdfDate() + "' where id='" + taskApp.getFormDataId() + "'";
                 }
                 this.jdbcTemplate.execute(updateSql);
                 System.out.println("u_information_query修改语句:"+updateSql);

+ 34 - 8
blade-service/blade-e-visa/src/main/java/org/springblade/evisa/utils/PDFUtils.java

@@ -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 "";
+        }
+    }
+
 }