Browse Source

fix: 兼容动态时间为空

许家凯 3 years ago
parent
commit
91397be05f

+ 3 - 0
src/main/scala/com/winhc/bigdata/spark/jobs/chance/CompanyChangeHandle.scala

@@ -25,6 +25,9 @@ trait CompanyChangeHandle extends Serializable with Logging {
    * @return rowkey,cid,类型【insert or update】,新数据,更新字段,更新标题,变更标签【1.一般变更,2.风险变更 ...】,业务时间
    * @return rowkey,cid,类型【insert or update】,新数据,更新字段,更新标题,变更标签【1.一般变更,2.风险变更 ...】,业务时间
    */
    */
   def handle(rowkey: String, oldMap: Map[String, String], newMap: Map[String, String]): (String, String, String, Map[String, String], String, String, String, String, Map[String, String]) = {
   def handle(rowkey: String, oldMap: Map[String, String], newMap: Map[String, String]): (String, String, String, Map[String, String], String, String, String, String, Map[String, String]) = {
+    if(getBizTime(newMap)==null){
+      return null
+    }
     if (oldMap == null) {
     if (oldMap == null) {
       (rowkey, getCid(rowkey, newMap), "insert", newMap, null, getInsertTitle(newMap), getLabel(oldMap, newMap), getBizTime(newMap), null)
       (rowkey, getCid(rowkey, newMap), "insert", newMap, null, getInsertTitle(newMap), getLabel(oldMap, newMap), getBizTime(newMap), null)
     } else {
     } else {

+ 15 - 3
src/main/scala/com/winhc/bigdata/spark/utils/DateUtils.scala

@@ -62,7 +62,19 @@ object DateUtils {
    * @param date
    * @param date
    * @return
    * @return
    */
    */
-  def getNotNullStr(date: String*): String = date.filter(_ != null).head
+  def getNotNullStr(date: String*): String = {
+    if (date == null || date.isEmpty) {
+      return null
+    }
+    try {
+      date.filter(_ != null).head
+
+    } catch {
+      case e: Exception => {
+        null
+      }
+    }
+  }
 
 
   /**
   /**
    * 获取最小的一个日期,如果有异常情况则反回第一个日期
    * 获取最小的一个日期,如果有异常情况则反回第一个日期
@@ -151,8 +163,8 @@ object DateUtils {
   }
   }
 
 
   def main(args: Array[String]): Unit = {
   def main(args: Array[String]): Unit = {
-    println(DateUtils.toMillisTimestamp(date = "2020-09-17 18:02:02"))
-    println(System.currentTimeMillis())
+    //    println(DateUtils.toMillisTimestamp(date = "2020-09-17 18:02:02"))
+    println(getNotNullStr(null, null))
     //    println(getNotNullStr(null, "2003-10-12 10:00:00", null, "2003-11-12 00:00:02"))
     //    println(getNotNullStr(null, "2003-10-12 10:00:00", null, "2003-11-12 00:00:02"))
   }
   }