forked from github/dataease
refactor: 重构视图插件
This commit is contained in:
parent
2ca5f9bcec
commit
2ee7ef58ae
@ -222,11 +222,7 @@
|
||||
<artifactId>dataease-plugin-view</artifactId>
|
||||
<version>1.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.7.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- kettle及数据源依赖 -->
|
||||
<dependency>
|
||||
<groupId>pentaho-kettle</groupId>
|
||||
|
@ -9,7 +9,7 @@ import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.datasource.JdbcConfiguration;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.query.pg.PgConstants;
|
||||
import io.dataease.plugins.common.constants.PgConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
package io.dataease.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 3:12 下午
|
||||
*/
|
||||
public class SQLConstants {
|
||||
/**
|
||||
* 维度类型list
|
||||
*/
|
||||
public static final List<Integer> DIMENSION_TYPE = new ArrayList<Integer>() {{
|
||||
add(0);// 文本
|
||||
add(1);// 时间
|
||||
add(5);// 地理位置
|
||||
}};
|
||||
|
||||
/**
|
||||
* 指标类型list
|
||||
*/
|
||||
public static final List<Integer> QUOTA_TYPE = new ArrayList<Integer>() {{
|
||||
add(2);// 整型
|
||||
add(3);// 浮点
|
||||
add(4);// 布尔
|
||||
}};
|
||||
|
||||
/**
|
||||
* sql ST模板
|
||||
*/
|
||||
public static final String SQL_TEMPLATE = "sql/sqlTemplate.stg";
|
||||
|
||||
public static final String TABLE_ALIAS_PREFIX = "t_a_%s";
|
||||
public static final String FIELD_ALIAS_X_PREFIX = "f_ax_%s";
|
||||
public static final String FIELD_ALIAS_Y_PREFIX = "f_ay_%s";
|
||||
public static final String GROUP_ALIAS_PREFIX = "g_a_%s";
|
||||
public static final String ORDER_ALIAS_X_PREFIX = "o_ax_%s";
|
||||
public static final String ORDER_ALIAS_Y_PREFIX = "o_ay_%s";
|
||||
public static final String WHERE_ALIAS_PREFIX = "w_a_%s";
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package io.dataease.provider.engine.doris;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.engine_doris;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class DorisConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = engine_doris.getKeywordPrefix() + "%s" + engine_doris.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + engine_doris.getKeywordPrefix() + "%s" + engine_doris.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)";
|
||||
|
||||
public static final String DATE_FORMAT = "DATE_FORMAT(%s,'%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "FROM_UNIXTIME(%s,'%s')";
|
||||
|
||||
public static final String STR_TO_DATE = "STR_TO_DATE(%s,'%s')";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "%Y-%m-%d %H:%i:%S";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "BIGINT";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String WHERE_NUMBER_VALUE = "%s";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
|
||||
public static final String ROUND = "ROUND(%s,%s)";
|
||||
|
||||
public static final String VARCHAR = "VARCHAR";
|
||||
}
|
@ -10,8 +10,9 @@ import io.dataease.dto.chart.ChartCustomFilterItemDTO;
|
||||
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.DorisConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -28,7 +29,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.dataease.provider.engine.mysql;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.engine_mysql;
|
||||
|
||||
|
@ -11,7 +11,7 @@ import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -28,7 +28,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,41 +0,0 @@
|
||||
package io.dataease.provider.query.ck;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.ck;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class CKConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = ck.getKeywordPrefix() + "%s" + ck.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + ck.getKeywordPrefix() + "%s" + ck.getKeywordSuffix();
|
||||
|
||||
public static final String toInt32 = "toInt32(%s)";
|
||||
|
||||
public static final String toDateTime = "toDateTime(%s)";
|
||||
|
||||
public static final String toInt64 = "toInt64(%s)";
|
||||
|
||||
public static final String toFloat64 = "toFloat64(%s)";
|
||||
|
||||
public static final String formatDateTime = "formatDateTime(%s,'%s')";
|
||||
|
||||
public static final String toDecimal = "toDecimal64(%s,2)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "%Y-%m-%d %H:%M:%S";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -11,8 +11,9 @@ import io.dataease.dto.chart.ChartCustomFilterItemDTO;
|
||||
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.CKConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -29,7 +30,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,39 +0,0 @@
|
||||
package io.dataease.provider.query.db2;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.db2;
|
||||
|
||||
public class Db2Constants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = db2.getKeywordPrefix() + "%s" + db2.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + db2.getKeywordPrefix() + "%s" + db2.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "BIGINT(TIMESTAMPDIFF(2,CHAR(%s -TIMESTAMP('1970-01-01 08:00:00'))))";
|
||||
|
||||
public static final String DATE_FORMAT = "TO_CHAR(TIMESTAMP(%s),'%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "TO_CHAR(TIMESTAMP('1970-01-01 08:00:00') +(%s)SECONDS, '%s')";
|
||||
|
||||
public static final String STR_TO_DATE = "timestamp(trim(char(%s)))";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH24:MI:SS";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "BIGINT";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -13,8 +13,9 @@ import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.datasource.Db2Configuration;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.Db2Constants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -31,7 +32,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
@Service("db2Query")
|
||||
public class Db2QueryProvider extends QueryProvider {
|
||||
|
@ -11,8 +11,9 @@ import io.dataease.dto.chart.ChartCustomFilterItemDTO;
|
||||
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.EsSqlLConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -29,7 +30,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
@Service("esQuery")
|
||||
public class EsQueryProvider extends QueryProvider {
|
||||
|
@ -1,37 +0,0 @@
|
||||
package io.dataease.provider.query.es;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.es;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class EsSqlLConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = es.getKeywordPrefix() + "%s" + es.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + es.getKeywordPrefix() + "%s" + es.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)";
|
||||
|
||||
public static final String DATETIME_FORMAT = "DATETIME_FORMAT(%s,'%s')";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String ROUND = "ROUND(%s, %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package io.dataease.provider.query.hive;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.mysql;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class HiveConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = mysql.getKeywordPrefix() + "%s" + mysql.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + mysql.getKeywordPrefix() + "%s" + mysql.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "unix_timestamp(%s)";
|
||||
|
||||
public static final String DATE_FORMAT = "DATE_FORMAT(%s,'%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "FROM_UNIXTIME(%s,'%s')";
|
||||
|
||||
public static final String STR_TO_DATE = "STR_TO_DATE(%s,'%s')";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "DECIMAL(20,0)";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -11,8 +11,9 @@ import io.dataease.dto.chart.ChartCustomFilterItemDTO;
|
||||
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.HiveConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -29,7 +30,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,43 +0,0 @@
|
||||
package io.dataease.provider.query.mongodb;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.mongo;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class MongoConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = "%s";
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + mongo.getKeywordPrefix() + "%s" + mongo.getKeywordSuffix();
|
||||
|
||||
public static final String ALIAS_FIX = mongo.getAliasPrefix() + "%s" + mongo.getAliasSuffix();
|
||||
|
||||
public static final String toInt32 = "toInt32(%s)";
|
||||
|
||||
public static final String toDateTime = "toDateTime(%s)";
|
||||
|
||||
public static final String toInt64 = "toInt64(%s)";
|
||||
|
||||
public static final String toFloat64 = "toFloat64(%s)";
|
||||
|
||||
public static final String formatDateTime = "formatDateTime(%s,'%s')";
|
||||
|
||||
public static final String toDecimal = "toDecimal64(%s,2)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "%Y-%m-%d %H:%M:%S";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -11,8 +11,9 @@ import io.dataease.dto.chart.ChartCustomFilterItemDTO;
|
||||
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.MongoConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -29,7 +30,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,43 +0,0 @@
|
||||
package io.dataease.provider.query.mysql;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.mysql;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class MySQLConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = mysql.getKeywordPrefix() + "%s" + mysql.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + mysql.getKeywordPrefix() + "%s" + mysql.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)";
|
||||
|
||||
public static final String DATE_FORMAT = "DATE_FORMAT(%s,'%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "FROM_UNIXTIME(%s,'%s')";
|
||||
|
||||
public static final String STR_TO_DATE = "STR_TO_DATE(%s,'%s')";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "%Y-%m-%d %H:%i:%S";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "DECIMAL(20,0)";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -10,8 +10,9 @@ import io.dataease.dto.chart.ChartCustomFilterItemDTO;
|
||||
import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.MySQLConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -28,7 +29,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,55 +0,0 @@
|
||||
package io.dataease.provider.query.oracle;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.oracle;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class OracleConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = oracle.getKeywordPrefix() + "%s" + oracle.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + oracle.getKeywordPrefix() + "%s" + oracle.getKeywordSuffix();
|
||||
|
||||
public static final String ALIAS_FIX = oracle.getAliasPrefix() + "%s" + oracle.getAliasSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)";
|
||||
|
||||
public static final String DATE_FORMAT = "to_timestamp(%s,'%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "FROM_UNIXTIME(%s,'%s')";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH24:MI:SS";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "DECIMAL(20,0)";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
|
||||
public static final String TO_NUMBER = "TO_NUMBER(%s)";
|
||||
|
||||
public static final String TO_DATE = "TO_DATE(%s,'%s')";
|
||||
|
||||
public static final String TO_CHAR = "TO_CHAR(%s,'%s')";
|
||||
|
||||
public static final String DEFAULT_START_DATE = "'1970-01-01 8:0:0'";
|
||||
|
||||
public static final String TO_MS = " * 24 * 60 * 60 * 100";
|
||||
|
||||
public static final String CALC_SUB = "%s - %s";
|
||||
}
|
@ -13,8 +13,9 @@ import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.datasource.JdbcConfiguration;
|
||||
import io.dataease.dto.datasource.OracleConfiguration;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.OracleConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -31,7 +32,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
|
@ -1,43 +0,0 @@
|
||||
package io.dataease.provider.query.pg;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.pg;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class PgConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = pg.getKeywordPrefix() + "%s" + pg.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + pg.getKeywordPrefix() + "%s" + pg.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "floor(extract(epoch from(( %s - timestamp '1970-01-01 00:00:00')*1000))) ";
|
||||
|
||||
public static final String DATE_FORMAT = "to_char(%s, '%s')";
|
||||
|
||||
public static final String FROM_UNIXTIME = "to_timestamp(%s)";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH24:MI:SS";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "numeric(18,0)";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "numeric(18,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
|
||||
|
||||
}
|
@ -13,9 +13,10 @@ import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.datasource.JdbcConfiguration;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.PgConstants;
|
||||
import io.dataease.plugins.common.constants.SqlServerSQLConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.query.sqlserver.SqlServerSQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -32,7 +33,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
|
||||
@Service("pgQuery")
|
||||
|
@ -1,49 +0,0 @@
|
||||
package io.dataease.provider.query.redshift;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.pg;
|
||||
|
||||
/**
|
||||
* Redshift 静态变量
|
||||
*
|
||||
* @className: RedshiftConstants
|
||||
* @description: Redshift 静态变量
|
||||
* @author: Jiantao Yan
|
||||
* @date: 2021/10/11 17:12
|
||||
**/
|
||||
public class RedshiftConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = pg.getKeywordPrefix() + "%s" + pg.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + pg.getKeywordPrefix() + "%s" + pg.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "floor(extract(epoch from(( %s - timestamp '1970-01-01 00:00:00')*1000))) ";
|
||||
|
||||
public static final String DATE_FORMAT = "to_char(%s, %s)";
|
||||
|
||||
public static final String FROM_UNIXTIME = "to_timestamp(%s)";
|
||||
|
||||
public static final String TO_DATE = "to_date(%s,'%s')";
|
||||
|
||||
public static final String CAST = "CAST(%s AS %s)";
|
||||
|
||||
public static final String DEFAULT_DATE_FORMAT = "'YYYY-MM-DD HH24:MI:SS'";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "numeric(18,0)";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "numeric(18,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
|
||||
|
||||
}
|
@ -13,10 +13,11 @@ import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.datasource.JdbcConfiguration;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.RedshiftConstants;
|
||||
import io.dataease.plugins.common.constants.SqlServerSQLConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.provider.query.pg.PgConstants;
|
||||
import io.dataease.provider.query.sqlserver.SqlServerSQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.PgConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -33,7 +34,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1,43 +0,0 @@
|
||||
package io.dataease.provider.query.sqlserver;
|
||||
|
||||
import io.dataease.provider.SQLConstants;
|
||||
|
||||
import static io.dataease.commons.constants.DatasourceTypes.sqlServer;
|
||||
|
||||
/**
|
||||
* @Author gin
|
||||
* @Date 2021/7/8 7:22 下午
|
||||
*/
|
||||
public class SqlServerSQLConstants extends SQLConstants {
|
||||
public static final String KEYWORD_TABLE = sqlServer.getKeywordPrefix() + "%s" + sqlServer.getKeywordSuffix();
|
||||
|
||||
public static final String KEYWORD_FIX = "%s." + sqlServer.getKeywordPrefix() + "%s" + sqlServer.getKeywordSuffix();
|
||||
|
||||
public static final String UNIX_TIMESTAMP = "CAST(DATEDIFF(ss,'1970-01-01 08:00:00', %s) as bigint ) * 1000 ";
|
||||
|
||||
public static final String DATE_FORMAT = "CONVERT(varchar(100), %s, %s)";
|
||||
|
||||
public static final String FROM_UNIXTIME = "convert(varchar, %s ,120)";
|
||||
|
||||
public static final String CONVERT = "CONVERT(%s, %s)";
|
||||
|
||||
public static final String LONG_TO_DATE = "DATEADD(second,%s,'1970-01-01 08:00:00')";
|
||||
|
||||
public static final String STRING_TO_DATE = "CONVERT(datetime, %s ,120)";
|
||||
|
||||
public static final String DEFAULT_INT_FORMAT = "DECIMAL(20,0)";
|
||||
|
||||
public static final String DEFAULT_FLOAT_FORMAT = "DECIMAL(20,2)";
|
||||
|
||||
public static final String WHERE_VALUE_NULL = "(NULL,'')";
|
||||
|
||||
public static final String WHERE_VALUE_VALUE = "'%s'";
|
||||
|
||||
public static final String AGG_COUNT = "COUNT(*)";
|
||||
|
||||
public static final String AGG_FIELD = "%s(%s)";
|
||||
|
||||
public static final String WHERE_BETWEEN = "'%s' AND '%s'";
|
||||
|
||||
public static final String BRACKETS = "(%s)";
|
||||
}
|
@ -13,8 +13,9 @@ import io.dataease.dto.chart.ChartFieldCustomFilterDTO;
|
||||
import io.dataease.dto.chart.ChartViewFieldDTO;
|
||||
import io.dataease.dto.datasource.JdbcConfiguration;
|
||||
import io.dataease.dto.sqlObj.SQLObj;
|
||||
import io.dataease.plugins.common.constants.SqlServerSQLConstants;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
import io.dataease.provider.SQLConstants;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -31,7 +32,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dataease.provider.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
@Service("sqlserverQuery")
|
||||
public class SqlserverQueryProvider extends QueryProvider {
|
||||
|
@ -13,8 +13,10 @@ import io.dataease.base.mapper.ext.ExtChartViewMapper;
|
||||
import io.dataease.commons.constants.ColumnPermissionConstants;
|
||||
import io.dataease.commons.constants.CommonConstants;
|
||||
import io.dataease.commons.constants.JdbcConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.commons.utils.CommonBeanFactory;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.controller.request.chart.*;
|
||||
import io.dataease.controller.request.datasource.DatasourceRequest;
|
||||
@ -27,6 +29,9 @@ import io.dataease.dto.dataset.DataTableInfoDTO;
|
||||
import io.dataease.exception.DataEaseException;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
import io.dataease.plugins.config.SpringContextUtil;
|
||||
import io.dataease.plugins.view.entity.*;
|
||||
import io.dataease.plugins.view.service.ViewPluginService;
|
||||
import io.dataease.provider.ProviderFactory;
|
||||
import io.dataease.provider.datasource.DatasourceProvider;
|
||||
import io.dataease.provider.QueryProvider;
|
||||
@ -59,6 +64,9 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
public class ChartViewService {
|
||||
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
@Resource
|
||||
private ChartViewMapper chartViewMapper;
|
||||
@Resource
|
||||
@ -504,16 +512,41 @@ public class ChartViewService {
|
||||
|
||||
// 判断连接方式,直连或者定时抽取 table.mode
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
Datasource ds = table.getMode() == 0 ? datasourceService.get(table.getDataSourceId()) : engineService.getDeEngine();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
List<String[]> data = new ArrayList<>();
|
||||
|
||||
|
||||
// 如果是插件视图 走插件内部的逻辑
|
||||
if (view.getIsPlugin()) {
|
||||
Map<String, List<ChartViewFieldDTO>> fieldMap = new HashMap<>();
|
||||
fieldMap.put("xAxis",xAxis);
|
||||
fieldMap.put("yAxis",yAxis);
|
||||
fieldMap.put("extStack",extStack);
|
||||
fieldMap.put("extBubble",extBubble);
|
||||
PluginViewParam pluginViewParam = buildPluginParam(fieldMap, fieldCustomFilter, extFilterList, ds, table, view);
|
||||
String sql = pluginViewSql(pluginViewParam, view);
|
||||
datasourceRequest.setQuery(sql);
|
||||
data = datasourceProvider.getData(datasourceRequest);
|
||||
|
||||
Map<String, Object> mapChart = pluginViewResult(pluginViewParam, view, data, isDrill);
|
||||
Map<String, Object> mapTableNormal = ChartDataBuild.transTableNormal(xAxis, yAxis, view, data, extStack, desensitizationList);
|
||||
|
||||
return uniteViewResult(datasourceRequest.getQuery(), mapChart, mapTableNormal,view, isDrill, drillFilters);
|
||||
// 如果是插件到此结束
|
||||
}
|
||||
|
||||
//如果不是插件视图 走原生逻辑
|
||||
if (table.getMode() == 0) {// 直连
|
||||
Datasource ds = datasourceService.get(table.getDataSourceId());
|
||||
// Datasource ds = datasourceService.get(table.getDataSourceId());
|
||||
if (ObjectUtils.isEmpty(ds)) {
|
||||
throw new RuntimeException(Translator.get("i18n_datasource_delete"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(ds.getStatus()) && ds.getStatus().equalsIgnoreCase("Error")) {
|
||||
throw new Exception(Translator.get("i18n_invalid_ds"));
|
||||
}
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
// DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
datasourceRequest.setDatasource(ds);
|
||||
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(table.getInfo(), DataTableInfoDTO.class);
|
||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||
@ -577,8 +610,8 @@ public class ChartViewService {
|
||||
data = datasourceProvider.getData(datasourceRequest);
|
||||
} else if (table.getMode() == 1) {// 抽取
|
||||
// 连接doris,构建doris数据源查询
|
||||
Datasource ds = engineService.getDeEngine();
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
// Datasource ds = engineService.getDeEngine();
|
||||
// DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
datasourceRequest.setDatasource(ds);
|
||||
String tableName = "ds_" + table.getId().replaceAll("-", "_");
|
||||
datasourceRequest.setTable(tableName);
|
||||
@ -737,12 +770,16 @@ public class ChartViewService {
|
||||
mapChart = ChartDataBuild.transChartDataAntV(xAxis, yAxis, view, data, isDrill);
|
||||
}
|
||||
}
|
||||
|
||||
// table组件,明细表,也用于导出数据
|
||||
Map<String, Object> mapTableNormal = ChartDataBuild.transTableNormal(xAxis, yAxis, view, data, extStack, desensitizationList);
|
||||
return uniteViewResult(datasourceRequest.getQuery(), mapChart, mapTableNormal,view, isDrill, drillFilters);
|
||||
}
|
||||
|
||||
map.putAll(mapChart);
|
||||
map.putAll(mapTableNormal);
|
||||
public ChartViewDTO uniteViewResult(String sql, Map<String, Object> chartData, Map<String, Object> tabelData, ChartViewDTO view, Boolean isDrill, List<ChartExtFilterRequest> drillFilters) {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.putAll(chartData);
|
||||
map.putAll(tabelData);
|
||||
|
||||
List<DatasetTableField> sourceFields = dataSetTableFieldsService.getFieldsByTableId(view.getTableId());
|
||||
map.put("sourceFields", sourceFields);
|
||||
@ -750,13 +787,65 @@ public class ChartViewService {
|
||||
ChartViewDTO dto = new ChartViewDTO();
|
||||
BeanUtils.copyBean(dto, view);
|
||||
dto.setData(map);
|
||||
dto.setSql(datasourceRequest.getQuery());
|
||||
|
||||
dto.setSql(sql);
|
||||
dto.setDrill(isDrill);
|
||||
dto.setDrillFilters(drillFilters);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private PluginViewParam buildPluginParam(Map<String, List<ChartViewFieldDTO>> fieldMap, List<ChartFieldCustomFilterDTO> customFilters, List<ChartExtFilterRequest> extFilters, Datasource ds, DatasetTable table, ChartViewDTO view) {
|
||||
PluginViewParam pluginViewParam = new PluginViewParam();
|
||||
PluginViewSet pluginViewSet = BeanUtils.copyBean(new PluginViewSet(), table);
|
||||
pluginViewSet.setDsType(ds.getType());
|
||||
PluginViewLimit pluginViewLimit = BeanUtils.copyBean(new PluginViewLimit(), view);
|
||||
|
||||
List<PluginChartFieldCustomFilter> fieldFilters = customFilters.stream().map(filter -> BeanUtils.copyBean(new PluginChartFieldCustomFilter(), filter)).collect(Collectors.toList());
|
||||
List<PluginChartExtFilter> panelFilters = extFilters.stream().map(filter -> BeanUtils.copyBean(new PluginChartExtFilter(), filter)).collect(Collectors.toList());
|
||||
|
||||
List<PluginViewField> pluginViewFields = fieldMap.entrySet().stream().flatMap(entry -> entry.getValue().stream().map(field -> {
|
||||
PluginViewField pluginViewField = BeanUtils.copyBean(new PluginViewField(), field);
|
||||
pluginViewField.setTypeField(entry.getKey());
|
||||
return pluginViewField;
|
||||
})).collect(Collectors.toList());
|
||||
pluginViewParam.setPluginViewSet(pluginViewSet);
|
||||
pluginViewParam.setPluginViewFields(pluginViewFields);
|
||||
pluginViewParam.setPluginChartFieldCustomFilters(fieldFilters);
|
||||
pluginViewParam.setPluginChartExtFilters(panelFilters);
|
||||
pluginViewParam.setPluginViewLimit(pluginViewLimit);
|
||||
pluginViewParam.setUserId(AuthUtils.getUser().getUserId());
|
||||
return pluginViewParam;
|
||||
}
|
||||
|
||||
private ViewPluginService getPluginService(String viewType) {
|
||||
Map<String, ViewPluginService> beanMap = SpringContextUtil.getApplicationContext().getBeansOfType(ViewPluginService.class);
|
||||
|
||||
if (beanMap.keySet().size() == 0) {
|
||||
DEException.throwException("没有此插件");
|
||||
|
||||
}
|
||||
ViewPluginService viewPluginService = null;
|
||||
for (Map.Entry<String, ViewPluginService> entry : beanMap.entrySet()) {
|
||||
if (StringUtils.equals(entry.getValue().viewType().getValue(), viewType)) {
|
||||
viewPluginService = entry.getValue();
|
||||
return viewPluginService;
|
||||
}
|
||||
}
|
||||
if (null == viewPluginService) DEException.throwException("没有此插件");
|
||||
return viewPluginService;
|
||||
}
|
||||
|
||||
private String pluginViewSql(PluginViewParam param, ChartViewDTO view) {
|
||||
ViewPluginService viewPluginService = getPluginService(view.getType());
|
||||
String sql = viewPluginService.generateSQL(param);
|
||||
return sql;
|
||||
}
|
||||
|
||||
private Map<String, Object> pluginViewResult(PluginViewParam param, ChartViewDTO view, List<String[]> args, Boolean isDrill) {
|
||||
ViewPluginService viewPluginService = getPluginService(view.getType());
|
||||
Map<String, Object> result = viewPluginService.formatResult(param, args, isDrill);
|
||||
return result;
|
||||
}
|
||||
|
||||
private ChartViewDTO emptyChartViewDTO(ChartViewDTO view) {
|
||||
ChartViewDTO dto = new ChartViewDTO();
|
||||
BeanUtils.copyBean(dto, view);
|
||||
|
@ -0,0 +1,506 @@
|
||||
package io.dataease.service.chart;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.base.domain.DatasetTableField;
|
||||
import io.dataease.base.domain.DatasetTableFieldExample;
|
||||
import io.dataease.base.domain.Datasource;
|
||||
import io.dataease.base.mapper.DatasetTableFieldMapper;
|
||||
import io.dataease.dto.dataset.DataSetTableUnionDTO;
|
||||
import io.dataease.dto.dataset.DataTableInfoDTO;
|
||||
import io.dataease.plugins.common.constants.SQLConstants;
|
||||
import io.dataease.plugins.common.util.BeanUtils;
|
||||
import io.dataease.plugins.common.util.ConstantsUtil;
|
||||
import io.dataease.plugins.view.entity.*;
|
||||
import io.dataease.plugins.view.service.ViewPluginBaseService;
|
||||
import io.dataease.service.dataset.DataSetTableService;
|
||||
import io.dataease.service.dataset.DataSetTableUnionService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static io.dataease.plugins.common.constants.SQLConstants.TABLE_ALIAS_PREFIX;
|
||||
|
||||
@Service
|
||||
public class ViewPluginBaseServiceImpl implements ViewPluginBaseService {
|
||||
|
||||
|
||||
private static final Integer STRING = 0;
|
||||
private static final Integer TIME = 1;
|
||||
private static final Integer INT = 2;
|
||||
private static final Integer FLOAT = 3;
|
||||
/*private static final Integer BOOLEAN = 4;*/
|
||||
|
||||
@Resource
|
||||
private DataSetTableUnionService dataSetTableUnionService;
|
||||
|
||||
@Resource
|
||||
private DatasetTableFieldMapper datasetTableFieldMapper;
|
||||
|
||||
@Resource
|
||||
private DataSetTableService dataSetTableService;
|
||||
|
||||
|
||||
@Override
|
||||
public PluginSingleField buildField(String dsType, PluginViewField pluginViewField, PluginViewSQL tableObj, int index) {
|
||||
PluginSingleField result = new PluginSingleField();
|
||||
String FIELD_ALIAS_PREFIX = StringUtils.equals(pluginViewField.getTypeField(), "xAxis") ? SQLConstants.FIELD_ALIAS_X_PREFIX : SQLConstants.FIELD_ALIAS_Y_PREFIX;
|
||||
|
||||
String originField = getOriginName(dsType, pluginViewField, tableObj);
|
||||
|
||||
PluginViewSQL field = null;
|
||||
String where = null;
|
||||
String alias_fix = ConstantsUtil.constantsValue(dsType, "ALIAS_FIX");
|
||||
String fieldAlias = String.format(alias_fix, String.format(FIELD_ALIAS_PREFIX, index));
|
||||
if (StringUtils.equals(pluginViewField.getTypeField(), "xAxis") || StringUtils.equals(pluginViewField.getTypeField(), "extStack")) {
|
||||
field = getXFields(dsType, pluginViewField, originField, fieldAlias);
|
||||
|
||||
}else {
|
||||
field = getYFields(dsType, pluginViewField, originField, fieldAlias);
|
||||
where = getYWheres(dsType, pluginViewField, fieldAlias);
|
||||
}
|
||||
PluginViewSQL sort = addSort(pluginViewField.getSort(), originField, fieldAlias);
|
||||
|
||||
Optional.ofNullable(field).ifPresent(f -> result.setField(f));
|
||||
Optional.ofNullable(sort).ifPresent(s -> result.setSort(s));
|
||||
Optional.ofNullable(where).ifPresent(w -> result.setWhere(w));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String customWhere(String dsType, List<PluginChartFieldCustomFilter> list, PluginViewSQL pluginViewSQL) {
|
||||
return transCustomFilterList(dsType, pluginViewSQL, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String panelWhere(String dsType, List<PluginChartExtFilter> list, PluginViewSQL pluginViewSQL) {
|
||||
return transExtFilterList(dsType, pluginViewSQL, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginViewSQL getTableObj(PluginViewSet pluginViewSet) {
|
||||
String tableName = null;
|
||||
DataTableInfoDTO dataTableInfoDTO = new Gson().fromJson(pluginViewSet.getInfo(), DataTableInfoDTO.class);
|
||||
switch (pluginViewSet.getType()) {
|
||||
case "db":
|
||||
tableName = dataTableInfoDTO.getTable();
|
||||
break;
|
||||
case "sql":
|
||||
tableName = dataTableInfoDTO.getSql();
|
||||
break;
|
||||
case "custom":
|
||||
List<DataSetTableUnionDTO> list = dataSetTableUnionService.listByTableId(dataTableInfoDTO.getList().get(0).getTableId());
|
||||
Datasource ds = new Datasource();
|
||||
ds.setType(pluginViewSet.getDsType());
|
||||
tableName = dataSetTableService.getCustomSQLDatasource(dataTableInfoDTO, list, ds);
|
||||
break;
|
||||
case "union":
|
||||
Datasource datasource = new Datasource();
|
||||
datasource.setType(pluginViewSet.getDsType());
|
||||
Map<String, Object> sqlMap = dataSetTableService.getUnionSQLDatasource(dataTableInfoDTO, datasource);
|
||||
tableName = (String) sqlMap.get("sql");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
String keyword = ConstantsUtil.constantsValue(pluginViewSet.getDsType(), "KEYWORD_TABLE");
|
||||
String tabelName = (tableName.startsWith("(") && tableName.endsWith(")")) ? tableName : String.format(keyword, tableName);
|
||||
String tabelAlias = String.format(TABLE_ALIAS_PREFIX, 0);
|
||||
PluginViewSQL tableObj = PluginViewSQL.builder().tableName(tabelName).tableAlias(tabelAlias).build();
|
||||
return tableObj;
|
||||
}
|
||||
|
||||
private String getOriginName(String dsType, PluginViewField pluginViewField, PluginViewSQL tableObj) {
|
||||
String keyword_fix = ConstantsUtil.constantsValue(dsType, "KEYWORD_FIX");
|
||||
String originField;
|
||||
if (ObjectUtils.isNotEmpty(pluginViewField.getExtField()) && pluginViewField.getExtField() == 2) {
|
||||
// 解析origin name中有关联的字段生成sql表达式
|
||||
originField = calcFieldRegex(dsType,pluginViewField.getOriginName(), tableObj);
|
||||
} else if (ObjectUtils.isNotEmpty(pluginViewField.getExtField()) && pluginViewField.getExtField() == 1) {
|
||||
originField = String.format(keyword_fix, tableObj.getTableAlias(), pluginViewField.getOriginName());
|
||||
} else {
|
||||
originField = String.format(keyword_fix, tableObj.getTableAlias(), pluginViewField.getOriginName());
|
||||
}
|
||||
return originField;
|
||||
}
|
||||
|
||||
private String calcFieldRegex(String dsType, String originField, PluginViewSQL tableObj) {
|
||||
originField = originField.replaceAll("[\\t\\n\\r]]", "");
|
||||
// 正则提取[xxx]
|
||||
String regex = "\\[(.*?)]";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(originField);
|
||||
Set<String> ids = new HashSet<>();
|
||||
while (matcher.find()) {
|
||||
String id = matcher.group(1);
|
||||
ids.add(id);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return originField;
|
||||
}
|
||||
DatasetTableFieldExample datasetTableFieldExample = new DatasetTableFieldExample();
|
||||
datasetTableFieldExample.createCriteria().andIdIn(new ArrayList<>(ids));
|
||||
List<DatasetTableField> calcFields = datasetTableFieldMapper.selectByExample(datasetTableFieldExample);
|
||||
String keyword_fix = ConstantsUtil.constantsValue(dsType, "KEYWORD_FIX");
|
||||
for (DatasetTableField ele : calcFields) {
|
||||
originField = originField.replaceAll("\\[" + ele.getId() + "]", String.format(keyword_fix, tableObj.getTableAlias(), ele.getOriginName()));
|
||||
}
|
||||
return originField;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private PluginViewSQL getXFields(String dsType, PluginViewField x, String originField, String fieldAlias) {
|
||||
|
||||
String fieldName = "";
|
||||
String calc_sub = ConstantsUtil.constantsValue(dsType, "CALC_SUB");
|
||||
String to_date = ConstantsUtil.constantsValue(dsType, "TO_DATE");
|
||||
String default_start_date = ConstantsUtil.constantsValue(dsType, "DEFAULT_START_DATE");
|
||||
String default_date_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_DATE_FORMAT");
|
||||
String to_number = ConstantsUtil.constantsValue(dsType, "TO_NUMBER");
|
||||
String to_ms = ConstantsUtil.constantsValue(dsType, "TO_MS");
|
||||
String to_char = ConstantsUtil.constantsValue(dsType, "TO_CHAR");
|
||||
String default_start_date_c = ConstantsUtil.constantsValue(dsType, "DEFAULT_START_DATE");
|
||||
if (x.getDeExtractType() == TIME) {
|
||||
if (x.getDeType() == INT || x.getDeType() == FLOAT) { //时间转数值
|
||||
if (x.getType().equalsIgnoreCase("DATE")) {
|
||||
String date = String.format(calc_sub, originField, String.format(to_date, default_start_date, default_date_format));
|
||||
fieldName = String.format(to_number, date) + to_ms;
|
||||
} else {
|
||||
String toChar = String.format(to_char, originField, default_date_format);
|
||||
String toDate = String.format(to_date, toChar, default_date_format);
|
||||
String toDate1 = String.format(to_date, default_start_date_c, default_date_format);
|
||||
fieldName = String.format(to_number, String.format(calc_sub, toDate, toDate1)) + to_ms;
|
||||
}
|
||||
} else if (x.getDeType() == TIME) { //格式化显示时间
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
if (x.getType().equalsIgnoreCase("DATE")) {
|
||||
fieldName = String.format(to_char, originField, format);
|
||||
} else {
|
||||
String toChar = String.format(to_char, originField, default_date_format);
|
||||
String toDate = String.format(to_date, toChar, default_date_format);
|
||||
fieldName = String.format(to_char, toDate, format);
|
||||
}
|
||||
} else {
|
||||
fieldName = originField;
|
||||
}
|
||||
} else {
|
||||
if (x.getDeType() == TIME) {
|
||||
String format = transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||
if (x.getDeExtractType() == STRING) { //字符串转时间
|
||||
String toDate = String.format(to_date, originField, default_date_format);
|
||||
fieldName = String.format(to_char, toDate, format);
|
||||
} else { //数值转时间
|
||||
String date = originField + "/(1000 * 60 * 60 * 24)+" + String.format(to_date, default_start_date_c, default_date_format);
|
||||
fieldName = String.format(to_char, date, format);
|
||||
}
|
||||
} else {
|
||||
fieldName = originField;
|
||||
}
|
||||
}
|
||||
return PluginViewSQL.builder().fieldName(fieldName).fieldAlias(fieldAlias).build();
|
||||
}
|
||||
|
||||
private PluginViewSQL getYFields(String dsType, PluginViewField y, String originField, String fieldAlias) {
|
||||
String fieldName = "";
|
||||
if (StringUtils.equalsIgnoreCase(y.getOriginName(), "*")) {
|
||||
|
||||
fieldName = ConstantsUtil.constantsValue(dsType, "AGG_COUNT");
|
||||
} else if (SQLConstants.DIMENSION_TYPE.contains(y.getDeType())) {
|
||||
fieldName = String.format(ConstantsUtil.constantsValue(dsType, "AGG_FIELD"), y.getSummary(), originField);
|
||||
} else {
|
||||
String cast_constants = ConstantsUtil.constantsValue(dsType, "CAST");
|
||||
String agg_field_constants = ConstantsUtil.constantsValue(dsType, "AGG_FIELD");
|
||||
String default_int_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_INT_FORMAT");
|
||||
String default_float_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_FLOAT_FORMAT");
|
||||
if (StringUtils.equalsIgnoreCase(y.getSummary(), "avg") || StringUtils.containsIgnoreCase(y.getSummary(), "pop")) {
|
||||
String cast = String.format(cast_constants, originField, y.getDeType() == 2 ? default_int_format : default_float_format);
|
||||
String agg = String.format(agg_field_constants, y.getSummary(), cast);
|
||||
fieldName = String.format(cast_constants, agg, ConstantsUtil.constantsValue(dsType, "DEFAULT_FLOAT_FORMAT"));
|
||||
} else {
|
||||
String cast = String.format(cast_constants, originField, y.getDeType() == 2 ? default_int_format : default_float_format);
|
||||
fieldName = String.format(agg_field_constants, y.getSummary(), cast);
|
||||
}
|
||||
}
|
||||
return PluginViewSQL.builder().fieldName(fieldName).fieldAlias(fieldAlias).build();
|
||||
}
|
||||
|
||||
private PluginViewSQL addSort(String sort, String originField, String fieldAlias) {
|
||||
if (StringUtils.isNotEmpty(sort) && !StringUtils.equalsIgnoreCase(sort, "none")) {
|
||||
return PluginViewSQL.builder().orderField(originField).orderAlias(fieldAlias).orderDirection(sort).build();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getYWheres(String dsType, PluginViewField y,String fieldAlias) {
|
||||
List<PluginViewSQL> list = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(y.getFilter()) && y.getFilter().size() > 0) {
|
||||
y.getFilter().forEach(f -> {
|
||||
String whereTerm = transMysqlFilterTerm(f.getTerm());
|
||||
String whereValue = "";
|
||||
// 原始类型不是时间,在de中被转成时间的字段做处理
|
||||
if (StringUtils.equalsIgnoreCase(f.getTerm(), "null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "not_null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "not_empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) {
|
||||
whereValue = "('" + StringUtils.join(f.getValue(), "','") + "')";
|
||||
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) {
|
||||
whereValue = "'%" + f.getValue() + "%'";
|
||||
} else {
|
||||
String where_value_value = ConstantsUtil.constantsValue(dsType, "WHERE_VALUE_VALUE");
|
||||
whereValue = String.format(where_value_value, f.getValue());
|
||||
}
|
||||
list.add(PluginViewSQL.builder().whereField(fieldAlias).whereAlias(fieldAlias).whereTermAndValue(whereTerm + whereValue).build());
|
||||
});
|
||||
}
|
||||
List<String> strList = new ArrayList<>();
|
||||
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
|
||||
return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" " + getLogic(y.getLogic()) + " ", strList) + ")" : null;
|
||||
}
|
||||
|
||||
public String getLogic(String logic) {
|
||||
if (logic != null) {
|
||||
switch (logic) {
|
||||
case "and":
|
||||
return "AND";
|
||||
case "or":
|
||||
return "OR";
|
||||
}
|
||||
}
|
||||
return "AND";
|
||||
}
|
||||
|
||||
private String transDateFormat(String dateStyle, String datePattern) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String transMysqlFilterTerm(String term) {
|
||||
switch (term) {
|
||||
case "eq":
|
||||
return " = ";
|
||||
case "not_eq":
|
||||
return " <> ";
|
||||
case "lt":
|
||||
return " < ";
|
||||
case "le":
|
||||
return " <= ";
|
||||
case "gt":
|
||||
return " > ";
|
||||
case "ge":
|
||||
return " >= ";
|
||||
case "in":
|
||||
return " IN ";
|
||||
case "not in":
|
||||
return " NOT IN ";
|
||||
case "like":
|
||||
return " LIKE ";
|
||||
case "not like":
|
||||
return " NOT LIKE ";
|
||||
case "null":
|
||||
return " IS NULL ";
|
||||
case "not_null":
|
||||
return " IS NOT NULL ";
|
||||
case "empty":
|
||||
return " = ";
|
||||
case "not_empty":
|
||||
return " <> ";
|
||||
case "between":
|
||||
return " BETWEEN ";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String transCustomFilterList(String dsType, PluginViewSQL tableObj, List<PluginChartFieldCustomFilter> requestList) {
|
||||
if (CollectionUtils.isEmpty(requestList)) {
|
||||
return null;
|
||||
}
|
||||
List<String> res = new ArrayList<>();
|
||||
String to_date = ConstantsUtil.constantsValue(dsType, "TO_DATE");
|
||||
String default_date_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_DATE_FORMAT");
|
||||
String cast_c = ConstantsUtil.constantsValue(dsType, "CAST");
|
||||
String default_int_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_INT_FORMAT");
|
||||
String from_unixtime = ConstantsUtil.constantsValue(dsType, "FROM_UNIXTIME");
|
||||
String default_float_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_FLOAT_FORMAT");
|
||||
String unix_timestamp = ConstantsUtil.constantsValue(dsType, "UNIX_TIMESTAMP");
|
||||
String where_value_value = ConstantsUtil.constantsValue(dsType, "WHERE_VALUE_VALUE");
|
||||
for (PluginChartFieldCustomFilter request : requestList) {
|
||||
List<PluginViewSQL> list = new ArrayList<>();
|
||||
PluginDatasetTableField field = request.getField();
|
||||
|
||||
if (ObjectUtils.isEmpty(field)) {
|
||||
continue;
|
||||
}
|
||||
String whereName = "";
|
||||
|
||||
PluginViewField pluginViewField = BeanUtils.copyBean(new PluginViewField(), field);
|
||||
String originName = getOriginName(dsType, pluginViewField, tableObj);
|
||||
|
||||
|
||||
|
||||
if (field.getDeType() == 1) {
|
||||
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {
|
||||
whereName = String.format(to_date, originName, default_date_format);
|
||||
}
|
||||
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
|
||||
String cast = String.format(cast_c, originName, default_int_format) + "/1000";
|
||||
whereName = String.format(from_unixtime, cast, default_float_format);
|
||||
}
|
||||
if (field.getDeExtractType() == 1) {
|
||||
whereName = originName;
|
||||
}
|
||||
} else if (field.getDeType() == 2 || field.getDeType() == 3) {
|
||||
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {
|
||||
whereName = String.format(cast_c, originName,default_float_format);
|
||||
}
|
||||
if (field.getDeExtractType() == 1) {
|
||||
whereName = String.format(unix_timestamp, originName) + "*1000";
|
||||
}
|
||||
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
|
||||
whereName = originName;
|
||||
}
|
||||
} else {
|
||||
whereName = originName;
|
||||
}
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(request.getFilterType(), "enum")) {
|
||||
if (CollectionUtils.isNotEmpty(request.getEnumCheckField())) {
|
||||
res.add("(" + whereName + " IN ('" + String.join("','", request.getEnumCheckField()) + "'))");
|
||||
}
|
||||
} else {
|
||||
List<PluginChartCustomFilterItem> filter = request.getFilter();
|
||||
for (PluginChartCustomFilterItem filterItemDTO : filter) {
|
||||
String value = filterItemDTO.getValue();
|
||||
String whereTerm = transMysqlFilterTerm(filterItemDTO.getTerm());
|
||||
String whereValue = "";
|
||||
|
||||
if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "not_null")) {
|
||||
whereValue = "";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.equalsIgnoreCase(filterItemDTO.getTerm(), "not_empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "in")) {
|
||||
whereValue = "('" + StringUtils.join(value, "','") + "')";
|
||||
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "like")) {
|
||||
whereValue = "'%" + value + "%'";
|
||||
} else {
|
||||
if (field.getDeType() == 1) {
|
||||
whereValue = String.format(to_date, "'" + value + "'", default_date_format);
|
||||
} else {
|
||||
whereValue = String.format(where_value_value, value);
|
||||
}
|
||||
}
|
||||
list.add(PluginViewSQL.builder()
|
||||
.whereField(whereName)
|
||||
.whereTermAndValue(whereTerm + whereValue)
|
||||
.build());
|
||||
}
|
||||
|
||||
List<String> strList = new ArrayList<>();
|
||||
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
res.add("(" + String.join(" " + getLogic(request.getLogic()) + " ", strList) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
return CollectionUtils.isNotEmpty(res) ? "(" + String.join(" AND ", res) + ")" : null;
|
||||
}
|
||||
|
||||
public String transExtFilterList(String dsType, PluginViewSQL tableObj, List<PluginChartExtFilter> requestList) {
|
||||
if (CollectionUtils.isEmpty(requestList)) {
|
||||
return null;
|
||||
}
|
||||
List<PluginViewSQL> list = new ArrayList<>();
|
||||
String where_between = ConstantsUtil.constantsValue(dsType, "WHERE_BETWEEN");
|
||||
String default_date_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_DATE_FORMAT");
|
||||
String to_date = ConstantsUtil.constantsValue(dsType, "TO_DATE");
|
||||
String cast_c = ConstantsUtil.constantsValue(dsType, "CAST");
|
||||
String from_unixtime = ConstantsUtil.constantsValue(dsType, "FROM_UNIXTIME");
|
||||
String default_int_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_INT_FORMAT");
|
||||
String default_float_format = ConstantsUtil.constantsValue(dsType, "DEFAULT_FLOAT_FORMAT");
|
||||
String unix_timestamp = ConstantsUtil.constantsValue(dsType, "UNIX_TIMESTAMP");
|
||||
String where_value_value = ConstantsUtil.constantsValue(dsType, "WHERE_VALUE_VALUE");
|
||||
|
||||
for (PluginChartExtFilter request : requestList) {
|
||||
List<String> value = request.getValue();
|
||||
PluginDatasetTableField field = request.getDatasetTableField();
|
||||
if (CollectionUtils.isEmpty(value) || ObjectUtils.isEmpty(field)) {
|
||||
continue;
|
||||
}
|
||||
String whereName = "";
|
||||
String whereTerm = transMysqlFilterTerm(request.getOperator());
|
||||
String whereValue = "";
|
||||
|
||||
String originName = getOriginName(dsType, BeanUtils.copyBean(new PluginViewField(), field), tableObj);
|
||||
|
||||
|
||||
if (field.getDeType() == 1) {
|
||||
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {
|
||||
whereName = String.format(to_date, originName, default_date_format);
|
||||
}
|
||||
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
|
||||
String cast = String.format(cast_c, originName, default_int_format) + "/1000";
|
||||
whereName = String.format(from_unixtime, cast, default_date_format);
|
||||
}
|
||||
if (field.getDeExtractType() == 1) {
|
||||
whereName = originName;
|
||||
}
|
||||
} else if (field.getDeType() == 2 || field.getDeType() == 3) {
|
||||
if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {
|
||||
whereName = String.format(cast_c, originName, default_float_format);
|
||||
}
|
||||
if (field.getDeExtractType() == 1) {
|
||||
whereName = String.format(unix_timestamp, originName) + "*1000";
|
||||
}
|
||||
if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
|
||||
whereName = originName;
|
||||
}
|
||||
} else {
|
||||
whereName = originName;
|
||||
}
|
||||
|
||||
if (StringUtils.containsIgnoreCase(request.getOperator(), "in")) {
|
||||
whereValue = "('" + StringUtils.join(value, "','") + "')";
|
||||
} else if (StringUtils.containsIgnoreCase(request.getOperator(), "like")) {
|
||||
whereValue = "'%" + value.get(0) + "%'";
|
||||
} else if (StringUtils.containsIgnoreCase(request.getOperator(), "between")) {
|
||||
if (request.getDatasetTableField().getDeType() == 1) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String startTime = simpleDateFormat.format(new Date(Long.parseLong(value.get(0))));
|
||||
String endTime = simpleDateFormat.format(new Date(Long.parseLong(value.get(1))));
|
||||
String st = String.format(to_date, "'" + startTime + "'", default_date_format);
|
||||
String et = String.format(to_date, "'" + endTime + "'", default_date_format);
|
||||
whereValue = st + " AND " + et;
|
||||
} else {
|
||||
whereValue = String.format(where_between, value.get(0), value.get(1));
|
||||
}
|
||||
} else {
|
||||
whereValue = String.format(where_value_value, value.get(0));
|
||||
}
|
||||
list.add(PluginViewSQL.builder().whereField(whereName).whereTermAndValue(whereTerm + whereValue).build());
|
||||
|
||||
|
||||
|
||||
}
|
||||
List<String> strList = new ArrayList<>();
|
||||
list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue()));
|
||||
return CollectionUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user