|
|
@@ -13,11 +13,12 @@ import java.net.MalformedURLException;
|
|
|
import java.net.URI;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+import static com.ydtech.modules.order.utils.InsuranceLog.logger;
|
|
|
+
|
|
|
/**
|
|
|
* @version
|
|
|
* @author: hxl
|
|
|
@@ -172,6 +173,7 @@ public class PDFUtil {
|
|
|
pdfStripper.setShouldSeparateByBeads(true);
|
|
|
text= pdfStripper.getText(document);
|
|
|
text = text.replaceAll("\\s+", " ");
|
|
|
+ logger.info(text);
|
|
|
document.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
@@ -180,6 +182,9 @@ public class PDFUtil {
|
|
|
}
|
|
|
|
|
|
public static String getPdfContentStr(String pdfText, String beginStr,String endStr,String dateType) {
|
|
|
+ if("end".equals(endStr)){
|
|
|
+ return getEndString(pdfText, beginStr);
|
|
|
+ }
|
|
|
String contentStr = getContentStr(pdfText, beginStr, endStr);
|
|
|
if(StringUtils.isNotBlank(contentStr)){
|
|
|
contentStr=contentStr.replaceAll(" ", "");
|
|
|
@@ -189,11 +194,27 @@ public class PDFUtil {
|
|
|
contentStr = contentStr.replaceAll("\\s+", "");
|
|
|
contentStr = contentStr.replaceAll("[^\u4E00-\u9FA50-9年月日:-]+", "");
|
|
|
contentStr = contentStr.replaceAll("时", "");
|
|
|
+ String longestRepeat = getRepeatedData(contentStr);
|
|
|
+ if(StringUtils.isNotBlank(longestRepeat)){
|
|
|
+ contentStr = longestRepeat;
|
|
|
+ }
|
|
|
}
|
|
|
return contentStr;
|
|
|
}
|
|
|
|
|
|
public static LocalDateTime getPdfContentDate(String pdfText, String beginStr,String endStr,String dateType) {
|
|
|
+ if("end".equals(endStr)){
|
|
|
+ String substring = getEndString(pdfText, beginStr);
|
|
|
+ String patten ="";
|
|
|
+ if("1".equals(dateType)){
|
|
|
+ patten ="yyyy-MM-dd HH:mm:ss";
|
|
|
+ }else if("2".equals(dateType)){
|
|
|
+ patten = "yyyy/MM/dd HH:mm:ss";
|
|
|
+ }else if("3".equals(dateType)){
|
|
|
+ patten = "yyyy年MM月dd日 HH:mm:ss";
|
|
|
+ }
|
|
|
+ return LocalDateTime.parse(substring, DateTimeFormatter.ofPattern(patten));
|
|
|
+ }
|
|
|
String payDate = getContentStr(pdfText, beginStr, endStr);
|
|
|
LocalDateTime payDateTime = null;
|
|
|
if("1".equals(dateType)){
|
|
|
@@ -205,6 +226,31 @@ public class PDFUtil {
|
|
|
}
|
|
|
return payDateTime;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/23 9:26
|
|
|
+ * @Description: 截取开始到字符串结尾的字符
|
|
|
+ */
|
|
|
+ private static String getEndString(String pdfText, String beginStr) {
|
|
|
+ String substring = pdfText.substring(pdfText.indexOf(beginStr), pdfText.length());
|
|
|
+ substring=substring.replaceAll(beginStr, "");
|
|
|
+ substring=substring.replaceAll(beginStr, "");
|
|
|
+ substring = substring.replaceAll(" ", "");
|
|
|
+ substring = substring.replaceAll("\\n+", "");
|
|
|
+ substring = substring.replaceAll("\\t+", "");
|
|
|
+ substring = substring.replaceAll("\\r+", "");
|
|
|
+ substring = substring.replaceAll("\\s+", "");
|
|
|
+ if(substring.length() == 18){
|
|
|
+ substring = substring.substring(0,10)+" "+ substring.substring(10,18);
|
|
|
+ }else if(substring.length() == 15){
|
|
|
+ substring = substring.substring(0,10)+" "+ substring.substring(10,15)+":00";
|
|
|
+ }else if(substring.length() == 10){
|
|
|
+ substring = substring+" 00:00:00";
|
|
|
+ }
|
|
|
+ return substring;
|
|
|
+ }
|
|
|
+
|
|
|
public static HashMap<String,LocalDateTime> getPdfContent(String pdfPath, String companyId){
|
|
|
HashMap<String,LocalDateTime> map =new HashMap<String,LocalDateTime>();
|
|
|
String pdfText = getPdfText(pdfPath);
|
|
|
@@ -421,6 +467,10 @@ public class PDFUtil {
|
|
|
payDate = payDate.replaceAll("\\s+", "");
|
|
|
payDate = payDate.replaceAll("[^\u4E00-\u9FA50-9年月日:]+", "");
|
|
|
payDate = payDate.replaceAll("时", "");
|
|
|
+ String longestRepeat = getRepeatedData(payDate);
|
|
|
+ if(StringUtils.isNotBlank(longestRepeat)){
|
|
|
+ payDate = longestRepeat;
|
|
|
+ }
|
|
|
int count = 0;
|
|
|
int index = 0;
|
|
|
while ((index = payDate.indexOf(":", index)) != -1) {
|
|
|
@@ -469,7 +519,21 @@ public class PDFUtil {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * @version
|
|
|
+ * @author: hxl
|
|
|
+ * @Date: 2024/10/22 15:08
|
|
|
+ * @Description: 找出字符串中的重复值
|
|
|
+ */
|
|
|
+ private static String getRepeatedData(String input) {
|
|
|
+ String repeatedData = "";
|
|
|
+ Pattern pattern = Pattern.compile("(\\d{4}年\\d{1,2}月\\d{1,2}日)\\s*\\1");
|
|
|
+ Matcher matcher = pattern.matcher(input);
|
|
|
+ if (matcher.find()) {
|
|
|
+ repeatedData= matcher.group(1);
|
|
|
+ }
|
|
|
+ return repeatedData;
|
|
|
+ }
|
|
|
public static String trafferHttpToLocalPath(String path) {
|
|
|
if (path.contains("http") || path.contains("https")) {
|
|
|
//转成本地路径
|
|
|
@@ -508,8 +572,8 @@ public class PDFUtil {
|
|
|
// String pdfFilePath = "D:\\nasData\\carInsPolicy\\1823634528262541312\\晋JH6836-交强险保单.pdf"; // PDF文件路径
|
|
|
// HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "TPBX");
|
|
|
//恒邦
|
|
|
- String pdfFilePath = "D:\\nasData\\carInsPolicy\\晋KLY103\\晋KLY103-交强险保单.pdf"; // PDF文件路径
|
|
|
- HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "HBIC");
|
|
|
+ // String pdfFilePath = "D:\\nasData\\carInsPolicy\\晋KLY103\\晋KLY103-交强险保单.pdf"; // PDF文件路径
|
|
|
+ // HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "HBIC");
|
|
|
//国任
|
|
|
// String pdfFilePath = "D:\\nasData\\carInsPolicy\\晋A139LV\\晋A139LV-交强险保单.pdf"; // PDF文件路径
|
|
|
// HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "XDCX");
|
|
|
@@ -602,11 +666,13 @@ public class PDFUtil {
|
|
|
// String pdfFilePath = "D:\\bx\\ancheng\\f0b6430219fe3f32b2d63ab41dba95c4.pdf"; // PDF文件路径
|
|
|
// HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "ACIC");
|
|
|
// 永安
|
|
|
- // String pdfFilePath = "D:\\bx\\yongan\\交强.pdf"; // PDF文件路径
|
|
|
- // HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "YAIC");
|
|
|
+ String pdfFilePath = "D:\\bx\\yongan\\交强.pdf"; // PDF文件路径
|
|
|
+ HashMap<String, LocalDateTime> zmbx = getPdfContent(pdfFilePath, "YAIC");
|
|
|
|
|
|
System.out.println(zmbx.toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|