|
@@ -24,6 +24,7 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
val inc_ads_company_legal_entity = "winhc_ng.inc_ads_company_legal_entity"
|
|
|
val inc_ads_company_holder = "winhc_ng.inc_ads_company_holder"
|
|
|
val inc_ads_company_human_relation = "winhc_ng.inc_ads_company_human_relation"
|
|
|
+ val inc_ads_company_human_relation_merge = "winhc_ng.inc_ads_company_human_relation_merge"
|
|
|
val inc_ads_company_staff = "winhc_ng.inc_ads_company_staff"
|
|
|
|
|
|
val ads_change_extract = "winhc_ng.bds_change_extract"
|
|
@@ -141,8 +142,6 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
| ,ds
|
|
|
| FROM $inc_ads_company
|
|
|
| WHERE ds > '0'
|
|
|
- | AND legal_entity_id IS NOT NULL
|
|
|
- | AND length(trim(legal_entity_name)) > 0
|
|
|
| -- AND deleted <> 9
|
|
|
| union all
|
|
|
| SELECT CONCAT_WS('_',company_id,hash(legal_entity_name)) AS rowkey
|
|
@@ -159,8 +158,6 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
| ,ds
|
|
|
| FROM $ads_company
|
|
|
| WHERE ds > '0'
|
|
|
- | AND legal_entity_id IS NOT NULL
|
|
|
- | AND length(trim(legal_entity_name)) > 0
|
|
|
| -- AND deleted <> 9
|
|
|
|)
|
|
|
|)c
|
|
@@ -168,6 +165,7 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
|""".stripMargin).createOrReplaceTempView("company_view_all")
|
|
|
|
|
|
//新增人员关系表
|
|
|
+ //TODO 过滤 deleted = 1
|
|
|
sql(
|
|
|
s"""
|
|
|
|INSERT INTO TABLE $inc_ads_company_human_relation PARTITION(ds= '$ds')
|
|
@@ -187,7 +185,7 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
|FROM (
|
|
|
| SELECT *,concat('p',md5(uuid())) human_pid
|
|
|
| FROM (
|
|
|
- | SELECT company_id,company_name,human_name,hid,status,create_time,update_time,0 as deleted
|
|
|
+ | SELECT company_id,company_name,name_cleanup(human_name) human_name,hid,status,create_time,update_time,0 as deleted
|
|
|
| ,ROW_NUMBER() OVER (PARTITION BY company_id,human_name ORDER BY ds desc,update_time desc) num
|
|
|
| FROM (
|
|
|
| --股东
|
|
@@ -211,15 +209,23 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
|LEFT JOIN (
|
|
|
| SELECT company_id,human_name,human_pid
|
|
|
| FROM (
|
|
|
- | SELECT company_id,human_name,human_pid
|
|
|
- | ,ROW_NUMBER() OVER (PARTITION BY company_id,human_name ORDER BY ds desc,update_time desc) num
|
|
|
- | FROM $inc_ads_company_human_relation
|
|
|
- | WHERE ds > '0'
|
|
|
+ | SELECT company_id,human_name,human_pid
|
|
|
+ | ,ROW_NUMBER() OVER (PARTITION BY company_id,human_name ORDER BY ds desc,update_time desc) num
|
|
|
+ | FROM(
|
|
|
+ | SELECT company_id,human_name,human_pid,ds,update_time
|
|
|
+ | FROM $inc_ads_company_human_relation
|
|
|
+ | WHERE ds > '0'
|
|
|
+ | UNION ALL
|
|
|
+ | SELECT company_id,human_name,human_pid,ds,update_time
|
|
|
+ | FROM $inc_ads_company_human_relation_merge
|
|
|
+ | WHERE ds > '0'
|
|
|
+ | AND deleted = 0
|
|
|
+ | )
|
|
|
| )
|
|
|
| WHERE num = 1
|
|
|
|) b
|
|
|
|ON a.company_id = b.company_id
|
|
|
- |AND a.human_name = b.human_name
|
|
|
+ |AND name_cleanup(a.human_name) = name_cleanup(b.human_name)
|
|
|
|JOIN (
|
|
|
|SELECT * FROM company_view_all
|
|
|
|) c
|
|
@@ -232,10 +238,18 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
s"""
|
|
|
|SELECT company_id,human_name,human_pid
|
|
|
|FROM (
|
|
|
- | SELECT company_id,human_name,human_pid
|
|
|
- | ,ROW_NUMBER() OVER (PARTITION BY company_id,human_name ORDER BY ds desc,update_time desc) num
|
|
|
- | FROM $inc_ads_company_human_relation
|
|
|
- | WHERE ds > '0'
|
|
|
+ | SELECT company_id,human_name,human_pid
|
|
|
+ | ,ROW_NUMBER() OVER (PARTITION BY company_id,human_name ORDER BY ds desc,update_time desc) num
|
|
|
+ | FROM (
|
|
|
+ | SELECT company_id,human_name,human_pid,ds,update_time
|
|
|
+ | FROM $inc_ads_company_human_relation
|
|
|
+ | WHERE ds > '0'
|
|
|
+ | UNION ALL
|
|
|
+ | SELECT company_id,human_name,human_pid,ds,update_time
|
|
|
+ | FROM $inc_ads_company_human_relation_merge
|
|
|
+ | WHERE ds > '0'
|
|
|
+ | AND deleted = 0
|
|
|
+ | )
|
|
|
| )
|
|
|
|WHERE num = 1
|
|
|
|""".stripMargin).createOrReplaceTempView("company_human_relation_all")
|
|
@@ -259,7 +273,7 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
|(
|
|
|
|SELECT * FROM company_human_relation_all
|
|
|
|) c
|
|
|
- |ON a.company_id = c.company_id and a.holder_name = c.human_name
|
|
|
+ |ON a.company_id = c.company_id and name_cleanup(a.holder_name) = name_cleanup(c.human_name)
|
|
|
|JOIN
|
|
|
| (
|
|
|
| SELECT rowkey
|
|
@@ -308,7 +322,7 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
|(
|
|
|
|SELECT * FROM company_human_relation_all
|
|
|
|) c
|
|
|
- |ON a.company_id = c.company_id and a.staff_name = c.human_name
|
|
|
+ |ON a.company_id = c.company_id and name_cleanup(a.staff_name) = name_cleanup(c.human_name)
|
|
|
|JOIN
|
|
|
| (
|
|
|
| SELECT rowkey
|
|
@@ -342,7 +356,7 @@ case class inc_company_relation_v2(s: SparkSession,
|
|
|
|(
|
|
|
|SELECT * FROM company_human_relation_all
|
|
|
|) c
|
|
|
- |ON a.company_id = c.company_id and a.legal_entity_name = c.human_name
|
|
|
+ |ON a.company_id = c.company_id and name_cleanup(a.legal_entity_name) = name_cleanup(c.human_name)
|
|
|
|UNION ALL
|
|
|
|SELECT legal_entity_id start_id,name_cleanup(legal_entity_name) start_name,a.company_id end_id,name_cleanup(company_name) end_name,deleted,legal_entity_type,label
|
|
|
|from (
|