forked from github/dataease
Merge pull request #11323 from dataease/pr@dev-v2@fix_table
fix(图表): 修复SQL Server明细表排序报错的问题
This commit is contained in:
commit
68a7ad6ed7
@ -90,7 +90,7 @@ public class TableInfoHandler extends DefaultChartHandler {
|
||||
var querySql = originSql + limit;
|
||||
|
||||
var tablePageMode = (String) filterResult.getContext().get("tablePageMode");
|
||||
var totalPageSql = "SELECT COUNT(*) FROM (" + SQLProvider.createQuerySQL(sqlMeta, false, false, view) + ") COUNT_TEMP";
|
||||
var totalPageSql = "SELECT COUNT(*) FROM (" + SQLProvider.createQuerySQLNoSort(sqlMeta, false, view) + ") COUNT_TEMP";
|
||||
if (StringUtils.isNotEmpty(totalPageSql) && StringUtils.equalsIgnoreCase(tablePageMode, "page")) {
|
||||
totalPageSql = provider.rebuildSQL(totalPageSql, sqlMeta, crossDs, dsMap);
|
||||
datasourceRequest.setQuery(totalPageSql);
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.dataease.engine.sql;
|
||||
|
||||
import io.dataease.engine.constant.SQLConstants;
|
||||
import io.dataease.extensions.datasource.model.SQLMeta;
|
||||
import io.dataease.extensions.datasource.model.SQLObj;
|
||||
import io.dataease.extensions.view.dto.ChartViewDTO;
|
||||
import io.dataease.engine.constant.SQLConstants;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.stringtemplate.v4.ST;
|
||||
@ -132,6 +132,48 @@ public class SQLProvider {
|
||||
return sqlLimit(st.render(), view);
|
||||
}
|
||||
|
||||
public static String createQuerySQLNoSort(SQLMeta sqlMeta, boolean isGroup, ChartViewDTO view) {
|
||||
STGroup stg = new STGroupString(SqlTemplate.PREVIEW_SQL);
|
||||
ST st_sql = stg.getInstanceOf("previewSql");
|
||||
|
||||
st_sql.add("isGroup", isGroup);
|
||||
|
||||
SQLObj tableObj = sqlMeta.getTable();
|
||||
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
|
||||
|
||||
List<SQLObj> xFields = sqlMeta.getXFields();
|
||||
if (ObjectUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
|
||||
|
||||
List<SQLObj> yFields = sqlMeta.getYFields();
|
||||
List<String> yWheres = sqlMeta.getYWheres();
|
||||
if (ObjectUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
|
||||
|
||||
String customWheres = sqlMeta.getCustomWheres();
|
||||
String extWheres = sqlMeta.getExtWheres();
|
||||
String whereTrees = sqlMeta.getWhereTrees();
|
||||
List<String> wheres = new ArrayList<>();
|
||||
if (customWheres != null) wheres.add(customWheres);
|
||||
if (extWheres != null) wheres.add(extWheres);
|
||||
if (whereTrees != null) wheres.add(whereTrees);
|
||||
if (ObjectUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
|
||||
String sql = st_sql.render();
|
||||
|
||||
ST st = stg.getInstanceOf("previewSql");
|
||||
st_sql.add("isGroup", isGroup);
|
||||
|
||||
SQLObj tableSQL = SQLObj.builder()
|
||||
.tableName(String.format(SQLConstants.BRACKETS, sql))
|
||||
.tableAlias(String.format(SQLConstants.TABLE_ALIAS_PREFIX, 1))
|
||||
.build();
|
||||
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
|
||||
|
||||
List<String> aggWheres = new ArrayList<>();
|
||||
if (ObjectUtils.isNotEmpty(yWheres)) aggWheres.addAll(yWheres);
|
||||
if (ObjectUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
|
||||
|
||||
return sqlLimit(st.render(), view);
|
||||
}
|
||||
|
||||
public static String sqlLimit(String sql, ChartViewDTO view) {
|
||||
if (StringUtils.equalsIgnoreCase(view.getType(), "table-info")) {
|
||||
return sql;
|
||||
|
Loading…
Reference in New Issue
Block a user