parent
2c8fa9ec93
commit
0da8d5faff
@ -0,0 +1,87 @@ |
||||
package cn.iocoder.yudao.server.service; |
||||
|
||||
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.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.IntStream; |
||||
|
||||
@Service |
||||
public class ProductQualifiedService { |
||||
@Autowired |
||||
private FieldMappingService fieldMappingService; |
||||
|
||||
/** |
||||
* 合格证书 |
||||
* |
||||
* @param texts |
||||
* @return |
||||
*/ |
||||
public EquipmentRegistryRespVO getCertificateOfApproval(List<String> texts, String postfix) { |
||||
boolean productQualified = texts.stream().anyMatch(t -> t.equals("工作压力")); |
||||
Map<String, String> fieldMap = new HashMap<>(); |
||||
if (productQualified) { |
||||
fieldMap = fieldMappingService.getCertificateMapping("工作压力", texts); |
||||
} else { |
||||
fieldMap = fieldMappingService.getCertificateMapping("公称工作压力:", texts); |
||||
} |
||||
EquipmentRegistryRespVO equipmentRegistryRespVO = new EquipmentRegistryRespVO(); |
||||
equipmentRegistryRespVO.setEquipmentType("特种气瓶"); |
||||
equipmentRegistryRespVO.setProductName("车用气瓶"); |
||||
equipmentRegistryRespVO.setCylinderQuantity(1); |
||||
int fillingMediumOffset = 4; |
||||
if (!postfix.equals("pdf")) { |
||||
fillingMediumOffset = 3; |
||||
} |
||||
String fillingMedium = extractManufacturer(texts, fieldMap.get("fillingMedium"), fillingMediumOffset); |
||||
if (ObjectUtil.isNotEmpty(fillingMedium)) { |
||||
//充装介质
|
||||
equipmentRegistryRespVO.setFillingMedium(fillingMedium); |
||||
} |
||||
int nominalWorkingPressureOffset = 1; |
||||
if (!postfix.equals("pdf")) { |
||||
nominalWorkingPressureOffset = 2; |
||||
} |
||||
String nominalWorkingPressure = extractManufacturer(texts, fieldMap.get("nominalWorkingPressure"), nominalWorkingPressureOffset); |
||||
if (ObjectUtil.isNotEmpty(nominalWorkingPressure)) { |
||||
//气瓶公称工作压力
|
||||
equipmentRegistryRespVO.setNominalWorkingPressure(nominalWorkingPressure); |
||||
} |
||||
int cylinderVolumeOffset = 1; |
||||
if (!postfix.equals("pdf")) { |
||||
cylinderVolumeOffset = 1; |
||||
} |
||||
String cylinderVolume = extractManufacturer(texts, fieldMap.get("cylinderVolume"), cylinderVolumeOffset); |
||||
if (ObjectUtil.isNotEmpty(cylinderVolume)) { |
||||
//气瓶容积
|
||||
equipmentRegistryRespVO.setCylinderVolume(cylinderVolume); |
||||
} else { |
||||
equipmentRegistryRespVO.setCylinderVolume(extractManufacturer(texts, "实测水容机: ", 1)); |
||||
} |
||||
return equipmentRegistryRespVO; |
||||
|
||||
} |
||||
|
||||
public static String extractManufacturer(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
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue