|
@@ -25,40 +25,35 @@ trait NgCompanyChangeHandle extends Serializable with Logging {
|
|
|
* @param newMap
|
|
|
* @return rowkey,company_id,类型【insert or update or deleted】,老数据,新数据,更新字段,更新标题,数据标签,业务时间
|
|
|
*/
|
|
|
- def handle(rowkey: String, oldMap: Map[String, String], newMap: Map[String, String]): (String, String, String, Map[String, String], Map[String, String], String, String, String, String) = {
|
|
|
- var update_type: NgCompanyUpdateType.UpdateType = null
|
|
|
+ def handle(rowkey: String, oldMap: Map[String, String], newMap: Map[String, String]): (String, String, String, Map[String, String], Map[String, String], String, String) = {
|
|
|
+ var dynamic_type: NgCompanyUpdateType.UpdateType = NgCompanyUpdateType.Other
|
|
|
|
|
|
val company_id = getCompanyId(rowkey, newMap)
|
|
|
var update_fields: String = null
|
|
|
|
|
|
- var title: String = null
|
|
|
- val label = getLabel(oldMap, newMap)
|
|
|
val biz_time = getBizDate(newMap)
|
|
|
|
|
|
if (oldMap == null) {
|
|
|
newMap.getOrElse("deleted", "0") match {
|
|
|
case "0" => {
|
|
|
- update_type = NgCompanyUpdateType.Insert
|
|
|
- title = getInsertTitle(newMap)
|
|
|
+ dynamic_type = NgCompanyUpdateType.Insert
|
|
|
}
|
|
|
case _ => null
|
|
|
}
|
|
|
} else {
|
|
|
val new_deleted = newMap.getOrElse("deleted", "0")
|
|
|
val old_deleted = oldMap.getOrElse("deleted", "0")
|
|
|
-
|
|
|
+ update_fields = getNotEquFields(oldMap, newMap)
|
|
|
+ if (update_fields == null) {
|
|
|
+ //没有发生字段变化则只接过滤
|
|
|
+ return null
|
|
|
+ }
|
|
|
s"$old_deleted$new_deleted" match {
|
|
|
case "00" => {
|
|
|
- val t = getEquAndFields(oldMap, newMap)
|
|
|
- if (!t._1) {
|
|
|
- update_type = NgCompanyUpdateType.Update
|
|
|
- title = getUpdateTitle(newMap)
|
|
|
- update_fields = t._2
|
|
|
- }
|
|
|
+ dynamic_type = NgCompanyUpdateType.Update
|
|
|
}
|
|
|
case "01" => {
|
|
|
- update_type = NgCompanyUpdateType.Deleted
|
|
|
- title = getDeletedTitle(newMap)
|
|
|
+ dynamic_type = NgCompanyUpdateType.Deleted
|
|
|
}
|
|
|
case "10" | "90" | "09" | "19" => null
|
|
|
|
|
@@ -66,12 +61,9 @@ trait NgCompanyChangeHandle extends Serializable with Logging {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (update_type == null || title == null || biz_time == null) {
|
|
|
- return null
|
|
|
- }
|
|
|
- (rowkey, company_id, update_type.toString, oldMap, newMap,
|
|
|
+ (rowkey, company_id, dynamic_type.toString, oldMap, newMap,
|
|
|
update_fields
|
|
|
- , title, label, biz_time)
|
|
|
+ , biz_time)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -84,39 +76,6 @@ trait NgCompanyChangeHandle extends Serializable with Logging {
|
|
|
protected def getCompanyId(rowkey: String, newMap: Map[String, String]): String = rowkey.split("_")(0)
|
|
|
|
|
|
/**
|
|
|
- * 如果数据发生更新,则显示该标题
|
|
|
- *
|
|
|
- * @param newMap
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected def getUpdateTitle(newMap: Map[String, String]): String
|
|
|
-
|
|
|
- /**
|
|
|
- * 如果数据发生新增,则显示该标题
|
|
|
- *
|
|
|
- * @param newMap
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected def getInsertTitle(newMap: Map[String, String]): String
|
|
|
-
|
|
|
- /**
|
|
|
- * 如果数据发生移除,则显示该标题,deleted:x->9 删除不算
|
|
|
- *
|
|
|
- * @param newMap
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected def getDeletedTitle(newMap: Map[String, String]): String
|
|
|
-
|
|
|
- /**
|
|
|
- * 用于展示的标签
|
|
|
- *
|
|
|
- * @param oldMap
|
|
|
- * @param newMap
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected def getLabel(oldMap: Map[String, String], newMap: Map[String, String]): String
|
|
|
-
|
|
|
- /**
|
|
|
* 获取变更的业务时间
|
|
|
*
|
|
|
* @param newMap
|
|
@@ -131,13 +90,17 @@ trait NgCompanyChangeHandle extends Serializable with Logging {
|
|
|
* @param newMap
|
|
|
* @return true(相同) 差异字段
|
|
|
*/
|
|
|
- protected def getEquAndFields(oldMap: Map[String, String], newMap: Map[String, String]): (Boolean, String) = {
|
|
|
- val tmp = equCols.map(f => (f, cleanup(newMap(f)).equals(cleanup(oldMap(f)))))
|
|
|
+ protected def getNotEquFields(oldMap: Map[String, String], newMap: Map[String, String]): String = {
|
|
|
+ var cols: Seq[String] = equCols
|
|
|
+ if (oldMap.contains("deleted") && newMap.contains("deleted")) {
|
|
|
+ cols = equCols :+ "deleted"
|
|
|
+ }
|
|
|
+ val tmp = cols.distinct.map(f => (f, cleanup(newMap(f)).equals(cleanup(oldMap(f)))))
|
|
|
val eq = tmp.map(_._2).reduce((a1, a2) => a1 && a2)
|
|
|
if (eq) {
|
|
|
- (true, null)
|
|
|
+ null
|
|
|
} else {
|
|
|
- (eq, tmp.filter(!_._2).map(_._1).mkString(","))
|
|
|
+ tmp.filter(!_._2).map(_._1).mkString(",")
|
|
|
}
|
|
|
}
|
|
|
|