1、公式校验,校验if判断
This commit is contained in:
parent
edb450daad
commit
6c89e1665c
|
@ -246,23 +246,92 @@ public class AeConfVoucherTemplateServiceImpl extends BaseService<AeConfVoucherT
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公式校验
|
||||||
|
* -:判断前后是否为数值,数值相减,字符连接
|
||||||
|
* +-+:为连接符
|
||||||
|
* if(A>0?b:c)
|
||||||
|
* substr(A,0,4)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAbstract(AeConfVoucherTemplateEntity entity) {
|
public boolean checkAbstract(AeConfVoucherTemplateEntity entity) {
|
||||||
String abstractRes = entity.getAbstractRes();
|
String abstractRes = entity.getAbstractRes();
|
||||||
|
|
||||||
// 校验基本格式
|
// // 提取括号中的内容
|
||||||
if (abstractRes.contains("++") || abstractRes.startsWith("+") || abstractRes.endsWith("+")) {
|
// List<String> parenthesesContents = new ArrayList<>();
|
||||||
|
// Pattern contentPattern = Pattern.compile("\\((.*?)\\)");
|
||||||
|
// Matcher contentMatcher = contentPattern.matcher(abstractRes);
|
||||||
|
// while (contentMatcher.find()) {
|
||||||
|
// parenthesesContents.add(contentMatcher.group(1));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 提取运算符(-或+)
|
||||||
|
// List<String> 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] parts = abstractRes.split("\\+");
|
String[] parts = abstractRes.split("\\+");
|
||||||
for (String part : parts) {
|
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公式
|
//判断substr公式
|
||||||
if (part.startsWith("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);
|
Pattern pattern = Pattern.compile(regex);
|
||||||
Matcher matcher = pattern.matcher(part);
|
Matcher matcher = pattern.matcher(part);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
|
Loading…
Reference in New Issue