refactor: 计算字段变更后的自动更新
Some checks are pending
Typos Check / Spell Check with Typos (push) Waiting to run

This commit is contained in:
junjun 2025-01-14 09:49:54 +08:00 committed by 王嘉豪
parent bcbd54bc1a
commit 949ea35368

View File

@ -38,7 +38,7 @@ public class Utils {
Map.Entry<Long, DatasourceSchemaDTO> next = dsMap.entrySet().iterator().next();
datasourceType = getDs(pluginManage, next.getValue().getType());
}
return buildCalcField(chartField, tableObj, originFields, i, isCross, datasourceType, paramMap, true);
return buildCalcField(chartField, tableObj, originFields, i, isCross, datasourceType, paramMap, true, chartField.getOriginName());
} catch (Exception e) {
DEException.throwException(Translator.get("i18n_field_circular_ref"));
}
@ -53,20 +53,20 @@ public class Utils {
Map.Entry<Long, String> next = dsTypeMap.entrySet().iterator().next();
datasourceType = getDs(pluginManage, next.getValue());
}
return buildCalcField(chartField, tableObj, originFields, i, isCross, datasourceType, null, true);
return buildCalcField(chartField, tableObj, originFields, i, isCross, datasourceType, null, true, chartField.getOriginName());
} catch (Exception e) {
DEException.throwException(Translator.get("i18n_field_circular_ref"));
}
return null;
}
public static String buildCalcField(DatasetTableFieldDTO chartField, SQLObj tableObj, List<DatasetTableFieldDTO> originFields, int i, boolean isCross, DsTypeDTO datasourceType, Map<String, String> paramMap, boolean isFirst) throws Exception {
public static String buildCalcField(DatasetTableFieldDTO chartField, SQLObj tableObj, List<DatasetTableFieldDTO> originFields, int i, boolean isCross, DsTypeDTO datasourceType, Map<String, String> paramMap, boolean isFirst, String fieldExpression) throws Exception {
try {
i++;
if (i > 100) {
DEException.throwException(Translator.get("i18n_field_circular_error"));
}
String originField = getCalcField(chartField, originFields, isFirst);
String originField = getCalcField(chartField, originFields, isFirst, fieldExpression);
originField = originField.replaceAll("[\\t\\n\\r]]", "");
// 正则提取[xxx]
String regex = "\\[(.*?)]";
@ -99,8 +99,7 @@ public class Utils {
}
} else {
originField = originField.replaceAll("\\[" + ele.getId() + "]", "(" + ele.getOriginName() + ")");
chartField.setOriginName(originField);
originField = buildCalcField(chartField, tableObj, originFields, i, isCross, datasourceType, paramMap, false);
originField = buildCalcField(chartField, tableObj, originFields, i, isCross, datasourceType, paramMap, false, originField);
}
}
}
@ -111,7 +110,7 @@ public class Utils {
return null;
}
public static String getCalcField(DatasetTableFieldDTO ele, List<DatasetTableFieldDTO> originFields, boolean isFirst) {
public static String getCalcField(DatasetTableFieldDTO ele, List<DatasetTableFieldDTO> originFields, boolean isFirst, String fieldExpression) {
if (isFirst) {
for (DatasetTableFieldDTO field : originFields) {
if (Objects.equals(ele.getId(), field.getId())) {
@ -120,7 +119,7 @@ public class Utils {
}
return "";
} else {
return ele.getOriginName();
return fieldExpression;
}
}