|
@@ -6,7 +6,7 @@ import com.winhc.bigdata.spark.utils._
|
|
|
import org.apache.spark.internal.Logging
|
|
|
import org.apache.spark.sql.functions.col
|
|
|
import org.apache.spark.sql.types.{MapType, StringType, StructField, StructType}
|
|
|
-import org.apache.spark.sql.{DataFrame, Row, SparkSession}
|
|
|
+import org.apache.spark.sql.{Row, SparkSession}
|
|
|
|
|
|
import scala.annotation.meta.getter
|
|
|
import scala.collection.mutable
|
|
@@ -31,7 +31,30 @@ object NgChangeExtract {
|
|
|
) extends LoggingUtils with Logging {
|
|
|
@(transient@getter) val spark: SparkSession = s
|
|
|
|
|
|
- val target_eci_change_extract = "ads_change_extract"
|
|
|
+ val target_tab = "bds_change_extract"
|
|
|
+
|
|
|
+ def init() {
|
|
|
+ sql(
|
|
|
+ s"""
|
|
|
+ |CREATE TABLE IF NOT EXISTS `$project`.`$target_tab` (
|
|
|
+ | `rowkey` STRING COMMENT '该行数据主键',
|
|
|
+ | `company_id` STRING '公司id',
|
|
|
+ | `table_name` STRING 'hbase表名',
|
|
|
+ | `update_type` STRING comment '变更类型',
|
|
|
+ | `old_data` MAP<STRING,STRING> COMMENT '原数据'),
|
|
|
+ | `new_data` MAP<STRING,STRING> COMMENT '新数据',
|
|
|
+ | `change_fields` STRING comment '哪些字段发生变更',
|
|
|
+ | `title` STRING comment '用于展示的标题',
|
|
|
+ | `label` STRING comment '展示的标签',
|
|
|
+ | `biz_date` STRING comment '数据变更的时间',
|
|
|
+ | `update_time` STRING comment '当前计算时间'
|
|
|
+ | COMMENT '变更动态'
|
|
|
+ |PARTITIONED BY (
|
|
|
+ | `ds` STRING COMMENT '时间分区',
|
|
|
+ | `tn` STRING COMMENT '表名分区')
|
|
|
+ |""".stripMargin)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
val updateTimeMapping = Map(
|
|
|
"wenshu_detail_combine" -> "update_date", //文书排序时间
|
|
@@ -66,7 +89,6 @@ object NgChangeExtract {
|
|
|
|
|
|
val handle = ReflectUtils.getClazz[NgCompanyChangeHandle](s"com.winhc.bigdata.spark.ng.change.table.$tableName1", cols)
|
|
|
|
|
|
- val update_time = BaseUtil.nowDate()
|
|
|
|
|
|
val df = sql(
|
|
|
s"""
|
|
@@ -113,24 +135,22 @@ object NgChangeExtract {
|
|
|
|
|
|
val new_map = m._1
|
|
|
val old_map = m._2
|
|
|
- if (new_map == null && old_map == null) {
|
|
|
- null
|
|
|
- } else if (old_map == null) {
|
|
|
- val res = handle.handle(rowkey, null, map_list.head)
|
|
|
- if (res == null) {
|
|
|
- null
|
|
|
- } else {
|
|
|
- Row(res._1, res._2, tableName, res._3, res._4, res._5, res._6, res._7, res._8, update_time, res._9)
|
|
|
- }
|
|
|
- } else if (new_map == null) {
|
|
|
+ val res = handle.handle(rowkey, old_map, new_map)
|
|
|
+ if (res == null) {
|
|
|
null
|
|
|
} else {
|
|
|
- val res = handle.handle(rowkey, old_map, new_map)
|
|
|
- if (res == null) {
|
|
|
- null
|
|
|
- } else {
|
|
|
- Row(res._1, res._2, tableName, res._3, res._4, res._5, res._6, res._7, res._8, update_time, res._9)
|
|
|
- }
|
|
|
+ val rowkey = res._1
|
|
|
+ val company_id = res._2
|
|
|
+ val update_type = res._3
|
|
|
+ val old_map = res._4
|
|
|
+ val new_map = res._5
|
|
|
+ val change_fields = res._6
|
|
|
+ val title = res._7
|
|
|
+ val label = res._8
|
|
|
+ val biz_date = res._9
|
|
|
+ val update_time = BaseUtil.nowDate()
|
|
|
+
|
|
|
+ Row(rowkey, company_id, tableName, update_type, old_map, new_map, change_fields, title, label, biz_date, update_time)
|
|
|
}
|
|
|
}).filter(_ != null)
|
|
|
|
|
@@ -138,14 +158,14 @@ object NgChangeExtract {
|
|
|
StructField("rowkey", StringType), //表数据主建
|
|
|
StructField("company_id", StringType), //公司id
|
|
|
StructField("table_name", StringType), //表名
|
|
|
- StructField("type", StringType), // 变更类型 insert update
|
|
|
- StructField("data", MapType(StringType, StringType)), //变更后数据
|
|
|
- StructField("fields", StringType), //如果是更新 则显示更新字段
|
|
|
+ StructField("update_type", StringType), // 变更类型 insert update
|
|
|
+ StructField("old_data", MapType(StringType, StringType)), //变更前数据
|
|
|
+ StructField("new_data", MapType(StringType, StringType)), //变更后数据
|
|
|
+ StructField("change_fields", StringType), //如果是更新 则显示更新字段
|
|
|
StructField("title", StringType), // 动态数据展示 ps. 新增某土地公示
|
|
|
- StructField("label", StringType), // 1.一般变更,2.风险变更
|
|
|
- StructField("biz_time", StringType), //业务时间
|
|
|
- StructField("update_time", StringType), //处理时间
|
|
|
- StructField("old_data", MapType(StringType, StringType)) //变更前数据
|
|
|
+ StructField("label", StringType), // 数据标签
|
|
|
+ StructField("biz_date", StringType), //业务时间
|
|
|
+ StructField("update_time", StringType) //处理时间
|
|
|
))
|
|
|
|
|
|
spark.createDataFrame(rdd, schema)
|
|
@@ -153,7 +173,7 @@ object NgChangeExtract {
|
|
|
|
|
|
sql(
|
|
|
s"""
|
|
|
- |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE ${project}.$target_eci_change_extract PARTITION(ds='$ds',tn='$tableName1')
|
|
|
+ |INSERT ${if (isWindows) "INTO" else "OVERWRITE"} TABLE ${project}.$target_tab PARTITION(ds='$ds',tn='$tableName1')
|
|
|
|SELECT *
|
|
|
|FROM
|
|
|
| tmp_change_extract_view_$tableName1
|
|
@@ -165,7 +185,7 @@ object NgChangeExtract {
|
|
|
private val startArgs = Seq(
|
|
|
Args(tableName = "company_holder", primaryFields = "percent,deleted")
|
|
|
, Args(tableName = "company_staff", primaryFields = "staff_type,deleted")
|
|
|
- , Args(tableName = "company", primaryKey ="company_id", primaryFields = "name,cate_third_code,county_code,reg_capital_amount")
|
|
|
+ , Args(tableName = "company", primaryKey = "company_id", primaryFields = "name,cate_third_code,county_code,reg_capital_amount")
|
|
|
)
|
|
|
|
|
|
|
|
@@ -199,5 +219,4 @@ object NgChangeExtract {
|
|
|
|
|
|
spark.stop()
|
|
|
}
|
|
|
-
|
|
|
}
|