工具类,案件压缩包导入优化

This commit is contained in:
18792927508
2023-12-12 16:22:41 +08:00
parent 5730bb12a7
commit a78e3e23d6
28 changed files with 1876 additions and 1096 deletions
@@ -118,10 +118,10 @@ public class OCRUtils {
for (FatchRule fatchRule : fatchRules) {
// 从后往前抓取
if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) {
reverseSubstringText(ocrText, fatchRule, fatchMap);
reverseSubstringText(ocrText, fatchRule, fatchMap,null);
} else {
// 从前往后抓取
substringText(ocrText, fatchRule, fatchMap);
substringText(ocrText, fatchRule, fatchMap,null);
}
}
@@ -129,43 +129,32 @@ public class OCRUtils {
}
public static void sub1(String text, FatchRule fatchRule, Map<String, String> fatchMap) {
if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())) {
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
} else if (StrUtil.isNotEmpty(fatchRule.getStartContent())) {
int startContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getStartContent(), fatchRule.getStartContentRepeatOrder());
if (startContIndex != -1) {
// 开始不为空结束为空
if (StrUtil.isEmpty(fatchRule.getEndContent())) {
if ((startContIndex + fatchRule.getStartContent().length()) <= text.length()) {
String substring = text.substring(startContIndex + fatchRule.getStartContent().length());
// 去除\n
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
}
/**
* 根据抓取规则获取内容
*
* @param ocrText ocr识别的text
* @param fatchRules 抓取规则
* @return
*/
public static void fatchRuleGetContent(String ocrText, List<FatchRule> fatchRules, Map<String, String> fatchMap, Long caseId) {
if (StrUtil.isEmpty(ocrText) || CollectionUtil.isEmpty(fatchRules)) {
return;
}
for (FatchRule fatchRule : fatchRules) {
// 从后往前抓取
if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) {
reverseSubstringText(ocrText, fatchRule, fatchMap, caseId);
} else {
// 从前往后抓取
substringText(ocrText, fatchRule, fatchMap, caseId);
} else {
// 开始不为空结束不为空
int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder());
if (endContIndex != -1 && endContIndex <= text.length() && (startContIndex + fatchRule.getStartContent().length()) <= endContIndex) {
String substring = text.substring(startContIndex + fatchRule.getStartContent().length(), endContIndex);
// 去除\n
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
}
}
//
}
} else if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isNotEmpty(fatchRule.getEndContent())) {
// 开始为空结束不为空
int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder());
if (endContIndex != -1) {
String substring = text.substring(0, endContIndex);
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
}
}
}
/**
* 正向截取字段
*
@@ -173,19 +162,19 @@ public class OCRUtils {
* @param fatchRule
* @param fatchMap
*/
private static void substringText(String text, FatchRule fatchRule, Map<String, String> fatchMap) {
private static void substringText(String text, FatchRule fatchRule, Map<String, String> fatchMap, Long caseId) {
String startContent = fatchRule.getStartContent();
String endContent = fatchRule.getEndContent();
// 开始为空结束为空
if (StrUtil.isEmpty(startContent) && StrUtil.isEmpty(endContent)) {
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(text));
} else if (StrUtil.isNotEmpty(startContent) && StrUtil.isEmpty(endContent)) {
// 开始不为空结束为空
int startContIndex = StrUtil.ordinalIndexOf(text, startContent, fatchRule.getStartContentRepeatOrder());
if (startContIndex != -1 && text.length() >= (startContIndex + startContent.length())) {
String substring = text.substring(startContIndex + startContent.length());
// 去除\n
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(substring));
}
} else if (StrUtil.isEmpty(startContent) && StrUtil.isNotEmpty(endContent)) {
@@ -193,7 +182,7 @@ public class OCRUtils {
int endContIndex = StrUtil.ordinalIndexOf(text, endContent, fatchRule.getEndContentRepeatOrder());
if (endContIndex != -1) {
String substring = text.substring(0, endContIndex);
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(substring));
}
} else if (StrUtil.isNotEmpty(startContent) && StrUtil.isNotEmpty(endContent)) {
// 开始结束不为空
@@ -202,12 +191,72 @@ public class OCRUtils {
if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + startContent.length()) && text.length() >= endIndexOf) {
String substring = text.substring(startIndexOf + startContent.length(), endIndexOf);
fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(substring));
}
}
}
/**
* 从后往前截取字符串
*
* @param text
* @param fatchRule
* @param fatchMap
*/
public static void reverseSubstringText(String text, FatchRule fatchRule, Map<String, String> fatchMap, Long caseId) {
// 反正字符串
String reverseText = StrUtil.reverse(text);
// 结束截取字段
String reverseEndContent = "";
// 开始截取字段
String reverseStartContent = "";
if (StrUtil.isNotEmpty(fatchRule.getEndContent())) {
reverseEndContent = StrUtil.reverse(fatchRule.getEndContent());
}
if (StrUtil.isNotEmpty(fatchRule.getStartContent())) {
reverseStartContent = StrUtil.reverse(fatchRule.getStartContent());
}
// 开始和结束截取都为空
if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) {
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(text));
} else if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) {
// 开始为空,结束不为空
// 根据截取的序号查找出位置
int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder());
if (indexOf != -1) {
String substring = reverseText.substring(0, indexOf);
if (StrUtil.isNotEmpty(substring)) {
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(StrUtil.reverse(substring)));
}
}
} else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) {
// 开始不为空,结束为空
int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder());
if (indexOf != -1 && (indexOf + reverseStartContent.length() <= text.length())) {
String substring = reverseText.substring(indexOf + reverseStartContent.length());
if (StrUtil.isNotEmpty(substring)) {
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(StrUtil.reverse(substring)));
}
}
} else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) {
// 开始结束都不为空
int endIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder());
int startIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder());
if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + reverseStartContent.length()) && text.length() >= endIndexOf) {
String substring = reverseText.substring(startIndexOf + reverseStartContent.length(), endIndexOf);
if (StrUtil.isNotEmpty(substring)) {
fatchMap.put(fatchRule.getColumnName()+Constants.PDFSTR+caseId, trimStr(StrUtil.reverse(substring)));
}
}
}
}
/**
* 去除末尾空格
*
@@ -223,63 +272,4 @@ public class OCRUtils {
}
/**
* 从后往前截取字符串
*
* @param text
* @param fatchRule
* @param fatchMap
*/
public static void reverseSubstringText(String text, FatchRule fatchRule, Map<String, String> fatchMap) {
// 反正字符串
String reverseText = StrUtil.reverse(text);
// 结束截取字段
String reverseEndContent = "";
// 开始截取字段
String reverseStartContent = "";
if (StrUtil.isNotEmpty(fatchRule.getEndContent())) {
reverseEndContent = StrUtil.reverse(fatchRule.getEndContent());
}
if (StrUtil.isNotEmpty(fatchRule.getStartContent())) {
reverseStartContent = StrUtil.reverse(fatchRule.getStartContent());
}
// 开始和结束截取都为空
if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) {
fatchMap.put(fatchRule.getColumnName(), trimStr(text));
} else if (StrUtil.isEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) {
// 开始为空,结束不为空
// 根据截取的序号查找出位置
int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder());
if (indexOf != -1) {
String substring = reverseText.substring(0, indexOf);
if (StrUtil.isNotEmpty(substring)) {
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
}
}
} else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isEmpty(reverseEndContent)) {
// 开始不为空,结束为空
int indexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder());
if (indexOf != -1 && (indexOf + reverseStartContent.length() <= text.length())) {
String substring = reverseText.substring(indexOf + reverseStartContent.length());
if (StrUtil.isNotEmpty(substring)) {
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
}
}
} else if (StrUtil.isNotEmpty(reverseStartContent) && StrUtil.isNotEmpty(reverseEndContent)) {
// 开始结束都不为空
int endIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseEndContent, fatchRule.getEndContentRepeatOrder());
int startIndexOf = StrUtil.ordinalIndexOf(reverseText, reverseStartContent, fatchRule.getStartContentRepeatOrder());
if (startIndexOf != -1 && endIndexOf != -1 && endIndexOf >= (startIndexOf + reverseStartContent.length()) && text.length() >= endIndexOf) {
String substring = reverseText.substring(startIndexOf + reverseStartContent.length(), endIndexOf);
if (StrUtil.isNotEmpty(substring)) {
fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
}
}
}
}
}