初步审核

This commit is contained in:
tangw 2025-09-24 10:16:11 +08:00
parent fd7a7c0cbf
commit 6e216e8650
5 changed files with 196 additions and 23 deletions

View File

@ -15,9 +15,10 @@ public class CalcUtils {
* 工具类,计算公式计算,使用PB的计算公式加入参得出结果值
* @param CalcExpression PB原始计算公式
* @param variableMap 入参MAP
* @param def 默认返回值,当计算公式失败不符合计算条件时返回默认值
* @return
*/
public static String getValueFromCalc(String CalcExpression, Map<String, String> variableMap) {
public static String getValueFromCalc(String CalcExpression, Map<String, String> variableMap,String def) {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
variableMap=replaceAllSpecialKeys(variableMap);
@ -56,7 +57,7 @@ public class CalcUtils {
} catch (Exception e) {
//throw new RuntimeException("表达式计算失败: " + expression, e);
return "0";
return def;
}
}
public static boolean getnumbervalue(String keyname) {
@ -66,9 +67,13 @@ public class CalcUtils {
return true;
}
public static boolean getBooleanFromCalc(String CalcExpression, Map<String, String> variableMap) {
String resultcondition = "if(" + CalcExpression + ",1,0)";
String result1 = getValueFromCalc(resultcondition, variableMap);
return getBooleanFromCalc(CalcExpression,variableMap,false);
}
public static boolean getBooleanFromCalc(String CalcExpression, Map<String, String> variableMap,boolean def) {
String resultcondition = "if((" + CalcExpression + "),1,0)";
String result1 = getValueFromCalc(resultcondition, variableMap,"-1");
if ("1".equals(result1)) return true;
if ("-1".equals(result1)) return def;
return false;
}
/**
@ -93,7 +98,9 @@ public class CalcUtils {
* @return
*/
public static String getCalc(String CalcExpression){
CalcExpression=trimCalc(CalcExpression);
// 匹配 isnull(...) 格式,兼容括号内外的空格
CalcExpression = CalcExpression.replaceAll("isnull\\s*\\(\\s*(.*?)\\s*\\)", "($1 == null)");
// 1. 替换逻辑运算符:and→&&,or→||
String processed = CalcExpression.replaceAll("\\band|AND\\b", "&&").replaceAll("\\bor|OR\\b", "||");
// 2. 替换变量格式:[a] → #a
@ -103,12 +110,31 @@ public class CalcUtils {
processed = replaceLenFunction(processed);
//4.like '%aa'或者 like 'aa%'或者 like '%aa%'
processed = replaceLikeExpressions(processed);
processed = processed.replaceAll("not\\s*\\.contains", "!contains");
// 1. 先将所有比较用的=替换为==(关键修复)
processed = processed.replaceAll("(\\w+)\\s*=\\s*('.*?'|\\w+)", "$1 == $2");
//5. 递归处理if结构:if(cond, trueExpr, falseExpr) → cond?trueExpr:falseExpr
return processIf(processed);
}
/**
* 规整公式
* @param CalcExpression
* @return
*/
public static String trimCalc(String CalcExpression){
String expr=CalcExpression.replace(" "," ");
expr=expr.replace(" (","(");
expr=expr.replace(") ",")");
expr=expr.replace(", ",",");
expr=expr.replace(" ,",",");
expr=expr.replace("isNull","isnull");
expr=expr.replace("ISNULL","isnull");
expr=expr.replace(" LIKE "," like ");
expr=expr.replace(" NOT "," not ");
expr = expr.replace("IF(", "if(");
return expr;
}
/**
* 取出公式中所有[参数]返回数组,供调用传值引用
* @param input
@ -148,9 +174,6 @@ public class CalcUtils {
* 递归解析并替换if表达式
*/
private static String processIf(String expr) {
expr = expr.replace("IF(", "if(");
expr = expr.replace("IF (", "if(");
expr = expr.replace("if (", "if(");
int start = expr.indexOf("if(");
if (start == -1) {
return expr;
@ -181,7 +204,7 @@ public class CalcUtils {
String wrappedFalse = needsParentheses(processedFalse) ? "(" + processedFalse + ")" : processedFalse;
// 拼接三元表达式
String ternary = condition + "?" + wrappedTrue + ":" + wrappedFalse;
String ternary ="(("+condition + ")?" + wrappedTrue + ":" + wrappedFalse+")";
String before = expr.substring(0, start);
String after = expr.substring(end + 1);
@ -283,33 +306,47 @@ public class CalcUtils {
return result.toString();
}
/**
* 处理like表达式转换
* 支持:like '%xxx'、like 'xxx%'、like '%xxx%'、like 'xxx'(精确匹配)
* 处理like和not like表达式转换
* 支持:
* - like '%xxx'、like 'xxx%'、like '%xxx%'、like 'xxx'(精确匹配)
* - not like '%xxx'、not like 'xxx%'、not like '%xxx%'、not like 'xxx'
*/
private static String replaceLikeExpressions(String expression) {
// 修正正则:左侧表达式允许包含#、字母、数字、下划线(#[a-zA-Z0-9_]+)
Pattern pattern = Pattern.compile("([#\\w]+)\\s+like\\s+'([^']+)'", Pattern.CASE_INSENSITIVE);
// 修正正则:
// 1. 增加 (not\\s+)? 分组,用于匹配可选的 "not " 前缀,CASE_INSENSITIVE 会处理大小写
// 2. 左侧表达式允许包含#、字母、数字、下划线(#[a-zA-Z0-9_]+)
Pattern pattern = Pattern.compile("([#\\w]+)\\s+(not\\s+)?like\\s+'([^']+)'", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(expression);
StringBuffer result = new StringBuffer();
while (matcher.find()) {
String leftExpr = matcher.group(1); // 支持#变量(如#RESULT)
String patternStr = matcher.group(2);
String replacement = generateLikeReplacement(leftExpr, patternStr);
String leftExpr = matcher.group(1); // 左侧表达式,如 #DEPT
String notPrefix = matcher.group(2); // 匹配到的 "not " 部分,如果是 like 则为 null
String patternStr = matcher.group(3); // like 后面的匹配模式,如 '%内分泌%'
// 生成 like 的基础替换字符串
String likeReplacement = generateLikeReplacement(leftExpr, patternStr);
// 如果存在 "not " 前缀,则在整个表达式前加上 "!"
String replacement = (notPrefix != null && !notPrefix.isEmpty())
? "!" + likeReplacement
: likeReplacement;
matcher.appendReplacement(result, replacement);
}
matcher.appendTail(result);
return result.toString();
}
/**
* 根据like模式生成对应的SpEL方法调用
* 根据like模式生成对应的SpEL方法调用(内部使用)
*/
private static String generateLikeReplacement(String leftExpr, String patternStr) {
boolean startsWithWildcard = patternStr.startsWith("%");
boolean endsWithWildcard = patternStr.endsWith("%");
String content = patternStr.replace("%", ""); // 提取实际匹配内容
// 处理三种like场景
// 处理三种like场景和一种精确匹配场景
if (startsWithWildcard && endsWithWildcard) {
// like '%xxx%' → 包含:xxx.contains('content')
return String.format("%s.contains('%s')", leftExpr, escapeQuotes(content));
@ -324,6 +361,8 @@ public class CalcUtils {
return String.format("%s.equals('%s')", leftExpr, escapeQuotes(content));
}
}
/**
* 转义字符串中的单引号,避免SpEL语法错误
*/
@ -352,7 +391,9 @@ public class CalcUtils {
// variables.put("TP", "6.0");
String testCalc = "[DEPT] like '%内分泌%'";
// testCalc=testCalc.replace("[结果]", "[RESULT]");
//System.out.println(getCalc(testCalc));
System.out.println(getCalc(testCalc));
testCalc = "[DEPT] not like '%内分泌%'";
System.out.println(getCalc(testCalc));
System.out.println(getBooleanFromCalc(testCalc,variables));
}

View File

@ -125,8 +125,8 @@ public class CheckResultUtils {
}
//项目不全,此公式跳过
if (setjgsg) {
boolean result = CalcUtils.getBooleanFromCalc(jsgs, variables);
if (result) {
boolean result = CalcUtils.getBooleanFromCalc(jsgs, variables,true);
if (!result) {
errmsg = errmsg + LisUtil.LINE_SEPARATOR + "审核条件: " + jsgs + " 规则触发,未通过审核!";
}

View File

@ -72,11 +72,21 @@ public class LisWorkOperController extends BaseController {
public Result check2( Date jyrq, String yq, String ybh, String yhdh){
return lisWorkOperService.confirm(jyrq, yq, ybh, yhdh);
}
@ApiOperation("初审报告")
@GetMapping("/check1")
public Result check1( Date jyrq, String yq, String ybh, String yhdh){
return lisWorkOperService.confirm1(jyrq, yq, ybh, yhdh);
}
@ApiOperation("取消审核")
@GetMapping("/uncheck2")
public Result uncheck2( Date jyrq, String yq, String ybh, String yhdh){
return lisWorkOperService.unconfirm(jyrq, yq, ybh, yhdh);
}
@ApiOperation("取消初审")
@GetMapping("/uncheck1")
public Result uncheck1( Date jyrq, String yq, String ybh, String yhdh){
return lisWorkOperService.unconfirm1(jyrq, yq, ybh, yhdh);
}
@GetMapping("/unconfirmlog")
public Result unconfirmlog( Date jyrq, String yq, String ybh, String yhdh,String reason){
return lisWorkOperService.unconfirmlog(jyrq, yq, ybh, yhdh,reason);

View File

@ -41,6 +41,7 @@ public interface LisWorkOperService {
* @return
*/
Result confirm(Date jyrq, String yq, String ybh, String hdys);
Result confirm1(Date jyrq, String yq, String ybh, String hdys);
/**
* 解除审核
@ -52,6 +53,7 @@ public interface LisWorkOperService {
* @return
*/
Result unconfirm(Date jyrq, String yq, String ybh, String hdys);
Result unconfirm1(Date jyrq, String yq, String ybh, String hdys);
Result unconfirmlog(Date jyrq, String yq, String ybh, String hdys, String reason);

View File

@ -381,6 +381,69 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
}
return new Result("3", "审核成功!");
}
@Override
public Result confirm1(Date jyrq, String yq, String ybh, String hdys) {
if (hdys == null || "".equals(hdys)) return new Result("-1", "审核者为空,无法审核!");
//入参通过GET推送时使用ServletUtils.getParameterToInt获取
//入参通过POSTJSON时使用JsonParamUtils.getParameterToInt获取
int problemId = ServletUtils.getParameterToInt("problemId", 0);
LabPat labPat = commonUtil.getLabPatOne(jyrq, yq, ybh);
labPat.setHdys(hdys);
List<LabResult> labResultList = commonUtil.getLabResultList(jyrq, yq, ybh);
if (problemId < 3) {
//1,审核权限校验
if (!commonUtil.getUserPower(yq, hdys, 20)) {
return new Result("-1", "当前核对者无权对本仪器报告审核!");
}
//2:数据合法性校验
Result result0 = beforeconfirm(labPat, labResultList, 1, problemId);
if (!"0".equals(result0.getCode())) return result0;
}
if (problemId < 3) problemId = 3;
if (problemId < 4) {
//3:数据完整保存
labResultList = saveallresult(labPat, labResultList);
boolean wjz = getAlarmFlag(labResultList);
//同步主表危急值标识
String alarmflag = labPat.getAlarmflag();
if (("1".equals(alarmflag) && !wjz)) {
labPat.setAlarmflag("");
commonUtil.updateLabPat(labPat);
} else if (("".equals(alarmflag) || alarmflag == null) && wjz) {
labPat.setAlarmflag("1");
commonUtil.updateLabPat(labPat);
}
if(wjz){
return new Result("4", getAlarmMsg(labResultList),4);
}
}
if (problemId < 5) problemId = 5;
if (problemId < 6) {
//医学审核条件判断
Result result = chksample(labPat, labResultList, problemId);
if (!"0".equals(result.getCode())) return result;
}
if (problemId < 6) problemId = 6;
if (problemId < 99) {
//高级医学审核条件判断
Result result = chksamplenew(labPat, labResultList, problemId);
if ("99".equals(result.getCode())) {
labPat.setBz(result.getMsg());
result.setCode("0");
}
if (!"0".equals(result.getCode())) return result;
}
if (problemId < 99) problemId = 99;
//5:数据状态修改,异步上传接口作业创建
Result result1 = afterconfirm1(labPat, problemId);
if (!"0".equals(result1.getCode())) return result1;
setComLog(jyrq, yq, ybh,hdys, ComLogConstants.LG_CK1,"");
// String sqh=labPat.getSqh();
// if(sqh!=null){
// setlabReqsteplog(sqh,SampleStatusConstants.CONFIRM,hdys);
// }
return new Result("3", "审核成功!");
}
/**
* 审核前校验数据完整性,审核业务和初审业务都可使用
@ -668,6 +731,37 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
return ret;
}
/**
* 初步审核状态修改
* @param labPat
* @param problemId
* @return
*/
private Result afterconfirm1(LabPat labPat, Integer problemId) {
Date jyrq = labPat.getJyrq();
String yq = labPat.getYq();
String ybh = labPat.getYbh();
String hdys = labPat.getHdys();
String yqdl = commonUtil.getYqdl(yq);
String itemvs = commonUtil.getHISOPT("itemvs");
Result ret = new Result("0", "保存成功!");
if ("1".equals(itemvs)) {
if (!"细菌仪".equals(yqdl)) {
String nullcount = lisWorkOperMapper.checkresultnosqxmdh(jyrq, yq, ybh);
if (!"".equals(nullcount) && nullcount != null)
ret = new Result("3", "警告!" + LisUtil.LINE_SEPARATOR + " 报告项目未对应申请项目,请进(收费项目报告项目对照)菜单维护对照:" + LisUtil.LINE_SEPARATOR + nullcount);
}
}
Date Confirmdt = new Date();
labPat.setLastdt(Confirmdt);
labPat.setLastuser(hdys);
String finish = labPat.getFinish();
if (!"细菌仪".equals(yqdl) && finish != null) labPat.setFinish("1");
labPat.setJgbz(ReportStatusConstants.PRELIM);
commonUtil.updateLabPat(labPat);
return ret;
}
/**
* 申请单表校验TAT时间顺序,恢复时间倒置的时间轴
*
@ -906,7 +1000,7 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
}
}
if (setjgsg) {
String result = CalcUtils.getValueFromCalc(jsgs, variables);
String result = CalcUtils.getValueFromCalc(jsgs, variables,"0");
if ("0".equals(result) && lb_jsx) result = null;
if (result != null && !result.trim().isEmpty()) {
//插入结果值
@ -1550,7 +1644,33 @@ public class LisWorkOperServiceImpl implements LisWorkOperService {
if(sqh!=null){
setlabReqsteplog(sqh,SampleStatusConstants.START,yhdh);
}
return new Result("3", msg);
if (!"取消成功!".equals(msg)) return new Result("3", msg);
return new Result("1", msg);
}
@Override
public Result unconfirm1(Date jyrq, String yq, String ybh, String yhdh) {
if (yhdh == null || "".equals(yhdh)) return new Result("-1", "操作者为空,无法解除审核!");
int problemId = ServletUtils.getParameterToInt("problemId", 0);
LabPat labPat = commonUtil.getLabPatOne(jyrq, yq, ybh);
if (problemId < 3) {
//1,解除审核权限校验
if (!commonUtil.getUserPower(yq, yhdh, 10)) return new Result("-1", "当前操作者无权对本仪器报告解除审核!");
//2:数据合法性校验
String jgbz = labPat.getJgbz();
if ("2".equals(jgbz)) return new Result("1", "报告已审核,不能解除初审!");
if (!"1".equals(jgbz)) return new Result("1", "报告未初审,不能解除初审!");
}
// if (problemId < 3) problemId = 3;
// if (problemId < 4) problemId = 4;
if (problemId < 5) problemId = 5;
labPat.setFslx("");
labPat.setJgbz(ReportStatusConstants.DEFAULT);
commonUtil.updateLabPat(labPat);
setComLog(jyrq, yq, ybh,yhdh, ComLogConstants.LG_UCK1,"");
return new Result("1", "取消成功!");
}
/**