mirror of
https://github.com/dataease/dataease.git
synced 2026-05-20 11:38:11 +08:00
feat(视图): MySQL时间字段支持按季度、周统计
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.dataease.provider.engine.mysql;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.sun.javafx.binding.StringFormatter;
|
||||
import io.dataease.plugins.common.base.domain.ChartViewWithBLOBs;
|
||||
import io.dataease.plugins.common.base.domain.DatasetTableField;
|
||||
import io.dataease.plugins.common.base.domain.DatasetTableFieldExample;
|
||||
@@ -1141,8 +1142,12 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
switch (dateStyle) {
|
||||
case "y":
|
||||
return "%Y";
|
||||
case "y_Q":
|
||||
return "CONCAT(%s,'" + split + "',%s)";
|
||||
case "y_M":
|
||||
return "%Y" + split + "%m";
|
||||
case "y_W":
|
||||
return "%Y" + split + "%u";
|
||||
case "y_M_d":
|
||||
return "%Y" + split + "%m" + split + "%d";
|
||||
case "H_m_s":
|
||||
@@ -1163,7 +1168,13 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
fieldName = String.format(MysqlConstants.UNIX_TIMESTAMP, originField) + "*1000";
|
||||
} else if (x.getDeType() == 1) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
fieldName = String.format(MysqlConstants.DATE_FORMAT, originField, format);
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MysqlConstants.DATE_FORMAT, originField, "%Y"),
|
||||
String.format(MysqlConstants.QUARTER, originField));
|
||||
} else {
|
||||
fieldName = String.format(MysqlConstants.DATE_FORMAT, originField, format);
|
||||
}
|
||||
} else {
|
||||
fieldName = originField;
|
||||
}
|
||||
@@ -1171,11 +1182,23 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
if (x.getDeType() == 1) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
if (x.getDeExtractType() == 0) {
|
||||
fieldName = String.format(MysqlConstants.DATE_FORMAT, originField, format);
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MysqlConstants.DATE_FORMAT, String.format(MysqlConstants.STR_TO_DATE, originField, MysqlConstants.DEFAULT_DATE_FORMAT), "%Y"),
|
||||
String.format(MysqlConstants.QUARTER, String.format(MysqlConstants.STR_TO_DATE, originField, MysqlConstants.DEFAULT_DATE_FORMAT)));
|
||||
} else {
|
||||
fieldName = String.format(MysqlConstants.DATE_FORMAT, originField, format);
|
||||
}
|
||||
} else {
|
||||
String cast = String.format(MysqlConstants.CAST, originField, MysqlConstants.DEFAULT_INT_FORMAT) + "/1000";
|
||||
String from_unixtime = String.format(MysqlConstants.FROM_UNIXTIME, cast, MysqlConstants.DEFAULT_DATE_FORMAT);
|
||||
fieldName = String.format(MysqlConstants.DATE_FORMAT, from_unixtime, format);
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MysqlConstants.DATE_FORMAT, from_unixtime, "%Y"),
|
||||
String.format(MysqlConstants.QUARTER, from_unixtime));
|
||||
} else {
|
||||
fieldName = String.format(MysqlConstants.DATE_FORMAT, from_unixtime, format);
|
||||
}
|
||||
}
|
||||
} else if (x.getDeType() == 0 && x.getDeExtractType() == 0) {
|
||||
fieldName = String.format(MysqlConstants.CAST, originField, MysqlConstants.CHAR);
|
||||
|
||||
@@ -18,8 +18,8 @@ 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.entity.PageInfo;
|
||||
import io.dataease.plugins.datasource.query.QueryProvider;
|
||||
import io.dataease.plugins.datasource.query.Utils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -1138,8 +1138,12 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
switch (dateStyle) {
|
||||
case "y":
|
||||
return "%Y";
|
||||
case "y_Q":
|
||||
return "CONCAT(%s,'" + split + "',%s)";
|
||||
case "y_M":
|
||||
return "%Y" + split + "%m";
|
||||
case "y_W":
|
||||
return "%Y" + split + "%u";
|
||||
case "y_M_d":
|
||||
return "%Y" + split + "%m" + split + "%d";
|
||||
case "H_m_s":
|
||||
@@ -1159,13 +1163,25 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
if (x.getDeType() == 2 || x.getDeType() == 3) {
|
||||
fieldName = String.format(MySQLConstants.UNIX_TIMESTAMP, originField) + "*1000";
|
||||
} else if (x.getDeType() == 1) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
if (x.getType().equalsIgnoreCase("YEAR")) {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, "CONCAT(" + originField + ",'-01-01')", transDateFormat(x.getDateStyle(), x.getDatePattern()));
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MySQLConstants.DATE_FORMAT, "CONCAT(" + originField + ",'-01-01')", "%Y"),
|
||||
String.format(MySQLConstants.QUARTER, "CONCAT(" + originField + ",'-01-01')"));
|
||||
} else {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, "CONCAT(" + originField + ",'-01-01')", format);
|
||||
}
|
||||
} else if (x.getType().equalsIgnoreCase("TIME")) {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, "CONCAT('1970-01-01', " + originField + ")", MySQLConstants.DEFAULT_DATE_FORMAT);
|
||||
} else {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, originField, format);
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MySQLConstants.DATE_FORMAT, originField, "%Y"),
|
||||
String.format(MySQLConstants.QUARTER, originField));
|
||||
} else {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, originField, format);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fieldName = originField;
|
||||
@@ -1174,11 +1190,23 @@ public class MysqlQueryProvider extends QueryProvider {
|
||||
if (x.getDeType() == 1) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
if (x.getDeExtractType() == 0) {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, String.format(MySQLConstants.STR_TO_DATE, originField, StringUtils.isNotEmpty(x.getDateFormat()) ? x.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT), format);
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MysqlConstants.DATE_FORMAT, String.format(MySQLConstants.STR_TO_DATE, originField, StringUtils.isNotEmpty(x.getDateFormat()) ? x.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT), "%Y"),
|
||||
String.format(MysqlConstants.QUARTER, String.format(MySQLConstants.STR_TO_DATE, originField, StringUtils.isNotEmpty(x.getDateFormat()) ? x.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT)));
|
||||
} else {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, String.format(MySQLConstants.STR_TO_DATE, originField, StringUtils.isNotEmpty(x.getDateFormat()) ? x.getDateFormat() : MysqlConstants.DEFAULT_DATE_FORMAT), format);
|
||||
}
|
||||
} else {
|
||||
String cast = String.format(MySQLConstants.CAST, originField, MySQLConstants.DEFAULT_INT_FORMAT) + "/1000";
|
||||
String from_unixtime = String.format(MySQLConstants.FROM_UNIXTIME, cast, MySQLConstants.DEFAULT_DATE_FORMAT);
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, from_unixtime, format);
|
||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||
fieldName = String.format(format,
|
||||
String.format(MySQLConstants.DATE_FORMAT, from_unixtime, "%Y"),
|
||||
String.format(MySQLConstants.QUARTER, from_unixtime));
|
||||
} else {
|
||||
fieldName = String.format(MySQLConstants.DATE_FORMAT, from_unixtime, format);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (x.getDeType() == DeTypeConstants.DE_INT) {
|
||||
|
||||
Reference in New Issue
Block a user