From 665ffec07abac9fa14e7613fe1c73922a537ff77 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 06 五月 2025 16:00:19 +0800
Subject: [PATCH] art: 设备管理-看板接口-维修统计接口

---
 lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java |   94 +++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java b/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java
index 92f023e..fa4d9a8 100644
--- a/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java
+++ b/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java
@@ -6,11 +6,10 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
+import java.time.YearMonth;
 import java.time.ZoneId;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 
 import org.jeecg.common.constant.SymbolConstant;
 import org.springframework.util.StringUtils;
@@ -783,4 +782,91 @@
     public static Date localDateToDate(LocalDate localDate) {
         return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
     }
+
+    /**
+     * 鑾峰彇鏈湀绗竴澶�
+     *
+     * @return
+     */
+    public static LocalDate getFirstOfMonth() {
+        LocalDate localDate = LocalDate.now();
+        return localDate.withDayOfMonth(1);
+    }
+
+    /**
+     * 鑾峰彇鏈湀绗竴澶�
+     *
+     * @return
+     */
+    public static LocalDate getFirstOfMonth(LocalDate localDate) {
+        return localDate.withDayOfMonth(1);
+    }
+
+    /**
+     * 鑾峰彇涓や釜鏈堜唤涓棿鐨勬墍鏈夋湀浠斤紝鍖呭惈寮�濮嬪拰缁撴潫鏈堜唤
+     *
+     * @param startMonth
+     * @param endMonth
+     * @return
+     */
+    public static List<String> getMonthsBetween(String startMonth, String endMonth) {
+        List<String> months = new ArrayList<>();
+
+        // 瀹氫箟鏃ユ湡鏍煎紡
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+
+        // 瑙f瀽璧峰鍜岀粨鏉熸湀浠�
+        YearMonth start = YearMonth.parse(startMonth, formatter);
+        YearMonth end = YearMonth.parse(endMonth, formatter);
+
+        // 纭繚start <= end 濡傛灉涓嶆槸 鍒欒繘琛屼氦鎹�
+        if (start.isAfter(end)) {
+            YearMonth temp = start;
+            start = end;
+            end = temp;
+        }
+
+        // 寰幆娣诲姞鏈堜唤
+        YearMonth current = start;
+        while (!current.isAfter(end)) {
+            months.add(current.format(formatter));
+            current = current.plusMonths(1);
+        }
+
+        return months;
+    }
+
+    /**
+     * 鑾峰彇涓や釜鏈堜唤涓棿鐨勬墍鏈夋湀浠斤紝鍖呭惈寮�濮嬪拰缁撴潫鏈堜唤
+     *
+     * @param startMonth
+     * @param endMonth
+     * @return
+     */
+    public static List<String> getMonthsBetween(LocalDate startMonth, LocalDate endMonth) {
+        List<String> months = new ArrayList<>();
+
+        // 瀹氫箟鏃ユ湡鏍煎紡
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+
+        // 瑙f瀽璧峰鍜岀粨鏉熸湀浠�
+        YearMonth start = YearMonth.of(startMonth.getYear(), startMonth.getMonth());
+        YearMonth end = YearMonth.of(endMonth.getYear(), endMonth.getMonth());
+
+        // 纭繚start <= end 濡傛灉涓嶆槸 鍒欒繘琛屼氦鎹�
+        if (start.isAfter(end)) {
+            YearMonth temp = start;
+            start = end;
+            end = temp;
+        }
+
+        // 寰幆娣诲姞鏈堜唤
+        YearMonth current = start;
+        while (!current.isAfter(end)) {
+            months.add(current.format(formatter));
+            current = current.plusMonths(1);
+        }
+
+        return months;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3