diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/OcrConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/OcrConstant.java index f58f388..8b62873 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/OcrConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/OcrConstant.java @@ -17,8 +17,13 @@ public class OcrConstant { */ public static String ruleCheckSplitChar="&"; - public static String ruleCheckOrChar="||"; - + public static String ruleHz="||"; + public static String ruleZkh="\\("; + public static String ruleYkh="\\)"; + public static String ruleDyh=">"; + public static String ruleXyh="<"; + public static String ruleTh="!"; + public static String ruleBq="&&"; public static String ruleCheckValueRightChar="="; /** diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrRuleCheckController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrRuleCheckController.java index b0dc7d7..bcc1cca 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrRuleCheckController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/controller/OcrRuleCheckController.java @@ -90,6 +90,7 @@ public class OcrRuleCheckController extends JeecgController configRuleMap=new LinkedHashMap<>(); + private Map configRuleMap=new LinkedHashMap<>(); private Map fieldMap=new LinkedHashMap<>(); - Map> configRuleTypeMap=new LinkedHashMap<>(); + Map> configRuleTypeMap=new LinkedHashMap<>(); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrRuleCheck.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrRuleCheck.java index ca08308..47d73e3 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrRuleCheck.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrRuleCheck.java @@ -64,4 +64,7 @@ public class OcrRuleCheck implements Serializable { @ApiModelProperty(value = "元数据配置id") /*@Excel(name = "元数据配置id", width = 15)*/ private String metadataConfigId; + + @ApiModelProperty(value = "是否并且或者表达式1不是,2是") + private Integer type; } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java index 49e29c9..a539642 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java @@ -411,7 +411,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap(); + Map> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap(); //=================== } @@ -550,27 +550,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl getCheckSemanticModelMap(Map configRuleMap, Map fieldMap, List sourceJsonObjects) { + public Map getCheckSemanticModelMap(Map configRuleMap, Map fieldMap, List sourceJsonObjects) { if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) { - //将 configRuleMap的 key 创建一个Set - Set 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); - } - } + //缩写转全称 + OcrJudgmentTools.abbreviationToFullName(configRuleMap); } - Map checkSemanticModelMap = new LinkedHashMap<>(); //校验正确的值 Map inputMap = new LinkedHashMap<>(); @@ -610,7 +594,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl ocrResultDTOList = new ArrayList<>(); Date startDataCheckTime = new Date(); Map fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map + OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId()); for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { i1++; String semanticResultJson = ocrIdentifyDetail.getSemanticResult(); @@ -806,8 +791,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson); String text = null;//ocr 识别的文本 Double probability = 0d; @@ -910,62 +893,119 @@ public class OcrIdentifyServiceImpl extends ServiceImpl 0) { - for (JSONObject ocrItem : ocrArray) { - text = null; - text = ocrItem.getString("text");//ocr 识别的文本 - probability = ocrItem.getDouble("probability");//置信度 - if ("101".equals(ruleInfo)) { - if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { - //没识别值 - mapPutIfTrue(fieldRightMap, field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true, ruleInfo); - } else { - double v = StrCharUtil.similarityRatio(inputText, text); - if (text.equals(inputText)) { + if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){ + for (JSONObject ocrItem : ocrArray) { + text = null; + text = ocrItem.getString("text");//ocr 识别的文本 + probability = ocrItem.getDouble("probability");//置信度 + if ("101".equals(ruleInfo)) { + if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { + //没识别值 mapPutIfTrue(fieldRightMap, field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101"); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true, ruleInfo); } else { - rMessage.append(value.getFieldName()).append("参数不匹配
"); + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { + mapPutIfTrue(fieldRightMap, field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101"); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } + } + } else { + if (StringUtils.isBlank(text)) { + //ocr识别参数为空,不通过 + rMessage.append(value.getFieldName()).append("参数未获取到结果
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); + } else if (StringUtils.isBlank(inputText)) { + //没有输入值. + fieldRightMap.put(field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo); + } else if ("0".equals(ruleInfo)) { + //不必校验,有识别到就行,通过 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo); + } else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) { + //在1~99之间,根据精准度匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (v >= Double.parseDouble(ruleInfo)) { + //准确度 可靠 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } + } else if ("100".equals(ruleInfo)) { + //必定验证参数,必须有值且匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } } } - } else { - if (StringUtils.isBlank(text)) { - //ocr识别参数为空,不通过 - rMessage.append(value.getFieldName()).append("参数未获取到结果
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); - } else if (StringUtils.isBlank(inputText)) { - //没有输入值. - fieldRightMap.put(field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo); - } else if ("0".equals(ruleInfo)) { - //不必校验,有识别到就行,通过 - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo); - } else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) { - //在1~99之间,根据精准度匹配 - double v = StrCharUtil.similarityRatio(inputText, text); - if (v >= Double.parseDouble(ruleInfo)) { - //准确度 可靠 - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); + } + } else if (ocrRuleCheckVo.getType()!= null&&ocrRuleCheckVo.getType()==2) { + for (JSONObject ocrItem : ocrArray) { + text = null; + text = ocrItem.getString("text");//ocr 识别的文本 + probability = ocrItem.getDouble("probability");//置信度 + if ("101".equals(ruleInfo)) { + if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { + //没识别值 + mapPutIfTrue(fieldRightMap, field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true, ruleInfo); } else { - rMessage.append(value.getFieldName()).append("参数不匹配
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { + mapPutIfTrue(fieldRightMap, field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101"); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } } - } else if ("100".equals(ruleInfo)) { - //必定验证参数,必须有值且匹配 - double v = StrCharUtil.similarityRatio(inputText, text); - if (text.equals(inputText)) { + } else { + if (StringUtils.isBlank(text)) { + //ocr识别参数为空,不通过 + rMessage.append(value.getFieldName()).append("参数未获取到结果
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); + } else if (StringUtils.isBlank(inputText)) { + //没有输入值. + fieldRightMap.put(field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo); + } else if ("0".equals(ruleInfo)) { + //不必校验,有识别到就行,通过 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo); + } else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) { + //在1~99之间,根据精准度匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + //准确度 可靠 fieldRightMap.put(field, true); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); - } else { - rMessage.append(value.getFieldName()).append("参数不匹配
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } else if ("100".equals(ruleInfo)) { + //必定验证参数,必须有值且匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } } } } @@ -1005,9 +1045,20 @@ public class OcrIdentifyServiceImpl extends ServiceImpl!o).count(); - //long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count(); - responseBody.put("taskResult",count>0?0:1);//匹配成功或失败 + if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){ + 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);//匹配成功或失败 + }else if(ocrRuleCheckVo.getType()!=null&&ocrRuleCheckVo.getType()==2){ + log.info(ocrResultDTOList.toString()); + String configRule = ocrRuleCheckVo.getConfigRule(); + Map params=new HashMap<>(); + for(OcrResultDTO ocrResultDTO:ocrResultDTOList){ + params.put(ocrResultDTO.getTag(),ocrResultDTO.getTextRate()); + } + Boolean rest=OcrJudgmentTools.judment(configRule,params); + responseBody.put("taskResult",rest?0:1); + } Set haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet()); List newResultDTOList=new ArrayList<>(); //过滤掉0的值 diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrRuleCheckServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrRuleCheckServiceImpl.java index b7825db..38093de 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrRuleCheckServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrRuleCheckServiceImpl.java @@ -18,6 +18,8 @@ import org.jeecg.modules.ocr.mapper.OcrMetadataConfigMapper; import org.jeecg.modules.ocr.mapper.OcrRuleCheckMapper; import org.jeecg.modules.ocr.service.IOcrRuleCheckDetailService; import org.jeecg.modules.ocr.service.IOcrRuleCheckService; +import org.jeecg.modules.ocr.utils.OcrJudgmentTools; +import org.jeecg.modules.ocr.utils.StrCharUtil; import org.jeecg.modules.ocr.vo.SaveOcrRuleCheckVO; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; @@ -39,10 +41,6 @@ import java.util.stream.Collectors; */ @Service public class OcrRuleCheckServiceImpl extends ServiceImpl implements IOcrRuleCheckService { - @Resource - IOcrRuleCheckDetailService ocrRuleCheckDetailService; - @Resource - OcrMetadataConfigMapper ocrMetadataConfigMapper; @Resource OcrMetadataConfigDetailMapper ocrMetadataConfigDetailMapper; @Override @@ -62,14 +60,31 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl saveOcrRuleCheckVOS) { for (SaveOcrRuleCheckVO saveOcrRuleCheckVO : saveOcrRuleCheckVOS) { OcrRuleCheck ocrRuleCheck=new OcrRuleCheck(); - if (StringUtils.isNotBlank(saveOcrRuleCheckVO.getConfigRule())) { - if (saveOcrRuleCheckVO.getConfigRule().contains("isrule=1") && saveOcrRuleCheckVO.getConfigRule().replace("isrule=1","").length()>0) { - throw new JeecgBootException("isrule=1规则只可单独使用"); + if(saveOcrRuleCheckVO.getType()==null||saveOcrRuleCheckVO.getType()==1){ + if (StringUtils.isNotBlank(saveOcrRuleCheckVO.getConfigRule())) { + if (saveOcrRuleCheckVO.getConfigRule().contains("isrule=1") && saveOcrRuleCheckVO.getConfigRule().replace("isrule=1","").length()>0) { + throw new JeecgBootException("isrule=1规则只可单独使用"); + } + } + saveOcrRuleCheckVO.setType(1); + }else if(saveOcrRuleCheckVO.getType()==2){ + String configRule = saveOcrRuleCheckVO.getConfigRule(); + String metadataConfigId = saveOcrRuleCheckVO.getMetadataConfigId(); + //获取规则配置元字段 + List ocrMetadataConfigDetails = ocrMetadataConfigDetailMapper.selectList(new LambdaQueryWrapper().eq(OcrMetadataConfigDetail::getMetadataConfigId, metadataConfigId)); + Map params=new HashMap<>(); + for(OcrMetadataConfigDetail configDetail:ocrMetadataConfigDetails){ + String fieldName = configDetail.getFieldName(); + params.put(fieldName,1); } + OcrJudgmentTools.fullNameToAbbreviation(params); + //做下表达式校验,看表达式是否正确,如果不正确这个方法里面会抛出异常如果正确就继续入库 + OcrJudgmentTools.judment(configRule, params); } ocrRuleCheck.setConfigRule(saveOcrRuleCheckVO.getConfigRule()); ocrRuleCheck.setMetadataConfigId(saveOcrRuleCheckVO.getMetadataConfigId()); ocrRuleCheck.setConfigName(saveOcrRuleCheckVO.getConfigName()); + ocrRuleCheck.setType(saveOcrRuleCheckVO.getType()); this.save(ocrRuleCheck); } } @@ -333,39 +348,45 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl> configRuleTypeMap=new LinkedHashMap<>(); - if (configRule.contains(OcrConstant.ruleCheckOrChar)) { - // || - String[] orSplit = configRule.split(OcrConstant.ruleCheckOrChar); - Map configRuleMap=new LinkedHashMap<>(); - String field=null;String fieldValue=null; - for (String s : orSplit) { - configRuleMap=new LinkedHashMap<>(); - String[] split1 = s.split(OcrConstant.ruleCheckValueRightChar); - if (split1.length<=1) { - continue; + if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){ + String configRule = ocrRuleCheckVo.getConfigRule(); + //TODO {key(&,||):{key(字段):value(1/0)}} + Map> configRuleTypeMap=new LinkedHashMap<>(); + if (configRule.contains(OcrConstant.ruleHz)) { + // || + String[] orSplit = configRule.split(OcrConstant.ruleHz); + Map configRuleMap=new LinkedHashMap<>(); + String field=null;String fieldValue=null; + for (String s : orSplit) { + configRuleMap=new LinkedHashMap<>(); + String[] split1 = s.split(OcrConstant.ruleCheckValueRightChar); + if (split1.length<=1) { + continue; + } + configRuleMap.put(split1[0],split1[1]); } - configRuleMap.put(split1[0],split1[1]); - } - configRuleTypeMap.put(OcrConstant.ruleCheckOrChar,configRuleMap); - }else { - //& - String[] split = configRule.split(OcrConstant.ruleCheckSplitChar); - //将 `配置规则` 转成 map - Map configRuleMap=new LinkedHashMap<>(); - for (String s : split) { - String[] split1 = s.split(OcrConstant.ruleCheckValueRightChar); - if (split1.length<=1) { - continue; + configRuleTypeMap.put(OcrConstant.ruleHz,configRuleMap); + }else { + //& + String[] split = configRule.split(OcrConstant.ruleCheckSplitChar); + //将 `配置规则` 转成 map + Map configRuleMap=new LinkedHashMap<>(); + for (String s : split) { + String[] split1 = s.split(OcrConstant.ruleCheckValueRightChar); + if (split1.length<=1) { + continue; + } + configRuleMap.put(split1[0],split1[1]); } - configRuleMap.put(split1[0],split1[1]); + ocrRuleCheckVo.setConfigRuleMap(configRuleMap); + configRuleTypeMap.put(OcrConstant.ruleCheckSplitChar,configRuleMap); } - ocrRuleCheckVo.setConfigRuleMap(configRuleMap); - configRuleTypeMap.put(OcrConstant.ruleCheckSplitChar,configRuleMap); + ocrRuleCheckVo.setConfigRuleTypeMap(configRuleTypeMap); + }else if(ocrRuleCheckVo.getType()!=null||ocrRuleCheckVo.getType()==2){ + String configRule = ocrRuleCheckVo.getConfigRule(); + Map restMap= StrCharUtil.strSplits(configRule); + ocrRuleCheckVo.setConfigRuleMap(restMap); } - ocrRuleCheckVo.setConfigRuleTypeMap(configRuleTypeMap); } if (StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) { String metadataConfigId = ocrRuleCheckVo.getMetadataConfigId(); @@ -379,4 +400,5 @@ public class OcrRuleCheckServiceImpl extends ServiceImpl engine =new HashMap<>(); + String str="value>5&&st==\"test\"&&(state==\"正常\"||state==\"不正常\")"; + engine.put("value",6); + engine.put("state","正常"); + engine.put("st","test"); + Boolean judment = judment(str, engine); + System.out.println(judment); + } + public static ScriptEngine getEngine(){ + ScriptEngineManager manager=new ScriptEngineManager(); + return manager.getEngineByName("nashorn"); + } + public static Boolean judment(String expression, Map params){ + Boolean eval=false; + ScriptEngine engine = getEngine(); + for(String key:params.keySet()){ + engine.put(key,params.get(key)); + } + try { + eval =(Boolean) engine.eval(expression); + } catch (ScriptException e) { + throw new JeecgBootException("条件表达式配置错误请检查"); + } + return eval; + } + + /*** + * 缩写转全称 + * @return + */ + public static void abbreviationToFullName(Map configRuleMap){ + Set keySet = new HashSet<>(configRuleMap.keySet()); + //循环keySet,判断字段是否是缩写,如果是缩写就把缩写的全称put一下 + for (String s : keySet) { + Object 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); + } + } + } + /*** + * 全称转缩写 + * @return + */ + public static void fullNameToAbbreviation(Map configRuleMap){ + Set keySet = new HashSet<>(configRuleMap.keySet()); + //循环keySet,判断字段是否是缩写,如果是缩写就把缩写的全称put一下 + for (String s : keySet) { + Object value = configRuleMap.get(s); + if ("hospitalName".equals(s)) { + configRuleMap.put("hn",value); + }else if("doctorName".equals(s)) { + configRuleMap.put("dn", value); + }else if("departmentName".equals(s)) { + configRuleMap.put("dmn", value); + }else if("tm".equals(s) || ("time".equals(s))) { + configRuleMap.put("time", value); + }else{ + configRuleMap.put(s,value); + } + } + } +} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/StrCharUtil.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/StrCharUtil.java index 77fcf55..c236a5c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/StrCharUtil.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/StrCharUtil.java @@ -1,8 +1,13 @@ package org.jeecg.modules.ocr.utils; +import org.jeecg.common.constant.OcrConstant; import org.xm.Similarity; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @Description 对比俩个字符串的相似度 @@ -10,6 +15,67 @@ import java.math.BigDecimal; * @Date 2023/8/11 13:50 */ public class StrCharUtil { + public static void main(String[] args) { + String configRule="hospitalName>=40&&(departmentName==0||doctorName==0)"; + Map stringObjectMap = strSplits(configRule); + } + /** + * 循环切割字符串 + */ + public static Map strSplits(String configRule){ + //去除不需要的字符如 括号,叹号 + configRule=configRule.replaceAll(" ","").replaceAll(OcrConstant.ruleZkh,"").replaceAll(OcrConstant.ruleYkh,""); + if(configRule.contains(OcrConstant.ruleTh+OcrConstant.ruleCheckValueRightChar)){ + configRule=configRule.replaceAll(OcrConstant.ruleTh+OcrConstant.ruleCheckValueRightChar,"~"+OcrConstant.ruleCheckValueRightChar);//如果有!=那就替换为b= + }else{ + configRule=configRule.replaceAll(OcrConstant.ruleTh,""); + } + if(configRule.contains(OcrConstant.ruleDyh+OcrConstant.ruleCheckValueRightChar)){ + configRule=configRule.replaceAll(OcrConstant.ruleDyh+OcrConstant.ruleCheckValueRightChar,"dydy"); + } + if(configRule.contains(OcrConstant.ruleDyh+OcrConstant.ruleCheckValueRightChar)){ + configRule=configRule.replaceAll(OcrConstant.ruleXyh+OcrConstant.ruleCheckValueRightChar,"xydy"); + } + //切割符组装 放入list中 + List splits=new ArrayList<>(); + splits.add(OcrConstant.ruleDyh); + splits.add(OcrConstant.ruleXyh); + splits.add("xydy"); + splits.add("dydy"); + splits.add(OcrConstant.ruleCheckValueRightChar+OcrConstant.ruleCheckValueRightChar); + splits.add("~"+OcrConstant.ruleCheckValueRightChar); + if(configRule.contains(OcrConstant.ruleHz)){ + configRule=configRule.replaceAll("\\|\\|",OcrConstant.ruleBq); + } + String[] strs = configRule.split(OcrConstant.ruleBq); + Map map=new HashMap<>(); + for(String strss:strs){ + strSplits(strss,splits,map); + } + return map; + } + public static void strSplits(String strs, List splits,Map rest){ + for(String split:splits){ + if(strs.contains(split)){ + String[] split1 = strs.split(split); + boolean sdf=false; + for(String s:split1){ + for(String sf:splits){ + if(!s.contains(sf)){ + sdf=true; + } + } + } + if(sdf){ + rest.put(split1[0],split1[1]); + }else{ + for(String str22:split1){ + strSplits(str22,splits,rest); + } + } + } + } + } /** * 获取最长子串 (参数顺序与字符串长短无关) @@ -176,15 +242,4 @@ public class StrCharUtil { return v;*/ } - - public static void main(String[] args) { - String strA = "河北唐山市协和医院"; - String strB = "河北省唐山协和医院"; - System.out.println(similarityRatio(strA,strB)); - //System.out.println(longestCommonSubstringNoOrder(strA, strB)); - //System.out.println(SimilarDegree(strA, strB)); - //System.out.println(compare(strA, strB)); - //System.out.println(similarityRatio(strA, strB)); - } - } \ No newline at end of file diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/SaveOcrRuleCheckVO.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/SaveOcrRuleCheckVO.java index 7bf232c..fa5256b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/SaveOcrRuleCheckVO.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/vo/SaveOcrRuleCheckVO.java @@ -37,6 +37,9 @@ public class SaveOcrRuleCheckVO implements Serializable { @ApiModelProperty(value = "元数据配置名称") @Excel(name = "元数据配置名称", width = 15) private String metadataConfigName; + @ApiModelProperty(value = "并且或者组合规则,1不是,2是") + @Excel(name = "是否为并且或者组合规则", width = 15) + private Integer type; /**选择的元数据明细id*/ //@ApiModelProperty(value = "选择的元数据明细id") //public List metadataConfigDetailIdList=new ArrayList<>();