wfansh 5 mesiacov pred
rodič
commit
3d23f02408

+ 7 - 11
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/constant/NumConstant.java

@@ -28,7 +28,7 @@ public class NumConstant {
 
     public static final Integer ELEVEN = 11;
 
-    public static final Integer TWELF = 12;
+    public static final Integer TWELVE = 12;
 
     public static final Integer THIRTEEN = 13;
 
@@ -40,21 +40,17 @@ public class NumConstant {
 
     public static final Integer TWENTY = 20;
 
-    public static final Integer THRITY = 30;
+    public static final Integer THIRTY = 30;
 
-    public static final Integer CONS_50 = 50;
+    public static final Integer FIFTY = 50;
 
-    public static final Integer CONS_80 = 80;
+    public static final Integer EIGHTY = 80;
 
-    public static final Integer CONS_100 = 100;
-
-    public static final Integer CONS_443 = 443;
+    public static final Integer ONE_HUNDRED = 100;
 
     public static final Integer SIXTY = 60;
 
-    public static final Integer ONEHUNDREDTWENTY = 120;
-
-    public static final Integer HUGE = 99999;
+    public static final Integer ONE_HUNDRED_TWENTY = 120;
 
-    public static final Integer MILLION = 1000000;
+    public static final Integer ONE_MILLION = 1_000_000;
 }

+ 32 - 96
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/util/DateUtil.java

@@ -1,6 +1,6 @@
 package org.jeecg.modules.adweb.common.util;
 
-import com.xkcoding.http.util.StringUtil;
+import com.google.common.collect.ImmutableMap;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -21,10 +21,10 @@ import java.util.*;
 @Slf4j
 public class DateUtil {
 
-    /** 时间格式(yyyy-MM-dd) */
+    /** 标准日期格式(yyyy-MM-dd) */
     public static final String DATE_FORMAT = "yyyy-MM-dd";
 
-    /** 时间格式(yyyy-MM-dd HH:mm:ss) */
+    /** 标准时间格式(yyyy-MM-dd HH:mm:ss) */
     public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
 
     /** 带时区的时间格式(yyyy-MM-dd HH:mm:ss +00:00) */
@@ -34,50 +34,43 @@ public class DateUtil {
     public static final String SUBJECT_DATE_FORMAT = "yyyy/MM/dd";
 
     /** 时间格式(yyyyMMdd) */
-    public static final String DATE_FORMAT_COMPACT = "yyyyMMdd";
+    public static final String COMPACT_DATE_FORMAT = "yyyyMMdd";
 
     /** 时间格式(yyyyMMddHHmmss) */
-    public static final String DATE_TIME_FORMAT_COMPACT = "yyyyMMddHHmmss";
+    public static final String COMPACT_DATE_TIME_FORMAT = "yyyyMMddHHmmss";
 
     public static final ZoneId DEFAULT_ZONE_ID = ZoneId.of("Asia/Shanghai");
 
-    public static Date plusDays(Date date, int daysToAdd) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(date);
-
-        calendar.add(Calendar.DAY_OF_MONTH, daysToAdd);
-        return calendar.getTime();
-    }
-
     /**
-     * 特殊时间数据处理
+     * 根据日期类型返回日期区间
      *
-     * @param dateType 时间
+     * @param dateType 日期类型
      */
-    public static Map<String, Date> dealDateType(String dateType) {
+    public static Map<String, Date> getDateRangeByType(String dateType) {
         Date now = new Date();
         Date start = null;
         Date end = null;
-        if ("yesterday".equals(dateType)) {
-            start = getTodayZeroTime(DateUtil.addDays(now, -1));
-            end = getTodayZeroTime(now);
-        }
-        if ("today".equals(dateType)) {
-            start = getTodayZeroTime(now);
-            end = getTmrZeroTime(now);
-        }
-        if ("sevenDay".equals(dateType)) {
-            end = getTmrZeroTime(now);
-            start = addDays(end, -7);
-        }
-        if ("thirtyDay".equals(dateType)) {
-            end = getTmrZeroTime(now);
-            start = addDays(end, -30);
+
+        switch (dateType) {
+            case "yesterday":
+                start = getTodayZeroTime(DateUtil.addDays(now, -1));
+                end = getTodayZeroTime(now);
+                break;
+            case "today":
+                start = getTodayZeroTime(now);
+                end = getTmrZeroTime(now);
+                break;
+            case "sevenDay":
+                end = getTmrZeroTime(now);
+                start = addDays(end, -7);
+                break;
+            case "thirtyDay":
+                end = getTmrZeroTime(now);
+                start = addDays(end, -30);
+                break;
         }
-        Map<String, Date> map = new HashMap<>();
-        map.put("start", start);
-        map.put("end", end);
-        return map;
+
+        return ImmutableMap.of("start", start, "end", end);
     }
 
     /**
@@ -117,74 +110,17 @@ public class DateUtil {
      * 在当前日期上追加N天
      *
      * @param date 当前日期
-     * @param num 添加天数
+     * @param daysToAdd 添加天数
      * @return 日期字符串形式
      */
-    public static Date addDays(Date date, int num) {
+    public static Date addDays(Date date, int daysToAdd) {
         Calendar c = Calendar.getInstance();
         c.setTime(date);
-        c.add(Calendar.DAY_OF_MONTH, num);
+        c.add(Calendar.DAY_OF_MONTH, daysToAdd);
         return c.getTime();
     }
 
     /**
-     * 按指定格式转化字符串为Date
-     *
-     * @param strDate String
-     * @param strFormat String
-     * @return FormatDate
-     * @throws ParseException ParseException
-     */
-    public static Date getFormatDate(String strDate, String strFormat) throws ParseException {
-        if (StringUtil.isEmpty(strDate) || StringUtil.isEmpty(strFormat)) {
-            return null;
-        }
-
-        SimpleDateFormat df = new SimpleDateFormat(strFormat);
-        df.setLenient(false);
-        return df.parse(strDate);
-    }
-
-    /**
-     * 按指定格式转化Date为字符串
-     *
-     * @param date Date
-     * @param toFormat String
-     * @return FormatDate String
-     */
-    public static String dateToString(Date date, String toFormat) {
-
-        if (date == null) {
-            return "";
-        }
-
-        SimpleDateFormat df = new SimpleDateFormat(toFormat);
-        df.setLenient(false);
-        return df.format(date);
-    }
-
-    /**
-     * 转换为指定格式Date
-     *
-     * @param date String
-     * @param strFormat String
-     * @return FormatDate
-     * @throws ParseException ParseException
-     */
-    public static Date formatDate(Date date, String strFormat) {
-        if (date == null) {
-            return null;
-        }
-        Date reDate = null;
-        try {
-            reDate = getFormatDate(dateToString(date, strFormat), strFormat);
-        } catch (ParseException e) {
-            date = null;
-        }
-        return reDate;
-    }
-
-    /**
      * 计算两个Date的日期差
      *
      * @param start
@@ -205,7 +141,7 @@ public class DateUtil {
      * @param format
      * @return
      */
-    public static String formatDateStr(Date date, String format) {
+    public static String formatDate(Date date, String format) {
         SimpleDateFormat dateFormat = new SimpleDateFormat(format);
         dateFormat.setLenient(false);
         return dateFormat.format(date);

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/util/GeoIpUtil.java

@@ -141,7 +141,7 @@ public class GeoIpUtil {
         String dateStr = sdf.format(date);
         Date res = new Date();
         try {
-            res = DateUtil.getFormatDate(dateStr, DateUtil.DATE_TIME_FORMAT);
+            res = DateUtil.parseDate(dateStr, DateUtil.DATE_TIME_FORMAT);
         } catch (Exception e) {
             log.error("获取ip时区时间失败", e);
         }

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/controller/AdwebEnquiryController.java

@@ -142,7 +142,7 @@ public class AdwebEnquiryController extends JeecgController<AdwebEnquiry, IAdweb
 		Date start = searchDto.getStart();
 		Date end = searchDto.getEnd();
 		if (StringUtils.isNotBlank(dateType)) {
-			Map<String, Date> map = DateUtil.dealDateType(dateType);
+			Map<String, Date> map = DateUtil.getDateRangeByType(dateType);
 			start = map.get("start");
 			end = map.get("end");
 		} else {

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/service/impl/AdwebEnquiryServiceImpl.java

@@ -638,7 +638,7 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
         adwebEnquiry.setSysEffective(NumConstant.ONE);
         adwebEnquiry.setUserEffective(NumConstant.TWO);
         adwebEnquiry.setSiteHost(enquiryDto.getSiteHost());
-        adwebEnquiry.setNo("xp" + DateUtil.dateToString(new Date(), DateUtil.DATE_FORMAT) + adwebOpenApiService.loadNo(adwebSite.getCode()));
+        adwebEnquiry.setNo("xp" + DateUtil.formatDate(new Date(), DateUtil.DATE_FORMAT) + adwebOpenApiService.loadNo(adwebSite.getCode()));
 
         // 外部编号暂无作用,且多查询一次数据库,暂时注释
 //        adwebEnquiry.setNoOut(DateUtil.dateToString(new Date(), DateUtil.DATE_FORMAT_THREE) + adwebOpenApiService.loadOutNoByUser(adwebSite.getUid()));

+ 2 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/service/dataforseo/DataForSEOService.java

@@ -282,8 +282,7 @@ public class DataForSEOService {
                                             .eq(SeoKeywordsSerp::getKeywordsId, keywordId)
                                             .eq(
                                                     SeoKeywordsSerp::getSeDate,
-                                                    DateUtil.formatDate(
-                                                            seDatetime, DateUtil.DATE_FORMAT)))
+                                                    DateUtil.getTodayZeroTime(seDatetime)))
                             .stream()
                             .findFirst()
                             .orElse(new SeoKeywordsSerp());
@@ -296,7 +295,7 @@ public class DataForSEOService {
             keywordSerp.setPageNumber(rankGroup > 0 ? rankGroup / GOOGLE_SEARCH_PAGE_SIZE + 1 : 0);
             keywordSerp.setRankGroup(rankGroup);
             keywordSerp.setRankAbsolute(rankAbsolute);
-            keywordSerp.setSeDate(DateUtil.formatDateStr(seDatetime, DateUtil.DATE_FORMAT));
+            keywordSerp.setSeDate(DateUtil.formatDate(seDatetime, DateUtil.DATE_FORMAT));
             keywordSerp.setSeDatetime(seDatetime);
             seoKeywordsSerpService.save(keywordSerp);
 

+ 1 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/service/impl/SeoKeywordsSerpServiceImpl.java

@@ -63,8 +63,7 @@ public class SeoKeywordsSerpServiceImpl extends ServiceImpl<SeoKeywordsSerpMappe
             serp.setPageNumber(latestSerp.getPageNumber());
             serp.setRankGroup(latestSerp.getRankGroup());
             serp.setRankAbsolute(latestSerp.getRankAbsolute());
-            serp.setSeDate(
-                    DateUtil.formatDateStr(currentDate, DateUtil.DATE_FORMAT)); // 复制Serp值的目标日期
+            serp.setSeDate(DateUtil.formatDate(currentDate, DateUtil.DATE_FORMAT)); // 复制Serp值的目标日期
             serp.setSeDatetime(latestSerp.getSeDatetime()); // 真实Serp返回的SearchingEngine时间
             serpsToFill.add(serp);
         }