forked from github/dataease
feat: 表格支持分页
This commit is contained in:
parent
b91a14d417
commit
0057ff13dd
@ -43,4 +43,5 @@ public class ChartViewDTO extends ChartViewWithBLOBs {
|
||||
private String yAxisExt;
|
||||
|
||||
private long totalPage;
|
||||
private long totalItems;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import io.dataease.plugins.common.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.request.chart.ChartExtFilterRequest;
|
||||
import io.dataease.plugins.common.request.permission.DataSetRowPermissionsTreeDTO;
|
||||
import io.dataease.plugins.common.request.permission.DatasetRowPermissionsTreeItem;
|
||||
import io.dataease.plugins.datasource.entity.PageInfo;
|
||||
import io.dataease.plugins.datasource.query.QueryProvider;
|
||||
import io.dataease.plugins.datasource.query.Utils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@ -393,8 +394,21 @@ public class CKQueryProvider extends QueryProvider {
|
||||
return sqlLimit(st.render(), view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLWithPage(boolean isTable, String table, List<ChartViewFieldDTO> xAxis, List<ChartFieldCustomFilterDTO> fieldCustomFilter, List<DataSetRowPermissionsTreeDTO> rowPermissionsTree, List<ChartExtFilterRequest> extFilterRequestList, Datasource ds, ChartViewWithBLOBs view, PageInfo pageInfo) {
|
||||
if (isTable) {
|
||||
return originalTableInfo(table, xAxis, fieldCustomFilter, rowPermissionsTree, extFilterRequestList, ds, view) + " LIMIT " + (pageInfo.getGoPage() - 1) * pageInfo.getPageSize() + "," + pageInfo.getPageSize();
|
||||
} else {
|
||||
return originalTableInfo("(" + sqlFix(table) + ")", xAxis, fieldCustomFilter, rowPermissionsTree, extFilterRequestList, ds, view) + " LIMIT " + (pageInfo.getGoPage() - 1) * pageInfo.getPageSize() + "," + pageInfo.getPageSize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSQLTableInfo(String table, List<ChartViewFieldDTO> xAxis, List<ChartFieldCustomFilterDTO> fieldCustomFilter, List<DataSetRowPermissionsTreeDTO> rowPermissionsTree, List<ChartExtFilterRequest> extFilterRequestList, Datasource ds, ChartViewWithBLOBs view) {
|
||||
return sqlLimit(originalTableInfo(table, xAxis, fieldCustomFilter, rowPermissionsTree, extFilterRequestList, ds, view), view);
|
||||
}
|
||||
|
||||
private String originalTableInfo(String table, List<ChartViewFieldDTO> xAxis, List<ChartFieldCustomFilterDTO> fieldCustomFilter, List<DataSetRowPermissionsTreeDTO> rowPermissionsTree, List<ChartExtFilterRequest> extFilterRequestList, Datasource ds, ChartViewWithBLOBs view) {
|
||||
SQLObj tableObj = SQLObj.builder()
|
||||
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(CKConstants.KEYWORD_TABLE, table))
|
||||
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 0))
|
||||
@ -466,7 +480,7 @@ public class CKQueryProvider extends QueryProvider {
|
||||
.build();
|
||||
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
|
||||
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
|
||||
return sqlLimit(st.render(), view);
|
||||
return st.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1072,10 +1086,14 @@ public class CKQueryProvider extends QueryProvider {
|
||||
if (ObjectUtils.isNotEmpty(datasetTableField) && datasetTableField.getDeType() == DeTypeConstants.DE_TIME && StringUtils.equalsIgnoreCase(request.getOperator(), "between")) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
request.setOperator("ge");
|
||||
request.setValue(new ArrayList<String>(){{add(String.format(toDateTime64, "'" + simpleDateFormat.format(new Date(Long.parseLong(requestValue.get(0)))) + "'"));}});
|
||||
request.setValue(new ArrayList<String>() {{
|
||||
add(String.format(toDateTime64, "'" + simpleDateFormat.format(new Date(Long.parseLong(requestValue.get(0)))) + "'"));
|
||||
}});
|
||||
ChartExtFilterRequest requestCopy = BeanUtils.copyBean(new ChartExtFilterRequest(), request);
|
||||
requestCopy.setOperator("le");
|
||||
requestCopy.setValue(new ArrayList<String>(){{add(String.format(toDateTime64, "'" + simpleDateFormat.format(new Date(Long.parseLong(requestValue.get(1)))) + "'"));}});
|
||||
requestCopy.setValue(new ArrayList<String>() {{
|
||||
add(String.format(toDateTime64, "'" + simpleDateFormat.format(new Date(Long.parseLong(requestValue.get(1)))) + "'"));
|
||||
}});
|
||||
atomicReference.set(requestCopy);
|
||||
}
|
||||
});
|
||||
|
@ -860,6 +860,7 @@ public class ChartViewService {
|
||||
|
||||
String querySql = null;
|
||||
long totalPage = 0l;
|
||||
long totalItems = 0l;
|
||||
String totalPageSql = null;
|
||||
PageInfo pageInfo = new PageInfo();
|
||||
pageInfo.setGoPage(chartExtRequest.getGoPage() != null ? chartExtRequest.getGoPage() : 1);
|
||||
@ -941,8 +942,8 @@ public class ChartViewService {
|
||||
}
|
||||
if (StringUtils.isNotEmpty(totalPageSql)) {
|
||||
datasourceRequest.setQuery(totalPageSql);
|
||||
totalPage = Long.valueOf(datasourceProvider.getData(datasourceRequest).get(0)[0]);
|
||||
totalPage = totalPage / pageInfo.getPageSize() + totalPage % pageInfo.getPageSize() > 0 ? 1 : 0;
|
||||
totalItems = Long.valueOf(datasourceProvider.getData(datasourceRequest).get(0)[0]);
|
||||
totalPage = totalItems / pageInfo.getPageSize() + totalItems % pageInfo.getPageSize() > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
datasourceRequest.setQuery(querySql);
|
||||
@ -1158,6 +1159,7 @@ public class ChartViewService {
|
||||
Map<String, Object> mapTableNormal = ChartDataBuild.transTableNormal(xAxis, yAxis, view, data, extStack, desensitizationList);
|
||||
chartViewDTO = uniteViewResult(datasourceRequest.getQuery(), mapChart, mapTableNormal, view, isDrill, drillFilters, dynamicAssistFields, assistData);
|
||||
chartViewDTO.setTotalPage(totalPage);
|
||||
chartViewDTO.setTotalItems(totalItems);
|
||||
return chartViewDTO;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user