|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
package cn.iocoder.yudao.server.service; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.iocoder.yudao.module.special.controller.admin.equipmentregistry.vo.EquipmentRegistryRespVO; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -9,6 +9,8 @@ import java.math.BigDecimal; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
@ -24,6 +26,51 @@ public class CertificateOfApprovalService { |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public EquipmentRegistryRespVO getCertificateOfApproval(List<String> texts, String postfix) { |
|
|
|
|
EquipmentRegistryRespVO equipmentRegistryRespVO = new EquipmentRegistryRespVO(); |
|
|
|
|
equipmentRegistryRespVO.setEquipmentType("特种气瓶"); |
|
|
|
|
equipmentRegistryRespVO.setProductName("车用气瓶"); |
|
|
|
|
equipmentRegistryRespVO.setCylinderQuantity(1); |
|
|
|
|
|
|
|
|
|
boolean beijingfute = texts.stream().anyMatch(t -> t.equals("减压器编号") && t.equals("生产厂家") && t.equals("容积、数量")); |
|
|
|
|
if (beijingfute) { |
|
|
|
|
//北京福田汽车股份有限公司特殊处理
|
|
|
|
|
equipmentRegistryRespVO.setContractor("北京福田汽车股份有限公司"); |
|
|
|
|
String vehicleVin = extractManufacturer(texts, "车架号", 1); |
|
|
|
|
if (vehicleVin != null) { |
|
|
|
|
equipmentRegistryRespVO.setVehicleVin(vehicleVin); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String one = extractManufacturer(texts, "气瓶1编号", 1); |
|
|
|
|
String oneL = extractManufacturerContains(texts, "气瓶1:", 0); |
|
|
|
|
|
|
|
|
|
String productId = ""; |
|
|
|
|
if (one != null) { |
|
|
|
|
String two = extractManufacturer(texts, "气瓶2编号", 1); |
|
|
|
|
if (two == null) { |
|
|
|
|
productId = one; |
|
|
|
|
} else { |
|
|
|
|
productId = one+"/"+two; |
|
|
|
|
} |
|
|
|
|
equipmentRegistryRespVO.setProductId(productId); |
|
|
|
|
} |
|
|
|
|
if (oneL != null) { |
|
|
|
|
//气瓶1:65.4L
|
|
|
|
|
String numStr1 = StrUtil.subBetween(oneL, ":", "L"); |
|
|
|
|
String twoL = extractManufacturerContains(texts, "气瓶2:", 0); |
|
|
|
|
if (twoL == null) { |
|
|
|
|
equipmentRegistryRespVO.setCylinderVolume(numStr1); |
|
|
|
|
} else { |
|
|
|
|
String numStr2 = StrUtil.subBetween(twoL, ":", "L"); |
|
|
|
|
double num1 = Double.parseDouble(numStr1); |
|
|
|
|
double num2 = Double.parseDouble(numStr2); |
|
|
|
|
double sum = num1 + num2; |
|
|
|
|
String resultStr = String.valueOf(sum); |
|
|
|
|
|
|
|
|
|
equipmentRegistryRespVO.setCylinderVolume(resultStr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return equipmentRegistryRespVO; |
|
|
|
|
} |
|
|
|
|
boolean productQualified = texts.stream().anyMatch(t -> t.equals("安装单位名称")); |
|
|
|
|
Map<String, String> fieldMap = new HashMap<>(); |
|
|
|
|
if (productQualified) { |
|
|
|
@ -31,10 +78,7 @@ public class CertificateOfApprovalService { |
|
|
|
|
} else { |
|
|
|
|
fieldMap = fieldMappingService.getCertificateMapping("安装单位", texts); |
|
|
|
|
} |
|
|
|
|
EquipmentRegistryRespVO equipmentRegistryRespVO = new EquipmentRegistryRespVO(); |
|
|
|
|
equipmentRegistryRespVO.setEquipmentType("特种气瓶"); |
|
|
|
|
equipmentRegistryRespVO.setProductName("车用气瓶"); |
|
|
|
|
equipmentRegistryRespVO.setCylinderQuantity(1); |
|
|
|
|
|
|
|
|
|
int productIdOffset = 1; |
|
|
|
|
if (!postfix.equals("pdf")) { |
|
|
|
|
productIdOffset = 1; |
|
|
|
@ -52,6 +96,10 @@ public class CertificateOfApprovalService { |
|
|
|
|
String vehicleVin = extractManufacturer(texts, fieldMap.get("vehicleVin"), 1); |
|
|
|
|
if (ObjectUtil.isNotEmpty(vehicleVin)) { |
|
|
|
|
//车辆识别代号
|
|
|
|
|
if (extractVin(vehicleVin) == null) { |
|
|
|
|
vehicleVin = extractManufacturer(texts, fieldMap.get("vehicleVin"), 2); |
|
|
|
|
vehicleVin = extractVin(vehicleVin); |
|
|
|
|
} |
|
|
|
|
equipmentRegistryRespVO.setVehicleVin(vehicleVin); |
|
|
|
|
} |
|
|
|
|
int contractorOffset = 1; |
|
|
|
@ -67,7 +115,20 @@ public class CertificateOfApprovalService { |
|
|
|
|
return equipmentRegistryRespVO; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
private static String extractVin(String text) { |
|
|
|
|
// 正则表达式直接匹配以 L 开头的 17 位字符
|
|
|
|
|
Pattern pattern = Pattern.compile("^L[A-Za-z0-9]{16}"); |
|
|
|
|
Matcher matcher = pattern.matcher(text); |
|
|
|
|
|
|
|
|
|
if (matcher.find()) { |
|
|
|
|
String code = matcher.group(0); |
|
|
|
|
System.out.println("匹配到的代号: " + code); // 输出:LFWSRX9L8RIF18215
|
|
|
|
|
return code; |
|
|
|
|
} else { |
|
|
|
|
System.out.println("未找到符合要求的代号"); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
public static String extractManufacturer(List<String> recTexts, String keyword, int offset) { |
|
|
|
|
// 防御性检查:列表为空或为null时直接返回null
|
|
|
|
|
if (recTexts == null || recTexts.isEmpty()) { |
|
|
|
@ -86,4 +147,21 @@ public class CertificateOfApprovalService { |
|
|
|
|
} |
|
|
|
|
return null; // 未找到或越界时返回null
|
|
|
|
|
} |
|
|
|
|
public static String extractManufacturerContains(List<String> recTexts, String keyword, int offset) { |
|
|
|
|
// 防御性检查:列表为空或为null时直接返回null
|
|
|
|
|
if (recTexts == null || recTexts.isEmpty()) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 使用 Stream 查找关键词位置
|
|
|
|
|
int index = IntStream.range(0, recTexts.size()) |
|
|
|
|
.filter(i -> recTexts.get(i).contains(keyword)) |
|
|
|
|
.findFirst() |
|
|
|
|
.orElse(-1); // 未找到返回-1
|
|
|
|
|
|
|
|
|
|
// 检查是否找到关键词,且偏移后不越界
|
|
|
|
|
if (index != -1 && index + offset < recTexts.size()) { |
|
|
|
|
return recTexts.get(index + offset); |
|
|
|
|
} |
|
|
|
|
return null; // 未找到或越界时返回null
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|