From beb40a62ce723b391964dab56de6aa0f98f50613 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Fri, 11 Mar 2022 15:08:25 +0800
Subject: [PATCH] city_aqi月,年数据定时任务修改,每日累计统计

---
 screen-common/src/main/java/com/moral/util/DateUtils.java |  165 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 114 insertions(+), 51 deletions(-)

diff --git a/screen-common/src/main/java/com/moral/util/DateUtils.java b/screen-common/src/main/java/com/moral/util/DateUtils.java
index a02f9b5..5de2f15 100644
--- a/screen-common/src/main/java/com/moral/util/DateUtils.java
+++ b/screen-common/src/main/java/com/moral/util/DateUtils.java
@@ -80,6 +80,10 @@
      * ������������(yyyy-MM-dd HH)
      * */
     public static final String yyyy_MM_dd_HH_EN = "yyyy-MM-dd HH";
+    /*
+     * ������������(MM-dd)
+     * */
+    public static final String MM_dd_EN = "MM-dd";
 
     /*
      * Date���toString������
@@ -651,6 +655,8 @@
         return new Date();
     }
 
+
+
     public static String getAfterNDays(Date date, int n, String formateStr) {
         SimpleDateFormat sdf = new SimpleDateFormat(formateStr);
         Calendar calendar = new GregorianCalendar();
@@ -940,13 +946,95 @@
     }
 
     /*
-    * ������������������������
-    * */
-    public static Date getFirstDayOfCurrYear(){
+     * ������������������������
+     * */
+    public static Date getFirstDayOfCurrYear() {
         Calendar cal = Calendar.getInstance();
-        cal.set(Calendar.DAY_OF_YEAR,1);
+        cal.set(Calendar.DAY_OF_YEAR, 1);
         return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
     }
+
+    /*
+     * ������������������������������
+     * */
+    public static Date getFirstDayOfYear(Date date) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        final int last = cal.getActualMinimum(Calendar.DAY_OF_YEAR);
+        cal.set(Calendar.DAY_OF_YEAR, last);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        return cal.getTime();
+    }
+
+    /*
+     * ���������������������������������
+     * */
+    public static Date getLastDayOfYear(Date date) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        final int last = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
+        cal.set(Calendar.DAY_OF_YEAR, last);
+        cal.set(Calendar.HOUR_OF_DAY, 23);
+        cal.set(Calendar.MINUTE, 59);
+        cal.set(Calendar.SECOND, 59);
+        return cal.getTime();
+    }
+
+    /*
+     * ���������������������������������
+     * */
+    public static Date getFirstDayOfMonth(Date date) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        final int last = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
+        cal.set(Calendar.DAY_OF_MONTH, last);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        return cal.getTime();
+    }
+
+    /*
+     * ������������������������������������
+     * */
+    public static Date getLastDayOfMonth(Date date) {
+        final Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        final int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
+        cal.set(Calendar.DAY_OF_MONTH, last);
+        cal.set(Calendar.HOUR_OF_DAY, 23);
+        cal.set(Calendar.MINUTE, 59);
+        cal.set(Calendar.SECOND, 59);
+        return cal.getTime();
+    }
+
+
+    /*
+     * ���������������������������
+     * */
+    public static boolean isCurrentYear(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(new Date());
+        int currentYear = cal.get(Calendar.YEAR);
+        cal.setTime(date);
+        int year = cal.get(Calendar.YEAR);
+        return year == currentYear;
+    }
+
+    /*
+     * ���������������������������
+     * */
+    public static boolean isCurrentMonth(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(new Date());
+        int currentYear = cal.get(Calendar.MONTH);
+        cal.setTime(date);
+        int year = cal.get(Calendar.MONTH);
+        return year == currentYear;
+    }
+
 
     /**
      * ������������������������������
@@ -981,50 +1069,6 @@
     }
 
     /**
-     * ������������������������������
-     *
-     * @param year
-     * @param month
-     * @return
-     */
-    public static String getFirstDayOfMonth(int year, int month) {
-        Calendar cal = Calendar.getInstance();
-        // ������������
-        cal.set(Calendar.YEAR, year);
-        // ������������
-        cal.set(Calendar.MONTH, month - 1);
-        // ������������������������
-        int lastDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
-        // ������������������������������������
-        cal.set(Calendar.DAY_OF_MONTH, lastDay);
-        // ���������������
-        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
-        return df.format(cal.getTime());
-    }
-
-    /**
-     * ������������������������������
-     *
-     * @param year
-     * @param month
-     * @return
-     */
-    public static String getLastDayOfMonth(int year, int month) {
-        Calendar cal = Calendar.getInstance();
-        // ������������
-        cal.set(Calendar.YEAR, year);
-        // ������������
-        cal.set(Calendar.MONTH, month - 1);
-        // ������������������������
-        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
-        // ������������������������������������
-        cal.set(Calendar.DAY_OF_MONTH, lastDay);
-        // ���������������
-        DateFormat df = getDateFormat(yyyy_MM_dd_EN);
-        return df.format(cal.getTime());
-    }
-
-    /**
      * ������������������
      *
      * @param date
@@ -1040,9 +1084,9 @@
     }
 
     /*
-    * ������������Date
-    * */
-    public static Date getYesterdayDate(){
+     * ������������Date
+     * */
+    public static Date getYesterdayDate() {
         Calendar cal = Calendar.getInstance();
         cal.setTime(new Date());
         cal.set(Calendar.HOUR_OF_DAY, 0);
@@ -1405,6 +1449,7 @@
         calendar.add(Calendar.MONTH, months);
         return calendar.getTime();
     }
+
 
     /**
      * <p>
@@ -1771,4 +1816,22 @@
         String lastYear = getDateAddYear(DateUtils.dateToDateString(getDate(), DateUtils.yyyy), -1);
         return DateUtils.getDate(lastYear, DateUtils.yyyy);
     }
+
+    //���������������������������������������������������
+    public static Map<Date, List<Integer>> getBeforeAndAfterHourDate(Date date) {
+        String s = dateToDateString(date, yyyy_MM_dd_EN);
+        List<String> timeLag = getTimeLag(s);
+        Map<Date, List<Integer>> result = new HashMap<>();
+        for (String s1 : timeLag) {
+            List<Integer> objects = new ArrayList<>();
+            Date current = getDate(s1, yyyy_MM_dd_HH_EN);
+            Date before = addHours(current, -1);
+            Date after = addHours(current, 1);
+            objects.add(getHour(before));
+            objects.add(getHour(current));
+            objects.add(getHour(after));
+            result.put(current, objects);
+        }
+        return result;
+    }
 }

--
Gitblit v1.8.0