diff --git a/backend/src/main/java/io/dataease/dto/dataset/DataTableInfoDTO.java b/backend/src/main/java/io/dataease/dto/dataset/DataTableInfoDTO.java index 00f2eea13f..e78e0cd0c7 100644 --- a/backend/src/main/java/io/dataease/dto/dataset/DataTableInfoDTO.java +++ b/backend/src/main/java/io/dataease/dto/dataset/DataTableInfoDTO.java @@ -15,6 +15,7 @@ import java.util.List; public class DataTableInfoDTO { private String table; private String sql; + private boolean isBase64Encryption = false; private List excelSheetDataList; private String data;// file path private List list;// 自定义数据集 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 d776ffee4e..11b373dab1 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -458,7 +458,7 @@ public class ChartViewService { datasourceRequest.setQuery(qp.getSQL(dataTableInfoDTO.getTable(), xAxis, yAxis, fieldCustomFilter, rowPermissionsTree, extFilterList, ds, view)); } } else if (StringUtils.equalsIgnoreCase(table.getType(), DatasetType.SQL.name())) { - String sql = new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())); + String sql = dataTableInfoDTO.isBase64Encryption()? new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())): dataTableInfoDTO.getSql(); sql = handleVariable(sql, requestList, qp); if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType()) || StringUtils.equalsIgnoreCase("liquid", view.getType())) { datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(sql, yAxis, fieldCustomFilter, rowPermissionsTree, extFilterList, view)); @@ -854,7 +854,7 @@ public class ChartViewService { datasourceRequest.setQuery(qp.getSQL(dataTableInfoDTO.getTable(), xAxis, yAxis, fieldCustomFilter, rowPermissionsTree, extFilterList, ds, view)); } } else if (StringUtils.equalsIgnoreCase(table.getType(), DatasetType.SQL.name())) { - String sql = new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())); + String sql = dataTableInfoDTO.isBase64Encryption()? new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())): dataTableInfoDTO.getSql(); sql = handleVariable(sql, requestList, qp); if (StringUtils.equalsIgnoreCase("text", view.getType()) || StringUtils.equalsIgnoreCase("gauge", view.getType()) || StringUtils.equalsIgnoreCase("liquid", view.getType())) { datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(sql, yAxis, fieldCustomFilter, rowPermissionsTree, extFilterList, view)); 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 33bab12dbe..42e49b1711 100644 --- a/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java +++ b/backend/src/main/java/io/dataease/service/chart/ViewPluginBaseServiceImpl.java @@ -106,7 +106,8 @@ public class ViewPluginBaseServiceImpl implements ViewPluginBaseService { tableName = dataTableInfoDTO.getTable(); break; case SQL: - tableName = dataSetTableService.handleVariableDefaultValue( new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())), null); + String sql = dataTableInfoDTO.isBase64Encryption()? new String(java.util.Base64.getDecoder().decode(dataTableInfoDTO.getSql())): dataTableInfoDTO.getSql(); + tableName = dataSetTableService.handleVariableDefaultValue( sql, null); tableName = "(" + 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 ac660b476c..5e2ea85f25 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -660,7 +660,9 @@ public class DataSetTableService { Provider datasourceProvider = ProviderFactory.getProvider(ds.getType()); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(ds); - String sql = handleVariableDefaultValue( new String(java.util.Base64.getDecoder().decode(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getSql())), null); + 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); QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType()); datasourceRequest.setQuery( qp.createQuerySQLWithPage(sql, fields, page, pageSize, realSize, false, null, rowPermissionsTree)); @@ -1029,7 +1031,7 @@ public class DataSetTableService { if (CollectionUtils.isNotEmpty(select.getWithItemsList())) { builder.append("WITH"); builder.append(" "); - for (Iterator iter = select.getWithItemsList().iterator(); iter.hasNext();) { + for (Iterator iter = select.getWithItemsList().iterator(); iter.hasNext(); ) { WithItem withItem = iter.next(); builder.append(withItem.toString()); if (iter.hasNext()) { @@ -1038,7 +1040,7 @@ public class DataSetTableService { } } - builder.append( " " + plainSelect); + builder.append(" " + plainSelect); return builder.toString(); } @@ -1050,7 +1052,9 @@ public class DataSetTableService { Provider datasourceProvider = ProviderFactory.getProvider(ds.getType()); DatasourceRequest datasourceRequest = new DatasourceRequest(); datasourceRequest.setDatasource(ds); - String sql = handleVariableDefaultValue(new String(java.util.Base64.getDecoder().decode(new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class).getSql())), dataSetTableRequest.getSqlVariableDetails()); + DataTableInfoDTO dataTableInfo = new Gson().fromJson(dataSetTableRequest.getInfo(), DataTableInfoDTO.class); + String sql = dataTableInfo.isBase64Encryption() ? new String(java.util.Base64.getDecoder().decode(dataTableInfo.getSql())) : dataTableInfo.getSql(); + sql = handleVariableDefaultValue(sql, dataSetTableRequest.getSqlVariableDetails()); if (StringUtils.isEmpty(sql)) { DataEaseException.throwException(Translator.get("i18n_sql_not_empty")); } @@ -2474,7 +2478,7 @@ public class DataSetTableService { datasetTables.forEach(datasetTable -> { if (StringUtils.isNotEmpty(datasetTable.getQrtzInstance()) && !activeQrtzInstances.contains(datasetTable.getQrtzInstance().substring(0, datasetTable.getQrtzInstance().length() - 13))) { jobStoppeddDatasetTables.add(datasetTable); - }else { + } else { syncDatasetTables.add(datasetTable); } }); @@ -2483,7 +2487,7 @@ public class DataSetTableService { DatasetTableTaskExample datasetTableTaskExample = new DatasetTableTaskExample(); DatasetTableTaskExample.Criteria criteria = datasetTableTaskExample.createCriteria(); criteria.andTableIdEqualTo(datasetTable.getId()).andLastExecStatusEqualTo(JobStatus.Underway.name()); - if(CollectionUtils.isEmpty(dataSetTableTaskService.list(datasetTableTaskExample))){ + if (CollectionUtils.isEmpty(dataSetTableTaskService.list(datasetTableTaskExample))) { DatasetTable record = new DatasetTable(); record.setSyncStatus(JobStatus.Error.name()); example.clear(); @@ -2583,33 +2587,33 @@ public class DataSetTableService { public void visit(MinorThan minorThan) { getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" < "); - getBuffer().append( minorThan.getRightExpression()); + getBuffer().append(minorThan.getRightExpression()); } @Override public void visit(MinorThanEquals minorThan) { getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" <= "); - getBuffer().append( minorThan.getRightExpression()); + getBuffer().append(minorThan.getRightExpression()); } @Override public void visit(GreaterThanEquals minorThan) { getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" >= "); - getBuffer().append( minorThan.getRightExpression()); + getBuffer().append(minorThan.getRightExpression()); } @Override public void visit(GreaterThan minorThan) { getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" > "); - getBuffer().append( minorThan.getRightExpression()); + getBuffer().append(minorThan.getRightExpression()); } @Override public void visit(ExpressionList expressionList) { - for (Iterator iter = expressionList.getExpressions().iterator(); iter.hasNext();) { + for (Iterator iter = expressionList.getExpressions().iterator(); iter.hasNext(); ) { Expression expression = iter.next(); expression.accept(this); if (iter.hasNext()) { @@ -2620,9 +2624,9 @@ public class DataSetTableService { @Override public void visit(Between between) { - if(hasVarible(between.getBetweenExpressionStart().toString()) || hasVarible(between.getBetweenExpressionEnd().toString())){ + if (hasVarible(between.getBetweenExpressionStart().toString()) || hasVarible(between.getBetweenExpressionEnd().toString())) { getBuffer().append(SubstitutedSql); - }else { + } else { getBuffer().append(between.getLeftExpression()).append(" BETWEEN ").append(between.getBetweenExpressionStart()).append(" AND ").append(between.getBetweenExpressionEnd()); } } 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 6332c6216c..2e7f2a069b 100644 --- a/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java +++ b/backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java @@ -1020,8 +1020,11 @@ public class ExtractDataService { } if (extractType.equalsIgnoreCase("all_scope") && datasetTable.getType().equalsIgnoreCase(DatasetType.SQL.name())) { - selectSQL = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getSql(); - selectSQL = new String(java.util.Base64.getDecoder().decode(selectSQL)); + DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class); + selectSQL = dataTableInfoDTO.getSql(); + if(dataTableInfoDTO.isBase64Encryption()){ + selectSQL = new String(java.util.Base64.getDecoder().decode(selectSQL)); + } QueryProvider qp = ProviderFactory.getQueryProvider(datasource.getType()); selectSQL = qp.createRawQuerySQLAsTmp(selectSQL, datasetTableFields); } 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 0bcba5a75d..b7a9fb503c 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 @@ -145,7 +145,9 @@ public class DirectFieldService implements DataSetFieldService { datasourceRequest.setQuery(qp.createQuerySQL(dataTableInfoDTO.getTable(), permissionFields, !needSort, ds, customFilter, rowPermissionsTree, deSortFields)); } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.SQL.toString())) { String sql = dataTableInfoDTO.getSql(); - sql = new String(java.util.Base64.getDecoder().decode(sql)); + if(dataTableInfoDTO.isBase64Encryption()){ + sql = new String(java.util.Base64.getDecoder().decode(sql)); + } sql = dataSetTableService.removeVariables(sql); datasourceRequest.setQuery(qp.createQuerySQLAsTmp(sql, permissionFields, !needSort, customFilter, rowPermissionsTree, deSortFields)); } else if (StringUtils.equalsIgnoreCase(datasetTable.getType(), DatasetType.CUSTOM.toString())) { diff --git a/frontend/src/views/dataset/add/AddSQL.vue b/frontend/src/views/dataset/add/AddSQL.vue index e46c861f80..2f408f6edb 100644 --- a/frontend/src/views/dataset/add/AddSQL.vue +++ b/frontend/src/views/dataset/add/AddSQL.vue @@ -351,7 +351,12 @@ export default { this.name = table.name this.dataSource = table.dataSourceId this.mode = table.mode + '' - this.sql = Base64.decode(JSON.parse(table.info).sql) + + if(JSON.parse(table.info).isBase64Encryption){ + this.sql = Base64.decode(JSON.parse(table.info).sql) + }else { + this.sql = JSON.parse(table.info.replace(/\n/g, '\\n').replace(/\r/g, '\\r')).sql + } this.variables= JSON.parse(table.sqlVariableDetails) this.getSQLPreview() }) @@ -372,7 +377,7 @@ export default { dataSourceId: this.dataSource, type: 'sql', sqlVariableDetails: JSON.stringify(this.variables), - info: JSON.stringify({sql: Base64.encode(this.sql.trim())}) + info: JSON.stringify({sql: Base64.encode(this.sql.trim()), isBase64Encryption: true}) }).then(response => { this.fields = response.data.fields this.data = response.data.data @@ -416,7 +421,7 @@ export default { syncType: this.syncType, mode: parseInt(this.mode), sqlVariableDetails: JSON.stringify(this.variables), - info: JSON.stringify({sql: Base64.encode(this.sql.trim())}) + info: JSON.stringify({sql: Base64.encode(this.sql.trim()), isBase64Encryption: true}) } post('/dataset/table/update', table).then(response => { this.$emit('saveSuccess', table)