-- Databricks notebook source
-- 源表：DM.DM_TD_GEOGRAPHY,DWS.DWS_IMS_TD_GEO
-- 目标表：DM.DM_IMS_TD_GEO

-- COMMAND ----------

-- 20260119 地理数据 我感觉可以拉到前面去
--地理维度信息 AUDIT
-- 20260122 因为城市数据不再提供,改为硬编码省份数据. BY YUSUO/CHENWU
INSERT OVERWRITE TABLE DWS.DWS_IMS_TD_GEO
SELECT
	AUDIT_COD,
	AUDIT_DES,
	AUDIT_DES_C,
	AUDIT_TYPE,
	CITY_TIER,
	AZ_CITY_TIER,
	PROVINCE,
	PROVINCE_C,
	REGIONCENTER,
	ETL_INSERT_DT,
	ETL_UPDATE_DT
FROM 
	TMP.TMP_PROVINCE_RAWDATA

-- COMMAND ----------

CREATE OR REPLACE TEMPORARY VIEW DIM_PROVINCE 
AS
SELECT
  T2.PROVINCE_CODE,
  CASE
    WHEN T2.PROVINCE_NAME IN ('上海', '北京', '天津', '重庆') THEN CONCAT (T2.PROVINCE_NAME, '市')
    WHEN T2.PROVINCE_NAME IN ('内蒙古', '西藏') THEN CONCAT (T2.PROVINCE_NAME, '自治区')
    WHEN T2.PROVINCE_NAME = '宁夏' THEN CONCAT (T2.PROVINCE_NAME, '回族自治区')
    WHEN T2.PROVINCE_NAME = '广西' THEN CONCAT (T2.PROVINCE_NAME, '壮族自治区')
    WHEN T2.PROVINCE_NAME = '新疆' THEN CONCAT (T2.PROVINCE_NAME, '维吾尔自治区')
    ELSE CONCAT (T2.PROVINCE_NAME, '省')
  END AS PROVINCE_NAME
FROM
  DM.DM_TD_GEOGRAPHY T2
WHERE
  T2.GEO_KEY = T2.PROVINCE_CODE
  AND PROVINCE_NAME NOT IN ('台湾', '澳门', '香港')

-- COMMAND ----------

--DM 地理纬度表
INSERT OVERWRITE TABLE DM.DM_IMS_TD_GEO
SELECT DISTINCT
  T1.AUDIT_COD,
  T1.AUDIT_DES AS CITY,
  T1.AUDIT_DES_C AS CITY_C,
  T1.AUDIT_TYPE AS CITY_TYPE,
  T1.CITY_TIER,
  T1.AZ_CITY_TIER,
  T1.PROVINCE,
  T1.PROVINCE_C,
  T2.PROVINCE_CODE,
  T2.PROVINCE_NAME AS CITY_MAP,
  T2.PROVINCE_NAME,
  T1.REGIONCENTER AS REGION_CENTER,
  T1.ETL_INSERT_DT,
  T1.ETL_UPDATE_DT
FROM
  DWS.DWS_IMS_TD_GEO AS T1
  LEFT JOIN DIM_PROVINCE AS T2 ON T1.AUDIT_COD = T2.PROVINCE_CODE