|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.ocr.service.impl;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -10,6 +11,7 @@ import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
|
import org.jeecg.common.constant.OcrConstant;
|
|
|
|
|
import org.jeecg.common.util.AssertUtils;
|
|
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
|
|
import org.jeecg.common.util.RestUtil;
|
|
|
|
|
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
|
|
|
|
@ -25,6 +27,7 @@ import org.jeecg.modules.ocr.model.TaskModel;
|
|
|
|
|
import org.jeecg.modules.ocr.service.*;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.*;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.SimulateChecksVO;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -61,7 +64,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
|
|
|
|
|
|
|
|
|
|
@Value("${system.project.fileReviewUrlPrefix}")
|
|
|
|
|
private String fileReviewUrlPrefix;
|
|
|
|
|
@Value("${system.project.wlyCallback}")
|
|
|
|
|
private String wlyCallback;
|
|
|
|
|
@Override
|
|
|
|
|
public OcrIdentifyDTO findById(String id) {
|
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = baseMapper.findById(id);
|
|
|
|
@ -87,13 +93,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
log.debug("打印 ocr 结果:" + responseBody.toString());
|
|
|
|
|
String identifyId = responseBody.getString("identifyId");//任务id
|
|
|
|
|
String imgPath = responseBody.getString("img_path");//图片路径
|
|
|
|
|
String imgName = null;//图片名称
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
|
imgName = imgPath.substring(imgPath.lastIndexOf("/") + 1, imgPath.length());
|
|
|
|
|
} else {
|
|
|
|
|
log.error("异常,识别图片地址为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AssertUtils.notEmpty(imgPath,"异常,识别图片地址为空");
|
|
|
|
|
String imgName = imgPath.substring(imgPath.lastIndexOf("/") + 1, imgPath.length());//图片名称
|
|
|
|
|
String message = responseBody.getString("message");//描述
|
|
|
|
|
String taskStatus = responseBody.getString("taskStatus");//任务是否完成
|
|
|
|
|
Double ocrTime = responseBody.getDouble("ocr_time");//OCR识别时长
|
|
|
|
@ -248,8 +249,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, ruleInfo);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
@ -354,8 +355,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
@Override
|
|
|
|
|
@Async
|
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
|
log.info("id:{}",id);
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
@ -366,7 +367,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
|
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
|
String dataStructured = ocrIdentifyDetail.getDataStructured();
|
|
|
|
|
if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) {
|
|
|
|
|
if (StringUtils.isNotBlank(dataStructured)) {
|
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(dataStructured);
|
|
|
|
|
List<OcrResultDTO> resultList = jsonArray.toJavaList(OcrResultDTO.class);
|
|
|
|
|
for (OcrResultDTO result : resultList) {
|
|
|
|
@ -377,7 +378,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
|
//失败时就是未获取到结果
|
|
|
|
|
result.setFailureReason(result.getTagName() + "未获取到结果");
|
|
|
|
|
result.setFailureReason(result.getTagName() + "不匹配");
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -420,7 +421,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
public void callbackWly(String ocrIdentifyId) {
|
|
|
|
|
OcrIdentifyCallbackLog ocrIdentifyCallbackLog = new OcrIdentifyCallbackLog();
|
|
|
|
|
ocrIdentifyCallbackLog.setIdentifyId(ocrIdentifyId);
|
|
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
ocrIdentifyCallbackLog.setCreateTime(date);
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
@ -430,8 +430,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
OcrIdentify ocrIdentify = super.getById(ocrIdentifyId);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyId);
|
|
|
|
|
ocrIdentifyCallbackLog.setStartTime(date);
|
|
|
|
|
boolean b = CallBackWlyUtils.callbackWly(ocrIdentify, identifyDetailList);
|
|
|
|
|
ocrIdentifyCallbackLog.setStatus(b?1:0);
|
|
|
|
|
boolean b = CallBackWlyUtils.callbackWly(wlyCallback,ocrIdentify, identifyDetailList);
|
|
|
|
|
ocrIdentifyCallbackLog.setStatus(b?1:0);//0-失败,1-成功
|
|
|
|
|
ocrIdentifyCallbackLog.setEndTime(new Date());
|
|
|
|
|
ocrIdentifyCallbackLogService.save(ocrIdentifyCallbackLog);
|
|
|
|
|
if (b) {
|
|
|
|
@ -456,7 +456,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
*
|
|
|
|
|
* @param ruleValidationValue 检查要求
|
|
|
|
|
*/
|
|
|
|
|
public static void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d, String ruleValidationValue) {
|
|
|
|
|
public void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d, String ruleValidationValue) {
|
|
|
|
|
OcrResultDTO ocrResultDTO = new OcrResultDTO();
|
|
|
|
|
ocrResultDTO.setTag(field);
|
|
|
|
|
ocrResultDTO.setTagName(fieldName);
|
|
|
|
@ -476,7 +476,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
sourceImage.setPath(imgPath);
|
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
|
sourceImage.setFileName(imgPath.substring(i + 1, imgPath.length()));
|
|
|
|
|
sourceImage.setPreviewUrl(OcrConstant.FILE_REVIEW_URL_PREFIX+imgPath);
|
|
|
|
|
sourceImage.setPreviewUrl(fileReviewUrlPrefix+imgPath);
|
|
|
|
|
ocrResultDTO.setSourceImage(sourceImage);
|
|
|
|
|
}
|
|
|
|
|
ocrResultDTO.setFailureReason(failureReason);
|
|
|
|
@ -505,13 +505,45 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
/**
|
|
|
|
|
* 将数据 疯转成 OcrResult,追加到 ocrResultList
|
|
|
|
|
*/
|
|
|
|
|
public static void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, String ruleValidationValue) {
|
|
|
|
|
public void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, String ruleValidationValue) {
|
|
|
|
|
if (ruleValidation) {
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 100d,ruleValidationValue);
|
|
|
|
|
} else {
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 0d,ruleValidationValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 将数据 疯转成 OcrResult,追加到 ocrResultList
|
|
|
|
|
*/
|
|
|
|
|
public static void ocrResultAddV01(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d) {
|
|
|
|
|
OcrResultDTO ocrResultDTO = new OcrResultDTO();
|
|
|
|
|
ocrResultDTO.setTag(field);
|
|
|
|
|
ocrResultDTO.setTagName(fieldName);
|
|
|
|
|
ocrResultDTO.setOcrText(ocrText);
|
|
|
|
|
ocrResultDTO.setInputText(inputText);
|
|
|
|
|
ocrResultDTO.setOcrPrecisionRate(ocrPrecisionRate == null ? 0d : ocrPrecisionRate);
|
|
|
|
|
if (d == null) {
|
|
|
|
|
ocrResultDTO.setTextRate(0d);
|
|
|
|
|
} else {
|
|
|
|
|
ocrResultDTO.setTextRate(new BigDecimal(d).setScale(2, RoundingMode.HALF_UP).doubleValue());
|
|
|
|
|
}
|
|
|
|
|
/*System.out.println("-----------------");
|
|
|
|
|
System.out.println(failureReason);
|
|
|
|
|
System.out.println("-----------------");*/
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
|
SourceImage sourceImage = new SourceImage();
|
|
|
|
|
sourceImage.setPath(imgPath);
|
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
|
sourceImage.setFileName(imgPath.substring(i + 1, imgPath.length()));
|
|
|
|
|
sourceImage.setPreviewUrl(OcrConstant.FILE_REVIEW_URL_PREFIX+imgPath);
|
|
|
|
|
ocrResultDTO.setSourceImage(sourceImage);
|
|
|
|
|
}
|
|
|
|
|
ocrResultDTO.setFailureReason(failureReason);
|
|
|
|
|
if (ocrResultDTOList == null) {
|
|
|
|
|
ocrResultDTOList = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
ocrResultDTOList.add(ocrResultDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 组装 checkSemanticModelMap
|
|
|
|
@ -520,8 +552,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
* @param fieldMap 字段含义 map
|
|
|
|
|
*/
|
|
|
|
|
public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, String> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) {
|
|
|
|
|
if (configRuleMap!=null) {
|
|
|
|
|
for (String s : configRuleMap.keySet()) {
|
|
|
|
|
if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) {
|
|
|
|
|
//将 configRuleMap的 key 创建一个Set
|
|
|
|
|
Set<String> keySet = new HashSet<>(configRuleMap.keySet());
|
|
|
|
|
//循环keySet,判断字段是否是缩写,如果是缩写就把缩写的全称put一下
|
|
|
|
|
for (String s : keySet) {
|
|
|
|
|
String value = configRuleMap.get(s);
|
|
|
|
|
if ("hn".equals(s)) {
|
|
|
|
|
configRuleMap.put("hospitalName",value);
|
|
|
|
@ -529,8 +564,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
configRuleMap.put("doctorName", value);
|
|
|
|
|
}else if("dmn".equals(s)) {
|
|
|
|
|
configRuleMap.put("departmentName", value);
|
|
|
|
|
}else if("time".equals(s)) {
|
|
|
|
|
}else if("tm".equals(s) || ("time".equals(s))) {
|
|
|
|
|
configRuleMap.put("time", value);
|
|
|
|
|
}else{
|
|
|
|
|
configRuleMap.put(s,value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -656,6 +693,15 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
return Result.OK("已追加到任务");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateOcrIdentifyStartTime(String id) {
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStartTime, new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime,null);
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
super.update(updateWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateMasterTaskStartTime(String id) {
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
@ -694,7 +740,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
i1++;
|
|
|
|
|
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
|
|
|
|
|
String imgPath = ocrIdentifyDetail.getImageUrl();
|
|
|
|
|
if (StringUtils.isBlank(semanticResultJson)) continue;
|
|
|
|
|
if (StringUtils.isBlank(semanticResultJson)) {continue;}
|
|
|
|
|
String doctorName = simulateChecksVO.getDoctorName();
|
|
|
|
|
String hospitalName = simulateChecksVO.getHospitalName();
|
|
|
|
|
String departmentName = simulateChecksVO.getDepartmentName();
|
|
|
|
@ -769,7 +815,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
StringBuilder rMessage = new StringBuilder();
|
|
|
|
|
//==========================
|
|
|
|
|
for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String field = value.getField();//字段 name.
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
String inputText = value.getInputText();//校验文本 ,ocr识别的文本如果不包含该内容,则算作失败
|
|
|
|
@ -816,6 +862,46 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("患者姓名","患者").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("患者姓名","患者")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("病历号").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("病历号")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("入院日期").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("入院日期")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("出生日期").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("出生日期")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("年龄").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("年龄")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s);
|
|
|
|
|
}
|
|
|
|
@ -853,8 +939,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, ruleInfo);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
@ -935,6 +1021,35 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}else{
|
|
|
|
|
newResultDTOList.add(o);
|
|
|
|
|
}
|
|
|
|
|
//脱敏处理
|
|
|
|
|
String tagName = o.getTagName();
|
|
|
|
|
String ocrText = o.getOcrText();
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
if ("患者姓名".equals(tagName)) {
|
|
|
|
|
// 保留第一个字,其余用 "*" 替代
|
|
|
|
|
int length = Math.max(0, ocrText.length() - 1);
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
|
sb.append("*");
|
|
|
|
|
}
|
|
|
|
|
String desensitizedText = ocrText.substring(0, 1) + sb.toString();
|
|
|
|
|
o.setOcrText(desensitizedText);
|
|
|
|
|
}
|
|
|
|
|
if ("联系方式".equals(tagName) || "身份证号".equals(tagName)){
|
|
|
|
|
String desensitizedText = desensitizeText(ocrText); // 自定义的脱敏方法
|
|
|
|
|
// 更新脱敏后的值
|
|
|
|
|
o.setOcrText(desensitizedText);
|
|
|
|
|
}
|
|
|
|
|
if ("家庭住址".equals(tagName) || "工作地址".equals(tagName) || "病情陈述人".equals(tagName)
|
|
|
|
|
|| "户籍地".equals(tagName)){
|
|
|
|
|
|
|
|
|
|
sb.append(ocrText.charAt(0));
|
|
|
|
|
for (int i = 1; i < ocrText.length() - 1; i++) {
|
|
|
|
|
sb.append("*");
|
|
|
|
|
}
|
|
|
|
|
sb.append(ocrText.charAt(ocrText.length() - 1));
|
|
|
|
|
String desensitizedText= sb.toString();
|
|
|
|
|
o.setOcrText(desensitizedText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ocrResultDTOList = newResultDTOList;
|
|
|
|
|
}
|
|
|
|
@ -949,10 +1064,409 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
responseBody.put("min",min);
|
|
|
|
|
responseBody.put("max",max);
|
|
|
|
|
responseBody.put("detailList", ocrResultDTOList);
|
|
|
|
|
return responseBody;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<OcrIdentify> getSemanticTaskList() {
|
|
|
|
|
LambdaQueryWrapper<OcrIdentify> queryWrapper=new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.in(OcrIdentify::getStatus,0,2);
|
|
|
|
|
queryWrapper.orderByDesc(OcrIdentify::getPriority);//优先 加急 1>0 不加急
|
|
|
|
|
queryWrapper.ne(OcrIdentify::getTaskSource,"模拟实验");//不获取模拟实验室的数据
|
|
|
|
|
return this.list(queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject simulateChecksV01(SimulateChecksVO simulateChecksVO) {
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIds(simulateChecksVO.getIdentifyDetailIdList());
|
|
|
|
|
System.out.println("1111111111111111111111111111111");
|
|
|
|
|
//遍历任务,做匹配
|
|
|
|
|
int i1=1;
|
|
|
|
|
//用于数据结构化的对象
|
|
|
|
|
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
|
|
|
|
|
Date startDataCheckTime = new Date();
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
|
i1++;
|
|
|
|
|
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
|
|
|
|
|
String imgPath = ocrIdentifyDetail.getImageUrl();
|
|
|
|
|
if (StringUtils.isBlank(semanticResultJson)) {continue;}
|
|
|
|
|
String doctorName = simulateChecksVO.getDoctorName();
|
|
|
|
|
String hospitalName = simulateChecksVO.getHospitalName();
|
|
|
|
|
String departmentName = simulateChecksVO.getDepartmentName();
|
|
|
|
|
String time = simulateChecksVO.getTime();
|
|
|
|
|
List<JSONObject> sourceJson = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isNotBlank(doctorName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"doctorName\", \"inputText\":\"%s\"}", doctorName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(hospitalName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"hospitalName\", \"inputText\":\"%s\"}", hospitalName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(departmentName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"departmentName\", \"inputText\":\"%s\"}", departmentName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(time)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"time\", \"inputText\":\"%s\"}", time)));
|
|
|
|
|
}
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(ocrIdentifyDetail.getSemanticResult());
|
|
|
|
|
|
|
|
|
|
//判断是不是网络图片
|
|
|
|
|
Boolean onlineFile = FileOUtils.isOnlineFile(imgPath);
|
|
|
|
|
if (onlineFile) {
|
|
|
|
|
//如果是网络图片,则将图片下载
|
|
|
|
|
imgPath = FileOUtils.downLoadFromUrl(imgPath, FileOUtils.getFileName(imgPath), OcrConstant.FILE_DOWNLOAD_URL_PREFIX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File file = new File(imgPath);
|
|
|
|
|
//当原图片存在时.
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
|
//压缩图片
|
|
|
|
|
/*if (true) {
|
|
|
|
|
String fileUrl = "/data/ocrImage/thumbnail" + imgPath.substring(0, i);
|
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
|
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
|
File thumbnailFile = new File(outputImagePath);
|
|
|
|
|
//如果上次生成过缩率图,就不生成了
|
|
|
|
|
if (!thumbnailFile.exists()) {
|
|
|
|
|
ImageUtils.compressImage(file.getAbsolutePath(), outputImagePath, 0.3f, 0.3f);
|
|
|
|
|
}
|
|
|
|
|
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
|
|
|
|
|
}*/
|
|
|
|
|
//============================绘制虚线
|
|
|
|
|
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
|
|
|
|
|
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
|
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
|
if (semanticResult2!=null) {
|
|
|
|
|
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
|
|
|
|
|
boolean hasPoints=true;
|
|
|
|
|
if (CollectionUtils.isNotEmpty(resultToPoints)) {
|
|
|
|
|
for (List<Point> resultToPoint : resultToPoints) {
|
|
|
|
|
if (CollectionUtils.isEmpty(resultToPoint)) {
|
|
|
|
|
hasPoints=false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasPoints){
|
|
|
|
|
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath,"green");
|
|
|
|
|
imgPath = outputImagePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//============================
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findByIdV01(simulateChecksVO.getRuleCheckId());
|
|
|
|
|
// Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMapV0(ocrRuleCheckVo.getConfigRule(), ocrRuleCheckVo.getFieldMap(), sourceJson);
|
|
|
|
|
String text = null;//ocr 识别的文本
|
|
|
|
|
Double probability = 0d;
|
|
|
|
|
StringBuilder rMessage = new StringBuilder();
|
|
|
|
|
//==========================
|
|
|
|
|
for (String key : ocrRuleCheckVo.getFieldMap().keySet()) {
|
|
|
|
|
CheckSemanticModel checkSemanticModel=new CheckSemanticModel();
|
|
|
|
|
for(JSONObject jsonObject:sourceJson){
|
|
|
|
|
Object tag = jsonObject.get("tag");
|
|
|
|
|
if(tag.equals(key)){
|
|
|
|
|
checkSemanticModel.setField(key);
|
|
|
|
|
checkSemanticModel.setFieldName(ocrRuleCheckVo.getFieldMap().get(key));
|
|
|
|
|
checkSemanticModel.setInputText(jsonObject.getString("inputText"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String field = key;//字段 name.
|
|
|
|
|
String fieldName = checkSemanticModel.getFieldName();//校验的字段名称
|
|
|
|
|
// String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
String inputText = checkSemanticModel.getInputText();//校验文本 ,ocr识别的文本如果不包含该内容,则算作失败
|
|
|
|
|
if (StringUtils.isBlank(fieldName)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
|
|
|
|
|
text = null;
|
|
|
|
|
//boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet()));
|
|
|
|
|
//查看ocr识别返回的字段名称中是否有当前这个字段名称
|
|
|
|
|
//TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
|
|
|
|
|
List<JSONObject> ocrArray = new ArrayList<>();
|
|
|
|
|
for (String s : fieldNameList) {
|
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
|
if (Arrays.asList("医生名称","姓名","医生").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("医生名称", "姓名", "医生")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("科室名称","科室").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("科室名称","科室")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("医院名称","医院").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("医院名称", "医院")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("日期", "时间").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("日期", "时间")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("患者姓名","患者").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("患者姓名","患者")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("病历号").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("病历号")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("入院日期").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("入院日期")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("出生日期").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("出生日期")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else if (Arrays.asList("年龄").contains(s)) {
|
|
|
|
|
for (String s1 : Arrays.asList("年龄")) {
|
|
|
|
|
JSONArray semantic_result = semanticResult.getJSONObject("semantic_result").getJSONArray(s1);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(semantic_result)) {
|
|
|
|
|
jsonArray.addAll(semantic_result);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (jsonArray != null && jsonArray.size() > 0) {
|
|
|
|
|
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
for (JSONObject ocrItem : ocrArray) {
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
this.ocrResultAddV01(ocrResultDTOList, checkSemanticModel.getFieldName(), field, inputText, text, probability, imgPath, checkSemanticModel.getFieldName() + "参数未获取到结果", false,v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Date overDataCheckTime = new Date();
|
|
|
|
|
|
|
|
|
|
JSONObject responseBody=new JSONObject();
|
|
|
|
|
|
|
|
|
|
//OCR和NlU执行时间总和(秒)
|
|
|
|
|
double ocrAndNluTimeSum = identifyDetailList.stream().mapToDouble(i -> (i.getOcrTime() == null ? 0 : i.getOcrTime()) + (i.getNluTime() == null ? 0 : i.getNluTime())).sum();
|
|
|
|
|
//执行时间(毫秒)
|
|
|
|
|
double dataStructuredTime = new BigDecimal(overDataCheckTime.getTime() - startDataCheckTime.getTime()).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
|
|
double executionTime = new BigDecimal(ocrAndNluTimeSum+(dataStructuredTime/1000)).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
|
|
|
|
responseBody.put("dataStructuredTime",dataStructuredTime);
|
|
|
|
|
responseBody.put("allExecutionTime",executionTime);
|
|
|
|
|
|
|
|
|
|
//=========排序
|
|
|
|
|
if (CollectionUtils.isNotEmpty(ocrResultDTOList)) {
|
|
|
|
|
ocrResultDTOList.sort((h1, h2) -> h1.getTag().compareTo(h2.getTag()));
|
|
|
|
|
}
|
|
|
|
|
//============
|
|
|
|
|
if (CollectionUtils.isEmpty(ocrResultDTOList)) {
|
|
|
|
|
//没有匹配结果
|
|
|
|
|
responseBody.put("taskResult",1);
|
|
|
|
|
}else{
|
|
|
|
|
long count = fieldRightMap.values().stream().filter(o->!o).count();
|
|
|
|
|
//long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count();
|
|
|
|
|
responseBody.put("taskResult",count>0?0:1);//匹配成功或失败
|
|
|
|
|
Set<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet());
|
|
|
|
|
List<OcrResultDTO> newResultDTOList=new ArrayList<>();
|
|
|
|
|
//过滤掉0的值
|
|
|
|
|
|
|
|
|
|
for (OcrResultDTO o : ocrResultDTOList) {
|
|
|
|
|
if (haveRateTagList.contains(o.getTag())) {
|
|
|
|
|
if (o.getTextRate()>0) {
|
|
|
|
|
newResultDTOList.add(o);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
newResultDTOList.add(o);
|
|
|
|
|
}
|
|
|
|
|
//脱敏处理
|
|
|
|
|
String tagName = o.getTagName();
|
|
|
|
|
String ocrText = o.getOcrText();
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
if ("患者姓名".equals(tagName)) {
|
|
|
|
|
// 保留第一个字,其余用 "*" 替代
|
|
|
|
|
int length = Math.max(0, ocrText.length() - 1);
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
|
sb.append("*");
|
|
|
|
|
}
|
|
|
|
|
String desensitizedText = ocrText.substring(0, 1) + sb.toString();
|
|
|
|
|
o.setOcrText(desensitizedText);
|
|
|
|
|
}
|
|
|
|
|
if ("联系方式".equals(tagName) || "身份证号".equals(tagName)){
|
|
|
|
|
String desensitizedText = desensitizeText(ocrText); // 自定义的脱敏方法
|
|
|
|
|
// 更新脱敏后的值
|
|
|
|
|
o.setOcrText(desensitizedText);
|
|
|
|
|
}
|
|
|
|
|
if ("家庭住址".equals(tagName) || "工作地址".equals(tagName) || "病情陈述人".equals(tagName)
|
|
|
|
|
|| "户籍地".equals(tagName)){
|
|
|
|
|
|
|
|
|
|
sb.append(ocrText.charAt(0));
|
|
|
|
|
for (int i = 1; i < ocrText.length() - 1; i++) {
|
|
|
|
|
sb.append("*");
|
|
|
|
|
}
|
|
|
|
|
sb.append(ocrText.charAt(ocrText.length() - 1));
|
|
|
|
|
String desensitizedText= sb.toString();
|
|
|
|
|
o.setOcrText(desensitizedText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ocrResultDTOList = newResultDTOList;
|
|
|
|
|
}
|
|
|
|
|
//获取最小
|
|
|
|
|
double min = 0d;
|
|
|
|
|
//获取最大
|
|
|
|
|
double max = 0d;
|
|
|
|
|
if (CollectionUtils.isNotEmpty(ocrResultDTOList)) {
|
|
|
|
|
min = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).min().getAsDouble();
|
|
|
|
|
max = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).max().getAsDouble();
|
|
|
|
|
}
|
|
|
|
|
responseBody.put("min",min);
|
|
|
|
|
responseBody.put("max",max);
|
|
|
|
|
responseBody.put("detailList", ocrResultDTOList);
|
|
|
|
|
return responseBody;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, CheckSemanticModel> getCheckSemanticModelMapV0(String configRule, Map<String, String> fieldMap, List<JSONObject> sourceJson) {
|
|
|
|
|
if (configRule!=null) {
|
|
|
|
|
String[] split = configRule.split("&");
|
|
|
|
|
//将 configRuleMap的 key 创建一个Set
|
|
|
|
|
// Set<String> keySet = new HashSet<>(configRuleMap.keySet());
|
|
|
|
|
// //循环keySet,判断字段是否是缩写,如果是缩写就把缩写的全称put一下
|
|
|
|
|
// for (String s : keySet) {
|
|
|
|
|
// String value = configRuleMap.get(s);
|
|
|
|
|
// if ("hn".equals(s)) {
|
|
|
|
|
// configRuleMap.put("hospitalName",value);
|
|
|
|
|
// }else if("dn".equals(s)) {
|
|
|
|
|
// configRuleMap.put("doctorName", value);
|
|
|
|
|
// }else if("dmn".equals(s)) {
|
|
|
|
|
// configRuleMap.put("departmentName", value);
|
|
|
|
|
// }else if("tm".equals(s) || ("time".equals(s))) {
|
|
|
|
|
// configRuleMap.put("time", value);
|
|
|
|
|
// }else{
|
|
|
|
|
// configRuleMap.put(s,value);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>();
|
|
|
|
|
//校验正确的值
|
|
|
|
|
Map<String, String> inputMap = new LinkedHashMap<>();
|
|
|
|
|
if (sourceJson != null && sourceJson.size() > 0) {
|
|
|
|
|
String tag, inputText;
|
|
|
|
|
for (JSONObject sourceJsonObject : sourceJson) {
|
|
|
|
|
tag = sourceJsonObject.getString("tag");
|
|
|
|
|
if (StringUtils.isBlank(tag)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
inputText = sourceJsonObject.getString("inputText");
|
|
|
|
|
inputMap.put(tag, inputText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckSemanticModel copyEntity = null;
|
|
|
|
|
String fieldName = null, inputText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断 规则检查配置 是不是 isrule=1
|
|
|
|
|
if (configRule.contains("isrule==1")) {
|
|
|
|
|
//isrule=1
|
|
|
|
|
for (String field : inputMap.keySet()) {
|
|
|
|
|
fieldName = fieldMap.get(field);
|
|
|
|
|
copyEntity = new CheckSemanticModel();
|
|
|
|
|
inputText = inputMap.get(field);
|
|
|
|
|
copyEntity.setField(field);
|
|
|
|
|
copyEntity.setInputText(inputText);
|
|
|
|
|
copyEntity.setRuleInfo("1");
|
|
|
|
|
copyEntity.setFieldName(fieldName);
|
|
|
|
|
checkSemanticModelMap.put(field, copyEntity);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (fieldMap != null) {
|
|
|
|
|
for (String field : fieldMap.keySet()) {
|
|
|
|
|
copyEntity = new CheckSemanticModel();
|
|
|
|
|
copyEntity.setField(field);
|
|
|
|
|
//1/0
|
|
|
|
|
// if (configRuleMap != null && configRuleMap.containsKey(field)) {
|
|
|
|
|
// configRule = configRuleMap.get(field);
|
|
|
|
|
// copyEntity.setRuleInfo(configRule);
|
|
|
|
|
// //端字段含义
|
|
|
|
|
// fieldName = fieldMap.get(field);
|
|
|
|
|
// //检查数据
|
|
|
|
|
// inputText = inputMap.get(field);
|
|
|
|
|
//
|
|
|
|
|
// copyEntity.setFieldName(fieldName);
|
|
|
|
|
//
|
|
|
|
|
// copyEntity.setInputText(inputText);
|
|
|
|
|
//
|
|
|
|
|
// checkSemanticModelMap.put(field, copyEntity);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return checkSemanticModelMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 自定义的脱敏方法,对字段进行半脱敏
|
|
|
|
|
private String desensitizeText(String text) {
|
|
|
|
|
StringBuilder sb = new StringBuilder(text);
|
|
|
|
|
if (text == null) {
|
|
|
|
|
return text;
|
|
|
|
|
}else if (text.length() == 11){ //手机号脱敏
|
|
|
|
|
for (int i = 3; i < sb.length() - 4; i++) {
|
|
|
|
|
sb.setCharAt(i, '*');
|
|
|
|
|
}
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}else if(text.length() == 14){ //身份证号码脱敏
|
|
|
|
|
for (int i = 3; i < sb.length() - 4; i++) {
|
|
|
|
|
sb.setCharAt(i, '*');
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
sb.append(text.charAt(0));
|
|
|
|
|
for (int i = 1; i < text.length() - 1; i++) {
|
|
|
|
|
sb.append("*");
|
|
|
|
|
}
|
|
|
|
|
sb.append(text.charAt(text.length() - 1));
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void executeTask() {
|
|
|
|
|
//获取任务
|
|
|
|
@ -1115,4 +1629,28 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
return taskList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long calculateTimeDifferenceByRequestId(String requestId) {
|
|
|
|
|
LambdaQueryWrapper<OcrIdentify> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(OcrIdentify::getRequestId, requestId).orderByDesc(OcrIdentify::getCreateTime).last("LIMIT 1");
|
|
|
|
|
OcrIdentify lastIdentify = this.getOne(queryWrapper);
|
|
|
|
|
if (lastIdentify != null) {
|
|
|
|
|
Date lastCreateTime = lastIdentify.getCreateTime();
|
|
|
|
|
Date currentTime = new Date();
|
|
|
|
|
return (currentTime.getTime() - lastCreateTime.getTime()) / 1000;
|
|
|
|
|
}
|
|
|
|
|
return 11; // 如果没有找到数据,返回默认值
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public long calculateTimeDifferenceByTaskName(String taskName) {
|
|
|
|
|
LambdaQueryWrapper<OcrIdentify> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(OcrIdentify::getTaskName,taskName).orderByDesc(OcrIdentify::getCreateTime).last("LIMIT 1");
|
|
|
|
|
OcrIdentify lastIdentify = this.getOne(queryWrapper);
|
|
|
|
|
if (lastIdentify != null) {
|
|
|
|
|
Date lastCreateTime = lastIdentify.getCreateTime();
|
|
|
|
|
Date currentTime = new Date();
|
|
|
|
|
return (currentTime.getTime() - lastCreateTime.getTime()) / 1000;
|
|
|
|
|
}
|
|
|
|
|
return 11; // 如果没有找到数据,返回默认值
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|