diff --git a/dev/workflow/TK_Cust/tk_crm/CRM销售机会/t01_crm_opportunity.sql b/dev/workflow/TK_Cust/tk_crm/CRM销售机会/t01_crm_opportunity.sql new file mode 100644 index 0000000..198f46e --- /dev/null +++ b/dev/workflow/TK_Cust/tk_crm/CRM销售机会/t01_crm_opportunity.sql @@ -0,0 +1,124 @@ + +DROP TABLE IF EXISTS p20_pdm.t01_crm_opportunity; +CREATE TABLE IF NOT EXISTS p20_pdm.t01_crm_opportunity ( + tek_opportunity_id varchar(20) + , opportunity_name varchar(100) + , tektronix_apname text + , estimated_close_time timestamp(0) + , parent_account_name varchar(200) + , parent_contact_name varchar(20) + , product_name varchar(50) + , product_class varchar(50) + , currency_name varchar(20) + , uint_price int + , discount_percent numeric(12,4) + , discount_amount_base numeric(16,4) + , base_amount numeric(16,4) + , total_amount numeric(16,4) + , sales_funnel_stage varchar(50) + , sales_funnel_stage_id int + , status varchar(50) + , state varchar(10) + , region varchar(10) + , acount_manager varchar(20) + , territory_id varchar(50) + , forecast_opp_ind varchar(10) + , risk_ind varchar(10) + , opportunity_age int + , create_time timestamp(0) + , create_person varchar(50) + , pipline_last_update timestamp(0) + , status_last_update timestamp(0) + , channel_id varchar(50) + , purchase_method varchar(50) + , campaign_name varchar(50) + , web_medium varchar(50) + , web_source varchar(100) + , customer_app varchar(50) + , vertical_segment varchar(50) + , competitive_status varchar(50) + , important_opportunity_ind varchar(10) + , application_name varchar(100) + , opp_industry varchar(100) + , tag_list varchar(100) + , discount_amount numeric(16,4) + , area_id varchar(100) + , branch_id varchar(100) + , extension_id varchar(100) + , legal_company_name varchar(200) + , account_number varchar(100) + , marketing_program_type varchar(100) + , lead_number varchar(20) + , crm_contact_number varchar(20) + , Scd_Start_Dt date + , Scd_End_Dt date + , Etl_Batch_No varchar(50) + , Etl_First_Dt timestamp(0) + , Etl_Job varchar(50) + , Etl_Proc_Dt timestamp(0) + , Etl_Tx_Dt timestamp(0) + , Src_Sysname varchar(50) + , Src_Table varchar(50) + ,primary key( tek_opportunity_id,Scd_Start_Dt ) +); + + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.tek_opportunity_id IS '泰克机会编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.opportunity_name IS '机会名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.tektronix_apname IS 'tek_tektronixapname'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.estimated_close_time IS '预期关闭时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.parent_account_name IS '父账号名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.parent_contact_name IS '父联系人名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.product_name IS '产品名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.product_class IS '产品类别'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.currency_name IS '交易币种'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.uint_price IS '单价'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.discount_percent IS '折扣率'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.discount_amount_base IS '基础折扣金额'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.base_amount IS '基础金额'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.total_amount IS '总金额'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.sales_funnel_stage IS '销售漏斗层级'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.sales_funnel_stage_id IS '销售漏斗层级编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.status IS '状况'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.state IS '状态'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.region IS '区域'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.acount_manager IS '账号经理'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.territory_id IS '领域编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.forecast_opp_ind IS '预期机会标志'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.risk_ind IS '风险标志'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.opportunity_age IS '机会年份'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.create_time IS '创建时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.create_person IS '创建人'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.pipline_last_update IS 'pipline最后更新时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.status_last_update IS '状况最后更新时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.channel_id IS '渠道编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.purchase_method IS '采购方式'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.campaign_name IS '活动名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.web_medium IS '网络媒介'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.web_source IS '网络来源'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.customer_app IS '客户应用'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.vertical_segment IS '垂直领域'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.competitive_status IS '竞争状态'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.important_opportunity_ind IS '重要机会标志'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.application_name IS '应用名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.opp_industry IS '行业(opp)'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.tag_list IS '标签列表'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.discount_amount IS '折扣金额'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.area_id IS '地区编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.branch_id IS '分支编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.extension_id IS '扩展编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.legal_company_name IS '法定公司名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.account_number IS '账号编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.marketing_program_type IS '市场项目类型'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.lead_number IS '线索编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.crm_contact_number IS '联系人编号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Scd_Start_Dt IS '开始时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Scd_End_Dt IS '结束时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Etl_Batch_No IS '作业批次号'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Etl_First_Dt IS '最初入库时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Etl_Job IS '作业名称'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Etl_Proc_Dt IS '本次入库时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Etl_Tx_Dt IS '作业运行时间'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Src_Sysname IS '来源系统'; + COMMENT ON COLUMN p20_pdm.t01_crm_opportunity.Src_Table IS '来源表'; + +COMMENT ON TABLE p20_pdm.t01_crm_opportunity IS 'CRM销售机会'; \ No newline at end of file diff --git a/dev/workflow/TK_Cust/tk_crm/CRM销售机会/t01_crm_opportunity_agi.sql b/dev/workflow/TK_Cust/tk_crm/CRM销售机会/t01_crm_opportunity_agi.sql new file mode 100644 index 0000000..e414f3d --- /dev/null +++ b/dev/workflow/TK_Cust/tk_crm/CRM销售机会/t01_crm_opportunity_agi.sql @@ -0,0 +1,828 @@ +/***************************************************************************************************/ +/*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 :t01_crm_opportunity(CRM销售机会) */ +/*Create Date:2024-04-19 11:51:17 */ +/*SDM Developed By: dev */ +/*SDM Developed Date: 2024-04-19 */ +/*SDM Checked By: dev */ +/*SDM Checked Date: 2024-04-19 */ +/*Script Developed By: dev */ +/*Script Checked By: dev */ +/*Source table 1: p10_sa.s98_s_crm_opp */ +/*Job Type: Inbound transform (Tier 1 to Tier 2) */ +/*Target Table:t01_crm_opportunity */ +/*ETL Job Name:t01_crm_opportunity */ +/*ETL Frequency:Daily */ +/*ETL Policy:F5 */ +/********************************************************************************************/ +/*******Main Section**************************************************************************/ +\set ON_ERROR_STOP on +\set AUTOCOMMIT on +\timing on + + + +/*创建临时表加载当前数据 */ +CREATE TEMPORARY TABLE t01_crm_opportunity_agi_CUR_I + ( LIKE :PDMDB.t01_crm_opportunity) +ON COMMIT PRESERVE ROWS; + + + +/*创建临时表加载不同数据 */ +CREATE TEMPORARY TABLE t01_crm_opportunity_agi_INS +( LIKE :PDMDB.t01_crm_opportunity) +ON COMMIT PRESERVE ROWS; + +/*创建临时表加载当前有效数据 */ +CREATE TEMPORARY TABLE t01_crm_opportunity_agi_CUR +( LIKE :PDMDB.t01_crm_opportunity) +ON COMMIT PRESERVE ROWS; + +/*创建临时表加载缺失数据 */ +CREATE TEMPORARY TABLE t01_crm_opportunity_agi_CUR_D +( LIKE :PDMDB.t01_crm_opportunity) +ON COMMIT PRESERVE ROWS; + + +/*****************************************************************************************************/ +/* GROUP 1:Source Table:s98_s_crm_opp*****************************************************************/ +/*****************************************************************************************************/ +INSERT INTO t01_crm_opportunity_agi_CUR_I ( + tek_opportunitynumber /*tek_opportunitynumber*/ + ,name /*name*/ + ,tek_tektronixapname /*tek_tektronixapname*/ + ,estimatedclosedate /*estimatedclosedate*/ + ,parentaccountidname /*parentaccountidname*/ + ,parentcontactidname /*parentcontactidname*/ + ,tek_productidname /*tek_productidname*/ + ,tek_productfamilyidname /*tek_productfamilyidname*/ + ,transactioncurrencyidname /*transactioncurrencyidname*/ + ,tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + ,tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + ,totaldiscountamount_base /*totaldiscountamount_base*/ + ,estimatedvalue_base /*estimatedvalue_base*/ + ,totalamount /*totalamount*/ + ,tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + ,tek_funnelstagenumber /*tek_funnelstagenumber*/ + ,statuscodename /*statuscodename*/ + ,statecodename /*statecodename*/ + ,tek_regionidname /*tek_regionidname*/ + ,tek_accountmanageridname /*tek_accountmanageridname*/ + ,tek_oppterritoryidname /*tek_oppterritoryidname*/ + ,tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + ,tek_isriskname /*tek_isriskname*/ + ,tek_opportunityage /*tek_opportunityage*/ + ,createdon /*createdon*/ + ,createdbyname /*createdbyname*/ + ,tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + ,tek_laststatusdate /*tek_laststatusdate*/ + ,tek_channelidname /*tek_channelidname*/ + ,tek_purchasemethodname /*tek_purchasemethodname*/ + ,campaignidname /*campaignidname*/ + ,tek_webvisitormedium /*tek_webvisitormedium*/ + ,tek_webvisitorsource /*tek_webvisitorsource*/ + ,tek_customerapplication /*tek_customerapplication*/ + ,tek_vertical_segmentname /*tek_vertical_segmentname*/ + ,tek_competitivestatusname /*tek_competitivestatusname*/ + ,tek_importantopportunityname /*tek_importantopportunityname*/ + ,tek_applicationidname /*tek_applicationidname*/ + ,tek_industryidname /*tek_industryidname*/ + ,tek_taglist /*tek_taglist*/ + ,discountamount /*discountamount*/ + ,tek_terr_areaidname /*tek_terr_areaidname*/ + ,tek_terr_branchidname /*tek_terr_branchidname*/ + ,tek_extension /*tek_extension*/ + ,tek_companynamelegal /*tek_companynamelegal*/ + ,accountnumber /*accountnumber*/ + ,tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + ,tek_leadnumber /*tek_leadnumber*/ + ,tek_contactnumber /*tek_contactnumber*/ + ,Scd_Start_Dt /*开始时间*/ + ,Scd_End_Dt /*结束时间*/ + ,Etl_Batch_No /*作业批次号*/ + ,Etl_First_Dt /*最初入库时间*/ + ,Etl_Job /*作业名称*/ + ,Etl_Proc_Dt /*本次入库时间*/ + ,Etl_Tx_Dt /*作业运行时间*/ + ,Src_Sysname /*来源系统*/ + ,Src_Table /*来源表*/ + ) +SELECT + COALESCE(TRIM(p0.tek_opportunitynumber),'') /*tek_opportunitynumber*/ + ,COALESCE(TRIM(p0.name),'') /*name*/ + ,COALESCE(TRIM(p0.tek_tektronixapname),'') /*tek_tektronixapname*/ + ,COALESCE(TRIM(p0.estimatedclosedate),'') /*estimatedclosedate*/ + ,COALESCE(TRIM(p0.parentaccountidname),'') /*parentaccountidname*/ + ,COALESCE(TRIM(p0.parentcontactidname),'') /*parentcontactidname*/ + ,COALESCE(TRIM(p0.tek_productidname),'') /*tek_productidname*/ + ,COALESCE(TRIM(p0.tek_productfamilyidname),'') /*tek_productfamilyidname*/ + ,COALESCE(TRIM(p0.transactioncurrencyidname),'') /*transactioncurrencyidname*/ + ,COALESCE(TRIM(p0.tek_unitpricetotal_base),'') /*tek_unitpricetotal_base*/ + ,COALESCE(TRIM(p0.tek_totaldiscountpercent),'') /*tek_totaldiscountpercent*/ + ,COALESCE(TRIM(p0.totaldiscountamount_base),'') /*totaldiscountamount_base*/ + ,COALESCE(TRIM(p0.estimatedvalue_base),'') /*estimatedvalue_base*/ + ,COALESCE(TRIM(p0.totalamount),'') /*totalamount*/ + ,COALESCE(TRIM(p0.tek_salesfunnelstagename),'') /*tek_salesfunnelstagename*/ + ,COALESCE(TRIM(p0.tek_funnelstagenumber),'') /*tek_funnelstagenumber*/ + ,COALESCE(TRIM(p0.statuscodename),'') /*statuscodename*/ + ,COALESCE(TRIM(p0.statecodename),'') /*statecodename*/ + ,COALESCE(TRIM(p0.tek_regionidname),'') /*tek_regionidname*/ + ,COALESCE(TRIM(p0.tek_accountmanageridname),'') /*tek_accountmanageridname*/ + ,COALESCE(TRIM(p0.tek_oppterritoryidname),'') /*tek_oppterritoryidname*/ + ,COALESCE(TRIM(p0.tek_opp_includeinforecastname),'') /*tek_opp_includeinforecastname*/ + ,COALESCE(TRIM(p0.tek_isriskname),'') /*tek_isriskname*/ + ,COALESCE(TRIM(p0.tek_opportunityage),'') /*tek_opportunityage*/ + ,COALESCE(TRIM(p0.createdon),'') /*createdon*/ + ,COALESCE(TRIM(p0.createdbyname),'') /*createdbyname*/ + ,COALESCE(TRIM(p0.tek_piplinelastupdatedon),'') /*tek_piplinelastupdatedon*/ + ,COALESCE(TRIM(p0.tek_laststatusdate),'') /*tek_laststatusdate*/ + ,COALESCE(TRIM(p0.tek_channelidname),'') /*tek_channelidname*/ + ,COALESCE(TRIM(p0.tek_purchasemethodname),'') /*tek_purchasemethodname*/ + ,COALESCE(TRIM(p0.campaignidname),'') /*campaignidname*/ + ,COALESCE(TRIM(p0.tek_webvisitormedium),'') /*tek_webvisitormedium*/ + ,COALESCE(TRIM(p0.tek_webvisitorsource),'') /*tek_webvisitorsource*/ + ,COALESCE(TRIM(p0.tek_customerapplication),'') /*tek_customerapplication*/ + ,COALESCE(TRIM(p0.tek_vertical_segmentname),'') /*tek_vertical_segmentname*/ + ,COALESCE(TRIM(p0.tek_competitivestatusname),'') /*tek_competitivestatusname*/ + ,COALESCE(TRIM(p0.tek_importantopportunityname),'') /*tek_importantopportunityname*/ + ,COALESCE(TRIM(p0.tek_applicationidname),'') /*tek_applicationidname*/ + ,COALESCE(TRIM(p0.tek_industryidname),'') /*tek_industryidname*/ + ,COALESCE(TRIM(p0.tek_taglist),'') /*tek_taglist*/ + ,COALESCE(TRIM(p0.discountamount),'') /*discountamount*/ + ,COALESCE(TRIM(p0.tek_terr_areaidname),'') /*tek_terr_areaidname*/ + ,COALESCE(TRIM(p0.tek_terr_branchidname),'') /*tek_terr_branchidname*/ + ,COALESCE(TRIM(p0.tek_extension),'') /*tek_extension*/ + ,COALESCE(TRIM(p0.tek_companynamelegal),'') /*tek_companynamelegal*/ + ,COALESCE(TRIM(p0.accountnumber),'') /*accountnumber*/ + ,COALESCE(TRIM(p0.tek_marketing_program_type_idname),'') /*tek_marketing_program_type_idname*/ + ,COALESCE(TRIM(p0.tek_leadnumber),'') /*tek_leadnumber*/ + ,COALESCE(TRIM(p0.tek_contactnumber),'') /*tek_contactnumber*/ + ,COALESCE(p0.Scd_Start_Dt,TO_DATE(:NULLDATE,'YYYYMMDD')) /*Scd_Start_Dt*/ + ,COALESCE(p0.Scd_End_Dt,TO_DATE(:NULLDATE,'YYYYMMDD')) /*Scd_End_Dt*/ + ,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('s98_s_crm_opp',1,3) /*Src_Sysname*/ + ,'s98_s_crm_opp' /*Src_Table*/ + +FROM p10_sa.s98_s_crm_opp p0 +; + + + +/*避免同一天多次运行造成数据重复 */ + +DELETE FROM :PDMDB.t01_crm_opportunity +WHERE ETL_JOB=:ETLJOB +AND scd_End_Dt=TO_DATE(:MAXDATE,'YYYYMMDD') +AND scd_Start_Dt=TO_DATE(:TXDATE,'YYYYMMDD'); +UPDATE :PDMDB.t01_crm_opportunity +SET scd_End_Dt=TO_DATE(:MAXDATE,'YYYYMMDD') +WHERE ETL_JOB=:ETLJOB +AND scd_End_Dt=TO_DATE(:TXDATE,'YYYYMMDD'); + +/*往临时表插入当前数据。 */ +INSERT INTO t01_crm_opportunity_agi_CUR( + tek_opportunitynumber /*tek_opportunitynumber*/ + ,tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + ,tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + ,totaldiscountamount_base /*totaldiscountamount_base*/ + ,estimatedvalue_base /*estimatedvalue_base*/ + ,totalamount /*totalamount*/ + ,tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + ,tek_funnelstagenumber /*tek_funnelstagenumber*/ + ,statuscodename /*statuscodename*/ + ,statecodename /*statecodename*/ + ,tek_regionidname /*tek_regionidname*/ + ,name /*name*/ + ,tek_accountmanageridname /*tek_accountmanageridname*/ + ,tek_oppterritoryidname /*tek_oppterritoryidname*/ + ,tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + ,tek_isriskname /*tek_isriskname*/ + ,tek_opportunityage /*tek_opportunityage*/ + ,createdon /*createdon*/ + ,createdbyname /*createdbyname*/ + ,tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + ,tek_laststatusdate /*tek_laststatusdate*/ + ,tek_channelidname /*tek_channelidname*/ + ,tek_tektronixapname /*tek_tektronixapname*/ + ,tek_purchasemethodname /*tek_purchasemethodname*/ + ,campaignidname /*campaignidname*/ + ,tek_webvisitormedium /*tek_webvisitormedium*/ + ,tek_webvisitorsource /*tek_webvisitorsource*/ + ,tek_customerapplication /*tek_customerapplication*/ + ,tek_vertical_segmentname /*tek_vertical_segmentname*/ + ,tek_competitivestatusname /*tek_competitivestatusname*/ + ,tek_importantopportunityname /*tek_importantopportunityname*/ + ,tek_applicationidname /*tek_applicationidname*/ + ,tek_industryidname /*tek_industryidname*/ + ,estimatedclosedate /*estimatedclosedate*/ + ,tek_taglist /*tek_taglist*/ + ,discountamount /*discountamount*/ + ,tek_terr_areaidname /*tek_terr_areaidname*/ + ,tek_terr_branchidname /*tek_terr_branchidname*/ + ,tek_extension /*tek_extension*/ + ,tek_companynamelegal /*tek_companynamelegal*/ + ,accountnumber /*accountnumber*/ + ,tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + ,tek_leadnumber /*tek_leadnumber*/ + ,tek_contactnumber /*tek_contactnumber*/ + ,parentaccountidname /*parentaccountidname*/ + ,Scd_Start_Dt /*开始时间*/ + ,Scd_End_Dt /*结束时间*/ + ,Etl_Batch_No /*作业批次号*/ + ,Etl_First_Dt /*最初入库时间*/ + ,Etl_Job /*作业名称*/ + ,Etl_Proc_Dt /*本次入库时间*/ + ,Etl_Tx_Dt /*作业运行时间*/ + ,Src_Sysname /*来源系统*/ + ,Src_Table /*来源表*/ + ,parentcontactidname /*parentcontactidname*/ + ,tek_productidname /*tek_productidname*/ + ,tek_productfamilyidname /*tek_productfamilyidname*/ + ,transactioncurrencyidname /*transactioncurrencyidname*/ + ) +SELECT + P1.tek_opportunitynumber /*tek_opportunitynumber*/ + ,P1.tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + ,P1.tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + ,P1.totaldiscountamount_base /*totaldiscountamount_base*/ + ,P1.estimatedvalue_base /*estimatedvalue_base*/ + ,P1.totalamount /*totalamount*/ + ,P1.tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + ,P1.tek_funnelstagenumber /*tek_funnelstagenumber*/ + ,P1.statuscodename /*statuscodename*/ + ,P1.statecodename /*statecodename*/ + ,P1.tek_regionidname /*tek_regionidname*/ + ,P1.name /*name*/ + ,P1.tek_accountmanageridname /*tek_accountmanageridname*/ + ,P1.tek_oppterritoryidname /*tek_oppterritoryidname*/ + ,P1.tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + ,P1.tek_isriskname /*tek_isriskname*/ + ,P1.tek_opportunityage /*tek_opportunityage*/ + ,P1.createdon /*createdon*/ + ,P1.createdbyname /*createdbyname*/ + ,P1.tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + ,P1.tek_laststatusdate /*tek_laststatusdate*/ + ,P1.tek_channelidname /*tek_channelidname*/ + ,P1.tek_tektronixapname /*tek_tektronixapname*/ + ,P1.tek_purchasemethodname /*tek_purchasemethodname*/ + ,P1.campaignidname /*campaignidname*/ + ,P1.tek_webvisitormedium /*tek_webvisitormedium*/ + ,P1.tek_webvisitorsource /*tek_webvisitorsource*/ + ,P1.tek_customerapplication /*tek_customerapplication*/ + ,P1.tek_vertical_segmentname /*tek_vertical_segmentname*/ + ,P1.tek_competitivestatusname /*tek_competitivestatusname*/ + ,P1.tek_importantopportunityname /*tek_importantopportunityname*/ + ,P1.tek_applicationidname /*tek_applicationidname*/ + ,P1.tek_industryidname /*tek_industryidname*/ + ,P1.estimatedclosedate /*estimatedclosedate*/ + ,P1.tek_taglist /*tek_taglist*/ + ,P1.discountamount /*discountamount*/ + ,P1.tek_terr_areaidname /*tek_terr_areaidname*/ + ,P1.tek_terr_branchidname /*tek_terr_branchidname*/ + ,P1.tek_extension /*tek_extension*/ + ,P1.tek_companynamelegal /*tek_companynamelegal*/ + ,P1.accountnumber /*accountnumber*/ + ,P1.tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + ,P1.tek_leadnumber /*tek_leadnumber*/ + ,P1.tek_contactnumber /*tek_contactnumber*/ + ,P1.parentaccountidname /*parentaccountidname*/ + ,P1.Scd_Start_Dt /*开始时间*/ + ,P1.Scd_End_Dt /*结束时间*/ + ,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 /*来源表*/ + ,P1.parentcontactidname /*parentcontactidname*/ + ,P1.tek_productidname /*tek_productidname*/ + ,P1.tek_productfamilyidname /*tek_productfamilyidname*/ + ,P1.transactioncurrencyidname /*transactioncurrencyidname*/ + +FROM :PDMDB.t01_crm_opportunity P1 +WHERE P1.Scd_End_Dt = TO_DATE(:MAXDATE,'YYYYMMDD') + AND P1.ETL_Job = :ETLJOB + ; +/*"今日数据"与"当前有效数据"进行比较找出新增及更新的数据,比对条件是:除去开始日期和结束日期的所有 */ +/*字段。 */ +INSERT INTO t01_crm_opportunity_agi_INS( + tek_opportunitynumber /*tek_opportunitynumber*/ + , tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + , tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + , totaldiscountamount_base /*totaldiscountamount_base*/ + , estimatedvalue_base /*estimatedvalue_base*/ + , totalamount /*totalamount*/ + , tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + , tek_funnelstagenumber /*tek_funnelstagenumber*/ + , statuscodename /*statuscodename*/ + , statecodename /*statecodename*/ + , tek_regionidname /*tek_regionidname*/ + , name /*name*/ + , tek_accountmanageridname /*tek_accountmanageridname*/ + , tek_oppterritoryidname /*tek_oppterritoryidname*/ + , tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + , tek_isriskname /*tek_isriskname*/ + , tek_opportunityage /*tek_opportunityage*/ + , createdon /*createdon*/ + , createdbyname /*createdbyname*/ + , tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + , tek_laststatusdate /*tek_laststatusdate*/ + , tek_channelidname /*tek_channelidname*/ + , tek_tektronixapname /*tek_tektronixapname*/ + , tek_purchasemethodname /*tek_purchasemethodname*/ + , campaignidname /*campaignidname*/ + , tek_webvisitormedium /*tek_webvisitormedium*/ + , tek_webvisitorsource /*tek_webvisitorsource*/ + , tek_customerapplication /*tek_customerapplication*/ + , tek_vertical_segmentname /*tek_vertical_segmentname*/ + , tek_competitivestatusname /*tek_competitivestatusname*/ + , tek_importantopportunityname /*tek_importantopportunityname*/ + , tek_applicationidname /*tek_applicationidname*/ + , tek_industryidname /*tek_industryidname*/ + , estimatedclosedate /*estimatedclosedate*/ + , tek_taglist /*tek_taglist*/ + , discountamount /*discountamount*/ + , tek_terr_areaidname /*tek_terr_areaidname*/ + , tek_terr_branchidname /*tek_terr_branchidname*/ + , tek_extension /*tek_extension*/ + , tek_companynamelegal /*tek_companynamelegal*/ + , accountnumber /*accountnumber*/ + , tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + , tek_leadnumber /*tek_leadnumber*/ + , tek_contactnumber /*tek_contactnumber*/ + , parentaccountidname /*parentaccountidname*/ + , Scd_Start_Dt /*开始时间*/ + , Scd_End_Dt /*结束时间*/ + , Etl_Batch_No /*作业批次号*/ + , Etl_First_Dt /*最初入库时间*/ + , Etl_Job /*作业名称*/ + , Etl_Proc_Dt /*本次入库时间*/ + , Etl_Tx_Dt /*作业运行时间*/ + , Src_Sysname /*来源系统*/ + , Src_Table /*来源表*/ + , parentcontactidname /*parentcontactidname*/ + , tek_productidname /*tek_productidname*/ + , tek_productfamilyidname /*tek_productfamilyidname*/ + , transactioncurrencyidname /*transactioncurrencyidname*/ + ) +SELECT + P1.tek_opportunitynumber /*tek_opportunitynumber*/ + , P1.tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + , P1.tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + , P1.totaldiscountamount_base /*totaldiscountamount_base*/ + , P1.estimatedvalue_base /*estimatedvalue_base*/ + , P1.totalamount /*totalamount*/ + , P1.tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + , P1.tek_funnelstagenumber /*tek_funnelstagenumber*/ + , P1.statuscodename /*statuscodename*/ + , P1.statecodename /*statecodename*/ + , P1.tek_regionidname /*tek_regionidname*/ + , P1.name /*name*/ + , P1.tek_accountmanageridname /*tek_accountmanageridname*/ + , P1.tek_oppterritoryidname /*tek_oppterritoryidname*/ + , P1.tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + , P1.tek_isriskname /*tek_isriskname*/ + , P1.tek_opportunityage /*tek_opportunityage*/ + , P1.createdon /*createdon*/ + , P1.createdbyname /*createdbyname*/ + , P1.tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + , P1.tek_laststatusdate /*tek_laststatusdate*/ + , P1.tek_channelidname /*tek_channelidname*/ + , P1.tek_tektronixapname /*tek_tektronixapname*/ + , P1.tek_purchasemethodname /*tek_purchasemethodname*/ + , P1.campaignidname /*campaignidname*/ + , P1.tek_webvisitormedium /*tek_webvisitormedium*/ + , P1.tek_webvisitorsource /*tek_webvisitorsource*/ + , P1.tek_customerapplication /*tek_customerapplication*/ + , P1.tek_vertical_segmentname /*tek_vertical_segmentname*/ + , P1.tek_competitivestatusname /*tek_competitivestatusname*/ + , P1.tek_importantopportunityname /*tek_importantopportunityname*/ + , P1.tek_applicationidname /*tek_applicationidname*/ + , P1.tek_industryidname /*tek_industryidname*/ + , P1.estimatedclosedate /*estimatedclosedate*/ + , P1.tek_taglist /*tek_taglist*/ + , P1.discountamount /*discountamount*/ + , P1.tek_terr_areaidname /*tek_terr_areaidname*/ + , P1.tek_terr_branchidname /*tek_terr_branchidname*/ + , P1.tek_extension /*tek_extension*/ + , P1.tek_companynamelegal /*tek_companynamelegal*/ + , P1.accountnumber /*accountnumber*/ + , P1.tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + , P1.tek_leadnumber /*tek_leadnumber*/ + , P1.tek_contactnumber /*tek_contactnumber*/ + , P1.parentaccountidname /*parentaccountidname*/ + , P1.Scd_Start_Dt /*开始时间*/ + , P1.Scd_End_Dt /*结束时间*/ + , 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 /*来源表*/ + , P1.parentcontactidname /*parentcontactidname*/ + , P1.tek_productidname /*tek_productidname*/ + , P1.tek_productfamilyidname /*tek_productfamilyidname*/ + , P1.transactioncurrencyidname /*transactioncurrencyidname*/ + +FROM t01_crm_opportunity_agi_CUR_I P1 +LEFT JOIN t01_crm_opportunity_agi_CUR P2 + ON P1.tek_opportunitynumber = P2.tek_opportunitynumber + AND P1.Scd_Start_Dt = P2.Scd_Start_Dt + AND P1.name = P2.name + AND P1.tek_tektronixapname = P2.tek_tektronixapname + AND P1.estimatedclosedate = P2.estimatedclosedate + AND P1.parentaccountidname = P2.parentaccountidname + AND P1.parentcontactidname = P2.parentcontactidname + AND P1.tek_productidname = P2.tek_productidname + AND P1.tek_productfamilyidname = P2.tek_productfamilyidname + AND P1.transactioncurrencyidname = P2.transactioncurrencyidname + AND P1.tek_unitpricetotal_base = P2.tek_unitpricetotal_base + AND P1.tek_totaldiscountpercent = P2.tek_totaldiscountpercent + AND P1.totaldiscountamount_base = P2.totaldiscountamount_base + AND P1.estimatedvalue_base = P2.estimatedvalue_base + AND P1.totalamount = P2.totalamount + AND P1.tek_salesfunnelstagename = P2.tek_salesfunnelstagename + AND P1.tek_funnelstagenumber = P2.tek_funnelstagenumber + AND P1.statuscodename = P2.statuscodename + AND P1.statecodename = P2.statecodename + AND P1.tek_regionidname = P2.tek_regionidname + AND P1.tek_accountmanageridname = P2.tek_accountmanageridname + AND P1.tek_oppterritoryidname = P2.tek_oppterritoryidname + AND P1.tek_opp_includeinforecastname = P2.tek_opp_includeinforecastname + AND P1.tek_isriskname = P2.tek_isriskname + AND P1.tek_opportunityage = P2.tek_opportunityage + AND P1.createdon = P2.createdon + AND P1.createdbyname = P2.createdbyname + AND P1.tek_piplinelastupdatedon = P2.tek_piplinelastupdatedon + AND P1.tek_laststatusdate = P2.tek_laststatusdate + AND P1.tek_channelidname = P2.tek_channelidname + AND P1.tek_purchasemethodname = P2.tek_purchasemethodname + AND P1.campaignidname = P2.campaignidname + AND P1.tek_webvisitormedium = P2.tek_webvisitormedium + AND P1.tek_webvisitorsource = P2.tek_webvisitorsource + AND P1.tek_customerapplication = P2.tek_customerapplication + AND P1.tek_vertical_segmentname = P2.tek_vertical_segmentname + AND P1.tek_competitivestatusname = P2.tek_competitivestatusname + AND P1.tek_importantopportunityname = P2.tek_importantopportunityname + AND P1.tek_applicationidname = P2.tek_applicationidname + AND P1.tek_industryidname = P2.tek_industryidname + AND P1.tek_taglist = P2.tek_taglist + AND P1.discountamount = P2.discountamount + AND P1.tek_terr_areaidname = P2.tek_terr_areaidname + AND P1.tek_terr_branchidname = P2.tek_terr_branchidname + AND P1.tek_extension = P2.tek_extension + AND P1.tek_companynamelegal = P2.tek_companynamelegal + AND P1.accountnumber = P2.accountnumber + AND P1.tek_marketing_program_type_idname = P2.tek_marketing_program_type_idname + AND P1.tek_leadnumber = P2.tek_leadnumber + AND P1.tek_contactnumber = P2.tek_contactnumber + AND P2.ETL_Job =:ETLJOB +WHERE + P2.tek_opportunitynumber IS NULL + AND P2.Scd_Start_Dt IS NULL + AND P2.name IS NULL + AND P2.tek_tektronixapname IS NULL + AND P2.estimatedclosedate IS NULL + AND P2.parentaccountidname IS NULL + AND P2.parentcontactidname IS NULL + AND P2.tek_productidname IS NULL + AND P2.tek_productfamilyidname IS NULL + AND P2.transactioncurrencyidname IS NULL + AND P2.tek_unitpricetotal_base IS NULL + AND P2.tek_totaldiscountpercent IS NULL + AND P2.totaldiscountamount_base IS NULL + AND P2.estimatedvalue_base IS NULL + AND P2.totalamount IS NULL + AND P2.tek_salesfunnelstagename IS NULL + AND P2.tek_funnelstagenumber IS NULL + AND P2.statuscodename IS NULL + AND P2.statecodename IS NULL + AND P2.tek_regionidname IS NULL + AND P2.tek_accountmanageridname IS NULL + AND P2.tek_oppterritoryidname IS NULL + AND P2.tek_opp_includeinforecastname IS NULL + AND P2.tek_isriskname IS NULL + AND P2.tek_opportunityage IS NULL + AND P2.createdon IS NULL + AND P2.createdbyname IS NULL + AND P2.tek_piplinelastupdatedon IS NULL + AND P2.tek_laststatusdate IS NULL + AND P2.tek_channelidname IS NULL + AND P2.tek_purchasemethodname IS NULL + AND P2.campaignidname IS NULL + AND P2.tek_webvisitormedium IS NULL + AND P2.tek_webvisitorsource IS NULL + AND P2.tek_customerapplication IS NULL + AND P2.tek_vertical_segmentname IS NULL + AND P2.tek_competitivestatusname IS NULL + AND P2.tek_importantopportunityname IS NULL + AND P2.tek_applicationidname IS NULL + AND P2.tek_industryidname IS NULL + AND P2.tek_taglist IS NULL + AND P2.discountamount IS NULL + AND P2.tek_terr_areaidname IS NULL + AND P2.tek_terr_branchidname IS NULL + AND P2.tek_extension IS NULL + AND P2.tek_companynamelegal IS NULL + AND P2.accountnumber IS NULL + AND P2.tek_marketing_program_type_idname IS NULL + AND P2.tek_leadnumber IS NULL + AND P2.tek_contactnumber IS NULL + +; + + +INSERT INTO t01_crm_opportunity_agi_CUR_D ( + tek_opportunitynumber /*tek_opportunitynumber*/ + , tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + , tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + , totaldiscountamount_base /*totaldiscountamount_base*/ + , estimatedvalue_base /*estimatedvalue_base*/ + , totalamount /*totalamount*/ + , tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + , tek_funnelstagenumber /*tek_funnelstagenumber*/ + , statuscodename /*statuscodename*/ + , statecodename /*statecodename*/ + , tek_regionidname /*tek_regionidname*/ + , name /*name*/ + , tek_accountmanageridname /*tek_accountmanageridname*/ + , tek_oppterritoryidname /*tek_oppterritoryidname*/ + , tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + , tek_isriskname /*tek_isriskname*/ + , tek_opportunityage /*tek_opportunityage*/ + , createdon /*createdon*/ + , createdbyname /*createdbyname*/ + , tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + , tek_laststatusdate /*tek_laststatusdate*/ + , tek_channelidname /*tek_channelidname*/ + , tek_tektronixapname /*tek_tektronixapname*/ + , tek_purchasemethodname /*tek_purchasemethodname*/ + , campaignidname /*campaignidname*/ + , tek_webvisitormedium /*tek_webvisitormedium*/ + , tek_webvisitorsource /*tek_webvisitorsource*/ + , tek_customerapplication /*tek_customerapplication*/ + , tek_vertical_segmentname /*tek_vertical_segmentname*/ + , tek_competitivestatusname /*tek_competitivestatusname*/ + , tek_importantopportunityname /*tek_importantopportunityname*/ + , tek_applicationidname /*tek_applicationidname*/ + , tek_industryidname /*tek_industryidname*/ + , estimatedclosedate /*estimatedclosedate*/ + , tek_taglist /*tek_taglist*/ + , discountamount /*discountamount*/ + , tek_terr_areaidname /*tek_terr_areaidname*/ + , tek_terr_branchidname /*tek_terr_branchidname*/ + , tek_extension /*tek_extension*/ + , tek_companynamelegal /*tek_companynamelegal*/ + , accountnumber /*accountnumber*/ + , tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + , tek_leadnumber /*tek_leadnumber*/ + , tek_contactnumber /*tek_contactnumber*/ + , parentaccountidname /*parentaccountidname*/ + , Scd_Start_Dt /*开始时间*/ + , Scd_End_Dt /*结束时间*/ + , Etl_Batch_No /*作业批次号*/ + , Etl_First_Dt /*最初入库时间*/ + , Etl_Job /*作业名称*/ + , Etl_Proc_Dt /*本次入库时间*/ + , Etl_Tx_Dt /*作业运行时间*/ + , Src_Sysname /*来源系统*/ + , Src_Table /*来源表*/ + , parentcontactidname /*parentcontactidname*/ + , tek_productidname /*tek_productidname*/ + , tek_productfamilyidname /*tek_productfamilyidname*/ + , transactioncurrencyidname /*transactioncurrencyidname*/ + ) +SELECT + P1.tek_opportunitynumber /*tek_opportunitynumber*/ + , P1.tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + , P1.tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + , P1.totaldiscountamount_base /*totaldiscountamount_base*/ + , P1.estimatedvalue_base /*estimatedvalue_base*/ + , P1.totalamount /*totalamount*/ + , P1.tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + , P1.tek_funnelstagenumber /*tek_funnelstagenumber*/ + , P1.statuscodename /*statuscodename*/ + , P1.statecodename /*statecodename*/ + , P1.tek_regionidname /*tek_regionidname*/ + , P1.name /*name*/ + , P1.tek_accountmanageridname /*tek_accountmanageridname*/ + , P1.tek_oppterritoryidname /*tek_oppterritoryidname*/ + , P1.tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + , P1.tek_isriskname /*tek_isriskname*/ + , P1.tek_opportunityage /*tek_opportunityage*/ + , P1.createdon /*createdon*/ + , P1.createdbyname /*createdbyname*/ + , P1.tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + , P1.tek_laststatusdate /*tek_laststatusdate*/ + , P1.tek_channelidname /*tek_channelidname*/ + , P1.tek_tektronixapname /*tek_tektronixapname*/ + , P1.tek_purchasemethodname /*tek_purchasemethodname*/ + , P1.campaignidname /*campaignidname*/ + , P1.tek_webvisitormedium /*tek_webvisitormedium*/ + , P1.tek_webvisitorsource /*tek_webvisitorsource*/ + , P1.tek_customerapplication /*tek_customerapplication*/ + , P1.tek_vertical_segmentname /*tek_vertical_segmentname*/ + , P1.tek_competitivestatusname /*tek_competitivestatusname*/ + , P1.tek_importantopportunityname /*tek_importantopportunityname*/ + , P1.tek_applicationidname /*tek_applicationidname*/ + , P1.tek_industryidname /*tek_industryidname*/ + , P1.estimatedclosedate /*estimatedclosedate*/ + , P1.tek_taglist /*tek_taglist*/ + , P1.discountamount /*discountamount*/ + , P1.tek_terr_areaidname /*tek_terr_areaidname*/ + , P1.tek_terr_branchidname /*tek_terr_branchidname*/ + , P1.tek_extension /*tek_extension*/ + , P1.tek_companynamelegal /*tek_companynamelegal*/ + , P1.accountnumber /*accountnumber*/ + , P1.tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + , P1.tek_leadnumber /*tek_leadnumber*/ + , P1.tek_contactnumber /*tek_contactnumber*/ + , P1.parentaccountidname /*parentaccountidname*/ + , P1.Scd_Start_Dt /*开始时间*/ + , P1.Scd_End_Dt /*结束时间*/ + , 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 /*来源表*/ + , P1.parentcontactidname /*parentcontactidname*/ + , P1.tek_productidname /*tek_productidname*/ + , P1.tek_productfamilyidname /*tek_productfamilyidname*/ + , P1.transactioncurrencyidname /*transactioncurrencyidname*/ + +FROM t01_crm_opportunity_agi_CUR_I P1 +LEFT JOIN t01_crm_opportunity_agi_CUR P2 +ON P1.tek_opportunitynumber = P2.tek_opportunitynumber +AND P1.Scd_Start_Dt = P2.Scd_Start_Dt +WHERE P2.tek_opportunitynumber IS NULL + AND P2.Scd_Start_Dt IS NULL +AND P2.Scd_End_Dt = TO_DATE(:MAXDATE,'YYYYMMDD') +AND P2.ETL_Job = :ETLJOB +; + + +/*更新目标表中数据,对更新的数据进行封口,即置结束日期为TX_DATE */ +UPDATE :PDMDB.t01_crm_opportunity + SET Scd_End_Dt = TO_DATE(:TXDATE,'YYYYMMDD') + ,Etl_Tx_Dt=:TXDATE + ,Etl_Proc_Dt=CURRENT_TIMESTAMP(0) +WHERE Scd_End_Dt = TO_DATE(:MAXDATE, 'YYYYMMDD') + AND (:PDMDB.t01_crm_opportunity.ETL_Job = :ETLJOB) + AND ( tek_opportunitynumber , Scd_Start_Dt) +IN (SELECT tek_opportunitynumber , Scd_Start_Dt + FROM t01_crm_opportunity_agi_INS) + +/*根据比对条件将目标表中删除数据进行相应的处理 */ +;UPDATE :PDMDB.t01_crm_opportunity + SET Scd_End_Dt= TO_DATE(:TXDATE, 'YYYYMMDD') + ,Etl_Tx_Dt=:TXDATE + ,ETL_Proc_Dt=CURRENT_TIMESTAMP(0) + WHERE Scd_End_Dt=TO_DATE(:MAXDATE,'YYYYMMDD') + AND (:PDMDB.t01_crm_opportunity.ETL_Job = :ETLJOB) + AND ( tek_opportunitynumber , Scd_Start_Dt) +IN (SELECT + tek_opportunitynumber , Scd_Start_Dt +FROM t01_crm_opportunity_agi_CUR_D) +/*然后将新增的数据插入到目标表中,置开始日期为TX_DATE,结束日期置为MAXDATE */ +;INSERT INTO :PDMDB.t01_crm_opportunity ( + tek_opportunitynumber /*tek_opportunitynumber*/ + ,tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + ,tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + ,totaldiscountamount_base /*totaldiscountamount_base*/ + ,estimatedvalue_base /*estimatedvalue_base*/ + ,totalamount /*totalamount*/ + ,tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + ,tek_funnelstagenumber /*tek_funnelstagenumber*/ + ,statuscodename /*statuscodename*/ + ,statecodename /*statecodename*/ + ,tek_regionidname /*tek_regionidname*/ + ,name /*name*/ + ,tek_accountmanageridname /*tek_accountmanageridname*/ + ,tek_oppterritoryidname /*tek_oppterritoryidname*/ + ,tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + ,tek_isriskname /*tek_isriskname*/ + ,tek_opportunityage /*tek_opportunityage*/ + ,createdon /*createdon*/ + ,createdbyname /*createdbyname*/ + ,tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + ,tek_laststatusdate /*tek_laststatusdate*/ + ,tek_channelidname /*tek_channelidname*/ + ,tek_tektronixapname /*tek_tektronixapname*/ + ,tek_purchasemethodname /*tek_purchasemethodname*/ + ,campaignidname /*campaignidname*/ + ,tek_webvisitormedium /*tek_webvisitormedium*/ + ,tek_webvisitorsource /*tek_webvisitorsource*/ + ,tek_customerapplication /*tek_customerapplication*/ + ,tek_vertical_segmentname /*tek_vertical_segmentname*/ + ,tek_competitivestatusname /*tek_competitivestatusname*/ + ,tek_importantopportunityname /*tek_importantopportunityname*/ + ,tek_applicationidname /*tek_applicationidname*/ + ,tek_industryidname /*tek_industryidname*/ + ,estimatedclosedate /*estimatedclosedate*/ + ,tek_taglist /*tek_taglist*/ + ,discountamount /*discountamount*/ + ,tek_terr_areaidname /*tek_terr_areaidname*/ + ,tek_terr_branchidname /*tek_terr_branchidname*/ + ,tek_extension /*tek_extension*/ + ,tek_companynamelegal /*tek_companynamelegal*/ + ,accountnumber /*accountnumber*/ + ,tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + ,tek_leadnumber /*tek_leadnumber*/ + ,tek_contactnumber /*tek_contactnumber*/ + ,parentaccountidname /*parentaccountidname*/ + ,Scd_Start_Dt /*开始时间*/ + ,Scd_End_Dt /*结束时间*/ + ,Etl_Batch_No /*作业批次号*/ + ,Etl_First_Dt /*最初入库时间*/ + ,Etl_Job /*作业名称*/ + ,Etl_Proc_Dt /*本次入库时间*/ + ,Etl_Tx_Dt /*作业运行时间*/ + ,Src_Sysname /*来源系统*/ + ,Src_Table /*来源表*/ + ,parentcontactidname /*parentcontactidname*/ + ,tek_productidname /*tek_productidname*/ + ,tek_productfamilyidname /*tek_productfamilyidname*/ + ,transactioncurrencyidname /*transactioncurrencyidname*/ + ) +SELECT + P1.tek_opportunitynumber /*tek_opportunitynumber*/ + ,P1.tek_unitpricetotal_base /*tek_unitpricetotal_base*/ + ,P1.tek_totaldiscountpercent /*tek_totaldiscountpercent*/ + ,P1.totaldiscountamount_base /*totaldiscountamount_base*/ + ,P1.estimatedvalue_base /*estimatedvalue_base*/ + ,P1.totalamount /*totalamount*/ + ,P1.tek_salesfunnelstagename /*tek_salesfunnelstagename*/ + ,P1.tek_funnelstagenumber /*tek_funnelstagenumber*/ + ,P1.statuscodename /*statuscodename*/ + ,P1.statecodename /*statecodename*/ + ,P1.tek_regionidname /*tek_regionidname*/ + ,P1.name /*name*/ + ,P1.tek_accountmanageridname /*tek_accountmanageridname*/ + ,P1.tek_oppterritoryidname /*tek_oppterritoryidname*/ + ,P1.tek_opp_includeinforecastname /*tek_opp_includeinforecastname*/ + ,P1.tek_isriskname /*tek_isriskname*/ + ,P1.tek_opportunityage /*tek_opportunityage*/ + ,P1.createdon /*createdon*/ + ,P1.createdbyname /*createdbyname*/ + ,P1.tek_piplinelastupdatedon /*tek_piplinelastupdatedon*/ + ,P1.tek_laststatusdate /*tek_laststatusdate*/ + ,P1.tek_channelidname /*tek_channelidname*/ + ,P1.tek_tektronixapname /*tek_tektronixapname*/ + ,P1.tek_purchasemethodname /*tek_purchasemethodname*/ + ,P1.campaignidname /*campaignidname*/ + ,P1.tek_webvisitormedium /*tek_webvisitormedium*/ + ,P1.tek_webvisitorsource /*tek_webvisitorsource*/ + ,P1.tek_customerapplication /*tek_customerapplication*/ + ,P1.tek_vertical_segmentname /*tek_vertical_segmentname*/ + ,P1.tek_competitivestatusname /*tek_competitivestatusname*/ + ,P1.tek_importantopportunityname /*tek_importantopportunityname*/ + ,P1.tek_applicationidname /*tek_applicationidname*/ + ,P1.tek_industryidname /*tek_industryidname*/ + ,P1.estimatedclosedate /*estimatedclosedate*/ + ,P1.tek_taglist /*tek_taglist*/ + ,P1.discountamount /*discountamount*/ + ,P1.tek_terr_areaidname /*tek_terr_areaidname*/ + ,P1.tek_terr_branchidname /*tek_terr_branchidname*/ + ,P1.tek_extension /*tek_extension*/ + ,P1.tek_companynamelegal /*tek_companynamelegal*/ + ,P1.accountnumber /*accountnumber*/ + ,P1.tek_marketing_program_type_idname /*tek_marketing_program_type_idname*/ + ,P1.tek_leadnumber /*tek_leadnumber*/ + ,P1.tek_contactnumber /*tek_contactnumber*/ + ,P1.parentaccountidname /*parentaccountidname*/ + ,P1.Scd_Start_Dt /*开始时间*/ + ,P1.Scd_End_Dt /*结束时间*/ + ,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 /*来源表*/ + ,P1.parentcontactidname /*parentcontactidname*/ + ,P1.tek_productidname /*tek_productidname*/ + ,P1.tek_productfamilyidname /*tek_productfamilyidname*/ + ,P1.transactioncurrencyidname /*transactioncurrencyidname*/ + +FROM t01_crm_opportunity_agi_INS P1 +; + + +; + +; +/*****程序结束退出 */ +\q + diff --git a/dev/workflow/TK_Cust/tk_crm/泰克CRM/wf_dag_tk_crm.py b/dev/workflow/TK_Cust/tk_crm/泰克CRM/wf_dag_tk_crm.py index 363da3a..416df8a 100644 --- a/dev/workflow/TK_Cust/tk_crm/泰克CRM/wf_dag_tk_crm.py +++ b/dev/workflow/TK_Cust/tk_crm/泰克CRM/wf_dag_tk_crm.py @@ -193,6 +193,14 @@ depends_on_past=False, retries=3, dag=dag) +t01_crm_opportunity = SSHOperator( +ssh_hook=sshHook, +task_id='t01_crm_opportunity', +command='/data/airflow/etl/PDM/run_sa.sh {{ ds_nodash }} {{params.my_param}} >>/data/airflow/logs/run_tpt_{{ds_nodash}}.log 2>&1 ', +params={'my_param':"t01_crm_opportunity_agi"}, +depends_on_past=False, +retries=3, +dag=dag) file_CRM_account >> crm_account_4545 file_CRM_contact_ccp >> crm_contact_ccp_5681 file_CCP_mapping_table >> ccp_mapping_table_8972 @@ -203,4 +211,5 @@ ccp_mapping_table_8972 >> T01_CRM_CCP_TYPE crm_contact_part_605 >> t01_crm_contact crm_account_4545 >> t01_crm_account file_crm_opp >> crm_opp -crm_opp >> task_failed +crm_opp >> t01_crm_opportunity +t01_crm_opportunity >> task_failed