feat(数据集): 日期格式支持

This commit is contained in:
taojinlong 2022-11-18 00:01:03 +08:00
parent 1037623a08
commit 6cf8943a06
7 changed files with 85 additions and 19 deletions

View File

@ -16,10 +16,16 @@ import io.dataease.controller.response.DatasetTableField4Type;
import io.dataease.i18n.Translator;
import io.dataease.plugins.common.base.domain.DatasetTable;
import io.dataease.plugins.common.base.domain.DatasetTableField;
import io.dataease.plugins.common.base.domain.Datasource;
import io.dataease.plugins.datasource.entity.Dateformat;
import io.dataease.plugins.datasource.query.QueryProvider;
import io.dataease.provider.ProviderFactory;
import io.dataease.service.dataset.DataSetFieldService;
import io.dataease.service.dataset.DataSetTableFieldsService;
import io.dataease.service.dataset.DataSetTableService;
import io.dataease.service.dataset.PermissionService;
import io.dataease.service.datasource.DatasourceService;
import io.dataease.service.engine.EngineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
@ -46,14 +52,16 @@ import java.util.stream.Collectors;
public class DataSetTableFieldController {
@Resource
private DataSetTableFieldsService dataSetTableFieldsService;
@Autowired
private DataSetFieldService dataSetFieldService;
@Resource
private DataSetTableService dataSetTableService;
@Resource
private PermissionService permissionService;
@Resource
private EngineService engineService;
@Resource
private DatasourceService datasourceService;
@DePermission(type = DePermissionType.DATASET)
@ApiOperation("查询表下属字段")
@ -208,4 +216,14 @@ public class DataSetTableFieldController {
ArrayList::new));
return list;
}
@DePermission(type = DePermissionType.DATASET)
@ApiOperation("时间格式")
@PostMapping("dateformats/{tableId}")
public List<Dateformat> dateformats(@PathVariable String tableId) throws Exception{
DatasetTable datasetTable = dataSetTableService.get(tableId);
Datasource ds = datasetTable.getMode() == 0 ? datasourceService.get(datasetTable.getDataSourceId()) : engineService.getDeEngine();
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
return qp.dateformat();
}
}

View File

@ -1,5 +1,6 @@
package io.dataease.provider.engine.doris;
import com.alibaba.fastjson.JSONArray;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.plugins.common.base.domain.DatasetTableField;
import io.dataease.plugins.common.base.domain.DatasetTableFieldExample;
@ -16,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.Dateformat;
import io.dataease.plugins.datasource.query.QueryProvider;
import io.dataease.plugins.datasource.query.Utils;
import org.apache.commons.collections4.CollectionUtils;
@ -1311,4 +1313,15 @@ public class DorisQueryProvider extends QueryProvider {
return sql;
}
}
public List<Dateformat> dateformat() {
return JSONArray.parseArray("[\n" +
"{\"dateformat\": \"%Y-%m-%d\"},\n" +
"{\"dateformat\": \"%Y/%m/%d\"},\n" +
"{\"dateformat\": \"%Y%m%d\"},\n" +
"{\"dateformat\": \"%Y-%m-%d %H:%i:%S\"},\n" +
"{\"dateformat\": \"%Y/%m/%d %H:%i:%S\"},\n" +
"{\"dateformat\": \"%Y%m%d %H:%i:%S\"}\n" +
"]", Dateformat.class);
}
}

View File

@ -1,5 +1,6 @@
package io.dataease.provider.engine.mysql;
import com.alibaba.fastjson.JSONArray;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.plugins.common.base.domain.DatasetTableField;
import io.dataease.plugins.common.base.domain.DatasetTableFieldExample;
@ -16,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.Dateformat;
import io.dataease.plugins.datasource.query.QueryProvider;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
@ -1312,4 +1314,15 @@ public class MysqlQueryProvider extends QueryProvider {
return sql;
}
}
public List<Dateformat> dateformat() {
return JSONArray.parseArray("[\n" +
"{\"dateformat\": \"%Y-%m-%d\"},\n" +
"{\"dateformat\": \"%Y/%m/%d\"},\n" +
"{\"dateformat\": \"%Y%m%d\"},\n" +
"{\"dateformat\": \"%Y-%m-%d %H:%i:%S\"},\n" +
"{\"dateformat\": \"%Y/%m/%d %H:%i:%S\"},\n" +
"{\"dateformat\": \"%Y%m%d %H:%i:%S\"}\n" +
"]", Dateformat.class);
}
}

View File

@ -1,5 +1,6 @@
package io.dataease.provider.query.mysql;
import com.alibaba.fastjson.JSONArray;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.plugins.common.base.domain.DatasetTableField;
import io.dataease.plugins.common.base.domain.DatasetTableFieldExample;
@ -17,7 +18,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.entity.Dateformat;
import io.dataease.plugins.datasource.query.QueryProvider;
import io.dataease.plugins.datasource.query.Utils;
import org.apache.commons.collections4.CollectionUtils;
@ -374,20 +375,6 @@ public class MysqlQueryProvider extends QueryProvider {
@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);
}
@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) {
String limit = ((pageInfo.getGoPage() != null && pageInfo.getPageSize() != null) ? " LIMIT " + (pageInfo.getGoPage() - 1) * pageInfo.getPageSize() + "," + pageInfo.getPageSize() : "");
if (isTable) {
return originalTableInfo(table, xAxis, fieldCustomFilter, rowPermissionsTree, extFilterRequestList, ds, view) + limit;
} else {
return originalTableInfo("(" + sqlFix(table) + ")", xAxis, fieldCustomFilter, rowPermissionsTree, extFilterRequestList, ds, view) + limit;
}
}
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(MySQLConstants.KEYWORD_TABLE, table))
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 0))
@ -458,7 +445,7 @@ public class MysqlQueryProvider extends QueryProvider {
.build();
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
return st.render();
return sqlLimit(st.render(), view);
}
@Override
@ -1333,4 +1320,15 @@ public class MysqlQueryProvider extends QueryProvider {
public String sqlForPreview(String table, Datasource ds) {
return "SELECT * FROM " + String.format(MySQLConstants.KEYWORD_TABLE, table);
}
public List<Dateformat> dateformat() {
return JSONArray.parseArray("[\n" +
"{\"dateformat\": \"%Y-%m-%d\"},\n" +
"{\"dateformat\": \"%Y/%m/%d\"},\n" +
"{\"dateformat\": \"%Y%m%d\"},\n" +
"{\"dateformat\": \"%Y-%m-%d %H:%i:%S\"},\n" +
"{\"dateformat\": \"%Y/%m/%d %H:%i:%S\"},\n" +
"{\"dateformat\": \"%Y%m%d %H:%i:%S\"}\n" +
"]", Dateformat.class);
}
}

View File

@ -1,5 +1,7 @@
package io.dataease.provider.query.sqlserver;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
import io.dataease.plugins.common.base.domain.DatasetTableField;
@ -17,6 +19,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.Dateformat;
import io.dataease.plugins.datasource.entity.JdbcConfiguration;
import io.dataease.plugins.datasource.query.QueryProvider;
import io.dataease.plugins.datasource.query.Utils;
@ -1331,4 +1334,13 @@ public class SqlserverQueryProvider extends QueryProvider {
schema = String.format(SqlServerSQLConstants.KEYWORD_TABLE, schema);
return "SELECT * FROM " + schema + "." + String.format(SqlServerSQLConstants.KEYWORD_TABLE, table);
}
public List<Dateformat> dateformat() {
return JSONArray.parseArray("[\n" +
"{\"dateformat\": \"102\", \"desc\": \"yyyy.mm.dd\"},\n" +
"{\"dateformat\": \"23\", \"desc\": \"yyyy-mm-dd\"},\n" +
"{\"dateformat\": \"111\", \"desc\": \"yyyy/mm/dd\"},\n" +
"{\"dateformat\": \"120\", \"desc\": \"yyyy-mm-dd hh:mi:ss\"}\n" +
"]", Dateformat.class);
}
}

View File

@ -136,6 +136,14 @@ export function fieldListDQ(id, showLoading = true) {
})
}
export function dateformats(id, showLoading = true) {
return request({
url: '/dataset/field/dateformats/' + id,
loading: showLoading,
method: 'post'
})
}
export function batchEdit(data) {
return request({
url: '/dataset/field/batchEdit',

View File

@ -736,7 +736,7 @@
</template>
<script>
import { post, fieldListDQ, batchEdit } from '@/api/dataset/dataset'
import { post, fieldListDQ, batchEdit, dateformats } from '@/api/dataset/dataset'
import CalcFieldEdit from './CalcFieldEdit'
import { getFieldName } from '@/views/dataset/data/utils'
import msgCfm from '@/components/msgCfm/index'
@ -757,6 +757,7 @@ export default {
},
data() {
return {
dateFormats: [],
maxHeight: 'auto',
tableFields: {
dimensionList: [],
@ -823,6 +824,9 @@ export default {
this.dimensionChange()
this.quotaChange()
})
dateformats(this.param.id).then((response) => {
this.dateFormats = response.data
})
},
saveEdit(item) {
if (item.name && item.name.length > 50) {