From 173205cc7f6a657defe4677fb028f7c170eec1f0 Mon Sep 17 00:00:00 2001 From: junjun Date: Fri, 6 Sep 2024 10:49:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E8=BF=87=E6=BB=A4=E5=AD=98=E5=9C=A8=E6=97=B6?= =?UTF-8?q?=E5=8C=BA=E5=B7=AE=E5=BC=82=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataease/engine/trans/CustomWhere2Str.java | 18 ++++++++++++++---- .../io/dataease/engine/trans/ExtWhere2Str.java | 18 ++++++++++++++---- .../dataease/engine/trans/WhereTree2Str.java | 18 ++++++++++++++---- .../java/io/dataease/engine/utils/Utils.java | 6 ++++++ 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/engine/trans/CustomWhere2Str.java b/core/core-backend/src/main/java/io/dataease/engine/trans/CustomWhere2Str.java index 8bebb2bb2f..9ecd50b553 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/trans/CustomWhere2Str.java +++ b/core/core-backend/src/main/java/io/dataease/engine/trans/CustomWhere2Str.java @@ -138,7 +138,7 @@ public class CustomWhere2Str { res = "(" + whereName + " IN ('" + String.join("','", item.getEnumValue()) + "'))"; } } else { - if (field.getDeType() == 1) { + if (field.getDeType() == 1 && isCross) { // 规定几种日期格式,一一匹配,匹配到就是该格式 whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName); } @@ -168,13 +168,23 @@ public class CustomWhere2Str { whereTerm = " BETWEEN "; // 把value类似过滤组件处理,获得start time和end time Map stringLongMap = Utils.parseDateTimeValue(value); - whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + if (isCross) { + whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + } else { + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(stringLongMap.get("startTime")), Utils.transLong2Str(stringLongMap.get("endTime"))); + } } else if (StringUtils.equalsIgnoreCase(whereTerm, " <> ")) { whereTerm = " NOT BETWEEN "; Map stringLongMap = Utils.parseDateTimeValue(value); - whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + if (isCross) { + whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + } else { + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(stringLongMap.get("startTime")), Utils.transLong2Str(stringLongMap.get("endTime"))); + } } else { - value = Utils.allDateFormat2Long(value) + ""; + if (isCross) { + value = Utils.allDateFormat2Long(value) + ""; + } whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value); } } else { diff --git a/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java b/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java index 628c7eacc4..0beee01a53 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java +++ b/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java @@ -74,7 +74,9 @@ public class ExtWhere2Str { String cast = String.format(SQLConstants.CAST, originName, SQLConstants.DEFAULT_INT_FORMAT); // 此处获取标准格式的日期 whereName = String.format(SQLConstants.FROM_UNIXTIME, cast, SQLConstants.DEFAULT_DATE_FORMAT); - whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName); + if (isCross) { + whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName); + } } if (field.getDeExtractType() == 1) { // 如果都是时间类型,把date和time类型进行字符串拼接 @@ -136,10 +138,18 @@ public class ExtWhere2Str { if (request.getDatasetTableField().getDeExtractType() == 2 || request.getDatasetTableField().getDeExtractType() == 3 || request.getDatasetTableField().getDeExtractType() == 4) { - whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, value.get(0), value.get(1)); + if (isCross) { + whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, value.get(0), value.get(1)); + } else { + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(Long.parseLong(value.get(0))), Utils.transLong2Str(Long.parseLong(value.get(1)))); + } } else { - whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName); - whereValue = String.format(SQLConstants.WHERE_BETWEEN, Long.parseLong(value.get(0)), Long.parseLong(value.get(1))); + if (isCross) { + whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName); + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Long.parseLong(value.get(0)), Long.parseLong(value.get(1))); + } else { + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(Long.parseLong(value.get(0))), Utils.transLong2Str(Long.parseLong(value.get(1)))); + } } } else { whereValue = String.format(SQLConstants.WHERE_BETWEEN, value.get(0), value.get(1)); diff --git a/core/core-backend/src/main/java/io/dataease/engine/trans/WhereTree2Str.java b/core/core-backend/src/main/java/io/dataease/engine/trans/WhereTree2Str.java index 5372192317..9964e512c3 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/trans/WhereTree2Str.java +++ b/core/core-backend/src/main/java/io/dataease/engine/trans/WhereTree2Str.java @@ -155,7 +155,7 @@ public class WhereTree2Str { String whereTerm = Utils.transFilterTerm(item.getTerm()); String whereValue = ""; - if (field.getDeType() == 1) { + if (field.getDeType() == 1 && isCross) { whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName); } @@ -178,13 +178,23 @@ public class WhereTree2Str { whereTerm = " BETWEEN "; // 把value类似过滤组件处理,获得start time和end time Map stringLongMap = Utils.parseDateTimeValue(value); - whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + if (isCross) { + whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + } else { + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(stringLongMap.get("startTime")), Utils.transLong2Str(stringLongMap.get("endTime"))); + } } else if (StringUtils.equalsIgnoreCase(whereTerm, " <> ")) { whereTerm = " NOT BETWEEN "; Map stringLongMap = Utils.parseDateTimeValue(value); - whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + if (isCross) { + whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime")); + } else { + whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(stringLongMap.get("startTime")), Utils.transLong2Str(stringLongMap.get("endTime"))); + } } else { - value = Utils.allDateFormat2Long(value) + ""; + if (isCross) { + value = Utils.allDateFormat2Long(value) + ""; + } whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value); } } else { diff --git a/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java b/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java index 8844fd6f22..b69009d51b 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java +++ b/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java @@ -419,6 +419,12 @@ public class Utils { return map; } + public static String transLong2Str(Long ts) { + Date date = new Date(ts); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return simpleDateFormat.format(date); + } + public static List getParams(List list) { if (ObjectUtils.isEmpty(list)) return Collections.emptyList(); List param = new ArrayList<>();