|
|
|
@ -428,7 +428,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
OcrIdentify ocrIdentify = super.getById(ocrIdentifyId);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyId);
|
|
|
|
|
ocrIdentifyCallbackLog.setStartTime(date);
|
|
|
|
|
log.info("执行CallBackWlyUtils.callbackWly({}, {})",ocrIdentify,identifyDetailList);
|
|
|
|
|
boolean b = CallBackWlyUtils.callbackWly(ocrIdentify, identifyDetailList);
|
|
|
|
|
log.info("执行CallBackWlyUtils.callbackWly 结束",ocrIdentify,identifyDetailList);
|
|
|
|
|
ocrIdentifyCallbackLog.setStatus(b?1:0);//0-失败,1-成功
|
|
|
|
|
ocrIdentifyCallbackLog.setEndTime(new Date());
|
|
|
|
|
ocrIdentifyCallbackLogService.save(ocrIdentifyCallbackLog);
|
|
|
|
@ -510,6 +512,38 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
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
|
|
|
|
@ -1042,6 +1076,372 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
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);
|
|
|
|
|