Browse Source

Pull request #5641: REPORT-58124 公式编辑器优化:不支持实时计算的功能提示处理

Merge in DESIGN/design from ~HOKY.HE/design-hoky:release/11.0 to release/11.0

* commit '63267aac4b7b5c54ef809643b5c0d6989f4a61c0':
  解决冲突
  解决冲突
  解决冲突
  REPORT-58124 公式编辑器优化:不支持实时计算的功能提示处理 1.修改遍历不支持公式的逻辑
  REPORT-57892 公式编辑器优化:实时计算返回结果为日期格式时不正确 1.添加一个object2string
  REPORT-54887 公式编辑器优化一期 1.添加了公式的参数个数和参数类型的校验; 2.添加了实时计算的功能。
fix-lag
Hoky.He 3 years ago
parent
commit
d5ad16d097
  1. 43
      designer-base/src/main/java/com/fr/design/formula/FormulaPane.java
  2. 49
      designer-base/src/main/java/com/fr/design/formula/UnsupportedFormulaScanner.java

43
designer-base/src/main/java/com/fr/design/formula/FormulaPane.java

@ -39,7 +39,6 @@ import com.fr.parser.BlockIntervalLiteral;
import com.fr.parser.ColumnRowRangeInPage;
import com.fr.parser.FRLexer;
import com.fr.parser.FRParser;
import com.fr.parser.FunctionCall;
import com.fr.parser.SheetIntervalLiteral;
import com.fr.report.core.namespace.SimpleCellValueNameSpace;
import com.fr.script.Calculator;
@ -100,7 +99,6 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -729,15 +727,16 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
@Override
public void actionPerformed(ActionEvent e) {
String formulaText = formulaTextArea.getText().trim();
if (containsUnsupportedSimulationFormulas(formulaText)) {
String formulaValidMessage = getFormulaValidMessage(formulaText);
String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText);
if (unSupportFormula != null) {
FineJOptionPane.showMessageDialog(
FormulaPane.this,
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula,
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
JOptionPane.INFORMATION_MESSAGE);
return;
}
String formulaValidMessage = getFormulaValidMessage(formulaText);
String messageTips;
if (formulaValidMessage.equals(INVALID_FORMULA)) {
messageTips = INVALID_FORMULA;
@ -777,20 +776,21 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
}
};
private boolean containsUnsupportedSimulationFormulas(String formulaText) {
private String containsUnsupportedSimulationFormulas(String formulaText) {
try {
Expression expression = Calculator.createCalculator().parse(formulaText);
String name = ((FunctionCall) expression.getConditionalExpression()).getName();
if (UnsupportedSimulationFormulaHunter.isUnsupportedFomula(name)) {
return true;
UnsupportedFormulaScanner scanner = new UnsupportedFormulaScanner();
if (!scanner.travelFormula(expression.getConditionalExpression())) {
return scanner.getUnSupportFormula();
}
UnsupportedSimulationFormulaHunter unsupportedSimulationFormulaHunter = new UnsupportedSimulationFormulaHunter();
expression.traversal4Tiny(unsupportedSimulationFormulaHunter);
return !unsupportedSimulationFormulaHunter.isSupported();
return unsupportedSimulationFormulaHunter.isSupported() ? null : unsupportedSimulationFormulaHunter.getUnSupportFormula();
} catch (Exception e) {
FineLoggerFactory.getLogger().error("", e);
}
return true;
return null;
}
private Map<String, Object> setParamsIfExist(String formulaText) {
@ -814,7 +814,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
}).setVisible(true);
//过滤出数组参数,如:[1,2]
for (Map.Entry<String, Object> entry : parameterMap.entrySet()) {
if (entry.getValue().toString().startsWith("[") && entry.getValue().toString().startsWith("]")) {
if (entry.getValue().toString().startsWith("[") && entry.getValue().toString().endsWith("]")) {
Expression parse = calculator.parse(entry.getValue());
ArrayExpression arrayExpression = (ArrayExpression) parse.getConditionalExpression();
FArray<Node> fArray = new FArray<>(arrayExpression.getArrays());
@ -839,7 +839,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
String statement = tiny.getStatement();
if (StringUtils.isNotBlank(statement) && statement.startsWith(ScriptConstants.DETAIL_TAG)) {
parameterList.add(new Parameter(statement.substring(1)));
} else if (tiny.getClass() == ColumnRowRange.class || tiny.getClass() == ColumnRowRangeInPage.class ||
} else if (tiny.getClass() == ColumnRowRange.class ||
tiny.getClass() == SheetIntervalLiteral.class || tiny.getClass() == BlockIntervalLiteral.class) {
parameterList.add(new Parameter(tiny.toString()));
}
@ -847,25 +847,26 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula {
}
private static class UnsupportedSimulationFormulaHunter extends TinyHunter {
public final static String[] UNSUPPORTED_FORMULAS = new String[]{"PROPORTION", "TOIMAGE",
"WEBIMAGE", "SORT", "CROSSLAYERTOTAL", "CIRCULAR", "LAYERTOTAL", "MOM", "HIERARCHY"};
private boolean supported = true;
private String unSupportFormula;
public boolean isSupported() {
return supported;
}
public String getUnSupportFormula() {
return unSupportFormula;
}
public void hunter4Tiny(Tiny tiny) {
String statement = tiny.getStatement().toUpperCase();
if (Arrays.asList(UNSUPPORTED_FORMULAS).contains(statement)) {
if (tiny.getClass() == ColumnRowRangeInPage.class) {
supported = false;
unSupportFormula = tiny.toString();
}
}
public static boolean isUnsupportedFomula(String formula) {
return Arrays.asList(UNSUPPORTED_FORMULAS).contains(formula);
}
}
public class VariableTreeAndDescriptionArea extends JPanel {

49
designer-base/src/main/java/com/fr/design/formula/UnsupportedFormulaScanner.java

@ -0,0 +1,49 @@
package com.fr.design.formula;
import com.fr.parser.BinaryExpression;
import com.fr.parser.FunctionCall;
import com.fr.stable.script.Node;
import java.util.Arrays;
/**
* @author Hoky
* @date 2021/8/30
*/
public class UnsupportedFormulaScanner {
public final static String[] UNSUPPORTED_FORMULAS = new String[]{"PROPORTION", "TOIMAGE",
"WEBIMAGE", "SORT", "CROSSLAYERTOTAL", "CIRCULAR", "LAYERTOTAL", "MOM", "HIERARCHY",
"FILENAME", "FILESIZE", "FILETYPE", "TREELAYER", "GETUSERDEPARTMENTS", "GETUSERJOBTITLES"};
private String unSupportFormula = "";
public boolean travelFormula(Node node) {
if (node instanceof FunctionCall) {
if (isUnsupportedFomula(((FunctionCall) node).getName())) {
unSupportFormula = ((FunctionCall) node).getName();
return false;
} else {
for (Node argument : ((FunctionCall) node).getArguments()) {
if (!travelFormula(argument)) {
return false;
}
}
}
} else if (node instanceof BinaryExpression) {
for (Node array : ((BinaryExpression) node).getNodes()) {
if (!travelFormula(array)) {
return false;
}
}
}
return true;
}
public String getUnSupportFormula() {
return unSupportFormula;
}
private static boolean isUnsupportedFomula(String formula) {
return Arrays.asList(UNSUPPORTED_FORMULAS).contains(formula.toUpperCase());
}
}
Loading…
Cancel
Save