Commit 1bedcdf0 by 江名洋

feat(etl): 新增策略记录表同步及员工日宽表重构

1 parent 6b8d7232
......@@ -45,6 +45,8 @@ class ETLService:
('dj_car_life_merchant_output_target_config', 'ods_merchant_output_target_config', 'id', True),
# --- 成交率表 ---
('employee_delivery_deal_rate', 'ods_employee_delivery_deal_rate', 'id', True),
# --- 策略记录表 ---
('dj_car_life_strategy_info', 'ods_strategy_info', 'id', True),
]
# 数仓各层表的时间维度字段映射 (用于删除旧数据)
......@@ -555,25 +557,76 @@ class ETLService:
@staticmethod
def _get_sql_staff_daily_wide(start, end):
filter_str = f"AND report_date BETWEEN '{start}' AND '{end}'" if start and end else ""
filter_str = f"AND sdrh.report_date BETWEEN '{start}' AND '{end}'" if start and end else ""
return f"""
INSERT IGNORE INTO dws_staff_daily_wide (
INSERT INTO dws_staff_daily_wide (
report_date, merchant_id, merchant_name, store_code,
province_id, province_name, city_id, city_name, area_name, region, channel_type,
area_supervision, online_supervision, flight_supervision,
staff_uuid, staff_name, phone_number,
scene_type, first_brand_id, first_brand_name, brand_id, brand_name,
on_break, delivery_count, not_delivery_count,
equity_to_shop_count, extended_warranty_to_shop_count, real_equity_to_shop_count,
after_sale_equity_to_shop_count, after_sale_extended_warranty_to_shop_count, after_sale_real_equity_to_shop_count,
total_order_count, extended_warranty_count, tire_warranty_count, ax_package_count,
battery_extended_warranty_count, battery_extended_warranty_money,
total_order_money, cancel_order_count, cancel_order_money,
staff_count, to_shop_film_count, template_type,
etl_date
)
SELECT
sdrh.report_date, sdrh.merchant_id, sm.merchant_name, sm.store_code,
sm.province_id, sm.province_name, sm.city_id, sm.city_name, sm.area_name, sm.region, sm.channel_type,
sdrh.staff_uuid, IFNULL(si.staff_name, sdrh.staff_uuid), si.phone_number,
sdrh.report_date, sdrh.merchant_id,
MAX(sm.merchant_name), MAX(sm.store_code),
MAX(sm.province_id), MAX(sm.province_name), MAX(sm.city_id), MAX(sm.city_name), MAX(sm.area_name), MAX(sm.region), MAX(sm.channel_type),
MAX(dir_area.director_name), MAX(dir_online.director_name), MAX(dir_flight.director_name),
sdrh.staff_uuid, MAX(IFNULL(si.staff_name, sdrh.staff_uuid)), MAX(si.phone_number),
sdrh.scene_type, sdrh.first_brand_id, '鸿蒙智行', sdrh.brand_id, '问界',
'N', 0, SUM(IFNULL(sdrh.not_delivery_count, 0)),
SUM(IFNULL(sdrh.equity_to_shop_count, 0)), SUM(IFNULL(sdrh.extended_warranty_to_shop_count, 0)), SUM(IFNULL(sdrh.real_equity_to_shop_count, 0)),
SUM(IFNULL(sdrh.after_sale_equity_to_shop_count, 0)), SUM(IFNULL(sdrh.after_sale_extended_warranty_to_shop_count, 0)), SUM(IFNULL(sdrh.after_sale_real_equity_to_shop_count, 0)),
SUM(IFNULL(sdrh.total_order_count, 0)), SUM(IFNULL(sdrh.extended_warranty_count, 0)), SUM(IFNULL(sdrh.tire_warranty_count, 0)), SUM(IFNULL(sdrh.ax_package_count, 0)),
SUM(IFNULL(sdrh.battery_extended_warranty_count, 0)), SUM(IFNULL(sdrh.battery_extended_warranty_money, 0)),
0, 0, 0,
0, 0, NULL,
CURDATE()
FROM ods_staff_daily_report_huawei sdrh
LEFT JOIN ods_service_merchant sm ON sdrh.merchant_id = sm.merchant_id
LEFT JOIN ods_service_merchant sm ON sdrh.merchant_id = sm.merchant_id AND sm.deleted_flag = 'N'
LEFT JOIN ods_staff_info si ON sdrh.staff_uuid = si.staff_uuid
LEFT JOIN (
SELECT merchant_id, GROUP_CONCAT(DISTINCT director_name SEPARATOR '/') AS director_name
FROM ods_shop_merchant_director_config
WHERE director_type IN (9, 8) AND deleted_flag = 'N'
GROUP BY merchant_id
) dir_area ON sdrh.merchant_id = dir_area.merchant_id
LEFT JOIN (
SELECT merchant_id, GROUP_CONCAT(DISTINCT director_name SEPARATOR '/') AS director_name
FROM ods_shop_merchant_director_config
WHERE director_type IN (7, 5) AND deleted_flag = 'N'
GROUP BY merchant_id
) dir_online ON sdrh.merchant_id = dir_online.merchant_id
LEFT JOIN (
SELECT merchant_id, GROUP_CONCAT(DISTINCT director_name SEPARATOR '/') AS director_name
FROM ods_shop_merchant_director_config
WHERE director_type IN (13, 6) AND deleted_flag = 'N'
GROUP BY merchant_id
) dir_flight ON sdrh.merchant_id = dir_flight.merchant_id
WHERE sdrh.deleted_flag = 'N' {filter_str}
GROUP BY sdrh.merchant_id, sdrh.staff_uuid, sdrh.report_date, sdrh.scene_type, sdrh.first_brand_id, sdrh.brand_id
ON DUPLICATE KEY UPDATE
equity_to_shop_count = VALUES(equity_to_shop_count),
extended_warranty_to_shop_count = VALUES(extended_warranty_to_shop_count),
real_equity_to_shop_count = VALUES(real_equity_to_shop_count),
after_sale_equity_to_shop_count = VALUES(after_sale_equity_to_shop_count),
after_sale_extended_warranty_to_shop_count = VALUES(after_sale_extended_warranty_to_shop_count),
after_sale_real_equity_to_shop_count = VALUES(after_sale_real_equity_to_shop_count),
not_delivery_count = VALUES(not_delivery_count),
total_order_count = VALUES(total_order_count),
extended_warranty_count = VALUES(extended_warranty_count),
tire_warranty_count = VALUES(tire_warranty_count),
ax_package_count = VALUES(ax_package_count),
battery_extended_warranty_count = VALUES(battery_extended_warranty_count),
battery_extended_warranty_money = VALUES(battery_extended_warranty_money),
etl_date = CURDATE()
"""
@staticmethod
......
......@@ -245,6 +245,41 @@ CREATE TABLE ods_merchant_output_target_config (
INDEX idx_merchant_month (merchant_id, target_month)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='门店产值目标配置-ODS';
-- ods_strategy_info — 策略记录表(线下运营发现门店异常时做出的策略)
DROP TABLE IF EXISTS ods_strategy_info;
CREATE TABLE ods_strategy_info (
`id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`strategy_type` INT NOT NULL COMMENT '执行策略类型,0-学习类、1-优秀录音分享类、2-带教、3-任务型、4-销售精英到店提拉、5-强力促销、6-最终盘点与低客单产品购入、7-留言、8-带教申请、9-人员更换评估、10-商务政策更新评估、11-多品类拓张、12-流量问题改善',
`title` VARCHAR(20) DEFAULT NULL COMMENT '标题',
`sub_title` VARCHAR(255) DEFAULT NULL COMMENT '副标题',
`start_date` DATETIME DEFAULT NULL COMMENT '执行开始日期',
`end_date` DATETIME DEFAULT NULL COMMENT '执行结束日期',
`description` VARCHAR(200) DEFAULT NULL COMMENT '策略说明',
`content` TEXT DEFAULT NULL COMMENT '内容',
`handler_type` VARCHAR(10) DEFAULT NULL COMMENT '处理人类型,0-区域运营,1-驻店人员,用逗号分割',
`push_type` INT NOT NULL COMMENT '推送方式,0-定时推送,1-立即推送',
`created_by` VARCHAR(64) NOT NULL COMMENT '创建人',
`created_date` DATETIME NOT NULL COMMENT '创建时间',
`updated_by` VARCHAR(64) DEFAULT NULL COMMENT '修改人',
`updated_date` DATETIME DEFAULT NULL COMMENT '修改时间',
`deleted_flag` CHAR(1) NOT NULL DEFAULT 'N' COMMENT '删除标识(D:已删除;N:未删除)',
`merchant_id` INT DEFAULT NULL COMMENT '商户号',
`merchant_name` VARCHAR(255) DEFAULT NULL COMMENT '商户名称',
`biz` INT DEFAULT NULL COMMENT '业务类型:1.延保 2.轻改 3.权益 4.二手车',
`push_flag` INT DEFAULT 0 COMMENT '状态,0-未推送、1-已推送、2-未完成、3-审批中、4-执行中、5-已驳回、6-已完成',
`created_uuid` VARCHAR(64) DEFAULT NULL COMMENT '创建人uuid',
`data_source` INT DEFAULT 1 COMMENT '数据来源,1-策略中心 2-区域督导助手小程序 3-区域运营助手小程序',
`data_source_id` BIGINT DEFAULT NULL COMMENT '数据来源id',
`etl_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'ETL抽取时间',
PRIMARY KEY (id),
INDEX idx_merchant_id (merchant_id),
INDEX idx_strategy_type (strategy_type),
INDEX idx_push_flag (push_flag),
INDEX idx_created_date (created_date),
INDEX idx_updated_date (updated_date),
INDEX idx_biz (biz)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='策略记录表-ODS';
-- ods_employee_delivery_deal_rate — 员工交付成交率
DROP TABLE IF EXISTS ods_employee_delivery_deal_rate;
CREATE TABLE ods_employee_delivery_deal_rate (
......
......@@ -19,6 +19,7 @@ FROM (
SELECT 'dj_car_life_goods_order_customer', 'ods_goods_order_customer' UNION ALL
SELECT 'dj_car_life_merchant_deliver_target_config', 'ods_merchant_deliver_target_config' UNION ALL
SELECT 'dj_car_life_merchant_output_target_config', 'ods_merchant_output_target_config' UNION ALL
SELECT 'dj_car_life_strategy_info', 'ods_strategy_info' UNION ALL
SELECT 'employee_delivery_deal_rate', 'ods_employee_delivery_deal_rate'
) t
ON DUPLICATE KEY UPDATE last_sync_time = NOW(), sync_mode = 'full';
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!