From 6077089c5f6ced73cf46a0abdca2c6d77a3b3878 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期三, 12 三月 2025 14:53:32 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java |   73 +++++++++++++++++++++++++-----------
 1 files changed, 51 insertions(+), 22 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java
index 87fee61..127c42e 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java
@@ -139,7 +139,9 @@
                 whereSql.append(indItem.getTimeLabel());
                 whereSql.append(" <= '");
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE));
-                whereSql.append("' AND >= '");
+                whereSql.append("' AND ");
+                whereSql.append(indItem.getTimeLabel());
+                whereSql.append(" >= '");
                 calendar.add(Calendar.DAY_OF_YEAR, -7);
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE));
                 whereSql.append("'");
@@ -148,7 +150,9 @@
                 whereSql.append(indItem.getTimeLabel());
                 whereSql.append(" <= '");
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE));
-                whereSql.append("' AND >= '");
+                whereSql.append("' AND ");
+                whereSql.append(indItem.getTimeLabel());
+                whereSql.append(" >= '");
                 calendar.add(Calendar.DAY_OF_YEAR, -30);
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_DATE));
                 whereSql.append("'");
@@ -160,22 +164,21 @@
                 whereSql.append("'");
                 break;
             case LAST_MONTH:
-                calendar.add(Calendar.MONTH, -1); // 将当前日期减去一个月,得到上个月的日期
-                whereSql.append(indItem.getTimeLabel());
-                whereSql.append(" >= '");
-                whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); // 上个月的第一天
-                calendar.add(Calendar.MONTH, 1); // 再加一个月,回到当前月
-                whereSql.append("' AND '");
                 whereSql.append(indItem.getTimeLabel());
                 whereSql.append("' < '");
-                whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); // 当前月
+                whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
+                whereSql.append("' AND ");
+                whereSql.append(indItem.getTimeLabel());
+                whereSql.append(" >= '");
+                calendar.add(Calendar.MONTH, -1);
+                whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
                 whereSql.append("'");
                 break;
             case LAST_MONTH_12:
                 whereSql.append(indItem.getTimeLabel());
                 whereSql.append(" <= '");
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
-                whereSql.append("' AND '");
+                whereSql.append("' AND ");
                 whereSql.append(indItem.getTimeLabel());
                 whereSql.append("' >= '");
                 calendar.add(Calendar.MONTH, -12);
@@ -183,10 +186,13 @@
                 whereSql.append("'");
                 break;
             case THIS_YEAR_MONTH:
-                calendar.set(Calendar.MONTH, 11);
+                whereSql.append(indItem.getTimeLabel());
                 whereSql.append(" <= '");
+                calendar.set(Calendar.MONTH, 11);
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
-                whereSql.append("' AND >= '");
+                whereSql.append("' AND ");
+                whereSql.append(indItem.getTimeLabel());
+                whereSql.append(" >= '");
                 calendar.set(Calendar.MONTH, 0);
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
                 whereSql.append("'");
@@ -202,6 +208,17 @@
                 whereSql.append(indItem.getTimeLabel());
                 whereSql.append("='");
                 whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_YEAR));
+                whereSql.append("'");
+                break;
+            case LAST_HOUR_24:
+                whereSql.append(indItem.getTimeLabel());
+                whereSql.append(" <= '");
+                whereSql.append(DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
+                whereSql.append("' AND ");
+                whereSql.append(indItem.getTimeLabel());
+                whereSql.append(" >= '");
+                calendar.add(Calendar.HOUR_OF_DAY, -24);
+                whereSql.append(DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
                 whereSql.append("'");
                 break;
             case CUSTOM:
@@ -248,9 +265,15 @@
 
         // 拼接SELECT
         StringBuilder selectSql = new StringBuilder();
-        selectSql.append(indItem.getDimension());
-        selectSql.append(", ");
-        selectSql.append(result.getSelectSql());
+        if (StringUtils.isNotBlank(indItem.getDimension()) && StringUtils.isNotBlank(result.getIndItemAtom().getStatFunc())) {
+            selectSql.append(indItem.getDimension());
+            selectSql.append(", ");
+            selectSql.append(result.getSelectSql());
+        } else if (StringUtils.isBlank(indItem.getDimension()) && StringUtils.isNotBlank(result.getIndItemAtom().getStatFunc())) {
+            selectSql.append(result.getSelectSql());
+        } else {
+            selectSql.append(result.getSelectSql());
+        }
         selectSql.append(", ");
         selectSql.append(indItem.getTimeLabel());
         selectSql.append(" data_time");
@@ -261,22 +284,28 @@
         whereSql.append(" ");
         whereSql.append(indItem.getTimeLabel());
         whereSql.append(" <= '");
-        whereSql.append(DateUtils.format(endTime, PATTERN_MON));
-        whereSql.append("' AND >= '");
-        whereSql.append(DateUtils.format(startTime, PATTERN_MON));
+        whereSql.append(DateUtils.format(endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
+        whereSql.append("' AND ");
+        whereSql.append(indItem.getTimeLabel());
+        whereSql.append(" >= '");
+        whereSql.append(DateUtils.format(startTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND));
         whereSql.append("'");
         result.setWhereSql(whereSql.toString());
 
         // 拼接GROUP
         StringBuilder groupSql = new StringBuilder();
-        groupSql.append(" GROUP BY ");
-        groupSql.append(indItem.getDimension());
+        if (StringUtils.isNotBlank(indItem.getDimension())) {
+            groupSql.append(indItem.getDimension());
+        }
         result.setGroupSql(groupSql.toString());
 
         // 拼接ORDER
         StringBuilder orderBySql = new StringBuilder();
-        orderBySql.append(indItem.getTimeLabel());
-        result.setOrderBySql(orderBySql.toString());
+        if (StringUtils.isNotBlank(indItem.getDimension()) && indItem.getDimension().equals(indItem.getTimeLabel())) {
+            orderBySql.append(indItem.getTimeLabel());
+            result.setOrderBySql(orderBySql.toString());
+        }
+
         return result;
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3