new file: 02 dm_td_external_keycompatitor.sql new file: 03 dm_td_external_brand_market.sql new file: 04 dm_td_external_calendar.sql new file: 05 dm_td_external_exchangerate.sql new file: 07 dm_td_external_packinfo.sql new file: 08 dm_td_external_corp.sql new file: 09 dm_td_external_geo_type.sql new file: 11 DM_TD_EXTERNAL_MARKET_NEW.sql new file: 12 dm_td_external_org.sql new file: 13 external auth.sql new file: 14 dm_tf_external_retail_special_bkp.sql new file: AIA/01 dm_aia_pack_property.sql new file: AIA/02 dm_ext_aia_sales.sql new file: AIA/02 dm_ext_aia_sales_bakup_20230327.sql new file: AIA/03 dm_aia_flag.sql new file: AIA/04 dm_aia_provided_flag.sql new file: AIA/06 DM_TD_EXT_AIA_PACK_PROPERTY.sql new file: AIA/07 DM_TD_EXT_AIA_PACK2MARKET.sql new file: AIA/08 DM_TD_EXT_AIA_MARKET_RATIO.sql new file: AIA/09 DM_TD_EXT_AIA_MARKET_BRAND_RATIO.sql new file: AIA/10 DM_TD_EXT_AIA_MARKET_PACK_MAPPING.sql new file: AIA/11 DM_TD_EXT_AIA_TARGET_INST.sql new file: AIA/11 dm_aia_targethp_flag.sql new file: "AIA/z_03 dm_aia_flag_\345\244\207\344\273\275\347\224\250.sql" new file: CHC/01 dm_chc_pack_property.sql new file: CHC/02 DM_TF_EXT_CHC_SALES.sql new file: CHC/03 DM_TD_EXT_CHC_PACK_PROPERTY.sql new file: CHC/04 DM_TD_EXT_CHC_PACK2MARKET.sql new file: CHC/05 DM_TD_EXT_CHC_MARKET_RATIO.sql new file: CHC/06 DM_TD_EXT_CHC_MARKET_BRAND_RATIO.sql new file: CHC/07 DM_TD_EXT_CHC_MARKET_PACK_MAPPING.sql new file: CHPA/01 dwd_ims_atc_hierarchy.sql new file: CHPA/01 dwd_ims_nfc_hierarchy.sql new file: CHPA/01 dwd_ims_td_manufacturer_corp.sql new file: CHPA/01 dwd_ims_td_pack_property.sql new file: CHPA/01 dwd_update.sql new file: CHPA/01_FB_BLOB_TO_DWD.sql new file: CHPA/02 DWS_IMS_TD_GEO.sql new file: CHPA/02 dws_ims_td_atc_cn.sql new file: CHPA/02 dws_ims_td_corp_cn.sql new file: CHPA/02 dws_ims_td_date.sql new file: CHPA/02 dws_ims_td_manu_cn.sql new file: CHPA/02 dws_ims_td_market.sql new file: CHPA/02 dws_ims_td_market_ta.sql new file: CHPA/02 dws_ims_td_nfc_cn.sql new file: CHPA/02 dws_ims_td_prod_cn.sql new file: CHPA/02 tmp_ims_td_prod_tmp.sql new file: CHPA/02 tmp_ims_tf_fact_sales.sql new file: CHPA/03 DM_TD_EXT_CHPA_MARKET_BRAND_RATIO.sql new file: CHPA/03 DM_TD_EXT_CHPA_MARKET_PACK_MAPPING.sql new file: CHPA/03 DM_TD_EXT_CHPA_MARKET_RATIO.sql new file: CHPA/03 DM_TD_EXT_CHPA_PACK2MARKET.sql new file: CHPA/03 DM_TD_EXT_CHPA_PACK_PROPERTY.sql new file: CHPA/03 DM_TF_EXT_CHPA_SALES.sql new file: CHPA/03 dm_ims_td_calendar.sql new file: CHPA/03 dm_ims_td_geo.sql new file: CHPA/03 dm_ims_td_market_property.sql new file: CHPA/03 dm_ims_td_org.sql new file: CHPA/03 dm_ims_td_org_hvh.sql new file: CHPA/03 dm_ims_td_pack_property.sql new file: CHPA/03 dm_ims_tf_sales.sql new file: CHPA/03 dm_td_chpa_market_definition.sql new file: CHPA/03 dm_td_ims_city_mapping.sql new file: EC/03 ec_load_data.sql new file: EC/04 DM_TD_EXT_EC_PACK_PROPERTY.sql new file: EC/05 DM_TF_EXT_EC_SALES.sql new file: EC/06 DM_TD_EXT_EC_PACK2MARKET.sql new file: EC/07 DM_TD_EXT_EC_MARKET_RATIO.sql new file: EC/08 DM_TD_EXT_EC_MARKET_BRAND_RATIO.sql new file: EC/09 DM_TD_EXT_EC_MARKET_PACK_MAPPING.sql new file: EC/1 (ec)blob_to_dwd.sql new file: EC/2 dwd_inc_gnd_ext_ec_nationnal_pack_union_all.py new file: Merged_Data/Merged_Data_Config_table_bkp.sql new file: Merged_Data/Merged_Data_Config_table_bymonth.sql new file: Merged_Data/dm_tf_exteranl_sales_merged_data_dtp_others_bkp.sql new file: Merged_Data/dm_tf_exteranl_sales_merged_data_dtp_others_bymonth_bkp.sql new file: ORG/DM_TD_EXT_AIA_ORG.sql new file: ORG/DM_TD_EXT_CHC_ORG.sql new file: ORG/DM_TD_EXT_CHPA_ORG.sql new file: ORG/DM_TD_EXT_COUNTY_ORG.sql new file: ORG/DM_TD_EXT_EC_ORG.sql new file: ORG/DM_TD_EXT_RETAIL_ORG.sql new file: ORG/DM_TD_EXT_THC_ORG.sql new file: ORG/DM_TD_EXT_XIEHE_ORG.sql new file: OTHERS/01 dm_td_report_url.sql new file: OTHERS/02 dws_ext_email_warning.sql new file: OTHERS/external_triggered_email.py new file: Retail/01 load_tmp_data.py new file: Retail/02 split_brand_data.py new file: Retail/03 split_pack_data.py new file: Retail/04 map_to_dws_table.py new file: Retail/05 load_dtp_temp_data.py new file: Retail/06 split_dtp_brand_data.py new file: Retail/07 split_dtp_pack_data.py new file: Retail/08 map_to_dtp_dws_table.py new file: Retail/09 dwd_inc_gnd_ext_retail_nataional.py new file: Retail/10 map_to_retail_dm_table.py new file: Retail/11 map_to_overview_dm_table.py new file: Retail/12 dws_tf_external_retail_dtp_special.sql new file: Retail/13 DM_TF_EXT_RETAIL_SALES.sql new file: Retail/14 DM_TF_EXT_RETAIL_DTP_SALES.sql new file: Retail/15 DM_TD_EXT_RETAIL_PACK_PROPERTY.sql new file: Retail/16 DM_TD_EXT_RETAIL_DTP_PACK_PROPERTY.sql new file: Retail/17 DM_TD_EXT_DTP_PACK2MARKET.sql new file: Retail/17 DM_TD_EXT_RETAIL_PACK2MARKET.sql new file: Retail/18 DM_TD_EXT_DTP_MARKET_RATIO.sql new file: Retail/18 DM_TD_EXT_RETAIL_MARKET_RATIO.sql new file: Retail/19 DM_TD_EXT_DTP_MARKET_BRAND_RATIO.sql new file: Retail/19 DM_TD_EXT_RETAIL_MARKET_BRAND_RATIO.sql new file: Retail/20 DM_TD_EXT_DTP_MARKET_PACK_MAPPING.sql new file: Retail/20 DM_TD_EXT_RETAIL_MARKET_PACK_MAPPING.sql new file: "Retail/z1 dwd_inc_gnd_ext_retail_nataional_\344\275\234\345\272\237.py" new file: "Retail/z2 retail_load_data_\344\275\234\345\272\237.sql" new file: "Retail/z3 retail_overview_data_\344\275\234\345\272\237.sql" new file: THC/01 dm_thc_pack_property.sql new file: THC/02 dm_ext_thc_sales.sql new file: THC/02 dm_ext_thc_sales_bakup_20260327.sql new file: THC/03 DM_TF_EXT_THC_MARKET_SALES_CHT.sql new file: THC/04 dm_tf_external_sales_thc.sql new file: THC/05 DM_TD_EXT_THC_PACK_PROPERTY.sql new file: THC/06 DM_TD_EXT_THC_PACK2MARKET.sql new file: THC/07 DM_TD_EXT_THC_MARKET_RATIO.sql new file: THC/08 DM_TD_EXT_THC_MARKET_BRAND_RATIO.sql new file: THC/09 DM_TD_EXT_THC_MARKET_PACK_MAPPING.sql new file: UNIONALL/DM_TD_EXT_UNIONALL_MARKET_PACK_MAPPING.sql new file: UNIONALL/DM_TD_EXT_UNIONALL_PACKINFO.sql new file: UNIONALL/DM_TF_EXT_UNIONALL_MARKET_SALES.sql new file: UNIONALL/DM_TF_EXT_UNIONALL_MARKET_SALES_v1.0.sql new file: UNIONALL/DM_TF_EXT_UNIONALL_SALES.sql new file: UNIONALL/DM_TF_EXT_UNIONALL_SALES_MAPPING.sql new file: UNIONALL/DM_TF_EXT_UNIONALL_SALES_MAPPING_NIAD.sql new file: XIEHE/01 xiehe_blob_to_dwd.py new file: XIEHE/02 dm_xiehe_pack_property.sql new file: XIEHE/03 dm_ext_xiehe_geo.sql new file: XIEHE/04 dm_ext_xiehe_sales.sql new file: XIEHE/05 dm_td_xiehe_core_dept.sql new file: XIEHE/06 DM_TF_EXT_XIEHE_SALES.sql new file: XIEHE/07 DM_TD_EXT_XIEHE_PACK_PROPERTY.sql new file: XIEHE/08 DM_TD_EXT_XIEHE_PACK2MARKET.sql new file: XIEHE/09 DM_TD_EXT_XIEHE_MARKET_RATIO.sql new file: XIEHE/10 DM_TD_EXT_XIEHE_MARKET_BRAND_RATIO.sql new file: XIEHE/11 DM_TD_EXT_XIEHE_MARKET_PACK_MAPPING.sql new file: XIEHE/bkp_01 xiehe_blob2dwd.py new file: XIEHE/bkp_02 dm_ext_xiehe_sales.sql new file: XIEHE/bkp_03 dm_ext_xiehe_pack_property.sql new file: county/01 tmp_ims_county_fact_sales_sum.sql new file: county/02 tmp_imscounty_Result.sql new file: county/03 dm_ims_td_county_geo.sql new file: county/04 dws_ext_county_tf_sales.sql new file: county/05 dm_ext_county_td_pack_property.sql new file: county/06 dm_td_county_pack_region.sql new file: county/07 dm_ext_county_tf_sales_region.sql new file: county/08 DM_TD_EXT_COUNTY_PACK_PROPERTY.sql new file: county/09 DM_TF_EXT_COUNTY_SALES.sql new file: county/10 DM_TD_EXT_COUNTY_PACK2MARKET.sql new file: county/11 DM_TD_EXT_COUNTY_MARKET_RATIO.sql new file: county/12 DM_TD_EXT_COUNTY_MARKET_BRAND_RATIO.sql new file: county/13 DM_TD_EXT_COUNTY_MARKET_PACK_MAPPING.sql new file: for_AIA_Dashboard/01 dm_td_aia_inst_mkt.sql new file: for_AIA_Dashboard/02 dm_td_aia_auth_sales.sql new file: for_AIA_Dashboard/03 dm_td_aia_original_col.sql new file: for_AIA_Dashboard/04 dm_td_aia_nosales_inst.sql new file: for_AIA_Dashboard/05 dm_td_aia_is_eagle_flag.sql new file: for_AIA_Dashboard/06 dm_td_aia_rank.sql new file: for_AIA_Dashboard/07 dm_ext_aia_data_remove_flag.sql new file: for_AIA_Dashboard/07 dm_td_aia_remove_special_ins_bkp.py new file: for_AIA_Dashboard/08 dm_ext_aia_data_quality_flag.sql new file: z 01 dm_tf_external_sales.sql new file: "z 10 dm_td_external_market_pack_mapping_\344\275\234\345\272\237.sql" new file: "z 11 dm_td_external_market_\344\275\234\345\272\237.sql" new file: "\344\270\212\347\272\277\350\204\232\346\234\254.sql" new file: "\346\225\260\346\215\256\351\252\214\350\257\201.sql"
1230 lines
39 KiB
SQL
1230 lines
39 KiB
SQL
-- Databricks notebook source
|
||
-- log 20250226 auth:庄伟
|
||
-- MA和AIA权限表改造如下
|
||
--1.MA销售权限表(dm.dm_auth_sales_ta),通过辖区中销售负责的产品(Family)找到对应的TA,然后按照权限矩阵的限制对用户所能看到的BU进行筛选
|
||
-- Market Analysis_CHPA 全BU可看
|
||
-- Market Analysis_County 除BU:EC以外可以看
|
||
-- Market Analysis_CHC 除BU:EC&RDU 以外可以看
|
||
-- Market Analysis_THC 除BU:EC&RDU 以外可以看
|
||
-- Market Analysis_Retail/DTP 除BU:EC&RDU 以外可以看
|
||
-- Market Analysis_EC 仅EC可看 --修改 全BU可看
|
||
-- Market Analysis_AIA 除BU:EC以外可以看
|
||
-- Market Analysis_科室市场数据 全BU可看
|
||
|
||
--2.MA和AIA非销售权限表,按照workmate和mds用户申请的权限看
|
||
-- dm.dm_auth_nonsales_ta 直接按照用户申请的TA权限查看
|
||
-- dm.dm_auth_nonsales_org 根据用户申请的Sub_bu/BU转换为TA权限查看
|
||
|
||
-- log 20251105 auth:chenwu
|
||
-- MA和AIA权限范围修改 dm.dm_auth_sales_ta
|
||
-- Market Analysis_AIA 除BU:EC,Retail以外可以看
|
||
-- Market Analysis_科室市场数据 除BU:EC以外可以看
|
||
-- Market Analysis_Retail/DTP 除BU: EC以外可以看
|
||
|
||
-- COMMAND ----------
|
||
|
||
--for ec into retail
|
||
create or replace temporary view dm_td_org_temp
|
||
as
|
||
SELECT org_key,mr_trty_tag,district_code,rsm_name,rc_name,p2.region_name,p2.rsd_kcode,p2.rsd_name
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.bu_code = 'PC12' then 'PC09' else p2.bu_code end bu_code
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.bu_report = 'EC' THEN 'Retail' ELSE p2.bu_report end bu_report
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.sub_bu_code = 'NA27' then 'NA06' else p2.sub_bu_code end sub_bu_code
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.sub_bu_name = 'EC' then 'Retail' else p2.sub_bu_name end sub_bu_name
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.sub_bu_name_en = 'EC' then 'Retail' else p2.sub_bu_name_en end sub_bu_name_en
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.bu_name = 'EC' then 'Retail' else p2.bu_name end bu_name
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.nsd_kcode = 'ND_EC0001_V' then 'KSGX559' else p2.nsd_kcode end nsd_kcode
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.nsd_trty_code = 'ND_EC0001' then 'ND_RT0001' else p2.nsd_trty_code end nsd_trty_code
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.bsd_kcode = 'VP_EC0001_V' then 'VP_RT0001_V' else p2.bsd_kcode end bsd_kcode
|
||
,CASE WHEN p2.yyyymm >= '202601' and p2.bsd_trty_code = 'VP_EC0001' then 'VP_RT0001' else p2.bsd_trty_code end bsd_trty_code
|
||
,p2.rsm_kcode,p2.rc_code,p2.rc_name_en,p2.region_code,p2.region_name_en,BU_CATEGORY,yyyymm,mr_trty_code
|
||
,mr_kcode,dsm_trty_code,rsm_trty_code,dsm_kcode,rsd_trty_code
|
||
FROM DM.dm_td_org P2
|
||
|
||
-- COMMAND ----------
|
||
|
||
------销售权限
|
||
---从C月辖区中提取USER与TA映射
|
||
drop view if exists tmp_auth_sales_user_ta_mapping;
|
||
create temporary view tmp_auth_sales_user_ta_mapping
|
||
as
|
||
(
|
||
select
|
||
bu_active_list.bm_name,
|
||
org.bu_code,
|
||
org.bu_name,
|
||
org.sub_bu_code,
|
||
org.sub_bu_name,
|
||
org.dsm_trty_code,
|
||
org.dsm_kcode,
|
||
org.rsm_trty_code,
|
||
org.rsm_kcode,
|
||
org.rsd_trty_code,
|
||
org.rsd_kcode,
|
||
org.nsd_trty_code,
|
||
org.nsd_kcode,
|
||
org.rc_code,
|
||
prod.ta_code,
|
||
case when prod.ta_name ='ONC' then 'ONCO' else prod.ta_name end ta_name
|
||
from
|
||
(
|
||
select distinct
|
||
yyyymm,
|
||
trty_code,
|
||
family_code
|
||
from dm.dm_td_sd_territory_indication
|
||
where yyyymm in(
|
||
select key_value as yyyymm
|
||
from dm.dm_td_date_config
|
||
where key_code = 'pfmc_cvh'
|
||
) and bu not in ('CUBE','KA') and family_code not in ('RTRT','ECEC')
|
||
and key_hp<>3 --chenwu 20250904 排除双考影响
|
||
)trty_ind_c
|
||
left join dm.dm_td_product prod
|
||
on trty_ind_c.family_code = prod.prd_key
|
||
left join dm_td_org_temp org
|
||
on trty_ind_c.yyyymm = org.yyyymm and trty_ind_c.trty_code = org.mr_trty_code
|
||
left join dws.dws_td_bu_active bu_active_list
|
||
on org.bu_name =bu_active_list.bu_name
|
||
);
|
||
|
||
-- COMMAND ----------
|
||
|
||
insert overwrite table dm.dm_auth_sales_ta
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
data_source,
|
||
concat(ta,data_source) ta_source,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt
|
||
from
|
||
(
|
||
----chpa 1
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'IQVIA-CHPA(Monthly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
)auth_chpa
|
||
----county 2
|
||
union
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'IQVIA-COUNTY(Quarterly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where
|
||
-- bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where
|
||
-- bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where
|
||
-- bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where
|
||
-- bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
)auth_county
|
||
----chc 3
|
||
union
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'CHC(Quarterly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('RDU','EC')
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('RDU','EC')
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
)auth_chc
|
||
----thc 4
|
||
union
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'THC(Quarterly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('RDU','EC')
|
||
bu_name not in ('RDU') and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('RDU','EC')
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('RDU','EC')
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('RDU','EC')
|
||
bu_name not in ('RDU')
|
||
and not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
)auth_thc
|
||
union
|
||
----retail 5
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'Retail(Quarterly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
)auth_retail
|
||
----ec 6
|
||
union
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'EC(Monthly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
-- where --bu_name ='EC'
|
||
-- -- (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
-- not (bu_name in ('Retail') and rc_code in ('RC198')) -- EC 改成和CHPA一样, 全BU可看 20260305 yusuo
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
-- where --bu_name ='EC'
|
||
-- -- (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
-- not (bu_name in ('Retail') and rc_code in ('RC198')) -- EC 改成和CHPA一样, 全BU可看 20260305 yusuo
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
-- where --bu_name ='EC'
|
||
-- -- (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
-- not (bu_name in ('Retail') and rc_code in ('RC198')) -- EC 改成和CHPA一样, 全BU可看 20260305 yusuo
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
-- where --bu_name ='EC'
|
||
-- -- (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
-- not (bu_name in ('Retail') and rc_code in ('RC198')) -- EC 改成和CHPA一样, 全BU可看 20260305 yusuo
|
||
)auth_ec
|
||
----aia 7
|
||
union
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'AIA(Monthly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where bu_name not in ('Retail','EC')
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where bu_name not in ('Retail','EC')
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where bu_name not in ('Retail','EC')
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where bu_name not in ('Retail','EC')
|
||
)auth_aia
|
||
----xiehe 8
|
||
union
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'XH Data(Quarterly)' data_source
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
)auth_xiehe
|
||
)auth_sales_ta
|
||
|
||
----DTP 9
|
||
union all
|
||
select
|
||
bu_name,
|
||
user_trty_code,
|
||
user_kcode,
|
||
ta,
|
||
role,
|
||
'DTP(Quarterly)' data_source,
|
||
concat(ta,data_source) ta_source,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt
|
||
from
|
||
(
|
||
--dsm
|
||
select
|
||
bu_name,
|
||
dsm_trty_code user_trty_code,
|
||
dsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'dsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsm
|
||
select
|
||
bu_name,
|
||
rsm_trty_code user_trty_code,
|
||
rsm_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsm' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--rsd
|
||
select
|
||
bu_name,
|
||
rsd_trty_code user_trty_code,
|
||
rsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'rsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
union
|
||
--nsd
|
||
select
|
||
bu_name,
|
||
nsd_trty_code user_trty_code,
|
||
nsd_kcode user_kcode,
|
||
ta_name ta,
|
||
'nsd' role
|
||
from tmp_auth_sales_user_ta_mapping
|
||
where --bu_name not in ('EC')
|
||
not (bu_name in ('Retail') and rc_code in ('RC198')) --架构中 EC 合并到 Retail 调整 20260127
|
||
)auth_retail
|
||
|
||
;
|
||
|
||
|
||
-- COMMAND ----------
|
||
|
||
-----非销售权限 用户申请的TA维度权限
|
||
insert overwrite table dm.dm_auth_nonsales_ta
|
||
select
|
||
user_kcode,
|
||
user_role,
|
||
ta_code,
|
||
case when ta_name ='ONC' then 'ONCO' else ta_name end ta_name,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt
|
||
from
|
||
(
|
||
select distinct user_kcode,role user_role,ta_code,ta_name
|
||
from dm.dm_td_user_permission_derived
|
||
where nvl(ta_name,'')<>''
|
||
)nonsales_ta;
|
||
|
||
-- COMMAND ----------
|
||
|
||
drop view if exists tmp_auth_sales_bu_ta_mapping;
|
||
create temporary view tmp_auth_sales_bu_ta_mapping
|
||
as
|
||
(
|
||
select distinct bu_code,bu_name,sub_bu_code,sub_bu_name,ta_code,ta_name
|
||
from tmp_auth_sales_user_ta_mapping
|
||
);
|
||
|
||
-- COMMAND ----------
|
||
|
||
-----用户申请的BU维度权限转换为架构中负责的TA
|
||
insert overwrite table dm.dm_auth_nonsales_org
|
||
select
|
||
coalesce(subbu_ta_map.bu_code,nonsales_subbu.bu_code) bu_code,
|
||
coalesce(subbu_ta_map.bu_name,nonsales_subbu.bu_name) bu_name,
|
||
nonsales_subbu.user_kcode,
|
||
nonsales_subbu.user_role,
|
||
coalesce(subbu_ta_map.sub_bu_code,nonsales_subbu.sub_bu_code) sub_bu_code,
|
||
coalesce(subbu_ta_map.sub_bu_name,nonsales_subbu.sub_bu_name) sub_bu_name,
|
||
subbu_ta_map.ta_code,
|
||
subbu_ta_map.ta_name,
|
||
'SUB_BU' row_tag,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt
|
||
from
|
||
(
|
||
select
|
||
distinct
|
||
user_kcode,
|
||
role user_role,
|
||
bu_code,
|
||
bu_name,
|
||
sub_bu_code,
|
||
sub_bu_name
|
||
from dm.dm_td_user_permission_detail
|
||
where nvl(sub_bu_code,'')<>''
|
||
)nonsales_subbu
|
||
left join
|
||
(
|
||
select bu_code,bu_name,sub_bu_code,sub_bu_name,ta_code,ta_name
|
||
from tmp_auth_sales_bu_ta_mapping
|
||
)subbu_ta_map
|
||
on nonsales_subbu.sub_bu_code = subbu_ta_map.sub_bu_code
|
||
union
|
||
select
|
||
nonsales_bu.user_kcode,
|
||
nonsales_bu.user_role,
|
||
coalesce(bu_ta_map.bu_code,nonsales_bu.bu_code) bu_code,
|
||
coalesce(bu_ta_map.bu_name,nonsales_bu.bu_name) bu_name,
|
||
bu_ta_map.sub_bu_code,
|
||
bu_ta_map.sub_bu_name,
|
||
bu_ta_map.ta_code,
|
||
bu_ta_map.ta_name,
|
||
'BU' row_tag,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_insert_dt,
|
||
from_utc_timestamp(current_timestamp,'UTC+8') as etl_update_dt
|
||
from
|
||
(
|
||
select
|
||
distinct
|
||
user_kcode,
|
||
role user_role,
|
||
bu_code,
|
||
bu_name
|
||
from dm.dm_td_user_permission_detail
|
||
where nvl(sub_bu_code,'')='' and nvl(bu_code,'')<>''
|
||
)nonsales_bu
|
||
left join
|
||
(
|
||
select distinct bu_code,bu_name,sub_bu_code,sub_bu_name,ta_code,ta_name
|
||
from tmp_auth_sales_bu_ta_mapping
|
||
)bu_ta_map
|
||
on nonsales_bu.bu_code = bu_ta_map.bu_code;
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- DBTITLE 1,old version
|
||
-- insert overwrite dm.dm_auth_geo(KCODE,CITY_CODE)
|
||
-- select distinct
|
||
-- t1.k_account as KCODE,
|
||
-- t2.AUDIT_COD as CITY_CODE
|
||
-- from (
|
||
-- select K_ACCOUNT,
|
||
-- USER_NAME,
|
||
-- Province_GEO
|
||
-- from dm.DM_TD_SPECIAL_GROUP
|
||
-- where ROLE = 'PI_GEO_IMS'
|
||
-- and length(Province_GEO) > 0
|
||
-- ) t1
|
||
-- join
|
||
-- (
|
||
-- select distinct
|
||
-- PROVINCE_C,
|
||
-- AUDIT_COD
|
||
-- from dm.DM_IMS_TD_GEO
|
||
-- where length(AUDIT_COD) > 0
|
||
-- ) t2
|
||
-- on t1.Province_GEO = t2.PROVINCE_C
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- insert overwrite dm.dm_auth_org(KCODE,SUB_BU_CODE)
|
||
-- select
|
||
-- t1.user_kcode as KCODE,
|
||
-- t2.SUB_BU_CODE as SUB_BU_CODE
|
||
-- from (
|
||
-- select K_ACCOUNT as user_kcode,
|
||
-- bu_org as BU_NAME
|
||
-- from dm.DM_TD_SPECIAL_GROUP
|
||
-- where ROLE = 'PI_ORG_IMS'
|
||
-- and length(bu_org) > 0
|
||
-- ) t1
|
||
-- join (
|
||
-- select distinct
|
||
-- BU_NAME,
|
||
-- SUB_BU_CODE
|
||
-- from DM.DM_TD_ORG
|
||
-- ) t2
|
||
-- on t1.BU_NAME = t2.BU_NAME
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- ---------------------------------------------------------------------------
|
||
-- --修改时间:20241112
|
||
-- --修改人:Fanxujia
|
||
-- --修改内容:
|
||
-- --for AIA Dashboard:
|
||
-- --1)MA报告没有权限,旧AIA报告有权限:增加旧AIA报告的权限人员,以旧AIA报告的范围开权限(by TA)
|
||
-- --2)MA报告有权限,旧AIA报告也有权限:以旧AIA报告权限范围为准
|
||
-- --3)MA报告有权限,旧AIA报告没有权限:保持不变
|
||
-- ---------------------------------------------------------------------------
|
||
-- with AIA_USERS as (
|
||
-- select
|
||
-- distinct gu.k_account as KCODE,
|
||
-- upper(rg.ta_prd) as TA_PRD
|
||
-- from
|
||
-- dm.DM_TD_GROUP_USERS gu
|
||
-- join dm.DM_TD_REPORT_GROUP rg on gu.user_team = rg.user_group
|
||
-- where
|
||
-- rg.role = 'PI_PRD_CPA'
|
||
-- and length(rg.ta_prd) > 0
|
||
-- union
|
||
-- SELECT distinct
|
||
-- K_ACCOUNT as KCODE,
|
||
-- upper(TA_PRD) as TA_PRD
|
||
-- FROM
|
||
-- dm.DM_TD_SPECIAL_GROUP
|
||
-- WHERE
|
||
-- ROLE = 'PI_PRD_CPA'
|
||
-- AND length(TA_PRD) > 0
|
||
-- )
|
||
|
||
-- ,CHPA_USERS as (
|
||
-- select
|
||
-- distinct gu.k_account as KCODE,
|
||
-- upper(rg.ta_prd) as TA_PRD
|
||
-- from
|
||
-- dm.DM_TD_GROUP_USERS gu
|
||
-- join dm.DM_TD_REPORT_GROUP rg on gu.user_team = rg.user_group
|
||
-- where
|
||
-- rg.role = 'PI_PRD_IMS'
|
||
-- and length(rg.ta_prd) > 0
|
||
-- union
|
||
-- SELECT distinct
|
||
-- K_ACCOUNT as KCODE,
|
||
-- upper(TA_PRD) as TA_PRD
|
||
-- FROM
|
||
-- dm.DM_TD_SPECIAL_GROUP
|
||
-- WHERE
|
||
-- ROLE = 'PI_PRD_IMS'
|
||
-- AND length(TA_PRD) > 0
|
||
-- )
|
||
|
||
-- ,ALL_USERS as (
|
||
-- --单独CHPA用户
|
||
-- select distinct
|
||
-- KCODE,
|
||
-- TA_PRD
|
||
-- from CHPA_USERS
|
||
-- where KCODE not in (
|
||
-- select KCODE from AIA_USERS
|
||
-- )
|
||
-- union
|
||
-- --1:单独AIA用户
|
||
-- --2:同时存在于CHPA以及AIA的用户,以AIA的权限为准
|
||
-- select distinct
|
||
-- KCODE,
|
||
-- TA_PRD
|
||
-- from AIA_USERS
|
||
-- )
|
||
|
||
-- ,TA_MARKET as (
|
||
-- SELECT
|
||
-- DISTINCT TA,
|
||
-- MARKET
|
||
-- FROM
|
||
-- dm.dm_td_external_market_pack_mapping_temp
|
||
-- WHERE
|
||
-- length(TA) > 0
|
||
-- )
|
||
|
||
|
||
-- insert overwrite dm.dm_auth_prd(
|
||
-- KCODE,
|
||
-- MARKET
|
||
-- )
|
||
-- select distinct
|
||
-- t1.KCODE,
|
||
-- t2.MARKET
|
||
-- from ALL_USERS t1
|
||
-- inner join TA_MARKET t2
|
||
-- on t1.TA_PRD = t2.TA
|
||
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- ------------------------------------------------------------------------
|
||
-- --修改时间:20241108
|
||
-- --修改人:Fanxujia
|
||
-- --修改内容:
|
||
-- --增加产品粒度的权限表
|
||
-- ------------------------------------------------------------------------
|
||
-- insert overwrite table dm.dm_auth_prd_pack
|
||
-- (
|
||
-- KCODE,
|
||
-- PACK_COD
|
||
-- )
|
||
-- with market_pack as (
|
||
-- select distinct
|
||
-- PACK_COD,
|
||
-- MARKET
|
||
-- from dm.dm_td_external_market_pack_mapping
|
||
-- )
|
||
|
||
-- select distinct
|
||
-- t1.KCODE,
|
||
-- t2.PACK_COD
|
||
-- from dm.dm_auth_prd t1
|
||
-- inner join market_pack t2
|
||
-- on t1.MARKET = t2.MARKET
|
||
|
||
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- --------------------------------chpa--------------------------------------------------------------------
|
||
-- ------------------所有BU能看CHPA,用户需要排除非重点城市之外的人
|
||
-- insert overwrite dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- WITH EMP AS (
|
||
-- select distinct dsm_kcode KCODE,concat(bu_code,'IQVIA-CHPA(Monthly)') as bu_code_auth,bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat(bu_code,'IQVIA-CHPA(Monthly)') as bu_code_auth,bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat(bu_code,'IQVIA-CHPA(Monthly)') as bu_code_auth,bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat(bu_code,'IQVIA-CHPA(Monthly)') as bu_code_auth,bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 --and audit_cod is not null
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'IQVIA-CHPA(Monthly)') MKT_SOURCE,concat(B.AUDIT_COD,'IQVIA-CHPA(Monthly)') AUDIT_SOURCE
|
||
-- ,'IQVIA-CHPA(Monthly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- ----------------------------------------------------CHC------------------------------------------------------------------------------
|
||
-- -----------------------CHC的人能看
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- with emp as (
|
||
-- select distinct dsm_kcode KCODE,concat(bu_code,'CHC(Quarterly)') as bu_code_auth,'' bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) AND BU_NAME_EN = 'CHC'
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat(bu_code,'CHC(Quarterly)') as bu_code_auth,'' bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 AND BU_NAME_EN = 'CHC'
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat(bu_code,'CHC(Quarterly)') as bu_code_auth,'' bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 AND BU_NAME_EN = 'CHC'
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat(bu_code,'CHC(Quarterly)') as bu_code_auth,'' bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 AND BU_NAME_EN = 'CHC'
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'CHC(Quarterly)') MKT_SOURCE,concat(B.AUDIT_COD,'CHC(Quarterly)') AUDIT_SOURCE
|
||
-- ,'CHC(Quarterly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org ) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- ----------------------------------------------------county------------------------------------------------------------------------------
|
||
-- -----------------------除了Eagle、CHC、Retail、EC的人都能看
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- with emp as (
|
||
-- select distinct dsm_kcode KCODE,concat('','IQVIA-COUNTY(Quarterly)') bu_code_auth,'' bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) AND BU_NAME_EN NOT IN ('Eagle','CHC','EC','Retail')
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat('','IQVIA-COUNTY(Quarterly)') bu_code_auth,'' bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 AND BU_NAME_EN NOT IN ('Eagle','CHC','EC','Retail')
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat('','IQVIA-COUNTY(Quarterly)') bu_code_auth,'' bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 AND BU_NAME_EN NOT IN ('Eagle','CHC','EC','Retail')
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat('','IQVIA-COUNTY(Quarterly)') bu_code_auth,'' bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 AND BU_NAME_EN NOT IN ('Eagle','CHC','EC','Retail')
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'IQVIA-COUNTY(Quarterly)') MKT_SOURCE,concat(B.AUDIT_COD,'IQVIA-COUNTY(Quarterly)') AUDIT_SOURCE
|
||
-- ,'IQVIA-COUNTY(Quarterly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org ) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- ----------------------------------------------------THC------------------------------------------------------------------------------
|
||
-- -----------------------Eagle的人能看
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- with emp as (
|
||
-- select distinct dsm_kcode KCODE,concat('','THC(Quarterly)') as bu_code_auth,'' bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) AND BU_NAME_EN = 'Eagle'
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat('','THC(Quarterly)') as bu_code_auth,'' bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 AND BU_NAME_EN = 'Eagle'
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat('','THC(Quarterly)') as bu_code_auth,'' bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 AND BU_NAME_EN = 'Eagle'
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat('','THC(Quarterly)') as bu_code_auth,'' bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 AND BU_NAME_EN = 'Eagle'
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'THC(Quarterly)') MKT_SOURCE,concat(B.AUDIT_COD,'THC(Quarterly)') AUDIT_SOURCE
|
||
-- ,'THC(Quarterly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org ) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- --------------------------------Retail--------------------------------------------------------------------
|
||
-- ------------------------------------------------
|
||
-- --修改时间:20241016
|
||
-- --修改人:FanXujia
|
||
-- --修改内容:
|
||
-- --给Eagle的人查看Metoprolol Tartrate Market的权限
|
||
-- -------------------------------------------------
|
||
-- ------------------所有BU能看CHPA,用户需要排除非重点城市之外的人
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- with emp as (
|
||
-- select distinct dsm_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) and bu_name_en in ('Retail','OBU')
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 and bu_name_en in ('Retail','OBU')
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 and bu_name_en in ('Retail','OBU')
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 and bu_name_en in ('Retail','OBU')
|
||
-- )
|
||
-- ,Eagle as (
|
||
-- select distinct dsm_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) and bu_name_en in ('Eagle')
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 and bu_name_en in ('Eagle')
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 and bu_name_en in ('Eagle')
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat('PC09','Retail(Quarterly)') as bu_code_auth,bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 and bu_name_en in ('Eagle')
|
||
-- )
|
||
-- ,audit as (
|
||
-- select distinct t1.AUDIT_COD
|
||
-- from dm.dm_tf_external_sales t1
|
||
-- left join dm.dm_td_external_market_pack_mapping_temp t2
|
||
-- on t1.DATA_SOURCE = t2.DATA_SOURCE
|
||
-- and t1.PACK_COD = t2.PACK_COD
|
||
-- where t1.DATA_SOURCE = 'Retail(Quarterly)'
|
||
-- and t2.MARKET = 'Metoprolol Tartrate Market'
|
||
-- )
|
||
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'Retail(Quarterly)') MKT_SOURCE,concat(B.AUDIT_COD,'Retail(Quarterly)') AUDIT_SOURCE
|
||
-- ,'Retail(Quarterly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org ) B ON A.bu_code_auth = B.bu_code_auth
|
||
-- union all
|
||
-- select t1.KCODE,
|
||
-- t1.bu_code_auth,
|
||
-- t1.bu_name,
|
||
-- t1.role,
|
||
-- concat('Metoprolol Tartrate Market','Retail(Quarterly)') MKT_SOURCE,
|
||
-- concat(t2.AUDIT_COD,'Retail(Quarterly)') AUDIT_SOURCE,
|
||
-- 'Retail(Quarterly)' DATA_SOURCE
|
||
-- from Eagle t1
|
||
-- cross join audit t2
|
||
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- --------------------------------EC--------------------------------------------------------------------
|
||
-- ------------------EC的数据暂时开通给EC
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- with emp as (
|
||
-- select distinct dsm_kcode KCODE,concat('','EC(Monthly)') as bu_code_auth,bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) and bu_name_en = 'EC'
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat('','EC(Monthly)') as bu_code_auth,bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 and bu_name_en = 'EC'
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat('','EC(Monthly)') as bu_code_auth,bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 and bu_name_en = 'EC'
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat('','EC(Monthly)') as bu_code_auth,bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 and bu_name_en = 'EC'
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'EC(Monthly)') MKT_SOURCE,concat(B.AUDIT_COD,'EC(Monthly)') AUDIT_SOURCE
|
||
-- ,'EC(Monthly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org ) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- --------------------------------AIA--------------------------------------------------------------------
|
||
-- ------------------所有BU能看AIA
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- WITH EMP AS (
|
||
-- select distinct dsm_kcode KCODE,concat(bu_code,'AIA(Monthly)') as bu_code_auth,bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat(bu_code,'AIA(Monthly)') as bu_code_auth,bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat(bu_code,'AIA(Monthly)') as bu_code_auth,bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat(bu_code,'AIA(Monthly)') as bu_code_auth,bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 --and audit_cod is not null
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'AIA(Monthly)') MKT_SOURCE,concat(B.AUDIT_COD,'AIA(Monthly)') AUDIT_SOURCE
|
||
-- ,'AIA(Monthly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- --------------------------------XIEHE--------------------------------------------------------------------
|
||
-- ------------------所有BU能看XIEHE
|
||
-- insert into dm.dm_auth_sales(KCODE,bu_code_auth,bu_name,role,MKT_SOURCE,AUDIT_SOURCE,DATA_SOURCE)
|
||
-- WITH EMP AS (
|
||
-- select distinct dsm_kcode KCODE,concat(bu_code,'XH Data(Quarterly)') as bu_code_auth,bu_name,'dsm' role from DM.DM_IMS_TD_ORG_HVH where length(dsm_kcode) > 0 and yyyymm=(select max(yyyymm) from DM.DM_IMS_TD_ORG_HVH) --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct rsm_kcode KCODE,concat(bu_code,'XH Data(Quarterly)') as bu_code_auth,bu_name,'rsm' role from DM.DM_IMS_TD_ORG where length(rsm_kcode) > 0 --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct rsd_kcode KCODE,concat(bu_code,'XH Data(Quarterly)') as bu_code_auth,bu_name,'rsd' role from DM.DM_IMS_TD_ORG where length(rsd_kcode) > 0 --and audit_cod is not null
|
||
-- union all
|
||
-- select distinct nsd_kcode KCODE,concat(bu_code,'XH Data(Quarterly)') as bu_code_auth,bu_name,'nsd' role from DM.DM_IMS_TD_ORG where length(nsd_kcode) > 0 --and audit_cod is not null
|
||
-- )
|
||
-- SELECT A.KCODE,A.bu_code_auth,A.bu_name,A.role,concat(B.MARKET,'XH Data(Quarterly)') MKT_SOURCE,concat(B.AUDIT_COD,'XH Data(Quarterly)') AUDIT_SOURCE
|
||
-- ,'XH Data(Quarterly)' DATA_SOURCE FROM EMP A
|
||
-- INNER JOIN (SELECT DISTINCT bu_code_auth,AUDIT_COD,MARKET FROM DM.dm_td_external_org) B ON A.bu_code_auth = B.bu_code_auth
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- -------------------------------------------------------------------------
|
||
-- --修改时间:20241106
|
||
-- --修改人:Fanxujia
|
||
-- --修改内容:
|
||
-- --将PBI的逻辑移到DBR上(dm_auth_sales_geo)
|
||
-- -------------------------------------------------------------------------
|
||
-- insert overwrite table dm.dm_auth_sales_geo(
|
||
-- KCODE,
|
||
-- AUDIT_SOURCE
|
||
-- )
|
||
-- select
|
||
-- distinct KCODE,
|
||
-- AUDIT_SOURCE
|
||
-- from
|
||
-- dm.dm_auth_sales
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- -------------------------------------------------------------------------
|
||
-- --修改时间:20241106
|
||
-- --修改人:Fanxujia
|
||
-- --修改内容:
|
||
-- --将PBI的逻辑移到DBR上(dm_auth_sales_mkt)
|
||
-- -------------------------------------------------------------------------
|
||
-- insert overwrite table dm.dm_auth_sales_mkt(
|
||
-- KCODE,
|
||
-- MKT_SOURCE
|
||
-- )
|
||
-- select
|
||
-- distinct KCODE,
|
||
-- MKT_SOURCE
|
||
-- from
|
||
-- dm.dm_auth_sales
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- -------------------------------------------------------------------------
|
||
-- --修改时间:20241106
|
||
-- --修改人:Fanxujia
|
||
-- --修改内容:
|
||
-- --将PBI的逻辑移到DBR上(dm_auth_sales_org)
|
||
-- -------------------------------------------------------------------------
|
||
-- insert overwrite table dm.dm_auth_sales_org(
|
||
-- KCODE,
|
||
-- BU_CODE_AUTH
|
||
-- )
|
||
-- select
|
||
-- distinct KCODE,
|
||
-- BU_CODE_AUTH
|
||
-- from
|
||
-- dm.dm_auth_sales
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- DBTITLE 1,old version
|
||
-- -------------------------------------------------------------------------
|
||
-- --修改时间:20241106
|
||
-- --修改人:Fanxujia
|
||
-- --修改内容:
|
||
-- --将PBI的逻辑移到DBR上(dm_auth_sales_pack)
|
||
-- -------------------------------------------------------------------------
|
||
-- insert overwrite table dm.dm_auth_sales_pack(
|
||
-- KCODE,
|
||
-- PACK_SOURCE
|
||
-- )
|
||
-- with market_pack as (
|
||
-- select distinct
|
||
-- concat(MARKET,DATA_SOURCE) as MKT_SOURCE,
|
||
-- concat(PACK_COD,DATA_SOURCE) as PACK_SOURCE
|
||
-- from dm.dm_td_external_market_pack_mapping
|
||
-- )
|
||
-- ,user_market as (
|
||
-- select distinct KCODE,MKT_SOURCE
|
||
-- from dm.dm_auth_sales
|
||
-- )
|
||
|
||
-- select distinct
|
||
-- t1.KCODE,
|
||
-- t2.PACK_SOURCE
|
||
-- from user_market t1
|
||
-- inner join market_pack t2
|
||
-- on t1.MKT_SOURCE = t2.MKT_SOURCE
|
||
|
||
-- COMMAND ----------
|
||
|
||
-- MAGIC %md
|
||
-- MAGIC ### -------------------------
|
||
|
||
-- COMMAND ----------
|
||
|
||
------------------------------------------------------------------------
|
||
--修改时间:20241112
|
||
--修改人:Fanxujia
|
||
--修改内容:
|
||
--CHPA渠道不显示以下几个BU的架构 ('BBU_County','CHC','EC','Eagle','Retail')
|
||
------------------------------------------------------------------------
|
||
delete from DM.DM_TD_EXTERNAL_ORG
|
||
where bu_name_en in ('BBU_County','CHC','EC','Retail')
|
||
and data_source = 'IQVIA-CHPA(Monthly)';
|
||
/*
|
||
修改时间:20251124
|
||
修改人:Chenwu
|
||
修改内容:CHPA数据源,消化口服产品(Nexium Oral, Losec Oral)架构需要增加Eagle团队
|
||
*/
|
||
WITH market_list AS (
|
||
SELECT DISTINCT m.MARKET
|
||
FROM dws.dws_ims_td_market m
|
||
INNER JOIN dwd.dwd_td_imscode_azcode a ON m.PACK_COD = a.ims_pack_cod
|
||
WHERE a.brandcode IN ('B018','B019')
|
||
AND a.ims_pack_cod IS NOT NULL
|
||
)
|
||
DELETE FROM DM.DM_TD_EXTERNAL_ORG
|
||
WHERE data_source = 'IQVIA-CHPA(Monthly)'
|
||
AND bu_name_en = 'Eagle'
|
||
AND MARKET NOT IN (SELECT MARKET FROM market_list);
|
||
|
||
-- COMMAND ----------
|
||
|
||
---------------------------------------------------------------------------
|
||
--修改时间:20240828
|
||
--修改人:FanXujia
|
||
--修改内容:
|
||
--同一个城市的同一个市场同时对应了正常的大区以及ROC,这是不对的,需要把ROC的数据删除
|
||
----------------------------------------------------------------------------
|
||
with org as (
|
||
select distinct DATA_SOURCE,AUDIT_COD,MARKET,'ROC' as region_name_en
|
||
from DM.DM_TD_EXTERNAL_ORG
|
||
where region_name_en <> 'ROC'
|
||
)
|
||
|
||
merge into DM.DM_TD_EXTERNAL_ORG as t1
|
||
using org t2
|
||
on t1.DATA_SOURCE = t2.DATA_SOURCE
|
||
and t1.AUDIT_COD = t2.AUDIT_COD
|
||
and t1.MARKET = t2.MARKET
|
||
and t1.region_name_en = t2.region_name_en
|
||
when matched then
|
||
delete ;
|
||
|
||
-- COMMAND ----------
|
||
|
||
---------------------------------------------------------------------------
|
||
--修改时间:20240828
|
||
--修改人:FanXujia
|
||
--修改内容:
|
||
--在上一步删除完之后
|
||
--同一个城市的同一个市场只对应ROC,但是有多条数据对应ROC,保留1条数据,其余的删除
|
||
----------------------------------------------------------------------------
|
||
with org_1 as (
|
||
select DATA_SOURCE,AUDIT_COD,MARKET
|
||
from DM.DM_TD_EXTERNAL_ORG
|
||
where region_name_en = 'ROC'
|
||
group by DATA_SOURCE,AUDIT_COD,MARKET
|
||
having count(1) >1
|
||
)
|
||
,org_2 as (
|
||
select t1.DATA_SOURCE,t1.AUDIT_COD,t1.MARKET,
|
||
max(concat(t1.RSM_Name,t1.rc_name,t1.regioncenter,t1.bu_category,t1.bu_name_en,t1.sub_bu_name,t1.sub_bu_code_auth,t1.bu_code_auth,t1.MR_TRTY_CODE)) link_key
|
||
from DM.DM_TD_EXTERNAL_ORG t1
|
||
inner join org_1 t2
|
||
on t1.DATA_SOURCE = t2.DATA_SOURCE
|
||
and t1.AUDIT_COD = t2.AUDIT_COD
|
||
and t1.MARKET = t2.MARKET
|
||
group by t1.DATA_SOURCE,t1.AUDIT_COD,t1.MARKET
|
||
)
|
||
|
||
merge into DM.DM_TD_EXTERNAL_ORG as t1
|
||
using org_2 t2
|
||
on t1.DATA_SOURCE = t2.DATA_SOURCE
|
||
and t1.AUDIT_COD = t2.AUDIT_COD
|
||
and t1.MARKET = t2.MARKET
|
||
and concat(t1.RSM_Name,t1.rc_name,t1.regioncenter,t1.bu_category,t1.bu_name_en,t1.sub_bu_name,t1.sub_bu_code_auth,t1.bu_code_auth,t1.MR_TRTY_CODE) <> t2.link_key
|
||
when matched then
|
||
delete ; |