|
|
|
@ -8,11 +8,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@ -120,7 +119,14 @@ public class CertificateOfApprovalService { |
|
|
|
|
if (StrUtil.contains(productId, "瓶号")) { |
|
|
|
|
productId = StrUtil.removePrefix(productId, "瓶号"); |
|
|
|
|
} |
|
|
|
|
equipmentRegistryRespVO.setProductId(productId); |
|
|
|
|
// TODO 再次筛选一遍,查看有没有遗漏的编号
|
|
|
|
|
String ofo = extractRelatedNumbersAsString(texts, productId); |
|
|
|
|
String finalProductId = productId; |
|
|
|
|
String combinedId = Optional.ofNullable(ofo) |
|
|
|
|
.filter(s -> !s.isEmpty()) |
|
|
|
|
.map(s -> finalProductId + "/" + s) |
|
|
|
|
.orElse(productId); |
|
|
|
|
equipmentRegistryRespVO.setProductId(combinedId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
String nominalWorkingPressure = extractManufacturer(texts, fieldMap.get("nominalWorkingPressure"), 1); |
|
|
|
@ -331,4 +337,38 @@ public class CertificateOfApprovalService { |
|
|
|
|
} |
|
|
|
|
return null; // 未找到或越界时返回null
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String extractRelatedNumbersAsString(List<String> recTexts, String knownNumber) { |
|
|
|
|
if (recTexts == null || knownNumber == null) return ""; |
|
|
|
|
|
|
|
|
|
// 1. 动态生成匹配模式
|
|
|
|
|
String dynamicPattern = buildDynamicPattern(knownNumber); |
|
|
|
|
Pattern pattern = Pattern.compile(dynamicPattern); |
|
|
|
|
|
|
|
|
|
// 2. 提取所有匹配项(去重+跳过已知编号)
|
|
|
|
|
StringJoiner result = new StringJoiner("/"); |
|
|
|
|
boolean foundKnownNumber = false; |
|
|
|
|
|
|
|
|
|
for (String text : recTexts) { |
|
|
|
|
if (pattern.matcher(text).matches()) { |
|
|
|
|
if (!foundKnownNumber) { |
|
|
|
|
if (text.equals(knownNumber)) { |
|
|
|
|
foundKnownNumber = true; // 开始记录后续编号
|
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
// 避免重复添加
|
|
|
|
|
if (result.length() == 0 || !text.equals(result.toString().split("/")[result.toString().split("/").length - 1])) { |
|
|
|
|
result.add(text); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return result.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String buildDynamicPattern(String sample) { |
|
|
|
|
String prefix = sample.replaceAll("[^A-Za-z].*", ""); |
|
|
|
|
String digits = sample.replaceAll("[^0-9]", ""); |
|
|
|
|
return "^" + prefix + "\\d{" + digits.length() + "}$"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|