forked from github/dataease
feat(视图):为日期维度,增加日期显示与格式转换功能
This commit is contained in:
parent
89c758a50a
commit
4cbe01ca16
@ -38,4 +38,8 @@ public class ChartViewFieldDTO implements Serializable {
|
||||
private List<ChartViewFieldFilterDTO> filter;
|
||||
|
||||
private Integer deExtractType;
|
||||
|
||||
private String dateStyle;
|
||||
|
||||
private String datePattern;
|
||||
}
|
||||
|
@ -132,12 +132,16 @@ public class DorisQueryProvider extends QueryProvider {
|
||||
if (x.getDeExtractType() == 1) {
|
||||
if (x.getDeType() == 2 || x.getDeType() == 3) {
|
||||
stringBuilder.append("unix_timestamp(").append(x.getDataeaseName()).append(")*1000 as ").append(x.getDataeaseName());
|
||||
} else if (x.getDeType() == 1) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
stringBuilder.append("DATE_FORMAT(").append(x.getDataeaseName()).append(",'").append(format).append("')");
|
||||
} else {
|
||||
stringBuilder.append(x.getDataeaseName());
|
||||
}
|
||||
} else {
|
||||
if (x.getDeType() == 1) {
|
||||
stringBuilder.append("FROM_UNIXTIME(cast(").append(x.getDataeaseName()).append(" as decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') as ").append(x.getDataeaseName());
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
stringBuilder.append("DATE_FORMAT(").append("FROM_UNIXTIME(cast(").append(x.getDataeaseName()).append(" as decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S')").append(",'").append(format).append("') as ").append(x.getDataeaseName());
|
||||
} else {
|
||||
stringBuilder.append(x.getDataeaseName());
|
||||
}
|
||||
@ -330,4 +334,30 @@ public class DorisQueryProvider extends QueryProvider {
|
||||
}
|
||||
return filter.toString();
|
||||
}
|
||||
|
||||
private String transDateFormat(String dateStyle, String datePattern) {
|
||||
String split = "-";
|
||||
if (StringUtils.equalsIgnoreCase(datePattern, "date_sub")) {
|
||||
split = "-";
|
||||
} else if (StringUtils.equalsIgnoreCase(datePattern, "date_split")) {
|
||||
split = "/";
|
||||
}
|
||||
|
||||
switch (dateStyle) {
|
||||
case "y":
|
||||
return "%Y";
|
||||
case "y_M":
|
||||
return "%Y" + split + "%m";
|
||||
case "y_M_d":
|
||||
return "%Y" + split + "%m" + split + "%d";
|
||||
case "H_m_s":
|
||||
return "%H:%i:%S";
|
||||
case "y_M_d_H_m":
|
||||
return "%Y" + split + "%m" + split + "%d" + " %H:%i";
|
||||
case "y_M_d_H_m_s":
|
||||
return "%Y" + split + "%m" + split + "%d" + " %H:%i:%S";
|
||||
default:
|
||||
return "%Y-%m-%d %H:%i:%S";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,12 +138,16 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
if (x.getDeExtractType() == 1) {
|
||||
if (x.getDeType() == 2 || x.getDeType() == 3) {
|
||||
stringBuilder.append("unix_timestamp(").append(x.getDataeaseName()).append(")*1000 as ").append(x.getDataeaseName());
|
||||
} else if (x.getDeType() == 1) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
stringBuilder.append("DATE_FORMAT(").append(x.getDataeaseName()).append(",'").append(format).append("')");
|
||||
} else {
|
||||
stringBuilder.append(x.getDataeaseName());
|
||||
}
|
||||
} else {
|
||||
if (x.getDeType() == 1) {
|
||||
stringBuilder.append("FROM_UNIXTIME(cast(").append(x.getDataeaseName()).append(" as decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') as ").append(x.getDataeaseName());
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
stringBuilder.append("DATE_FORMAT(").append("FROM_UNIXTIME(cast(").append(x.getDataeaseName()).append(" as decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S')").append(",'").append(format).append("') as ").append(x.getDataeaseName());
|
||||
} else {
|
||||
stringBuilder.append(x.getDataeaseName());
|
||||
}
|
||||
@ -344,4 +348,30 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
private String transDateFormat(String dateStyle, String datePattern) {
|
||||
String split = "-";
|
||||
if (StringUtils.equalsIgnoreCase(datePattern, "date_sub")) {
|
||||
split = "-";
|
||||
} else if (StringUtils.equalsIgnoreCase(datePattern, "date_split")) {
|
||||
split = "/";
|
||||
}
|
||||
|
||||
switch (dateStyle) {
|
||||
case "y":
|
||||
return "%Y";
|
||||
case "y_M":
|
||||
return "%Y" + split + "%m";
|
||||
case "y_M_d":
|
||||
return "%Y" + split + "%m" + split + "%d";
|
||||
case "H_m_s":
|
||||
return "%H:%i:%S";
|
||||
case "y_M_d_H_m":
|
||||
return "%Y" + split + "%m" + split + "%d" + " %H:%i";
|
||||
case "y_M_d_H_m_s":
|
||||
return "%Y" + split + "%m" + split + "%d" + " %H:%i:%S";
|
||||
default:
|
||||
return "%Y-%m-%d %H:%i:%S";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -692,7 +692,17 @@ export default {
|
||||
chart_pie_rose: 'Rose Pie',
|
||||
chart_funnel: 'Funnel',
|
||||
chart_radar: 'Radar',
|
||||
chart_gauge: 'Gauge'
|
||||
chart_gauge: 'Gauge',
|
||||
dateStyle: '日期顯示',
|
||||
datePattern: '日期格式',
|
||||
y: 'Year',
|
||||
y_M: 'Year Month',
|
||||
y_M_d: 'Year Month Day',
|
||||
H_m_s: 'Hour Minute Second',
|
||||
y_M_d_H_m: 'Year Month Day Hour Minute',
|
||||
y_M_d_H_m_s: 'Year Month Day Hour Minute Second',
|
||||
date_sub: 'yyyy-MM-dd',
|
||||
date_split: 'yyyy/MM/dd'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default',
|
||||
|
@ -692,7 +692,17 @@ export default {
|
||||
chart_pie_rose: '南丁格爾玫瑰圖',
|
||||
chart_funnel: '漏鬥圖',
|
||||
chart_radar: '雷達圖',
|
||||
chart_gauge: '儀表盤'
|
||||
chart_gauge: '儀表盤',
|
||||
dateStyle: '日期顯示',
|
||||
datePattern: '日期格式',
|
||||
y: '年',
|
||||
y_M: '年月',
|
||||
y_M_d: '年月日',
|
||||
H_m_s: '時分秒',
|
||||
y_M_d_H_m: '年月日時分',
|
||||
y_M_d_H_m_s: '年月日時分秒',
|
||||
date_sub: 'yyyy-MM-dd',
|
||||
date_split: 'yyyy/MM/dd'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: '有多個sheet頁面,默認抽取第一個',
|
||||
|
@ -692,7 +692,17 @@ export default {
|
||||
chart_pie_rose: '南丁格尔玫瑰图',
|
||||
chart_funnel: '漏斗图',
|
||||
chart_radar: '雷达图',
|
||||
chart_gauge: '仪表盘'
|
||||
chart_gauge: '仪表盘',
|
||||
dateStyle: '日期显示',
|
||||
datePattern: '日期格式',
|
||||
y: '年',
|
||||
y_M: '年月',
|
||||
y_M_d: '年月日',
|
||||
H_m_s: '时分秒',
|
||||
y_M_d_H_m: '年月日时分',
|
||||
y_M_d_H_m_s: '年月日时分秒',
|
||||
date_sub: 'yyyy-MM-dd',
|
||||
date_split: 'yyyy/MM/dd'
|
||||
},
|
||||
dataset: {
|
||||
sheet_warn: '有多个Sheet页,默认抽取第一个',
|
||||
|
@ -26,6 +26,44 @@
|
||||
<el-dropdown-item icon="el-icon-files" :command="beforeClickItem('filter')">
|
||||
<span>{{ $t('chart.filter') }}...</span>
|
||||
</el-dropdown-item>
|
||||
|
||||
<el-dropdown-item v-show="item.deType === 1" divided>
|
||||
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="dateStyle">
|
||||
<span class="el-dropdown-link inner-dropdown-menu">
|
||||
<span>
|
||||
<i class="el-icon-c-scale-to-original" />
|
||||
<span>{{ $t('chart.dateStyle') }}</span>
|
||||
<span class="summary-span">({{ $t('chart.'+item.dateStyle) }})</span>
|
||||
</span>
|
||||
<i class="el-icon-arrow-right el-icon--right" />
|
||||
</span>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="beforeDateStyle('y')">{{ $t('chart.y') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeDateStyle('y_M')">{{ $t('chart.y_M') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeDateStyle('y_M_d')">{{ $t('chart.y_M_d') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeDateStyle('H_m_s')">{{ $t('chart.H_m_s') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeDateStyle('y_M_d_H_m')">{{ $t('chart.y_M_d_H_m') }}</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeDateStyle('y_M_d_H_m_s')">{{ $t('chart.y_M_d_H_m_s') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-show="item.deType === 1">
|
||||
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="datePattern">
|
||||
<span class="el-dropdown-link inner-dropdown-menu">
|
||||
<span>
|
||||
<i class="el-icon-timer" />
|
||||
<span>{{ $t('chart.datePattern') }}</span>
|
||||
<span class="summary-span">({{ $t('chart.'+item.datePattern) }})</span>
|
||||
</span>
|
||||
<i class="el-icon-arrow-right el-icon--right" />
|
||||
</span>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="beforeDatePattern('date_sub')">{{ $t('chart.date_sub') }}(1990-01-01)</el-dropdown-item>
|
||||
<el-dropdown-item :command="beforeDatePattern('date_split')">{{ $t('chart.date_split') }}(1990/01/01)</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-dropdown-item>
|
||||
|
||||
<el-dropdown-item icon="el-icon-edit-outline" divided :command="beforeClickItem('rename')">
|
||||
<span>{{ $t('chart.show_name_set') }}</span>
|
||||
</el-dropdown-item>
|
||||
@ -91,6 +129,26 @@ export default {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
dateStyle(param) {
|
||||
// console.log(param)
|
||||
this.item.dateStyle = param.type
|
||||
this.$emit('onDimensionItemChange', this.item)
|
||||
},
|
||||
beforeDateStyle(type) {
|
||||
return {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
datePattern(param) {
|
||||
// console.log(param)
|
||||
this.item.datePattern = param.type
|
||||
this.$emit('onDimensionItemChange', this.item)
|
||||
},
|
||||
beforeDatePattern(type) {
|
||||
return {
|
||||
type: type
|
||||
}
|
||||
},
|
||||
editFilter() {
|
||||
this.item.index = this.index
|
||||
this.$emit('editItemFilter', this.item)
|
||||
@ -129,4 +187,16 @@ export default {
|
||||
span {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.summary-span{
|
||||
margin-left: 4px;
|
||||
color: #878d9f;;
|
||||
}
|
||||
|
||||
.inner-dropdown-menu{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%
|
||||
}
|
||||
</style>
|
||||
|
@ -469,6 +469,12 @@ export default {
|
||||
// if (!ele.summary || ele.summary === '') {
|
||||
// ele.summary = 'sum'
|
||||
// }
|
||||
if (!ele.dateStyle || ele.dateStyle === '') {
|
||||
ele.dateStyle = 'y_M_d'
|
||||
}
|
||||
if (!ele.datePattern || ele.datePattern === '') {
|
||||
ele.datePattern = 'date_sub'
|
||||
}
|
||||
if (!ele.sort || ele.sort === '') {
|
||||
ele.sort = 'none'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user