diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index f504c372f4..940aad20ac 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -71,6 +71,8 @@ import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.locks.ReentrantLock; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -1795,8 +1797,7 @@ public class ChartViewService { } private String handleVariable(String sql, ChartExtRequest requestList, QueryProvider qp, DataSetTableDTO table, Datasource ds) throws Exception { - List sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken>() { - }.getType()); + List sqlVariables = new Gson().fromJson(table.getSqlVariableDetails(), new TypeToken>() {}.getType()); if (requestList != null && CollectionUtils.isNotEmpty(requestList.getFilter())) { for (ChartExtFilterRequest chartExtFilterRequest : requestList.getFilter()) { if (CollectionUtils.isEmpty(chartExtFilterRequest.getValue())) { @@ -1845,7 +1846,7 @@ public class ChartViewService { } } } - sql = dataSetTableService.removeVariables(sql, ds.getType()); + sql = dataSetTableService.handleVariableDefaultValue(sql, table.getSqlVariableDetails(), ds.getType()); return sql; } diff --git a/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java b/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java index c77eba238c..cc2c25f6be 100644 --- a/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java +++ b/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java @@ -123,7 +123,6 @@ public class ViewPluginBaseServiceImpl implements ViewPluginBaseService { case SQL: String sql = dataTableInfoDTO.isBase64Encryption() ? new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())) : dataTableInfoDTO.getSql(); tableName = dataSetTableService.handleVariableDefaultValue(sql, null, pluginViewSet.getDsType()); - tableName = "(" + sqlFix(tableName) + ")"; break; case CUSTOM: diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 2a6ba0f346..c6c75b97ed 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -144,7 +144,7 @@ public class DataSetTableService { private static boolean isUpdatingDatasetTableStatus = false; private static final String lastUpdateTime = "${__last_update_time__}"; private static final String currentUpdateTime = "${__current_update_time__}"; - private static final String regex = "\\$\\{(.*?)\\}"; + public static final String regex = "\\$\\{(.*?)\\}"; private static final String SubstitutedParams = "DATAEASE_PATAMS_BI"; private static final String SubstitutedSql = " 'BI' = 'BI' "; @@ -701,7 +701,7 @@ public class DataSetTableService { datasourceRequest.setDatasource(ds); DataTableInfoDTO dataTableInfo = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class); String sql = dataTableInfo.isBase64Encryption() ? new String(java.util.Base64.getDecoder().decode(dataTableInfo.getSql())) : dataTableInfo.getSql(); - sql = handleVariableDefaultValue(sql, null, ds.getType()); + sql = handleVariableDefaultValue(sql, datasetTable.getSqlVariableDetails(), ds.getType()); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); datasourceRequest.setQuery( qp.createQuerySQLWithPage(sql, fields, page, pageSize, realSize, false, null, rowPermissionsTree)); @@ -1058,15 +1058,15 @@ public class DataSetTableService { Matcher matcher = pattern.matcher(sql); while (matcher.find()) { SqlVariableDetails defaultsSqlVariableDetail = null; - List defaultsSqlVariableDetails = new Gson().fromJson(sqlVariableDetails, new TypeToken>() { - }.getType()); + List defaultsSqlVariableDetails = new Gson().fromJson(sqlVariableDetails, new TypeToken>() {}.getType()); for (SqlVariableDetails sqlVariableDetail : defaultsSqlVariableDetails) { if (matcher.group().substring(2, matcher.group().length() - 1).equalsIgnoreCase(sqlVariableDetail.getVariableName())) { defaultsSqlVariableDetail = sqlVariableDetail; break; } } - if (defaultsSqlVariableDetail != null && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) { + if (defaultsSqlVariableDetail != null && defaultsSqlVariableDetail.getDefaultValueScope() != null && + defaultsSqlVariableDetail.getDefaultValueScope().equals(SqlVariableDetails.DefaultValueScope.ALLSCOPE) && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) { sql = sql.replace(matcher.group(), defaultsSqlVariableDetail.getDefaultValue()); } } diff --git a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java index 9e2982175b..a128f5627e 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -70,6 +70,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; diff --git a/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java b/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java index a06283d097..75c5001c82 100644 --- a/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java +++ b/backend/src/main/java/io/dataease/service/dataset/impl/direct/DirectFieldService.java @@ -171,7 +171,7 @@ public class DirectFieldService implements DataSetFieldService { if (dataTableInfoDTO.isBase64Encryption()) { sql = new String(java.util.Base64.getDecoder().decode(sql)); } - sql = dataSetTableService.removeVariables(sql, ds.getType()); + sql = dataSetTableService.handleVariableDefaultValue(sql, datasetTable.getSqlVariableDetails(), ds.getType()); datasourceRequest.setQuery(qp.createQuerySQLAsTmp(sql, permissionFields, !needSort, customFilter, rowPermissionsTree, deSortFields)); } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.CUSTOM.toString())) { DataTableInfoDTO dt = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class); diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 765cc7595a..5f6f2743d5 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1519,6 +1519,8 @@ export default { p_center: 'Center' }, dataset: { + scope_edit: 'Effective only when editing', + scope_all: 'Global effective', spend_time: 'Spend', sql: 'SQL', sql_result: 'Result', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 8c23dfbe84..72aaff7c3d 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1513,6 +1513,8 @@ export default { p_center: '居中' }, dataset: { + scope_edit: '僅編輯時生效', + scope_all: '全域生效', spend_time: '耗時', sql: 'SQL 語句', sql_result: '運行結果', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 767c2d7f44..cc809ef196 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1512,6 +1512,8 @@ export default { p_center: '居中' }, dataset: { + scope_edit: '仅编辑时生效', + scope_all: '全局生效', spend_time: '耗时', sql: 'SQL 语句', sql_result: '运行结果', diff --git a/frontend/src/views/dataset/add/AddSQL.vue b/frontend/src/views/dataset/add/AddSQL.vue index 8d085773ef..391da9b87c 100644 --- a/frontend/src/views/dataset/add/AddSQL.vue +++ b/frontend/src/views/dataset/add/AddSQL.vue @@ -478,8 +478,21 @@ v-model="scope.row.defaultValue" size="small" type="text" - :placeholder="$t('fu.search_bar.please_input')" - /> + :placeholder="$t('fu.search_bar.please_input')"> + + + + + > + + + + + > + + + +