add workflow 天润dynamic邮件同步,dev
This commit is contained in:
		
							parent
							
								
									df1d2f5eb3
								
							
						
					
					
						commit
						fda9b7bc9c
					
				|  | @ -4,7 +4,7 @@ | |||
| /*Brilliance stems from wisdoms.                                                                   */ | ||||
| /*************Head Section**************************************************************************/ | ||||
| /*Script Use: Periodically load data to :f_ccc_work_ticket_integ(smartccc工单信息集成)             */ | ||||
| /*Create Date:2024-12-31 16:49:33                                                                  */ | ||||
| /*Create Date:2024-12-31 19:14:23                                                                  */ | ||||
| /*SDM Developed By: dev                                                                            */ | ||||
| /*SDM Developed Date: 2024-07-09                                                                   */ | ||||
| /*SDM Checked By: dev                                                                              */ | ||||
|  | @ -118,14 +118,14 @@ SELECT | |||
|         ,coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements(p1.customize::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'name') = '职位'),'')        /*JOB_TITLE*/ | ||||
|         ,	 coalesce(p3.city,(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')         /*CITY*/ | ||||
|         ,coalesce(p2.prov_name,p3.province,'')                     /*STATE_COUNTY_LOCATION*/ | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')        /*CITY*/ | ||||
|         ,coalesce(p2.prov_name,'')                                 /*STATE_COUNTY_LOCATION*/ | ||||
|         ,'CN'                                                      /*COUNTRY_CODE*/ | ||||
|         ,coalesce(p3.postnumber,p2.postalcode,'')                  /*POSTAL_CODE*/ | ||||
|         ,coalesce(p2.postalcode,'')                                /*POSTAL_CODE*/ | ||||
|         ,coalesce(find_first_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[]),find_first_not_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[]),'null')        /*CONTACT_MOBILE_NUMBER*/ | ||||
|         ,coalesce(p1.email,'')                                     /*EMAIL_ADDRESS*/ | ||||
|         ,'YES'                                                     /*REQUEST_A_DEMO*/ | ||||
|  | @ -225,16 +225,6 @@ LEFT JOIN :PDMDB.t00_china_city_info  p2 | |||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')::text||'%' else '' end | ||||
| LEFT JOIN :PDMDB.t00_china_city_postnum  p3 | ||||
|         ON 	 p3.full_name  like case when length(coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')::text)>0 then coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')::text||'%' else '' end | ||||
| where p0.state_selected in ('Leads') and p0.update_time >= current_date - interval '7 days' | ||||
| 
 | ||||
| ; | ||||
|  | @ -410,6 +400,196 @@ where p0 .state_selected ='TW_leads' and p0.update_time >= current_date - interv | |||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*****************************************************************************************************/ | ||||
| /* GROUP 3:Source Table:t01_ccc_work_ticket_info******************************************************/ | ||||
| /*****************************************************************************************************/ | ||||
| 
 | ||||
| INSERT INTO f_ccc_work_ticket_integ_agi_CUR_I ( | ||||
|             PEXTENSION_CODE                         /*来源代码*/ | ||||
|            ,PEXTENSION                              /*来源*/ | ||||
|            ,LAST_NAME                               /*姓名*/ | ||||
|            ,SUFFIX                                  /*工单ID*/ | ||||
|            ,COMPANY_NAME                            /*公司名称*/ | ||||
|            ,JOB_TITLE                               /*职位*/ | ||||
|            ,CITY                                    /*城市*/ | ||||
|            ,STATE_COUNTY_LOCATION                   /*省份*/ | ||||
|            ,COUNTRY_CODE                            /*国家*/ | ||||
|            ,POSTAL_CODE                             /*邮编*/ | ||||
|            ,CONTACT_MOBILE_NUMBER                   /*电话*/ | ||||
|            ,EMAIL_ADDRESS                           /*邮箱*/ | ||||
|            ,REQUEST_A_DEMO                          /*demo标志*/ | ||||
|            ,REQUEST_A_QUOTE                         /*引用标志*/ | ||||
|            ,HAMCAM                                  /*账户管理员标志*/ | ||||
|            ,PURCHASE_INTENT                         /*购买意向*/ | ||||
|            ,COMMENTS                                /*备注*/ | ||||
|            ,INDUSTRY                                /*行业*/ | ||||
|            ,CCP_PRODUCT_INTEREST_01                 /*产品偏好*/ | ||||
|            ,CCP_APP_01_5                            /*应用*/ | ||||
|            ,LEAD_PRODUCTS_01_5                      /*产品型号*/ | ||||
|            ,PERMISSION_PHONE                        /*电话授权标志*/ | ||||
|            ,PERMISSION_PHONE_DATE                   /*电话授权时间*/ | ||||
|            ,PERMISSION_EMAIL                        /*电子邮件授权标志*/ | ||||
|            ,PERMISSION_EMAIL_DATE                   /*电子邮件授权时间*/ | ||||
|            ,PERMISSION_MAIL                         /*邮件授权标志*/ | ||||
|            ,PERMISSION_MAIL_DATE                    /*邮件授权时间*/ | ||||
|            ,PERMISSION_SMS                          /*SMS授权标志*/ | ||||
|            ,PERMISSION_SMS_DATE                     /*SMS授权时间*/ | ||||
|            ,AGREES_TO_PRIVACY_POLICY                /*个人信息授权标志*/ | ||||
|            ,PORTAL_TERMS_AGREEMENT_DATE             /*协议授权时间*/ | ||||
|            ,CONSENT_TO_COLLECT_PERSONAL_INFO        /*个人信息收集标志*/ | ||||
|            ,CONSENT_TO_COLLECT_PERSONAL_INFO_DATE   /*个人信息收集时间*/ | ||||
|            ,MARKETING_CONSENT                       /*MARKETING_CONSENT*/ | ||||
|            ,MARKETING_CONSENT_DATE                  /*MARKETING_CONSENT_DATE*/ | ||||
|            ,MEANS_OF_CONSENT                        /*MEANS_OF_CONSENT*/ | ||||
|            ,SOURCE_OF_CONSENT                       /*SOURCE_OF_CONSENT*/ | ||||
|            ,VERSION_OF_PRIVACY_NOTICE               /*VERSION_OF_PRIVACY_NOTICE*/ | ||||
|            ,RECORD_OF_CONSENT                       /*RECORD_OF_CONSENT*/ | ||||
|            ,EXACT_CONSENT_LANGUAGE                  /*EXACT_CONSENT_LANGUAGE*/ | ||||
|            ,BRAND_TEKTRONIX                         /*BRAND_TEKTRONIX*/ | ||||
|            ,BRAND_SSO                               /*BRAND_SSO*/ | ||||
|            ,BRAND_KEITHLEY                          /*BRAND_KEITHLEY*/ | ||||
|            ,EMAIL_PREFERENCE                        /*EMAIL_PREFERENCE*/ | ||||
|            ,Src_Sysname                             /*来源系统*/ | ||||
|            ,Etl_Job                                 /*作业名称*/ | ||||
|            ,Src_Table                               /*来源表*/ | ||||
|            ,Etl_Tx_Dt                               /*作业运行时间*/ | ||||
|            ,Etl_First_Dt                            /*最初入库时间*/ | ||||
|            ,Etl_Proc_Dt                             /*本次入库时间*/ | ||||
|            ,Etl_Batch_No                            /*作业批次号*/ | ||||
|            ,second_mobile_number                    /*第二手机号*/ | ||||
|            ,company_phone_number                    /*固话号*/ | ||||
|         ) | ||||
| SELECT | ||||
|          case when coalesce(p0.start_form::json->>'formName','') ='选型报价_Outbound' then '449662X449662'  | ||||
|         else coalesce(case when p0."source" ='0' then '305972X317938' | ||||
|       when p0."source" ='11' then '445769X445769' | ||||
|       else '401890X401890' end,'') end        /*PEXTENSION_CODE*/ | ||||
|         ,coalesce(p1."source",'')                                  /*PEXTENSION*/ | ||||
|         ,''                                                        /*LAST_NAME*/ | ||||
|         ,coalesce(p0.id,'')                                        /*SUFFIX*/ | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '305038'),'')||(case when coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297756'),'') = '' then '' else ',Enduser: '||coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297756'),'') end)        /*COMPANY_NAME*/ | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements(p1.customize::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'name') = '职位'),'')        /*JOB_TITLE*/ | ||||
|         ,coalesce(p3.full_name,(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')        /*CITY*/ | ||||
|         ,coalesce(p3.province,'')                                  /*STATE_COUNTY_LOCATION*/ | ||||
|         ,'CN'                                                      /*COUNTRY_CODE*/ | ||||
|         ,coalesce(p3.postnumber,'')                                /*POSTAL_CODE*/ | ||||
|         ,coalesce(find_first_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[]),find_first_not_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[]),'null')        /*CONTACT_MOBILE_NUMBER*/ | ||||
|         ,coalesce(p1.email,'')                                     /*EMAIL_ADDRESS*/ | ||||
|         ,'YES'                                                     /*REQUEST_A_DEMO*/ | ||||
|         ,'YES'                                                     /*REQUEST_A_QUOTE*/ | ||||
|         ,'YES'                                                     /*HAMCAM*/ | ||||
|         ,4                                                         /*PURCHASE_INTENT*/ | ||||
|         ,'L - mql '||case when p0.workflow_name ='CN离线工单_选型报价' then  coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298245 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 297757),'') else coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298245 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 298246),'') end ||' 预算情况:'||coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298245 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 303805),' None ')||';决策权确认:'||coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298245 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 303806),' None ')||';计划购买时间:'||coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298245 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 298249),' None ')||';'        /*COMMENTS*/ | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_297729 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 297729),'')        /*INDUSTRY*/ | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298247 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 298247),'')        /*CCP_PRODUCT_INTEREST_01*/ | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_297730 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 297730),'')        /*CCP_APP_01_5*/ | ||||
|         ,coalesce((SELECT jsonb_extract_path_text(field, 'value') AS value_298300 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 304927),(SELECT jsonb_extract_path_text(field, 'value') AS value_298300 | ||||
| FROM ( | ||||
|   SELECT jsonb_array_elements(p0.start_form::jsonb->'fields') AS field | ||||
| ) AS t | ||||
| WHERE jsonb_extract_path_text(field, 'id')::int = 299137),'')        /*LEAD_PRODUCTS_01_5*/ | ||||
|         ,'YES'                                                     /*PERMISSION_PHONE*/ | ||||
|         ,p0.create_time                                            /*PERMISSION_PHONE_DATE*/ | ||||
|         ,'YES'                                                     /*PERMISSION_EMAIL*/ | ||||
|         ,p0.create_time                                            /*PERMISSION_EMAIL_DATE*/ | ||||
|         ,'YES'                                                     /*PERMISSION_MAIL*/ | ||||
|         ,p0.create_time                                            /*PERMISSION_MAIL_DATE*/ | ||||
|         ,'YES'                                                     /*PERMISSION_SMS*/ | ||||
|         ,p0.create_time                                            /*PERMISSION_SMS_DATE*/ | ||||
|         ,'YES'                                                     /*AGREES_TO_PRIVACY_POLICY*/ | ||||
|         ,p0.create_time                                            /*PORTAL_TERMS_AGREEMENT_DATE*/ | ||||
|         ,'YES'                                                     /*CONSENT_TO_COLLECT_PERSONAL_INFO*/ | ||||
|         ,p0.create_time                                            /*CONSENT_TO_COLLECT_PERSONAL_INFO_DATE*/ | ||||
|         ,''                                                        /*MARKETING_CONSENT*/ | ||||
|         ,TO_TIMESTAMP(:NULLDATE,'YYYYMMDD')                        /*MARKETING_CONSENT_DATE*/ | ||||
|         ,''                                                        /*MEANS_OF_CONSENT*/ | ||||
|         ,''                                                        /*SOURCE_OF_CONSENT*/ | ||||
|         ,''                                                        /*VERSION_OF_PRIVACY_NOTICE*/ | ||||
|         ,''                                                        /*RECORD_OF_CONSENT*/ | ||||
|         ,''                                                        /*EXACT_CONSENT_LANGUAGE*/ | ||||
|         ,''                                                        /*BRAND_TEKTRONIX*/ | ||||
|         ,''                                                        /*BRAND_SSO*/ | ||||
|         ,''                                                        /*BRAND_KEITHLEY*/ | ||||
|         ,''                                                        /*EMAIL_PREFERENCE*/ | ||||
|         ,Substr('t01_ccc_work_ticket_info',1,3)                    /*Src_Sysname*/ | ||||
|         ,:ETLJOB                                                   /*Etl_Job*/ | ||||
|         ,'t01_ccc_work_ticket_info'                                /*Src_Table*/ | ||||
|         ,TO_DATE(:TXDATE,'YYYYMMDD')                               /*Etl_Tx_Dt*/ | ||||
|         ,TO_DATE(:TXDATE,'YYYYMMDD')                               /*Etl_First_Dt*/ | ||||
|         ,current_timestamp(0)                                      /*Etl_Proc_Dt*/ | ||||
|         ,0                                                         /*Etl_Batch_No*/ | ||||
|         ,case when cardinality(array_remove(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[],find_first_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[])))=0 then '' | ||||
| else find_first_phone_number(array_remove(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[],find_first_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[]))) | ||||
| end        /*second_mobile_number*/ | ||||
|         ,coalesce(find_first_not_phone_number(replace(replace(replace(p1.tel,'"',''),'[','{'),']','}')::text[]),'')        /*company_phone_number*/ | ||||
|          | ||||
| FROM :PDMDB.t01_ccc_work_ticket_info  p0 | ||||
| LEFT JOIN :PDMDB.t01_ccc_cust_info  p1 | ||||
|         ON p0.customer_id =p1.id | ||||
| LEFT JOIN (SELECT * FROM :PDMDB.t00_china_city_postnum where full_name like '%-%') p3 | ||||
|         ON p3.full_name  = case when length(coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')::text)>0 then coalesce((SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '304585'),(SELECT jsonb_extract_path_text(j, 'value')  | ||||
|    FROM jsonb_array_elements((p0.start_form::json -> 'fields')::jsonb) j  | ||||
|    WHERE jsonb_extract_path_text(j, 'id') = '297755'),'')::text else '' end | ||||
| where p0.state_selected in ('Leads') and p3.full_name like '%-%' and p0.update_time >= current_date - interval '7 days' | ||||
| 
 | ||||
| ; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*将不同数据插入到临时表                                                                           */ | ||||
| ;INSERT INTO f_ccc_work_ticket_integ_agi_INS ( | ||||
|          PEXTENSION_CODE                                           /*来源代码*/ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue