Browse Source

+ 告警分析

chen.cheng 11 tháng trước cách đây
mục cha
commit
053ecd4cd2

+ 34 - 7
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/AdmOpAlarmController.java

@@ -1,26 +1,29 @@
 package com.ruoyi.ems.controller;
 
 import java.util.List;
-import java.io.IOException;
+
 import javax.servlet.http.HttpServletResponse;
+
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+
+import com.ruoyi.common.core.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.common.core.web.page.TableDataInfo;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
 import com.ruoyi.ems.domain.AdmOpAlarm;
 import com.ruoyi.ems.service.IAdmOpAlarmService;
-import com.ruoyi.common.core.web.controller.BaseController;
-import com.ruoyi.common.core.web.domain.AjaxResult;
-import com.ruoyi.common.core.utils.poi.ExcelUtil;
-import com.ruoyi.common.core.web.page.TableDataInfo;
 
 /**
  * 能源设施告警Controller
@@ -95,4 +98,28 @@ public class AdmOpAlarmController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(admOpAlarmService.deleteAdmOpAlarmByIds(ids));
     }
+
+    @GetMapping("/alarm/type/index")
+    @RequiresPermissions("ems:alarm-info:query")
+    public AjaxResult qryAlarmTypeIndex(@RequestParam("areaCode") String areaCode) {
+        return success(admOpAlarmService.qryAlarmTypeIndex(areaCode));
+    }
+
+    @GetMapping("/alarm/type/index/day")
+    @RequiresPermissions("ems:alarm-info:query")
+    public AjaxResult qryAlarmTypeIndexDay(@RequestParam("areaCode") String areaCode) {
+        return success(admOpAlarmService.qryAlarmTypeIndexDay(areaCode));
+    }
+
+    @GetMapping("/alarm/type/index/month")
+    @RequiresPermissions("ems:alarm-info:query")
+    public AjaxResult qryAlarmTypeIndexMonth(@RequestParam("areaCode") String areaCode) {
+        return success(admOpAlarmService.qryAlarmTypeIndexMonth(areaCode));
+    }
+
+    @GetMapping("/alarm/type/index/year")
+    @RequiresPermissions("ems:alarm-info:query")
+    public AjaxResult qryAlarmTypeIndexYear(@RequestParam("areaCode") String areaCode) {
+        return success(admOpAlarmService.qryAlarmTypeIndexYear(areaCode));
+    }
 }

+ 21 - 8
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/AdmOpAlarmMapper.java

@@ -1,19 +1,23 @@
 package com.ruoyi.ems.mapper;
 
 import java.util.List;
+import java.util.Map;
+
+import org.apache.ibatis.annotations.Param;
+
 import com.ruoyi.ems.domain.AdmOpAlarm;
 
 /**
  * 能源设施告警Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2024-08-26
  */
-public interface AdmOpAlarmMapper 
+public interface AdmOpAlarmMapper
 {
     /**
      * 查询能源设施告警
-     * 
+     *
      * @param id 能源设施告警主键
      * @return 能源设施告警
      */
@@ -21,7 +25,7 @@ public interface AdmOpAlarmMapper
 
     /**
      * 查询能源设施告警列表
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 能源设施告警集合
      */
@@ -29,7 +33,7 @@ public interface AdmOpAlarmMapper
 
     /**
      * 新增能源设施告警
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 结果
      */
@@ -37,7 +41,7 @@ public interface AdmOpAlarmMapper
 
     /**
      * 修改能源设施告警
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 结果
      */
@@ -45,7 +49,7 @@ public interface AdmOpAlarmMapper
 
     /**
      * 删除能源设施告警
-     * 
+     *
      * @param id 能源设施告警主键
      * @return 结果
      */
@@ -53,9 +57,18 @@ public interface AdmOpAlarmMapper
 
     /**
      * 批量删除能源设施告警
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteAdmOpAlarmByIds(Long[] ids);
+
+    List<Map<String, Object>> qryAlarmTypeIndex(String areaCode);
+
+    List<Map<String, Object>> qryAlarmTypeIndexDay(@Param("alarmDate") String alarmDate, @Param("areaCode") String areaCode);
+
+    List<Map<String, Object>> qryAlarmTypeIndexMonth(@Param("alarmDate") String alarmDate, @Param("areaCode") String areaCode);
+
+    List<Map<String, Object>> qryAlarmTypeIndexYear(@Param("alarmDate") String alarmDate, @Param("areaCode") String areaCode);
+
 }

+ 18 - 8
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IAdmOpAlarmService.java

@@ -1,19 +1,21 @@
 package com.ruoyi.ems.service;
 
 import java.util.List;
+import java.util.Map;
+
 import com.ruoyi.ems.domain.AdmOpAlarm;
 
 /**
  * 能源设施告警Service接口
- * 
+ *
  * @author ruoyi
  * @date 2024-08-26
  */
-public interface IAdmOpAlarmService 
+public interface IAdmOpAlarmService
 {
     /**
      * 查询能源设施告警
-     * 
+     *
      * @param id 能源设施告警主键
      * @return 能源设施告警
      */
@@ -21,7 +23,7 @@ public interface IAdmOpAlarmService
 
     /**
      * 查询能源设施告警列表
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 能源设施告警集合
      */
@@ -29,7 +31,7 @@ public interface IAdmOpAlarmService
 
     /**
      * 新增能源设施告警
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 结果
      */
@@ -37,7 +39,7 @@ public interface IAdmOpAlarmService
 
     /**
      * 修改能源设施告警
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 结果
      */
@@ -45,7 +47,7 @@ public interface IAdmOpAlarmService
 
     /**
      * 批量删除能源设施告警
-     * 
+     *
      * @param ids 需要删除的能源设施告警主键集合
      * @return 结果
      */
@@ -53,9 +55,17 @@ public interface IAdmOpAlarmService
 
     /**
      * 删除能源设施告警信息
-     * 
+     *
      * @param id 能源设施告警主键
      * @return 结果
      */
     public int deleteAdmOpAlarmById(Long id);
+
+    public List<Map<String, Object>> qryAlarmTypeIndex(String areaCode);
+
+    public List<Map<String, Object>> qryAlarmTypeIndexDay(String areaCode);
+
+    public List<Map<String, Object>> qryAlarmTypeIndexMonth(String areaCode);
+
+    public List<Map<String, Object>> qryAlarmTypeIndexYear(String areaCode);
 }

+ 42 - 22
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/AdmOpAlarmServiceImpl.java

@@ -1,93 +1,113 @@
 package com.ruoyi.ems.service.impl;
 
 import java.util.List;
+import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.ruoyi.ems.mapper.AdmOpAlarmMapper;
+
+import com.ruoyi.common.core.utils.DateTimeUtil;
 import com.ruoyi.ems.domain.AdmOpAlarm;
+import com.ruoyi.ems.mapper.AdmOpAlarmMapper;
 import com.ruoyi.ems.service.IAdmOpAlarmService;
 
 /**
  * 能源设施告警Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2024-08-26
  */
 @Service
-public class AdmOpAlarmServiceImpl implements IAdmOpAlarmService 
-{
+public class AdmOpAlarmServiceImpl implements IAdmOpAlarmService {
     @Autowired
     private AdmOpAlarmMapper admOpAlarmMapper;
 
     /**
      * 查询能源设施告警
-     * 
+     *
      * @param id 能源设施告警主键
      * @return 能源设施告警
      */
     @Override
-    public AdmOpAlarm selectAdmOpAlarmById(Long id)
-    {
+    public AdmOpAlarm selectAdmOpAlarmById(Long id) {
         return admOpAlarmMapper.selectAdmOpAlarmById(id);
     }
 
     /**
      * 查询能源设施告警列表
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 能源设施告警
      */
     @Override
-    public List<AdmOpAlarm> selectAdmOpAlarmList(AdmOpAlarm admOpAlarm)
-    {
+    public List<AdmOpAlarm> selectAdmOpAlarmList(AdmOpAlarm admOpAlarm) {
         return admOpAlarmMapper.selectAdmOpAlarmList(admOpAlarm);
     }
 
     /**
      * 新增能源设施告警
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 结果
      */
     @Override
-    public int insertAdmOpAlarm(AdmOpAlarm admOpAlarm)
-    {
+    public int insertAdmOpAlarm(AdmOpAlarm admOpAlarm) {
         return admOpAlarmMapper.insertAdmOpAlarm(admOpAlarm);
     }
 
     /**
      * 修改能源设施告警
-     * 
+     *
      * @param admOpAlarm 能源设施告警
      * @return 结果
      */
     @Override
-    public int updateAdmOpAlarm(AdmOpAlarm admOpAlarm)
-    {
+    public int updateAdmOpAlarm(AdmOpAlarm admOpAlarm) {
         return admOpAlarmMapper.updateAdmOpAlarm(admOpAlarm);
     }
 
     /**
      * 批量删除能源设施告警
-     * 
+     *
      * @param ids 需要删除的能源设施告警主键
      * @return 结果
      */
     @Override
-    public int deleteAdmOpAlarmByIds(Long[] ids)
-    {
+    public int deleteAdmOpAlarmByIds(Long[] ids) {
         return admOpAlarmMapper.deleteAdmOpAlarmByIds(ids);
     }
 
     /**
      * 删除能源设施告警信息
-     * 
+     *
      * @param id 能源设施告警主键
      * @return 结果
      */
     @Override
-    public int deleteAdmOpAlarmById(Long id)
-    {
+    public int deleteAdmOpAlarmById(Long id) {
         return admOpAlarmMapper.deleteAdmOpAlarmById(id);
     }
+
+    @Override
+    public List<Map<String, Object>> qryAlarmTypeIndex(String areaCode) {
+        return admOpAlarmMapper.qryAlarmTypeIndex(areaCode);
+    }
+
+    @Override
+    public List<Map<String, Object>> qryAlarmTypeIndexDay(String areaCode) {
+        String dateTime = DateTimeUtil.currentDateTime(DateTimeUtil.DateFormatter.yyyy_MM_dd);
+        return admOpAlarmMapper.qryAlarmTypeIndexDay(dateTime, areaCode);
+    }
+
+    @Override
+    public List<Map<String, Object>> qryAlarmTypeIndexMonth(String areaCode) {
+        String firstDayOfRecentMonth = DateTimeUtil.getFirstDayOfRecentMonth();
+        return admOpAlarmMapper.qryAlarmTypeIndexMonth(firstDayOfRecentMonth, areaCode);
+    }
+
+    @Override
+    public List<Map<String, Object>> qryAlarmTypeIndexYear(String areaCode) {
+        String firstDayOfRecentYear = DateTimeUtil.getFirstDayOfRecentYear();
+        return admOpAlarmMapper.qryAlarmTypeIndexYear(firstDayOfRecentYear, areaCode);
+    }
 }

+ 58 - 0
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/AdmOpAlarmMapper.xml

@@ -91,4 +91,62 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="qryAlarmTypeIndex" resultType="java.util.Map">
+        SELECT count(*)   cnt,
+               alarm_type alarmType
+        FROM adm_op_alarm
+        WHERE
+            area_code = #{areaCode}
+        GROUP BY alarm_type
+    </select>
+
+    <select id="qryAlarmTypeIndexDay" resultType="java.util.Map">
+        SELECT
+            count(*) cnt,
+            alarm_type alarmType,
+            DATE_FORMAT( alarm_time, '%H:00' ) dateIndex
+        FROM
+            adm_op_alarm
+        WHERE
+            area_code = #{areaCode} and
+            alarm_date = #{alarmDate}
+        GROUP BY
+            DATE_FORMAT( alarm_time, '%H:00' ),
+            alarm_type
+        ORDER BY
+            alarm_type,
+            dateIndex;
+    </select>
+
+    <select id="qryAlarmTypeIndexMonth" resultType="java.util.Map">
+        SELECT
+            count(*) cnt,
+            alarm_type alarmType ,
+            DATE_FORMAT( alarm_date, '%Y-%m-%d' ) AS dateIndex
+        FROM
+            adm_op_alarm
+        WHERE
+            area_code = #{areaCode} and
+            alarm_date >= #{alarmDate}
+        GROUP BY
+            alarm_type,
+            alarm_date
+        ORDER BY
+            alarm_type,
+            dateIndex;
+    </select>
+
+    <select id="qryAlarmTypeIndexYear" resultType="java.util.Map">
+        SELECT count(*)                            cnt,
+               alarm_type                          alarmType,
+               DATE_FORMAT(alarm_date, '%Y-%m') AS dateIndex
+        FROM adm_op_alarm
+        WHERE area_code = #{areaCode}
+          and alarm_date >= #{alarmDate}
+        GROUP BY alarm_type,
+                 DATE_FORMAT(alarm_date, '%Y-%m')
+        ORDER BY alarm_type,
+                 dateIndex;
+    </select>
 </mapper>

+ 626 - 0
ems-cloud/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/DateTimeUtil.java

@@ -0,0 +1,626 @@
+package com.ruoyi.common.core.utils;
+
+import java.text.SimpleDateFormat;
+import java.time.DayOfWeek;
+import java.time.Duration;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAdjusters;
+import java.time.temporal.WeekFields;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * The type Date time util.
+ *
+ * @author chen.cheng
+ */
+public class DateTimeUtil {
+
+    /**
+     * Current date time string.
+     *
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String currentDateTime() {
+        return DateTimeUtil.currentDateTime(DateFormatter.yyyy_MM_dd_HHmmss);
+    }
+
+    /**
+     * Parse date date.
+     *
+     * @param dateString the date string
+     * @return the date
+     * @author chen.cheng
+     */
+    public static Date parseDate(String dateString) {
+        return DateTimeUtil.parseDate(dateString, DateFormatter.yyyy_MM_dd_HHmmss);
+    }
+
+    /**
+     * Parse date date.
+     *
+     * @param dateString  the date string
+     * @param formatRegex the format regex
+     * @return the date
+     * @author chen.cheng
+     */
+    public static Date parseDate(String dateString, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegex);
+        LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
+        Instant instant = dateTime.atZone(ZoneId.of("GMT+08:00")).toInstant();
+        return Date.from(instant);
+    }
+
+    /**
+     * Minus day date.
+     *
+     * @param dayNum the day num
+     * @return the date
+     * @author chen.cheng
+     */
+    public static Date minusDay(Long dayNum) {
+        LocalDateTime now = LocalDateTime.now();
+        Instant instant = now.atZone(ZoneId.of("GMT+08:00")).toInstant();
+        return Date.from(instant);
+    }
+
+    /**
+     * Parse date string.
+     *
+     * @param localDateTime the local date time
+     * @param formatRegex   the format regex
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String parseDate(LocalDateTime localDateTime, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegex);
+        return localDateTime.format(formatter);
+    }
+
+    /**
+     * Parse date string.
+     *
+     * @param localDate   the local date
+     * @param formatRegex the format regex
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String parseDate(LocalDate localDate, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegex);
+        return localDate.format(formatter);
+    }
+
+    /**
+     * Current date time string.
+     *
+     * @param format the format
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String currentDateTime(String format) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
+        LocalDateTime now = LocalDateTime.now();
+        return now.format(formatter);
+    }
+
+    /**
+     * Parse local date local date time.
+     *
+     * @param dateString  the date string
+     * @param formatRegex the format regex
+     * @return the local date time
+     * @author chen.cheng
+     */
+    public static LocalDateTime parseLocalDateTime(String dateString, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegex);
+        LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
+        return dateTime;
+    }
+
+    /**
+     * Parse local date local date.
+     *
+     * @param dateString  the date string
+     * @param formatRegex the format regex
+     * @return the local date
+     * @author chen.cheng
+     */
+    public static LocalDate parseLocalDate(String dateString, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegex);
+        LocalDate dateTime = LocalDate.parse(dateString, formatter);
+        return dateTime;
+    }
+
+    /**
+     * Parse date string string.
+     *
+     * @param dateString  the date string
+     * @param formatRegex the format regex
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String parseDateString(String dateString, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateFormatter.yyyy_MM_dd_HHmmss);
+        LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
+        return parseDate(dateTime, formatRegex);
+    }
+
+    /**
+     * Parse date string string.
+     *
+     * @param dateString     the date string
+     * @param srcFormatRegex the src format regex
+     * @param formatRegex    the format regex
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String parseDateString(String dateString, String srcFormatRegex, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(srcFormatRegex);
+        LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
+        return parseDate(dateTime, formatRegex);
+    }
+
+    /**
+     * Parse short date string string(yyyyMMdd).
+     *
+     * @param dateString     the date string
+     * @param srcFormatRegex the src format regex
+     * @param formatRegex    the format regex
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String parseShortDateString(String dateString, String srcFormatRegex, String formatRegex) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(srcFormatRegex);
+        LocalDate date = LocalDate.parse(dateString, formatter);
+        return parseDate(date, formatRegex);
+    }
+
+    /**
+     * Days of range list.
+     *
+     * @param startDate the start date
+     * @param endDate   the end date DateTimeUtil.daysOfRange("2020-05-06",
+     *                  "2020-09-02",DateFormatter.yyyy_MM_dd,DateFormatter.yyyyMMdd)
+     * @return the list
+     * @author chen.cheng
+     */
+    public static List<String> daysOfRange(String startDate, String endDate) {
+        return daysOfRange(startDate, endDate, DateFormatter.yyyy_MM_dd, DateFormatter.yyyy_MM_dd);
+    }
+
+    /**
+     * Minus month string.
+     *
+     * @param monthNum   the month num
+     * @param formatRegx the format regx
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String minusMonth(Long monthNum, String formatRegx) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegx);
+        LocalDateTime now = LocalDateTime.now();
+        now = now.minusMonths(monthNum);
+        return now.format(formatter);
+    }
+
+    /**
+     * Minus month string
+     *
+     * @param monthNum   month num
+     * @param formatRegx format regx
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String minusMonth(Integer monthNum, String formatRegx) {
+        return minusMonth(monthNum.longValue(), formatRegx);
+    }
+
+    /**
+     * Yesterday string.
+     *
+     * @param formatRegx the format regx
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String yesterday(String formatRegx) {
+        return minusDay(1L, formatRegx);
+    }
+
+    /**
+     * Minus month string.
+     *
+     * @param monthNum   the month num
+     * @param formatRegx the format regx
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String minusMonth(String date, String formatRegx, Long monthNum) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegx);
+        LocalDateTime localDateTime = parseLocalDateTime(date, formatRegx);
+        localDateTime = localDateTime.minusMonths(monthNum);
+        return localDateTime.format(formatter);
+    }
+
+    /**
+     * Date minus month string
+     *
+     * @param date       date
+     * @param formatRegx format regx
+     * @param monthNum   month num
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String dateMinusMonth(String date, String formatRegx, Long monthNum) {
+        return dateMinusMonth(date, DateFormatter.yyyyMMdd, formatRegx, monthNum);
+    }
+
+    /**
+     * Date minus month string
+     *
+     * @param date          date
+     * @param srcFormatRegx src format regx
+     * @param formatRegx    format regx
+     * @param monthNum      month num
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String dateMinusMonth(String date, String srcFormatRegx, String formatRegx, Long monthNum) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegx);
+        LocalDate localDateTime = parseLocalDate(date, srcFormatRegx);
+        localDateTime = localDateTime.minusMonths(monthNum);
+        return localDateTime.format(formatter);
+    }
+
+    /**
+     * Minus day string.
+     *
+     * @param dayNum     the day num
+     * @param formatRegx the format regx
+     * @return the string
+     * @author chen.cheng
+     */
+    public static String minusDay(Long dayNum, String formatRegx) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatRegx);
+        LocalDateTime now = LocalDateTime.now();
+        now = now.minusDays(dayNum);
+        return now.format(formatter);
+    }
+
+    /**
+     * Days of range list.
+     *
+     * @param startDate    the start date
+     * @param endDate      the end date
+     * @param paramFormat  the param format
+     * @param resultFormat the result format
+     * @return the list
+     * @author chen.cheng
+     */
+    public static List<String> daysOfRange(String startDate, String endDate, String paramFormat, String resultFormat) {
+        DateTimeFormatter resultFormatter = DateTimeFormatter.ofPattern(resultFormat);
+        DateTimeFormatter paramFormatter = DateTimeFormatter.ofPattern(paramFormat);
+        LocalDate dateTimeOfStart = LocalDate.parse(startDate, paramFormatter);
+        LocalDate dateTimeOfEnd = LocalDate.parse(endDate, paramFormatter);
+        List<String> days = new ArrayList<>();
+        while (!dateTimeOfStart.isAfter(dateTimeOfEnd)) {
+            days.add(dateTimeOfStart.format(resultFormatter));
+            dateTimeOfStart = dateTimeOfStart.plusDays(1L);
+        }
+        return days;
+    }
+
+    public static List<String> monthOfRange(String startDate, String endDate, String paramFormat, String resultFormat) {
+        DateTimeFormatter resultFormatter = DateTimeFormatter.ofPattern(resultFormat);
+        DateTimeFormatter paramFormatter = DateTimeFormatter.ofPattern(paramFormat);
+        LocalDate dateTimeOfStart = LocalDate.parse(startDate, paramFormatter);
+        LocalDate dateTimeOfEnd = LocalDate.parse(endDate, paramFormatter);
+        List<String> month = new ArrayList<>();
+        while (!dateTimeOfStart.isAfter(dateTimeOfEnd)) {
+            month.add(dateTimeOfStart.format(resultFormatter));
+            dateTimeOfStart = dateTimeOfStart.plusMonths(1L);
+        }
+        DateTimeFormatter ddFormatter = DateTimeFormatter.ofPattern(DateFormatter.DD);
+        int startDd = Integer.parseInt(dateTimeOfStart.format(ddFormatter));
+        int endDd = Integer.parseInt(dateTimeOfEnd.format(ddFormatter));
+        if (startDd > endDd) {
+            month.add(dateTimeOfEnd.format(resultFormatter));
+        }
+        return month;
+    }
+
+    public static void main(String[] args) {
+        List<String> month = monthOfRange("20230731", "20240831", DateFormatter.yyyyMMdd, DateFormatter.yyyyMM);
+        System.out.println(month);
+    }
+
+    /**
+     * Days of range list.
+     *
+     * @param startDate   the start date
+     * @param endDate     the end date
+     * @param paramFormat the param format
+     * @return the list
+     * @author chen.cheng
+     */
+    public static List<String> daysOfRange(String startDate, String endDate, String paramFormat) {
+        DateTimeFormatter resultFormatter = DateTimeFormatter.ofPattern(paramFormat);
+        DateTimeFormatter paramFormatter = DateTimeFormatter.ofPattern(paramFormat);
+        LocalDate dateTimeOfStart = LocalDate.parse(startDate, paramFormatter);
+        LocalDate dateTimeOfEnd = LocalDate.parse(endDate, paramFormatter);
+        List<String> days = new ArrayList<>();
+        while (!dateTimeOfStart.isAfter(dateTimeOfEnd)) {
+            days.add(dateTimeOfStart.format(resultFormatter));
+            dateTimeOfStart = dateTimeOfStart.plusDays(1L);
+        }
+        return days;
+    }
+
+    /**
+     * Gets time step of time index.
+     *
+     * @param tp  the tp
+     * @param gap the gap (now + gap minutes)
+     * @return the time step of time index
+     * @author chen.cheng
+     */
+    public static Integer getTimeStepOfTimeIndex(Integer tp, Integer gap) {
+        return getTimeStepIndexOfNow(tp, LocalDateTime.now().plus(gap, ChronoUnit.MINUTES));
+    }
+
+    /**
+     * Get time step index of now integer.
+     *
+     * @param tp         the tp
+     * @param toDateTime the to date time
+     * @return the integer
+     * @author chen.cheng
+     */
+    public static int getTimeStepIndexOfNow(Integer tp, LocalDateTime toDateTime) {
+        LocalDateTime zero = LocalDateTime.of(toDateTime.getYear(), toDateTime.getMonth(), toDateTime.getDayOfMonth(), 0, 0, 0);
+        Duration duration = Duration.between(zero, toDateTime);
+        double minutes = duration.toMinutes();
+        return (int) Math.floor(minutes / tp);
+    }
+
+    /**
+     * Gets time from step index. tp is min the format hh:mm:00
+     *
+     * @param stepIndex the step index
+     * @param tp        the tp
+     * @return the time from step index
+     * @author chen.cheng
+     */
+    public static String getTimeFromStepIndex(Integer stepIndex, Integer tp) {
+        Integer stepIndex2Min = stepIndex * tp;
+        String hour = StringUtils.leftPad(String.valueOf(stepIndex2Min / 60), 2, "0");
+        String min = StringUtils.leftPad(String.valueOf(stepIndex2Min % 60), 2, "0");
+        return String.format("%s:%s:%s", hour, min, "00");
+    }
+
+    /**
+     * Gets time from step index with out second.
+     *
+     * @param stepIndex the step index
+     * @param tp        the tp
+     * @return the time from step index with out second
+     * @author chen.cheng
+     */
+    public static String getTimeFromStepIndexWithOutSecond(Integer stepIndex, Integer tp) {
+        Integer stepIndex2Min = stepIndex * tp;
+        String hour = StringUtils.leftPad(String.valueOf(stepIndex2Min / 60), 2, "0");
+        String min = StringUtils.leftPad(String.valueOf(stepIndex2Min % 60), 2, "0");
+        return String.format("%s:%s", hour, min);
+    }
+
+    /**
+     * Gets day of week.
+     *
+     * @param date           the date
+     * @param paramFormatter the param formatter
+     * @return the day of week
+     * @author chen.cheng
+     */
+    public static Integer getDayOfWeek(String date, String paramFormatter) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(paramFormatter);
+        LocalDate l_da1 = LocalDate.parse(date, formatter);
+        DayOfWeek dayOfWeek = l_da1.getDayOfWeek();
+        return dayOfWeek.getValue();
+    }
+
+    /**
+     * Gets ali day of week.
+     *
+     * @param date the date
+     * @return the ali day of week
+     * @author chen.cheng
+     */
+    public static Integer getAliDayOfWeek(String date) {
+        return getDayOfWeek(date, DateFormatter.yyyyMMdd) - 1;
+    }
+
+    /**
+     * Cal week of year integer.
+     *
+     * @return the integer
+     * @author chen.cheng
+     */
+    public static Integer calWeekOfYear() {
+        return calWeekOfYear(currentDateTime(DateFormatter.yyyy_MM_dd));
+    }
+
+    public static Integer calLastWeekOfYear() {
+        return calWeekOfYear(currentDateTime(DateFormatter.yyyy_MM_dd)) - 1;
+    }
+
+    /**
+     * Cal week of year integer.
+     *
+     * @param date the date yyyy-MM-dd
+     * @return the integer
+     * @author chen.cheng
+     */
+    public static Integer calWeekOfYear(String date) {
+        LocalDate localDate = LocalDate.parse(date);
+        // 第一个参数:一周的第一天,不能为空
+        // 第二个参数:第一周的最小天数,从1到7
+        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
+        return localDate.get(weekFields.weekOfYear());
+    }
+
+    /**
+     * Cal week of year integer.
+     *
+     * @param date           the date
+     * @param paramFormatter the param formatter
+     * @return the integer
+     * @author chen.cheng
+     */
+    public static Integer calWeekOfYear(String date, String paramFormatter) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(paramFormatter);
+        LocalDate localDate = LocalDate.parse(date, formatter);
+
+        return calWeekOfYear(localDate.toString());
+    }
+
+    /**
+     * Get week time section string [ ].
+     *
+     * @param weekIndex the week index
+     * @return the string [ ]
+     * @author chen.cheng
+     */
+    public static String[] getWeekTimeSection(int weekIndex) {
+        return getWeekTimeSection(weekIndex, DateFormatter.yyyyMMdd);
+    }
+
+    /**
+     * Get week time section string [ ]. 获取前几周内的日期范围
+     *
+     * @param weekIndex the week index
+     * @return the string [ ]
+     * @author chen.cheng
+     */
+    public static String[] getWeekTimeSection(int weekIndex, String dateFormat) {
+        // weekIndex为前几周的周数,如:获取当前时间前第二周的时间 weekIndex=2
+        // 获取本周第一天
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.WEEK_OF_MONTH, 0);
+        cal.set(Calendar.DAY_OF_WEEK, 2);
+        Date first = cal.getTime();
+        Date last = cal.getTime();
+        String firstString = new SimpleDateFormat("yyyy-MM-dd").format(first) + " 00:00:00";
+        String lastString = new SimpleDateFormat("yyyy-MM-dd").format(last) + " 23:59:59";
+        DateTimeFormatter formatPatten = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime firstTime = LocalDateTime.parse(firstString, formatPatten);
+        LocalDateTime lastTime = LocalDateTime.parse(lastString, formatPatten);
+        DateTimeFormatter resultDateFormat = DateTimeFormatter.ofPattern(dateFormat);
+        // 开始时间
+        firstTime = firstTime.plusDays(-(weekIndex * 7L));
+        // 结束时间
+        lastTime = lastTime.plusDays(-1);
+        return new String[]{firstTime.format(resultDateFormat), lastTime.format(resultDateFormat)};
+    }
+
+    public static String getFirstDayOfRecentYear(String dateFormat) {
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+
+        // 计算近一年的年份
+        int recentYear = today.getYear() - 1;
+
+        // 使用 TemporalAdjusters 来找到近一年的第一天
+        LocalDate localDate = LocalDate.of(recentYear, 1, 1).with(TemporalAdjusters.firstDayOfYear());
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
+        return localDate.format(formatter);
+    }
+
+    public static String getFirstDayOfRecentYear() {
+        return getFirstDayOfRecentYear(DateFormatter.yyyy_MM_dd);
+    }
+
+    public static String getFirstDayOfRecentMonth(String dateFormat) {
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+        // 使用 TemporalAdjusters 来找到近一个月的第一天
+        LocalDate with = today.minusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
+        return with.format(formatter);
+    }
+
+    public static String getFirstDayOfRecentMonth() {
+        return getFirstDayOfRecentMonth(DateFormatter.yyyy_MM_dd);
+    }
+
+    /**
+     * The interface Date formatter.
+     *
+     * @author chen.cheng
+     */
+    public interface DateFormatter {
+        /**
+         * The constant yyyy_MM_dd_HHmmss.
+         *
+         * @author chen.cheng
+         */
+        String yyyy_MM_dd_HHmmss = "yyyy-MM-dd HH:mm:ss";
+
+        /**
+         * The constant yyyyMMddHHmmss.
+         *
+         * @author chen.cheng
+         */
+        String yyyyMMddHHmmss = "yyyyMMddHHmmss";
+
+        /**
+         * The constant yyyy_MM_dd.
+         *
+         * @author chen.cheng
+         */
+        String yyyy_MM_dd = "yyyy-MM-dd";
+
+        String DD = "dd";
+
+        /**
+         * The constant yyyyMMdd.
+         *
+         * @author chen.cheng
+         */
+        String yyyyMMdd = "yyyyMMdd";
+
+        String yyyy_MM = "yyyy-MM";
+
+        /**
+         * The constant yyyyMM.
+         *
+         * @author chen.cheng
+         */
+        String yyyyMM = "yyyyMM";
+
+        /**
+         * The constant yyyy.
+         *
+         * @author chen.cheng
+         */
+        String yyyy = "yyyy";
+
+        /**
+         * To string string.
+         *
+         * @return the string
+         * @author chen.cheng
+         */
+        @Override
+        String toString();
+    }
+
+}