检验/证书

master
chenfeng 6 months ago
parent 95a7e1f4b1
commit 2c8fa9ec93
  1. 3
      yudao-module-special/yudao-module-special-biz/src/main/java/cn/iocoder/yudao/module/special/controller/admin/equipmentregistry/vo/EquipmentRegistryRespVO.java
  2. 2
      yudao-server/src/main/java/cn/iocoder/yudao/server/controller/OcrProcessController.java
  3. 5
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/FieldMappingService.java
  4. 13
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/SpecialGasCylinderService.java
  5. 22
      yudao-server/src/main/java/cn/iocoder/yudao/server/service/SupervisionService.java

@ -119,7 +119,8 @@ public class EquipmentRegistryRespVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "产品批号")
private String productBatchNumber;
private String type;
}

@ -51,7 +51,7 @@ public class OcrProcessController {
* @param param 请求参数
* @return 识别结果
*/
@PostMapping("/admin-api/getIdentifyAndObtain")
@PostMapping("/getIdentifyAndObtain")
@PermitAll
public CommonResult<Object> getIdentifyAndObtain(@RequestBody Map<String, Object> param) {
return supervisionService.getIdentifyAndObtain(param);

@ -28,6 +28,9 @@ public class FieldMappingService {
private static final List<String> SUPERVISION_AGENCY_CANDIDATES = Arrays.asList(
"监督检验机构", "监检机构", "监检单位", "监督检验单位"
);
private static final List<String> SUPERVISION_AGENCY_CANDIDATES_CPPH = Arrays.asList(
"产品批号","批号"
);
//合格证书
//充装介质
private static final List<String> MANUFACTURER_CANDIDATES_ZS = Arrays.asList(
@ -63,7 +66,7 @@ public class FieldMappingService {
fieldMap.put("manufacturerField", detectField(texts, MANUFACTURER_CANDIDATES));
fieldMap.put("productionDateField", detectField(texts, PRODUCTION_DATE_CANDIDATES));
fieldMap.put("supervisionAgencyField", detectField(texts, SUPERVISION_AGENCY_CANDIDATES));
fieldMap.put("productBatchNumber", detectField(texts, SUPERVISION_AGENCY_CANDIDATES_CPPH));
// 3. 存入缓存(有效期 30 天)
redisTemplate.opsForValue().set(redisKey, fieldMap, 365, TimeUnit.DAYS);
return fieldMap;

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.special.controller.admin.equipmentregistry.vo.EquipmentRegistryRespVO;
import com.baomidou.mybatisplus.generator.IFill;
import com.xingyuv.captcha.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -41,12 +42,22 @@ public class SpecialGasCylinderService {
}
String supervisionAgencyField = extractManufacturer(texts, fieldMap.get("supervisionAgencyField"), 0);
if (ObjectUtil.isNotEmpty(supervisionAgencyField)) {
equipmentRegistryRespVO.setSupervisionAgency(supervisionAgencyField.replace(fieldMap.get("supervisionAgencyField"), ""));
equipmentRegistryRespVO.setSupervisionAgency(supervisionAgencyField);
}
String productBatchNumber = extractManufacturer(texts, fieldMap.get("productBatchNumber"), 1);
if (ObjectUtil.isNotEmpty(productBatchNumber)) {
equipmentRegistryRespVO.setProductBatchNumber(productBatchNumber);
}
return equipmentRegistryRespVO;
}
public static void main(String[] args) {
String text = "监督检验机构:你好";
String result = StringUtils.substringAfter(text, ":");
System.out.println(result);
}
public static String extractManufacturer(List<String> recTexts, String keyword, int offset) {
// 防御性检查:列表为空或为null时直接返回null
if (recTexts == null || recTexts.isEmpty()) {

@ -62,20 +62,20 @@ public class SupervisionService {
return CommonResult.error(500, "参数异常");
}
try {
String fileName = param.get("imageUrl").toString().substring(param.get("imageUrl").toString().lastIndexOf('/') + 1);
String fileName = param.get("filePath").toString().substring(param.get("filePath").toString().lastIndexOf('/') + 1);
OcrResponseVo redisValue = redisTemplate.opsForValue().get(fileName);
if (redisValue != null) {
return CommonResult.success(determineDocumentType(redisValue));
// return CommonResult.success(redisValue);
}
String postfix = getFileExtensionFromUrl(param.get("imageUrl").toString());
String postfix = getFileExtensionFromUrl(param.get("filePath").toString());
String imageBase64 = null;
if (Objects.equals(postfix, "pdf")) {
//pdf
imageBase64 = convertPdfToBase64(param.get("imageUrl").toString());
imageBase64 = convertPdfToBase64(param.get("filePath").toString());
} else {
//图片
imageBase64 = convertImageToBase64(param.get("imageUrl").toString());
imageBase64 = convertImageToBase64(param.get("filePath").toString());
}
if (!StringUtils.hasText(imageBase64)) {
@ -102,11 +102,10 @@ public class SupervisionService {
//表格返回参数table_res_list
if (CollectionUtil.isNotEmpty(result.getPrunedResult().getTable_res_list())) {
texts = result.getPrunedResult().getTable_res_list().get(0).getTable_ocr_pred().getRec_texts();
} else {
texts = result.getPrunedResult().getOverall_ocr_res().getRec_texts();
}
if (null != result.getPrunedResult().getOverall_ocr_res()) {
texts.addAll(result.getPrunedResult().getOverall_ocr_res().getRec_texts());
}
EquipmentRegistryRespVO equipmentRegistryRespVO = new EquipmentRegistryRespVO();
EquipmentRegistryRespVO equipmentRegistryRespVO = null;
//监督检验
boolean supervisionAndInspection = texts.stream().anyMatch(t -> t.contains("监督检验"));
if (supervisionAndInspection) {
@ -119,6 +118,9 @@ public class SupervisionService {
equipmentRegistryRespVO = certificateOfApprovalService.getCertificateOfApproval(texts);
equipmentRegistryRespVO.setType("certificateOfApproval");
}
if (null == equipmentRegistryRespVO) {
continue;
}
equipmentRegistryRespVOS.add(equipmentRegistryRespVO);
}
param.put("extractedData", equipmentRegistryRespVOS);
@ -131,8 +133,8 @@ public class SupervisionService {
*/
private boolean validateParams(Map<String, Object> param) {
return !ObjectUtils.isEmpty(param) &&
!ObjectUtils.isEmpty(param.get("imageUrl")) &&
param.get("imageUrl") instanceof String;
!ObjectUtils.isEmpty(param.get("filePath")) &&
param.get("filePath") instanceof String;
}
/**

Loading…
Cancel
Save