Browse Source

Merge remote-tracking branch 'origin/release/11.0' into release/11.0

release/11.0
Jitorun 2 weeks ago
parent
commit
b2ca4707b8
  1. 3
      designer-base/src/main/java/com/fr/design/locale/impl/SupportLocaleImpl.java
  2. 46
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java
  3. 304
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java
  4. 19
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java

3
designer-base/src/main/java/com/fr/design/locale/impl/SupportLocaleImpl.java

@ -1,5 +1,6 @@
package com.fr.design.locale.impl;
import com.fr.general.locale.LocaleConstants;
import com.fr.general.locale.SupportLocale;
import java.util.HashSet;
@ -169,6 +170,8 @@ public enum SupportLocaleImpl implements SupportLocale {
set.add(Locale.KOREA);
set.add(Locale.CHINA);
set.add(Locale.TAIWAN);
set.add(LocaleConstants.IN_ID);
set.add(LocaleConstants.VI);
return set;
}
}

46
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java

@ -3,9 +3,11 @@ package com.fr.design.actions.replace.action.content.tabledata;
import com.fr.data.TableReplacementEntity;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.parser.Ambiguity;
import com.fr.parser.BinaryExpression;
import com.fr.parser.DatasetFunctionCall;
import com.fr.parser.FunctionCall;
import com.fr.parser.RelationExpression;
import com.fr.parser.StringLiteral;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
@ -107,18 +109,7 @@ public class TableDataFormulaUtils {
// 数据集名称
StringBuilder parent = new StringBuilder(datasetFunctionCall.getSourceName());
for (Node subNode : subNodes) {
// 嵌套普通公式
if (subNode instanceof FunctionCall) {
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
} else if (subNode instanceof StringLiteral) {
// 无嵌套,可以根据传进来的datasetFunctionCall进行替换
StringLiteral stringLiteral = (StringLiteral) subNode;
replaceDatasetFunctionCall0(stringLiteral, datasetFunctionCall, entities, parent);
} else if (subNode instanceof DatasetFunctionCall) {
// 嵌套datasetFunctionCall,递归回来该方法继续往下
DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode;
replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities);
}
replaceNode4DatasetFunctionCall(subNode, datasetFunctionCall, entities, parent);
}
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(parent.toString(), entity.getOldName())) {
@ -130,17 +121,40 @@ public class TableDataFormulaUtils {
}
}
private static void replaceDatasetFunctionCall0(StringLiteral stringLiteral, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
private static void replaceNode4DatasetFunctionCall(Node subNode, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
// 嵌套普通公式
if (subNode instanceof FunctionCall) {
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
} else if (subNode instanceof Ambiguity) {
// 无嵌套,可以根据传进来的datasetFunctionCall进行替换
// 这边产品确认只能替换无双引号的字段,因此是ambiguity而不是StringLiteral
Ambiguity ambiguity = (Ambiguity) subNode;
replaceDatasetFunctionCall0(ambiguity, datasetFunctionCall, entities, parent);
} else if (subNode instanceof DatasetFunctionCall) {
// 嵌套datasetFunctionCall,递归回来该方法继续往下
DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode;
replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities);
} else if (subNode instanceof RelationExpression) {
Node left = ((RelationExpression) subNode).getLeft();
Node right = ((RelationExpression) subNode).getRight();
replaceNode4DatasetFunctionCall(left, datasetFunctionCall, entities, parent);
replaceNode4DatasetFunctionCall(right, datasetFunctionCall, entities, parent);
}
}
private static void replaceDatasetFunctionCall0(Ambiguity ambiguity, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
try {
TableDataFormulaType type = TableDataFormulaType.get(datasetFunctionCall.getFnName());
if (type != null) {
String name = stringLiteral.eval(Calculator.createCalculator()).toString();
String name = ambiguity.toString();
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(parent.toString(), entity.getOldName())) {
// 如果是要替换的数据集
String field = entity.getTargetField(name);
// 替换成匹配后的字段
Reflect.on(stringLiteral).set(STATEMENT, field);
if (StringUtils.isNotEmpty(field)) {
// 替换成匹配后的字段
Reflect.on(ambiguity).set(STATEMENT, field);
}
break;
}
}

304
designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java

@ -1,6 +1,8 @@
package com.fr.design.actions.replace.utils;
import com.fr.base.Formula;
import com.fr.base.present.DictPresent;
import com.fr.base.present.Present;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.web.ChartHyperPoplink;
import com.fr.data.SimpleDSColumn;
@ -8,6 +10,7 @@ import com.fr.data.TableReplacementEntity;
import com.fr.data.condition.CommonCondition;
import com.fr.data.condition.JoinCondition;
import com.fr.data.condition.ListCondition;
import com.fr.data.condition.ObjectCondition;
import com.fr.data.core.Compare;
import com.fr.data.impl.NameTableData;
import com.fr.data.impl.TableDataDictionary;
@ -36,6 +39,7 @@ import com.fr.form.ui.TreeEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.concept.data.ValueInitializer;
import com.fr.form.ui.tree.LayerConfig;
import com.fr.form.ui.tree.LayerDependence;
import com.fr.general.ComparatorUtils;
import com.fr.general.data.Condition;
import com.fr.general.data.TableDataColumn;
@ -45,6 +49,7 @@ import com.fr.js.NameJavaScriptGroup;
import com.fr.main.impl.WorkBook;
import com.fr.main.parameter.ReportParameterAttr;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.Elem;
import com.fr.report.cell.FloatElement;
import com.fr.report.cell.TemplateCellElement;
import com.fr.report.cell.cellattr.core.group.DSColumn;
@ -60,6 +65,7 @@ import com.fr.report.utils.ElementCaseHelper;
import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -121,8 +127,12 @@ public class ReplaceUtils {
* @return 报表块使用的数据集
*/
public static Set<String> getElementCaseDependenceTables(ElementCaseEditor elementCaseEditor) {
FormElementCaseProvider elementCase = elementCaseEditor.getElementCase();
return elementCase.getCellTableDataSet();
Set<String> ans = new HashSet<>();
FormElementCaseProvider provider = elementCaseEditor.getElementCase();
if (provider instanceof ElementCase) {
ans.addAll(searchElementCaseDependenceTables((ElementCase) provider));
}
return ans;
}
/**
@ -155,10 +165,10 @@ public class ReplaceUtils {
String tableName = iterator.next();
ans.add(tableName);
}
ans.addAll(searchReport(workBook));
}
return ans;
}
/**
* 获取CPT里使用的公式
*
@ -326,6 +336,7 @@ public class ReplaceUtils {
private static void replaceHighlight(Highlight highlight, List<TableReplacementEntity> entities) {
if (highlight instanceof DefaultHighlight) {
DefaultHighlight defaultHighlight = (DefaultHighlight) highlight;
replaceCondition(defaultHighlight.getCondition(), entities);
for (int i = 0 ; i < defaultHighlight.actionCount() ; i++) {
if (defaultHighlight.getHighlightAction(i) instanceof PresentHighlightAction) {
PresentHighlightAction action = (PresentHighlightAction) defaultHighlight.getHighlightAction(i);
@ -485,35 +496,45 @@ public class ReplaceUtils {
//公式条件不需要修改,里面不会涉及到,有问题再加
//普通条件
//1条条件
if (condition instanceof CommonCondition) {
dealWithTableDataNameChange((CommonCondition) condition, entity);
}
replaceSingleCondition(condition, entity);
//N条条件
if (condition instanceof ListCondition) {
for (int k = 0; k < ((ListCondition) condition).getJoinConditionCount(); k++) {
JoinCondition joinCondition = ((ListCondition) condition).getJoinCondition(k);
Condition obCondition = joinCondition.getCondition();
if (obCondition != null) {
if (obCondition instanceof CommonCondition) {
dealWithTableDataNameChange((CommonCondition) obCondition, entity);
}
replaceSingleCondition(obCondition, entity);
}
}
}
}
}
private static void replaceSingleCondition(Condition condition, List<TableReplacementEntity> entity) {
if (condition instanceof CommonCondition) {
dealWithTableDataNameChange((CommonCondition) condition, entity);
}
if (condition instanceof ObjectCondition) {
dealWithCompare(((ObjectCondition) condition).getCompare(), entity);
}
}
private static void dealWithTableDataNameChange(CommonCondition condition, List<TableReplacementEntity> entities) {
Compare compare = condition.getCompare();
Object ob = compare.getValue();
if (ob instanceof SimpleDSColumn) {
for (TableReplacementEntity entity : entities) {
if (ComparatorUtils.equals(((SimpleDSColumn) ob).getDsName(), entity.getOldName())) {
((SimpleDSColumn) ob).setDsName(entity.getNewName());
((SimpleDSColumn) ob).setColumn(TableDataColumn.createColumn(entity.getTargetField(TableDataColumn.getColumnName(((SimpleDSColumn) ob).getColumn()))));
dealWithCompare(compare, entities);
}
private static void dealWithCompare(Compare compare, List<TableReplacementEntity> entities) {
if (compare != null) {
Object ob = compare.getValue();
if (ob instanceof SimpleDSColumn) {
for (TableReplacementEntity entity : entities) {
if (ComparatorUtils.equals(((SimpleDSColumn) ob).getDsName(), entity.getOldName())) {
((SimpleDSColumn) ob).setDsName(entity.getNewName());
((SimpleDSColumn) ob).setColumn(TableDataColumn.createColumn(entity.getTargetField(TableDataColumn.getColumnName(((SimpleDSColumn) ob).getColumn()))));
}
}
}
}
}
@ -609,6 +630,9 @@ public class ReplaceUtils {
layerConfig.setTableData(new NameTableData(entity.getNewName()));
layerConfig.setViewColumn(entity.getTargetIndex(layerConfig.getViewColumn()));
layerConfig.setModelColumn(entity.getTargetIndex(layerConfig.getModelColumn()));
for (LayerDependence dependence : layerConfig.getDependenceList()) {
dependence.setThisColumnIndex(entity.getTargetIndex(dependence.getThisColumnIndex()));
}
}
}
ElementCaseHelper.replaceTableDataDictionary(layerConfig.getDictionary(), (NameTableData) layerConfig.getDictionary().getTableData(), entities);
@ -635,5 +659,253 @@ public class ReplaceUtils {
}
/**
* ------------------------private search-----------------------------------
*/
private static Set<String> searchElementCasJs(ElementCase elementCase) {
Set<String> ans = new HashSet<>();
List<JavaScript> javaScripts = new ArrayList<>();
// 替换通用元素
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
CellElement cell = (CellElement) cellIterator.next();
javaScripts.addAll(SearchJSUtils.getJSDependenceTables(cell));
}
ans.addAll(searchJs(javaScripts));
return ans;
}
private static Set<String> searchJs(List<JavaScript> javaScripts) {
Set<String> ans = new HashSet<>();
for (JavaScript javaScript : javaScripts) {
if (javaScript instanceof ChartHyperPoplink) {
ChartHyperPoplink chartHyperPoplink = (ChartHyperPoplink) javaScript;
if (chartHyperPoplink.getChartCollection() instanceof ChartCollection) {
ans.addAll((chartHyperPoplink.getChartCollection().getDataSetNames()));
}
}
}
return ans;
}
private static Set<String> searchFormulaInfos(List<FormulaInfo> formulaInfos) {
Set<String> ans = new HashSet<>();
for (FormulaInfo formulaInfo : formulaInfos) {
ans.addAll(TableDataFormulaUtils.search4TableData(formulaInfo.getPureValue()));
}
return ans;
}
private static Set<String> searchTableDataWithOutFormula(ElementCase elementCase) {
Set<String> ans = new HashSet<>();
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
CellElement cell = (CellElement) cellIterator.next();
// 处理【形态、控件、数据字典】
ans.addAll(searchPresentAndDictionary(cell));
// 处理【单元格值】
ans.addAll(searchElemValue(cell));
// 处理【条件属性】
ans.addAll(searchCellHighlight(cell));
}
return ans;
}
private static Set<String> searchCellHighlight(CellElement cell) {
Set<String> ans = new HashSet<>();
if (cell instanceof TemplateCellElement) {
HighlightGroup group = ((TemplateCellElement) cell).getHighlightGroup();
if (group != null) {
for (int i = 0 ; i < group.size(); i++) {
Highlight highlight = group.getHighlight(i);
ans.addAll(searchHighlight(highlight));
}
}
}
return ans;
}
private static Set<String> searchHighlight(Highlight highlight) {
Set<String> ans = new HashSet<>();
if (highlight instanceof DefaultHighlight) {
DefaultHighlight defaultHighlight = (DefaultHighlight) highlight;
for (int i = 0 ; i < defaultHighlight.actionCount() ; i++) {
if (defaultHighlight.getHighlightAction(i) instanceof PresentHighlightAction) {
PresentHighlightAction action = (PresentHighlightAction) defaultHighlight.getHighlightAction(i);
ans.addAll(searchPresent(action.getPresent()));
} else if (defaultHighlight.getHighlightAction(i) instanceof WidgetHighlightAction) {
WidgetHighlightAction action = (WidgetHighlightAction) defaultHighlight.getHighlightAction(i);
ans.addAll(searchWidget(action.getWidget()));
} else if (defaultHighlight.getHighlightAction(i) instanceof HyperlinkHighlightAction) {
HyperlinkHighlightAction action = (HyperlinkHighlightAction) defaultHighlight.getHighlightAction(i);
NameJavaScriptGroup group = action.getHperlink();
ans.addAll(searchNameJavaScriptGroup(group));
}
}
}
return ans;
}
private static Set<String> searchNameJavaScriptGroup(NameJavaScriptGroup group) {
Set<String> ans = new HashSet<>();
if (group != null) {
for (int i = 0 ; i < group.size(); i++) {
NameJavaScript javaScript = group.getNameHyperlink(i);
if (javaScript.getJavaScript() instanceof ChartHyperPoplink) {
if (((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection() instanceof ChartCollection) {
ans.addAll((((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection().getDataSetNames()));
}
}
}
}
return ans;
}
private static Set<String> searchElemValue(Elem cell) {
Set<String> ans = new HashSet<>();
Object value = cell.getValue();
if (value instanceof DSColumn) {
// 查找【数据列】
ans.add(((DSColumn) value).getDSName());
// 查找【条件属性】
ans.addAll(searchCondition(((DSColumn) value).getCondition()));
} else if (value instanceof ChartCollection) {
ans.addAll(((ChartCollection) value).getDataSetNames());
}
return ans;
}
private static Set<String> searchCondition(Condition condition) {
Set<String> ans = new HashSet<>();
if (condition != null) {
//普通条件
//1条条件
if (condition instanceof CommonCondition) {
ans.addAll(searchCondition0((CommonCondition) condition));
}
//N条条件
if (condition instanceof ListCondition) {
for (int k = 0; k < ((ListCondition) condition).getJoinConditionCount(); k++) {
JoinCondition joinCondition = ((ListCondition) condition).getJoinCondition(k);
Condition obCondition = joinCondition.getCondition();
if (obCondition instanceof CommonCondition) {
ans.addAll(searchCondition0((CommonCondition) obCondition));
}
}
}
}
return ans;
}
private static Set<String> searchCondition0(CommonCondition condition) {
Set<String> ans = new HashSet<>();
Compare compare = condition.getCompare();
Object ob = compare.getValue();
if (ob instanceof SimpleDSColumn) {
ans.add(((SimpleDSColumn) ob).getDsName());
}
return ans;
}
private static Set<String> searchPresentAndDictionary(CellElement cell) {
Set<String> ans = new HashSet<>();
TemplateCellElement cellElement = (TemplateCellElement) cell;
// 处理单元格的控件
ans.addAll(searchWidget(cellElement.getWidget()));
// 处理形态
ans.addAll(searchPresent(cellElement.getPresent()));
return ans;
}
private static Set<String> searchPresent(Present p) {
Set<String> ans = new HashSet<>();
if (!(p instanceof DictPresent)) {
return ans;
}
DictPresent dp = (DictPresent) p;
if (!(dp.getDictionary() instanceof TableDataDictionary)) {
return ans;
}
TableDataDictionary td = (TableDataDictionary) dp.getDictionary();
if (!(td.getTableData() instanceof NameTableData)) {
return ans;
}
NameTableData nd = (NameTableData) td.getTableData();
ans.add(nd.getName());
return ans;
}
private static Set<String> searchWidget(Widget widget) {
Set<String> ans = new HashSet<>();
if (widget instanceof DictionaryContainer) {
DictionaryContainer db = (DictionaryContainer) widget;
if (db.getDictionary() instanceof TableDataDictionary) {
TableDataDictionary tdd = (TableDataDictionary) db.getDictionary();
NameTableData ndd = (NameTableData) tdd.getTableData();
if (ndd != null) {
ans.add(ndd.getName());
}
}
}
if (widget instanceof DataControl) {
ValueInitializer value = ((DataControl) widget).getWidgetValue();
if (value != null && value.getValue() instanceof DataBinding) {
DataBinding binding = (DataBinding) value.getValue();
ans.add(binding.getDataSourceName());
}
}
return ans;
}
private static Set<String> searchReport(WorkBook workBook) {
Set<String> ans = new HashSet<>();
for (int i = 0; i < workBook.getReportCount(); i++) {
Report report = workBook.getReport(i);
if (report != null) {
Iterator it = report.iteratorOfElementCase();
while (it.hasNext()) {
ElementCase elementCase = (ElementCase) it.next();
ans.addAll(searchElementCaseDependenceTables(elementCase));
}
}
}
return ans;
}
private static Collection<String> searchElementCaseDependenceTables(ElementCase provider) {
Set<String> ans = new HashSet<>();
// 非公式部分
ans.addAll(searchTableDataWithOutFormula(provider));
// 公式部分——理论上就只有单元格和控件(超链那些都包含)
List<FormulaInfo> formulaInfos = getElementCaseFormulas( provider);
ans.addAll(searchFormulaInfos(formulaInfos));
// 超链部分
ans.addAll(searchElementCasJs(provider));
// 悬浮元素
ans.addAll(searchFloat(provider));
return ans;
}
private static Set<String> searchFloat(ElementCase provider) {
Set<String> ans = new HashSet<>();
Iterator flotIt = provider.floatIterator();
while (flotIt.hasNext()) {
FloatElement flotEl = (FloatElement) flotIt.next();
// 值
ans.addAll(searchElemValue(flotEl));
// 超链
ans.addAll(searchFloatJs(flotEl));
}
return ans;
}
private static Set<String> searchFloatJs(FloatElement flotEl) {
List<JavaScript> javaScripts = new ArrayList<>(SearchJSUtils.getJSDependenceTables(flotEl));
return new HashSet<>(searchJs(javaScripts));
}
}

19
designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java

@ -387,11 +387,14 @@ public class SearchJSUtils {
if (chartCollection.getChart(i) instanceof VanChart) {
VanChart chart = ((VanChart) chartCollection.getChart(i));
if (chart.getPlot() != null) {
NameJavaScriptGroup nameJavaScriptGroup = chart.getPlot().getHotHyperLink();
if (isNameJavaScriptGroupExist(nameJavaScriptGroup)) {
for (int j = 0; j < nameJavaScriptGroup.size(); j++) {
nameJavaScriptArrayList.add(nameJavaScriptGroup.getNameHyperlink(j));
if (chart.getPlot() instanceof VanChartCustomPlot) {
VanChartCustomPlot plot = chart.getPlot();
for (Plot customPlot : plot.getCustomPlotList()) {
getChartJavaScriptFromGroup(customPlot.getHotHyperLink(), nameJavaScriptArrayList);
}
} else {
NameJavaScriptGroup nameJavaScriptGroup = chart.getPlot().getHotHyperLink();
getChartJavaScriptFromGroup(nameJavaScriptGroup, nameJavaScriptArrayList);
}
}
}
@ -399,6 +402,14 @@ public class SearchJSUtils {
return nameJavaScriptArrayList;
}
private static void getChartJavaScriptFromGroup(NameJavaScriptGroup nameJavaScriptGroup, ArrayList<NameJavaScript> nameJavaScriptArrayList) {
if (isNameJavaScriptGroupExist(nameJavaScriptGroup)) {
for (int j = 0; j < nameJavaScriptGroup.size(); j++) {
nameJavaScriptArrayList.add(nameJavaScriptGroup.getNameHyperlink(j));
}
}
}
/**
* 处理图表的交互属性可能存在多种地图
* @param content 存储信息的数据结构

Loading…
Cancel
Save