From 4624b6fd58f262ab95f2d60472560b9fc162d677 Mon Sep 17 00:00:00 2001 From: dongyukun <1208714201@qq.com> Date: 星期二, 01 四月 2025 14:56:15 +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 | 34 +++++++++++++++++++++++++++++----- 1 files changed, 29 insertions(+), 5 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 96a9661..8de5cd4 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 @@ -16,6 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.text.SimpleDateFormat; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; @@ -160,29 +163,29 @@ case THIS_MONTH: whereSql.append(indItem.getTimeLabel()); whereSql.append("='"); - whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); + whereSql.append(getYearMonth(calendar,indItem.getMonthStart())); whereSql.append("'"); break; case LAST_MONTH: whereSql.append(indItem.getTimeLabel()); whereSql.append("' < '"); - whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); + whereSql.append(getYearMonth(calendar,indItem.getMonthStart())); whereSql.append("' AND "); whereSql.append(indItem.getTimeLabel()); whereSql.append(" >= '"); calendar.add(Calendar.MONTH, -1); - whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); + whereSql.append(getYearMonth(calendar,indItem.getMonthStart())); whereSql.append("'"); break; case LAST_MONTH_12: whereSql.append(indItem.getTimeLabel()); whereSql.append(" <= '"); - whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); + whereSql.append(getYearMonth(calendar,indItem.getMonthStart())); whereSql.append("' AND "); whereSql.append(indItem.getTimeLabel()); whereSql.append("' >= '"); calendar.add(Calendar.MONTH, -12); - whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON)); + whereSql.append(getYearMonth(calendar,indItem.getMonthStart())); whereSql.append("'"); break; case THIS_YEAR_MONTH: @@ -255,6 +258,27 @@ return result; } + public static String getYearMonth(Calendar now,Integer monthStart) { + int day = now.get(Calendar.DAY_OF_MONTH); + + // 当前月 + if (monthStart > 0) { + if (day < monthStart) { + now.add(Calendar.MONTH, -1); + } + } + + if (monthStart < 0) { + if (day >= Math.abs(monthStart)) { + now.add(Calendar.MONTH, 1); + } + } + // 定义日期格式化对象,指定格式为 yyyy-MM + SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_MON); + // 格式化日期并返回结果 + return sdf.format(now.getTime()); + } + public QuerySourceValueDTO getDerSql(String itemId, Date startTime, Date endTime) { QuerySourceValueDTO result = getAtomSql(itemId); IndItemDerVO indItem = indItemDerService.getByItemId(itemId); -- Gitblit v1.9.3