Kaynağa Gözat

feat: dateUtil

许家凯 3 yıl önce
ebeveyn
işleme
592ad9ad77

+ 23 - 2
src/main/scala/com/winhc/bigdata/spark/utils/DateUtils.scala

@@ -163,7 +163,7 @@ object DateUtils {
    */
   def getBizDate(date1: String, date2: String): String = {
     if (StringUtils.isBlank(date1)) {
-      return date2
+      return getBizDate(date2)
     }
     val s = date1.replaceAll("年", "-").replaceAll("月", "-")
       .replaceAll("日", "").replaceAll("/", "-")
@@ -171,7 +171,28 @@ object DateUtils {
     if (s.length >= 10 && isLegalDate(s.substring(0, 10))) {
       s.substring(0, 10)
     } else {
-      date2
+      getBizDate(date2)
+    }
+  }
+
+  /**
+   * 判断bizdate是否合法,否则用update_time替代
+   *
+   * @param date1
+   * @param date2
+   * @return
+   */
+  def getBizDate(date: String): String = {
+    if (StringUtils.isBlank(date)) {
+      return null
+    }
+    val s = date.replaceAll("年", "-").replaceAll("月", "-")
+      .replaceAll("日", "").replaceAll("/", "-")
+
+    if (s.length >= 10 && isLegalDate(s.substring(0, 10))) {
+      s.substring(0, 10)
+    } else {
+      null
     }
   }