|
|
|
|
@ -11,6 +11,8 @@ import org.springframework.stereotype.Service; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
@ -37,14 +39,27 @@ public class SpecialGasCylinderService { |
|
|
|
|
EquipmentRegistryRespVO equipmentRegistryRespVO = new EquipmentRegistryRespVO(); |
|
|
|
|
equipmentRegistryRespVO.setEquipmentType("特种气瓶"); |
|
|
|
|
equipmentRegistryRespVO.setProductName("车用气瓶"); |
|
|
|
|
String manufacturerField = extractManufacturer(texts, fieldMap.get("manufacturerField"), 1); |
|
|
|
|
if (ObjectUtil.isNotEmpty(manufacturerField)) { |
|
|
|
|
equipmentRegistryRespVO.setManufacturer(manufacturerField); |
|
|
|
|
equipmentRegistryRespVO.setSupervisionAgency(manufacturerField); |
|
|
|
|
String manufacturerField = extractManufacturer(texts, fieldMap.get("manufacturerField"), 0); |
|
|
|
|
if (manufacturerField == null) { |
|
|
|
|
manufacturerField = extractManufacturer(texts, fieldMap.get("manufacturerField"), 1); |
|
|
|
|
if (ObjectUtil.isNotEmpty(manufacturerField)) { |
|
|
|
|
equipmentRegistryRespVO.setManufacturer(manufacturerField); |
|
|
|
|
equipmentRegistryRespVO.setSupervisionAgency(manufacturerField); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
manufacturerField = matchInstallationUnit(fieldMap.get("manufacturerField"), manufacturerField); |
|
|
|
|
if (manufacturerField != null) { |
|
|
|
|
equipmentRegistryRespVO.setManufacturer(manufacturerField); |
|
|
|
|
equipmentRegistryRespVO.setSupervisionAgency(manufacturerField); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
String productionDateField = extractManufacturer(texts, fieldMap.get("productionDateField"), 1); |
|
|
|
|
if (ObjectUtil.isNotEmpty(productionDateField)) { |
|
|
|
|
equipmentRegistryRespVO.setProductionDate(productionDateField); |
|
|
|
|
productionDateField = matchAndCompleteDate(productionDateField); |
|
|
|
|
if (productionDateField != null) { |
|
|
|
|
equipmentRegistryRespVO.setProductionDate(productionDateField); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
int productBatchNumberOffset = 1; |
|
|
|
|
if (!postfix.equals("pdf")) { |
|
|
|
|
@ -58,6 +73,68 @@ public class SpecialGasCylinderService { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 匹配日期字符串并补全日信息 |
|
|
|
|
* @param dateStr 输入的日期字符串 |
|
|
|
|
* @return 补全后的日期字符串,不匹配则返回null |
|
|
|
|
*/ |
|
|
|
|
public static String matchAndCompleteDate(String dateStr) { |
|
|
|
|
if (dateStr == null || dateStr.isEmpty()) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 匹配"2024年09月"或"2024年09月01日"
|
|
|
|
|
String regex1 = "^(\\d{4})年(\\d{1,2})月(\\d{1,2})日?$"; |
|
|
|
|
// 匹配"2024-09"或"2024-09-01"
|
|
|
|
|
String regex2 = "^(\\d{4})-(\\d{1,2})(?:-(\\d{1,2}))?$"; |
|
|
|
|
// 新增:专门匹配"2024年09月"(不带日)
|
|
|
|
|
String regex3 = "^(\\d{4})年(\\d{1,2})月$"; |
|
|
|
|
|
|
|
|
|
Pattern pattern1 = Pattern.compile(regex1); |
|
|
|
|
Pattern pattern2 = Pattern.compile(regex2); |
|
|
|
|
Pattern pattern3 = Pattern.compile(regex3); |
|
|
|
|
|
|
|
|
|
Matcher matcher1 = pattern1.matcher(dateStr); |
|
|
|
|
Matcher matcher2 = pattern2.matcher(dateStr); |
|
|
|
|
Matcher matcher3 = pattern3.matcher(dateStr); |
|
|
|
|
|
|
|
|
|
if (matcher1.matches()) { |
|
|
|
|
String year = matcher1.group(1); |
|
|
|
|
String month = matcher1.group(2); |
|
|
|
|
String day = matcher1.group(3) != null ? matcher1.group(3) : "01"; |
|
|
|
|
return year + "年" + month + "月" + day + "日"; |
|
|
|
|
} else if (matcher2.matches()) { |
|
|
|
|
String year = matcher2.group(1); |
|
|
|
|
String month = matcher2.group(2); |
|
|
|
|
String day = matcher2.group(3) != null ? matcher2.group(3) : "01"; |
|
|
|
|
return year + "-" + month + "-" + day; |
|
|
|
|
} else if (matcher3.matches()) { |
|
|
|
|
// 专门处理"2024年09月"这种不带日的情况
|
|
|
|
|
return matcher3.group(1) + "年" + matcher3.group(2) + "月01日"; |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 匹配制造单位名称,返回冒号后的单位名称 |
|
|
|
|
* @param keyword 关键字,如"制造单位"或"制造单位名称" |
|
|
|
|
* @param input 待匹配的字符串 |
|
|
|
|
* @return 匹配的单位名称,否则返回null |
|
|
|
|
*/ |
|
|
|
|
public static String matchInstallationUnit(String keyword, String input) { |
|
|
|
|
// 构建正则表达式,匹配关键字 + 可选冒号 + 单位名称(公司或修理厂)
|
|
|
|
|
String regex = keyword + "[::]?\\s*([^\\s]+(?:公司))"; |
|
|
|
|
Pattern pattern = Pattern.compile(regex); |
|
|
|
|
Matcher matcher = pattern.matcher(input); |
|
|
|
|
|
|
|
|
|
if (matcher.find()) { |
|
|
|
|
return matcher.group(1); // 返回匹配的单位名称
|
|
|
|
|
} |
|
|
|
|
return null; // 未匹配到有效单位
|
|
|
|
|
} |
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
String text = "监督检验机构:你好"; |
|
|
|
|
String result = StringUtils.substringAfter(text, ":"); |
|
|
|
|
|