测试结束

master
tyc 6 months ago
parent 3e90f55848
commit c1dc11d541
  1. 88
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/CertificateOfApprovalService.java
  2. 2
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/FieldMappingService.java
  3. 54
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/ProductQualifiedService.java
  4. 6
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/SupervisionService.java

@ -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
}
}

@ -38,7 +38,7 @@ public class FieldMappingService {
);
//气瓶公称工作压力
private static final List<String> PRODUCTION_DATE_CANDIDATES_ZS = Arrays.asList(
"工作压力", "公称压力", "公称工作压力:"
"工作压力", "公称压力", "公称工作压力:", "公称工作压力"
);
//气瓶容积
private static final List<String> SUPERVISION_AGENCY_CANDIDATES_ZS = Arrays.asList(

@ -4,7 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.special.controller.admin.equipmentregistry.vo.EquipmentRegistryRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -48,6 +49,9 @@ public class ProductQualifiedService {
}
String nominalWorkingPressure = extractManufacturer(texts, fieldMap.get("nominalWorkingPressure"), nominalWorkingPressureOffset);
if (ObjectUtil.isNotEmpty(nominalWorkingPressure)) {
if (nominalWorkingPressure.equals("MPa")) {
nominalWorkingPressure = extractManufacturer(texts, fieldMap.get("nominalWorkingPressure"), 2);
}
//气瓶公称工作压力
equipmentRegistryRespVO.setNominalWorkingPressure(nominalWorkingPressure);
}
@ -56,22 +60,54 @@ public class ProductQualifiedService {
cylinderVolumeOffset = 1;
}
String cylinderVolume = extractManufacturer(texts, fieldMap.get("cylinderVolume"), cylinderVolumeOffset);
if (ObjectUtil.isNotEmpty(cylinderVolume)) {
//气瓶容积
if (isNumeric(cylinderVolume)) {
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume);
return equipmentRegistryRespVO;
} else {
if (cylinderVolume.equals("L")) {
//处理识别到上一行的情况
cylinderVolume = extractManufacturer(texts, fieldMap.get("cylinderVolume"), -1);
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume);
if (isNumeric(cylinderVolume)) {
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume);
return equipmentRegistryRespVO;
}
} else {
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume);
cylinderVolume = extractManufacturer(texts, "实测水容机: ", 1);
if (isNumeric(cylinderVolume)) {
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume);
return equipmentRegistryRespVO;
}
}
} else {
equipmentRegistryRespVO.setCylinderVolume(extractManufacturer(texts, "实测水容机: ", 1));
}
//兜底方案,检测是否有符合特征的值
cylinderVolume = matchTexts(texts);
if (isNumeric(cylinderVolume)) {
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume);
}
return equipmentRegistryRespVO;
}
public static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?");
}
public static String matchTexts(List<String> texts) {
// 定义正则表达式,用于匹配如 90.4L 这样的字符串
Pattern pattern = Pattern.compile("^(\\d+(\\.\\d+)?)(L)$");
for (String text : texts) {
Matcher matcher = pattern.matcher(text);
if (matcher.matches()) {
try {
double value = Double.parseDouble(matcher.group(1));
// 检查数值是否在 0 到 3000 之间
if (value >= 0 && value <= 3000) {
return text;
}
} catch (NumberFormatException e) {
// 处理转换异常
}
}
}
return null;
}
public static String extractManufacturer(List<String> recTexts, String keyword, int offset) {
// 防御性检查:列表为空或为null时直接返回null
if (recTexts == null || recTexts.isEmpty()) {

@ -119,7 +119,7 @@ public class SupervisionService {
equipmentRegistryRespVOS.add(equipmentRegistryRespVO);
}
//车用气瓶安装合格证
boolean CertificateOfApproval = texts.stream().anyMatch(t -> t.contains("安装合格证") || t.contains("安装单位") || t.contains("安装单位名称"));
boolean CertificateOfApproval = texts.stream().anyMatch(t -> t.contains("安装合格证") || t.contains("安装单位") || t.contains("安装单位名称") || t.contains("减压器编号"));
if (CertificateOfApproval) {
equipmentRegistryRespVO = certificateOfApprovalService.getCertificateOfApproval(texts, postfix);
if (null == equipmentRegistryRespVO) {
@ -129,8 +129,8 @@ public class SupervisionService {
equipmentRegistryRespVOS.add(equipmentRegistryRespVO);
}
//车用气瓶产品合格证
boolean productQualified = texts.stream().anyMatch(t -> t.equals("产品合格证") || t.contains("公称工作压力") || t.contains("水溶机") ||
t.equals("实测水溶机:") || t.equals("工作压力")
boolean productQualified = texts.stream().anyMatch(t -> t.equals("产品合格证") || t.contains("公称工作压力") || t.contains("水溶机") ||
t.equals("实测水溶机:") || t.equals("工作压力") || t.equals("气瓶容积")
);
if (productQualified) {
equipmentRegistryRespVO = productQualifiedService.getCertificateOfApproval(texts, postfix);

Loading…
Cancel
Save