diff --git a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/comf/template/service/impl/AeConfVoucherTemplateServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/comf/template/service/impl/AeConfVoucherTemplateServiceImpl.java index df74b870..2a7c2164 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/comf/template/service/impl/AeConfVoucherTemplateServiceImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/voucher/ae/comf/template/service/impl/AeConfVoucherTemplateServiceImpl.java @@ -246,23 +246,92 @@ public class AeConfVoucherTemplateServiceImpl extends BaseService0?b:c) + * substr(A,0,4) + */ @Override public boolean checkAbstract(AeConfVoucherTemplateEntity entity) { String abstractRes = entity.getAbstractRes(); - // 校验基本格式 - if (abstractRes.contains("++") || abstractRes.startsWith("+") || abstractRes.endsWith("+")) { +// // 提取括号中的内容 +// List parenthesesContents = new ArrayList<>(); +// Pattern contentPattern = Pattern.compile("\\((.*?)\\)"); +// Matcher contentMatcher = contentPattern.matcher(abstractRes); +// while (contentMatcher.find()) { +// parenthesesContents.add(contentMatcher.group(1)); +// } +// +// // 提取运算符(-或+) +// List operators = new ArrayList<>(); +// Pattern operatorPattern = Pattern.compile("(?<=\\))([-+])(?=\\()"); +// Matcher operatorMatcher = operatorPattern.matcher(abstractRes); +// while (operatorMatcher.find()) { +// operators.add(operatorMatcher.group(1)); +// } +// +// // 输出结果 +// System.out.println("括号中的内容:"); +// for (int i = 0; i < parenthesesContents.size(); i++) { +// System.out.println("内容 " + (i + 1) + ": " + parenthesesContents.get(i)); +// } +// +// System.out.println("运算符:"); +// for (int i = 0; i < operators.size(); i++) { +// System.out.println("运算符 " + (i + 1) + ": " + operators.get(i)); +// } + + + +// // 校验基本格式 + if (abstractRes.contains("++") || abstractRes.endsWith("+")) { return false; } String[] parts = abstractRes.split("\\+"); for (String part : parts) { + //判断if公式 if(A>0?b:c) + if (part.startsWith("if(")) { + // 定义正则表达式模式 + String regex = "if\\(\\s*([^<>]+?)\\s*([<>]=?)\\s*(\\d+)\\s*\\?\\s*([^:]+?)\\s*:\\s*([^)]+?)\\s*\\)"; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(part); + if (matcher.find()) { + String left = matcher.group(1).trim(); // 条件左值 + String op = matcher.group(2); // 操作符 > >= < <= + String right = matcher.group(3); // 右值 3 + String trueValue = matcher.group(4); // ? 后的值 1 + String falseValue = matcher.group(5); // : 后的值 2 + if (left == null || op == null || right == null || trueValue == null || falseValue == null) { + return false; + } + String condition = left + op + right; // 完整条件:A>3 + + System.out.println("条件: " + condition); + System.out.println("真值: " + trueValue); + System.out.println("假值: " + falseValue); + if (left.startsWith("@@$")) { + String fieldPath = left.substring(3); // 去除 @@$ + if (!isValidFieldPath(entity.getMdmId(), fieldPath)) { + return false; + } + } + + }else { + return false; + } + } + //判断substr公式 if (part.startsWith("substr(")) { // 定义正则表达式模式 - String regex = "substr\\(([^(),]+|([^()]*\\([^()]*\\)[^()]*)*),\\s*(\\d+),\\s*(\\d+)\\)"; +// String regex = "substr\\(([^(),]+|([^()]*\\([^()]*\\)[^()]*)*),\\s*(\\d+),\\s*(\\d+)\\)"; + String regex = "if\\(([^<>]+)([<>]=?)(\\d+)\\?([^:]+):([^)]+)\\)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(part); if (matcher.find()) {