add workflow 天润Smart-ccc客户数据,dev

This commit is contained in:
root 2025-09-29 14:36:33 +08:00
parent 2689fb16c7
commit 05ec7d92ff
2 changed files with 446 additions and 0 deletions

View File

@ -0,0 +1,74 @@
DROP TABLE IF EXISTS p30_common.d_ccc_cust_info;
CREATE TABLE IF NOT EXISTS p30_common.d_ccc_cust_info (
id VARCHAR(10)
, name VARCHAR(20)
, sex VARCHAR(10)
, tel text
, email VARCHAR(100)
, address text
, prov varchar(10)
, city varchar(20)
, industry varchar(50)
, company varchar(50)
, app varchar(50)
, level VARCHAR(10)
, share_type VARCHAR(10)
, share VARCHAR(10)
, remark text
, source VARCHAR(10)
, last_contact_time timestamp(0)
, last_contact_type VARCHAR(10)
, create_time timestamp(0)
, update_time timestamp(0)
, visitor_ids text
, external_id VARCHAR(100)
, phase_id VARCHAR(10)
, phase_reason_id VARCHAR(10)
, promote_source VARCHAR(20)
, origin_tel text
, Etl_Batch_No varchar(50)
, Etl_First_Dt timestamp(0)
, Etl_Job varchar(200)
, Etl_Proc_Dt timestamp(0)
, Etl_Tx_Dt timestamp(0)
, Src_Sysname varchar(50)
, Src_Table varchar(50)
,primary key( id )
);
COMMENT ON COLUMN p30_common.d_ccc_cust_info.id IS '客户资料id';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.name IS '客户名称';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.sex IS '客户性别';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.tel IS '客户号码';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.email IS '邮箱';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.address IS '地址';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.prov IS '省份';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.city IS '城市';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.industry IS '行业';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.company IS '公司';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.app IS '应用';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.level IS '客户等级';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.share_type IS '归属类型0全体共享、1员工组共享、2员工私有、3无归属';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.share IS '客户归属';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.remark IS '备注';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.source IS '客户来源';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.last_contact_time IS '最后一次联系时间';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.last_contact_type IS '最后一次联系类型';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.create_time IS '创建时间';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.update_time IS '更新时间';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.visitor_ids IS '访客ids';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.external_id IS '外部企业客户ID (第三方平台 ID';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.phase_id IS '客户阶段id';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.phase_reason_id IS '阶段原因id';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.promote_source IS '推广来源';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.origin_tel IS '原始电话';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Etl_Batch_No IS '作业批次号';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Etl_First_Dt IS '最初入库时间';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Etl_Job IS '作业名称';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Etl_Proc_Dt IS '本次入库时间';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Etl_Tx_Dt IS '作业运行时间';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Src_Sysname IS '来源系统';
COMMENT ON COLUMN p30_common.d_ccc_cust_info.Src_Table IS '来源表';
COMMENT ON TABLE p30_common.d_ccc_cust_info IS 'ccc客户信息';

View File

@ -0,0 +1,372 @@
/***************************************************************************************************/
/*script in Sql, generate by SdmCreateScript 2020(by Qihang Feng, QF255001@TERADATA.COM) */
/*VERSION 01.10 revised on 2020-08-25 */
/*Brilliance stems from wisdoms. */
/*************Head Section**************************************************************************/
/*Script Use: Periodically load data to :d_ccc_cust_info(ccc客户信息) */
/*Create Date:2024-09-14 17:58:06 */
/*SDM Developed By: dev */
/*SDM Developed Date: 2024-08-01 */
/*SDM Checked By: dev */
/*SDM Checked Date: 2024-09-14 */
/*Script Developed By: dev */
/*Script Checked By: dev */
/*Source table 1: :PDMDB.t01_ccc_cust_info */
/*Job Type: Inbound transform (Tier 1 to Tier 2) */
/*Target Table:d_ccc_cust_info */
/*ETL Job Name:d_ccc_cust_info */
/*ETL Frequency:Daily */
/*ETL Policy:F2 */
/********************************************************************************************/
/*******Main Section**************************************************************************/
\set ON_ERROR_STOP on
\set AUTOCOMMIT on
\timing on
/*创建临时表加载当前数据 */
CREATE TEMPORARY TABLE d_ccc_cust_info_agi_CUR_I
( LIKE :COMMDB.d_ccc_cust_info)
ON COMMIT PRESERVE ROWS;
/*创建临时表加载不同数据 */
CREATE TEMPORARY TABLE d_ccc_cust_info_agi_INS
( LIKE :COMMDB.d_ccc_cust_info)
ON COMMIT PRESERVE ROWS;
/*****************************************************************************************************/
/* GROUP 1:Source Table:t01_ccc_cust_info*************************************************************/
/*****************************************************************************************************/
INSERT INTO d_ccc_cust_info_agi_CUR_I (
id /*客户资料id*/
,name /*客户名称*/
,sex /*客户性别*/
,tel /*客户号码*/
,email /*邮箱*/
,address /*地址*/
,prov /*省份*/
,city /*城市*/
,industry /*行业*/
,company /*公司*/
,app /*应用*/
,level /*客户等级*/
,share_type /*归属类型0全体共享、1员工组共享、2员工私有、3无归属*/
,share /*客户归属*/
,remark /*备注*/
,source /*客户来源*/
,last_contact_time /*最后一次联系时间*/
,last_contact_type /*最后一次联系类型*/
,create_time /*创建时间*/
,update_time /*更新时间*/
,visitor_ids /*访客ids*/
,external_id /*外部企业客户ID (第三方平台 ID*/
,phase_id /*客户阶段id*/
,phase_reason_id /*阶段原因id*/
,promote_source /*推广来源*/
,origin_tel /*原始电话*/
,Etl_Batch_No /*作业批次号*/
,Etl_First_Dt /*最初入库时间*/
,Etl_Job /*作业名称*/
,Etl_Proc_Dt /*本次入库时间*/
,Etl_Tx_Dt /*作业运行时间*/
,Src_Sysname /*来源系统*/
,Src_Table /*来源表*/
)
SELECT
COALESCE(TRIM(p0.id),'') /*id*/
,COALESCE(TRIM(p0.name),'') /*name*/
,COALESCE(TRIM(p0.sex),'') /*sex*/
,case when
p0.tel='' then '' else coalesce(find_first_phone_number(replace(replace(replace(p0.tel,'"',''),'[','{'),']','}')::text[]),find_first_not_phone_number(replace(replace(replace(p0.tel,'"',''),'[','{'),']','}')::text[]),'null') end /*tel*/
,COALESCE(TRIM(p0.email),'') /*email*/
,COALESCE(TRIM(p0.address),'') /*address*/
,coalesce((SELECT jsonb_extract_path_text(j, 'value')
FROM jsonb_array_elements(p0.customize::jsonb) j
WHERE jsonb_extract_path_text(j, 'name') = '省份'),'') /*prov*/
,coalesce((SELECT jsonb_extract_path_text(j, 'value')
FROM jsonb_array_elements(p0.customize::jsonb) j
WHERE jsonb_extract_path_text(j, 'name') = '城市'),'') /*city*/
,coalesce((SELECT jsonb_extract_path_text(j, 'value')
FROM jsonb_array_elements(p0.customize::jsonb) j
WHERE jsonb_extract_path_text(j, 'name') = '行业'),'') /*industry*/
,coalesce((SELECT jsonb_extract_path_text(j, 'value')
FROM jsonb_array_elements(p0.customize::jsonb) j
WHERE jsonb_extract_path_text(j, 'name') = '公司名称'),'') /*company*/
,coalesce((SELECT jsonb_extract_path_text(j, 'value')
FROM jsonb_array_elements(p0.customize::jsonb) j
WHERE jsonb_extract_path_text(j, 'name') = '应用'),'') /*app*/
,p0.level /*level*/
,COALESCE(TRIM(p0.share_type),'') /*share_type*/
,COALESCE(TRIM(p0.share),'') /*share*/
,COALESCE(TRIM(p0.remark),'') /*remark*/
,COALESCE(TRIM(p0.source),'') /*source*/
,COALESCE(p0.last_contact_time,TO_TIMESTAMP(:NULLDATE,'YYYYMMDD')) /*last_contact_time*/
,COALESCE(TRIM(p0.last_contact_type),'') /*last_contact_type*/
,COALESCE(p0.create_time,TO_TIMESTAMP(:NULLDATE,'YYYYMMDD')) /*create_time*/
,COALESCE(p0.update_time,TO_TIMESTAMP(:NULLDATE,'YYYYMMDD')) /*update_time*/
,COALESCE(TRIM(p0.visitor_ids),'') /*visitor_ids*/
,COALESCE(TRIM(p0.external_id),'') /*external_id*/
,COALESCE(TRIM(p0.phase_id),'') /*phase_id*/
,COALESCE(TRIM(p0.phase_reason_id),'') /*phase_reason_id*/
,COALESCE(TRIM(p0.promote_source),'') /*promote_source*/
,COALESCE(TRIM(p0.tel),'') /*origin_tel*/
,0 /*Etl_Batch_No*/
,TO_DATE(:TXDATE,'YYYYMMDD') /*Etl_First_Dt*/
,:ETLJOB /*Etl_Job*/
,current_timestamp(0) /*Etl_Proc_Dt*/
,TO_DATE(:TXDATE,'YYYYMMDD') /*Etl_Tx_Dt*/
,Substr('t01_ccc_cust_info',1,3) /*Src_Sysname*/
,'t01_ccc_cust_info' /*Src_Table*/
FROM :PDMDB.t01_ccc_cust_info p0
;
/*将不同数据插入到临时表 */
;INSERT INTO d_ccc_cust_info_agi_INS (
name /*客户名称*/
,sex /*客户性别*/
,tel /*客户号码*/
,email /*邮箱*/
,address /*地址*/
,prov /*省份*/
,city /*城市*/
,industry /*行业*/
,company /*公司*/
,app /*应用*/
,level /*客户等级*/
,share_type /*归属类型0全体共享、1员工组共享、2员工私有、3无归属*/
,share /*客户归属*/
,remark /*备注*/
,source /*客户来源*/
,last_contact_time /*最后一次联系时间*/
,last_contact_type /*最后一次联系类型*/
,create_time /*创建时间*/
,update_time /*更新时间*/
,visitor_ids /*访客ids*/
,external_id /*外部企业客户ID (第三方平台 ID*/
,phase_id /*客户阶段id*/
,phase_reason_id /*阶段原因id*/
,promote_source /*推广来源*/
,origin_tel /*原始电话*/
,id /*客户资料id*/
,Etl_Batch_No /*作业批次号*/
,Etl_First_Dt /*最初入库时间*/
,Etl_Job /*作业名称*/
,Etl_Proc_Dt /*本次入库时间*/
,Etl_Tx_Dt /*作业运行时间*/
,Src_Sysname /*来源系统*/
,Src_Table /*来源表*/
)
SELECT
P1.name /*客户名称*/
,P1.sex /*客户性别*/
,P1.tel /*客户号码*/
,P1.email /*邮箱*/
,P1.address /*地址*/
,P1.prov /*省份*/
,P1.city /*城市*/
,P1.industry /*行业*/
,P1.company /*公司*/
,P1.app /*应用*/
,P1.level /*客户等级*/
,P1.share_type /*归属类型0全体共享、1员工组共享、2员工私有、3无归属*/
,P1.share /*客户归属*/
,P1.remark /*备注*/
,P1.source /*客户来源*/
,P1.last_contact_time /*最后一次联系时间*/
,P1.last_contact_type /*最后一次联系类型*/
,P1.create_time /*创建时间*/
,P1.update_time /*更新时间*/
,P1.visitor_ids /*访客ids*/
,P1.external_id /*外部企业客户ID (第三方平台 ID*/
,P1.phase_id /*客户阶段id*/
,P1.phase_reason_id /*阶段原因id*/
,P1.promote_source /*推广来源*/
,P1.origin_tel /*原始电话*/
,P1.id /*客户资料id*/
,P1.Etl_Batch_No /*作业批次号*/
,P1.Etl_First_Dt /*最初入库时间*/
,P1.Etl_Job /*作业名称*/
,P1.Etl_Proc_Dt /*本次入库时间*/
,P1.Etl_Tx_Dt /*作业运行时间*/
,P1.Src_Sysname /*来源系统*/
,P1.Src_Table /*来源表*/
FROM d_ccc_cust_info_agi_CUR_I P1
LEFT JOIN :COMMDB.d_ccc_cust_info P2
ON P1.name = P2.name
AND P1.sex = P2.sex
AND P1.tel = P2.tel
AND P1.email = P2.email
AND P1.address = P2.address
AND P1.prov = P2.prov
AND P1.city = P2.city
AND P1.industry = P2.industry
AND P1.company = P2.company
AND P1.app = P2.app
AND P1.level = P2.level
AND P1.share_type = P2.share_type
AND P1.share = P2.share
AND P1.remark = P2.remark
AND P1.source = P2.source
AND P1.last_contact_time = P2.last_contact_time
AND P1.last_contact_type = P2.last_contact_type
AND P1.create_time = P2.create_time
AND P1.update_time = P2.update_time
AND P1.visitor_ids = P2.visitor_ids
AND P1.external_id = P2.external_id
AND P1.phase_id = P2.phase_id
AND P1.phase_reason_id = P2.phase_reason_id
AND P1.promote_source = P2.promote_source
AND P1.origin_tel = P2.origin_tel
AND P1.id = P2.id
WHERE P2.name IS NULL
OR P2.sex IS NULL
OR P2.tel IS NULL
OR P2.email IS NULL
OR P2.address IS NULL
OR P2.prov IS NULL
OR P2.city IS NULL
OR P2.industry IS NULL
OR P2.company IS NULL
OR P2.app IS NULL
OR P2.level IS NULL
OR P2.share_type IS NULL
OR P2.share IS NULL
OR P2.remark IS NULL
OR P2.source IS NULL
OR P2.last_contact_time IS NULL
OR P2.last_contact_type IS NULL
OR P2.create_time IS NULL
OR P2.update_time IS NULL
OR P2.visitor_ids IS NULL
OR P2.external_id IS NULL
OR P2.phase_id IS NULL
OR P2.phase_reason_id IS NULL
OR P2.promote_source IS NULL
OR P2.origin_tel IS NULL
OR P2.id IS NULL
;
/*将新增数据插入到目标表 */
;INSERT INTO :COMMDB.d_ccc_cust_info (
name /*客户名称*/
,sex /*客户性别*/
,tel /*客户号码*/
,email /*邮箱*/
,address /*地址*/
,prov /*省份*/
,city /*城市*/
,industry /*行业*/
,company /*公司*/
,app /*应用*/
,level /*客户等级*/
,share_type /*归属类型0全体共享、1员工组共享、2员工私有、3无归属*/
,share /*客户归属*/
,remark /*备注*/
,source /*客户来源*/
,last_contact_time /*最后一次联系时间*/
,last_contact_type /*最后一次联系类型*/
,create_time /*创建时间*/
,update_time /*更新时间*/
,visitor_ids /*访客ids*/
,external_id /*外部企业客户ID (第三方平台 ID*/
,phase_id /*客户阶段id*/
,phase_reason_id /*阶段原因id*/
,promote_source /*推广来源*/
,origin_tel /*原始电话*/
,id /*客户资料id*/
,Etl_Batch_No /*作业批次号*/
,Etl_First_Dt /*最初入库时间*/
,Etl_Job /*作业名称*/
,Etl_Proc_Dt /*本次入库时间*/
,Etl_Tx_Dt /*作业运行时间*/
,Src_Sysname /*来源系统*/
,Src_Table /*来源表*/
)
SELECT
P1.name /*客户名称*/
,P1.sex /*客户性别*/
,P1.tel /*客户号码*/
,P1.email /*邮箱*/
,P1.address /*地址*/
,P1.prov /*省份*/
,P1.city /*城市*/
,P1.industry /*行业*/
,P1.company /*公司*/
,P1.app /*应用*/
,P1.level /*客户等级*/
,P1.share_type /*归属类型0全体共享、1员工组共享、2员工私有、3无归属*/
,P1.share /*客户归属*/
,P1.remark /*备注*/
,P1.source /*客户来源*/
,P1.last_contact_time /*最后一次联系时间*/
,P1.last_contact_type /*最后一次联系类型*/
,P1.create_time /*创建时间*/
,P1.update_time /*更新时间*/
,P1.visitor_ids /*访客ids*/
,P1.external_id /*外部企业客户ID (第三方平台 ID*/
,P1.phase_id /*客户阶段id*/
,P1.phase_reason_id /*阶段原因id*/
,P1.promote_source /*推广来源*/
,P1.origin_tel /*原始电话*/
,P1.id /*客户资料id*/
,P1.Etl_Batch_No /*作业批次号*/
,P1.Etl_First_Dt /*最初入库时间*/
,P1.Etl_Job /*作业名称*/
,P1.Etl_Proc_Dt /*本次入库时间*/
,P1.Etl_Tx_Dt /*作业运行时间*/
,P1.Src_Sysname /*来源系统*/
,P1.Src_Table /*来源表*/
FROM d_ccc_cust_info_agi_INS P1
ON CONFLICT ( id)
DO UPDATE SET
id=excluded.id
,name=excluded.name
,sex=excluded.sex
,tel=excluded.tel
,email=excluded.email
,address=excluded.address
,prov=excluded.prov
,city=excluded.city
,industry=excluded.industry
,company=excluded.company
,app=excluded.app
,level=excluded.level
,share_type=excluded.share_type
,share=excluded.share
,remark=excluded.remark
,source=excluded.source
,last_contact_time=excluded.last_contact_time
,last_contact_type=excluded.last_contact_type
,create_time=excluded.create_time
,update_time=excluded.update_time
,visitor_ids=excluded.visitor_ids
,external_id=excluded.external_id
,phase_id=excluded.phase_id
,phase_reason_id=excluded.phase_reason_id
,promote_source=excluded.promote_source
,origin_tel=excluded.origin_tel
,Etl_Batch_No=excluded.Etl_Batch_No
,Etl_First_Dt=excluded.Etl_First_Dt
,Etl_Job=excluded.Etl_Job
,Etl_Proc_Dt=excluded.Etl_Proc_Dt
,Etl_Tx_Dt=excluded.Etl_Tx_Dt
,Src_Sysname=excluded.Src_Sysname
,Src_Table=excluded.Src_Table
;
/*****程序结束退出 */
\q