From 2e0a4e2ee76ec4a9178308bed1532050262f46e2 Mon Sep 17 00:00:00 2001 From: junjie Date: Fri, 14 May 2021 17:47:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E8=BF=87=E6=BB=A4=E5=81=9A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/chart/ChartViewService.java | 69 ++++++++++++++----- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index 57cd2328f8..ef7b44a338 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -231,9 +231,14 @@ public class ChartViewService { continue; } DatasetTableField field = request.getDatasetTableField(); - filter.append(" AND ") - .append(field.getDataeaseName()) - .append(" ") + if (field.getDeType() == 1 && field.getDeExtractType() != 1) { + filter.append(" AND FROM_UNIXTIME(cast(") + .append(field.getDataeaseName()) + .append(" AS decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') "); + } else { + filter.append(" AND ").append(field.getDataeaseName()); + } + filter.append(" ") .append(transMysqlFilterTerm(request.getOperator())) .append(" "); if (StringUtils.containsIgnoreCase(request.getOperator(), "in")) { @@ -303,7 +308,14 @@ public class ChartViewService { .map(x -> { String[] s = x.getFilter().stream().map(f -> { StringBuilder filter = new StringBuilder(); - filter.append(" AND ").append(x.getDataeaseName()).append(transMysqlFilterTerm(f.getTerm())); + if (x.getDeType() == 1 && x.getDeExtractType() != 1) { + filter.append(" AND FROM_UNIXTIME(cast(") + .append(x.getDataeaseName()) + .append(" AS decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') "); + } else { + filter.append(" AND ").append(x.getDataeaseName()); + } + filter.append(transMysqlFilterTerm(f.getTerm())); if (StringUtils.containsIgnoreCase(f.getTerm(), "null")) { } else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) { filter.append("('").append(StringUtils.join(f.getValue(), "','")).append("')"); @@ -332,7 +344,14 @@ public class ChartViewService { .map(y -> { String[] s = y.getFilter().stream().map(f -> { StringBuilder filter = new StringBuilder(); - filter.append(" AND _").append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()).append(transMysqlFilterTerm(f.getTerm())); + if (y.getDeType() == 1 && y.getDeExtractType() != 1) { + filter.append(" AND FROM_UNIXTIME(cast(_") + .append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()) + .append(" AS decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') "); + } else { + filter.append(" AND _").append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()); + } + filter.append(transMysqlFilterTerm(f.getTerm())); if (StringUtils.containsIgnoreCase(f.getTerm(), "null")) { } else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) { filter.append("('").append(StringUtils.join(f.getValue(), "','")).append("')"); @@ -362,13 +381,16 @@ public class ChartViewService { if (StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*")) { f.append(y.getSummary()).append("(").append(y.getDataeaseName()).append(")"); } else { -// f.append("CAST(") -// .append(y.getSummary()).append("(") -// .append("CAST(").append(y.getDataeaseName()).append(" AS ").append(y.getDeType() == 2 ? "DECIMAL(20,0)" : "DECIMAL(20,2)").append(")") -// .append(") AS DECIMAL(20,2)").append(")"); - f.append(y.getSummary()).append("(") - .append("CAST(").append(y.getDataeaseName()).append(" AS ").append(y.getDeType() == 2 ? "DECIMAL(20,0)" : "DECIMAL(20,2)").append(")") - .append(")"); + if (StringUtils.equalsIgnoreCase(y.getSummary(), "avg") || StringUtils.containsIgnoreCase(y.getSummary(), "pop")) { + f.append("CAST(") + .append(y.getSummary()).append("(") + .append("CAST(").append(y.getDataeaseName()).append(" AS ").append(y.getDeType() == 2 ? "DECIMAL(20,0)" : "DECIMAL(20,2)").append(")") + .append(") AS DECIMAL(20,2)").append(")"); + } else { + f.append(y.getSummary()).append("(") + .append("CAST(").append(y.getDataeaseName()).append(" AS ").append(y.getDeType() == 2 ? "DECIMAL(20,0)" : "DECIMAL(20,2)").append(")") + .append(")"); + } } f.append(" AS _").append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()); return f.toString(); @@ -403,14 +425,21 @@ public class ChartViewService { .map(x -> { String[] s = x.getFilter().stream().map(f -> { StringBuilder filter = new StringBuilder(); - filter.append(" AND ").append(x.getDataeaseName()).append(transMysqlFilterTerm(f.getTerm())); + if (x.getDeType() == 1 && x.getDeExtractType() != 1) { + filter.append(" AND FROM_UNIXTIME(cast(") + .append(x.getDataeaseName()) + .append(" AS decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') "); + } else { + filter.append(" AND ").append(x.getDataeaseName()); + } + filter.append(transMysqlFilterTerm(f.getTerm())); if (StringUtils.containsIgnoreCase(f.getTerm(), "null")) { } else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) { filter.append("('").append(StringUtils.join(f.getValue(), "','")).append("')"); } else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) { filter.append("%").append(f.getValue()).append("%"); } else { - filter.append("'" + f.getValue() + "'"); + filter.append("'").append(f.getValue()).append("'"); } return filter.toString(); }).toArray(String[]::new); @@ -432,14 +461,22 @@ public class ChartViewService { .map(y -> { String[] s = y.getFilter().stream().map(f -> { StringBuilder filter = new StringBuilder(); - filter.append(" AND _").append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()).append(transMysqlFilterTerm(f.getTerm())); + // 原始类型不是时间,在de中被转成时间的字段做处理 + if (y.getDeType() == 1 && y.getDeExtractType() != 1) { + filter.append(" AND FROM_UNIXTIME(cast(_") + .append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()) + .append(" AS decimal(20,0))/1000,'%Y-%m-%d %H:%i:%S') "); + } else { + filter.append(" AND _").append(y.getSummary()).append("_").append(StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*") ? "" : y.getDataeaseName()); + } + filter.append(transMysqlFilterTerm(f.getTerm())); if (StringUtils.containsIgnoreCase(f.getTerm(), "null")) { } else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) { filter.append("('").append(StringUtils.join(f.getValue(), "','")).append("')"); } else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) { filter.append("%").append(f.getValue()).append("%"); } else { - filter.append("'" + f.getValue() + "'"); + filter.append("'").append(f.getValue()).append("'"); } return filter.toString(); }).toArray(String[]::new);