Commit d29b00d3 by zhouhaibao

feat(data-process): 添加系统日报兜底逻辑处理未匹配门店数据

- 在收益报告处理器中引入 fetch_park_daily_report 函数调用
- 在权益处理器中引入 fetch_park_daily_report 函数调用
- 实现 Step1.5 步骤:当主机厂交车数未匹配门店时查询系统日报 scene_type=0 兜底
- 添加未匹配门店名称检测和系统日报查询日志记录
- 实现 Excel 数据未匹配时使用系统日报数据作为备选方案
- 当 delivery_cnt 为 0 且存在系统交付映射时从系统日报获取交付数量
1 parent 9348580b
......@@ -25,7 +25,7 @@ from report_utils import (
download_all_files,
parse_saas_base, parse_region_map, parse_delivery_table, merge_delivery_maps,
parse_budget_achieve_excel, extract_budget_ratio,
fetch_biz_sql_aggregated, fuzzy_match_store,
fetch_biz_sql_aggregated, fetch_park_daily_report, fuzzy_match_store,
fetch_indicator_data,
safe_div, safe_div_pct, safe_div_pct_decimal, clamp_ratio,
)
......@@ -149,6 +149,21 @@ class WarrantyProcessor:
finally:
cleanup_tmp_dir(tmp_dir)
# ========== Step1.5: 主机厂交车数未匹配门店 → 系统日报 scene_type=0 兜底 ==========
all_store_names = [r.get('store_name', '') for r in base_records if r.get('store_name')]
unfitted_names = [sn for sn in all_store_names if not fuzzy_match_store(sn, delivery_map)]
system_delivery_map = {}
if unfitted_names:
logger.info(f"[延保] Excel交车未匹配 {len(unfitted_names)} 家门店,查系统日报 scene_type=0 兜底")
start_str = period_start.strftime('%Y-%m-%d') if period_start else ''
end_str = period_end.strftime('%Y-%m-%d') if period_end else ''
try:
system_delivery_map = fetch_park_daily_report(start_str, end_str, scene_type=0)
logger.info(f"[延保] 系统日报 scene_type=0 → {len(system_delivery_map)} 个门店")
except Exception as e:
logger.warning(f"[延保] 系统日报兜底查询失败: {e}")
system_delivery_map = {}
# ========== Step2: 指标系统(延保 2.3)→ 产值/成交/触客/延保各项 ==========
# 注意:单值 biz 会被指标 API 忽略(返回全业务),必须传列表走 bizs="N" 才生效
try:
......@@ -178,7 +193,11 @@ class WarrantyProcessor:
# Excel 门店名 → 业务表 merchant_name 模糊匹配
biz_data = fuzzy_match_store(store_name, biz_sql_map) or {}
# 主机厂交车:SAAS表"门店名" 模糊匹配 主机厂表"厅店名称"/"基础信息-门店名称"
# Excel 未匹配时,系统日报 scene_type=0 兜底
delivery_cnt = fuzzy_match_store(store_name, delivery_map) or 0
if delivery_cnt == 0 and system_delivery_map:
_sys_entry = fuzzy_match_store(store_name, system_delivery_map) or {}
delivery_cnt = _sys_entry.get('delivery_cnt', 0) if isinstance(_sys_entry, dict) else 0
# 指标系统取值
touch_cnt = int(Decimal(str(ind.get('A084', 0))))
......
......@@ -25,7 +25,7 @@ from report_utils import (
download_all_files,
parse_saas_base, parse_region_map, parse_delivery_table, merge_delivery_maps,
parse_budget_achieve_excel, extract_budget_ratio,
fetch_biz_sql_aggregated, fuzzy_match_store,
fetch_biz_sql_aggregated, fetch_park_daily_report, fuzzy_match_store,
fetch_indicator_data,
safe_div, safe_div_pct, safe_div_pct_decimal, clamp_ratio,
)
......@@ -151,6 +151,21 @@ class EquityProcessor:
finally:
cleanup_tmp_dir(tmp_dir)
# ========== Step1.5: 主机厂交车数未匹配门店 → 系统日报 scene_type=0 兜底 ==========
all_store_names = [r.get('store_name', '') for r in base_records if r.get('store_name')]
unfitted_names = [sn for sn in all_store_names if not fuzzy_match_store(sn, delivery_map)]
system_delivery_map = {}
if unfitted_names:
logger.info(f"[权益] Excel交车未匹配 {len(unfitted_names)} 家门店,查系统日报 scene_type=0 兜底")
start_str = period_start.strftime('%Y-%m-%d') if period_start else ''
end_str = period_end.strftime('%Y-%m-%d') if period_end else ''
try:
system_delivery_map = fetch_park_daily_report(start_str, end_str, scene_type=0)
logger.info(f"[权益] 系统日报 scene_type=0 → {len(system_delivery_map)} 个门店")
except Exception as e:
logger.warning(f"[权益] 系统日报兜底查询失败: {e}")
system_delivery_map = {}
# ========== Step2: 指标系统(权益 2.1)→ 产值/成交/触客 ==========
# 注意:单值 biz 会被指标 API 忽略(返回全业务),必须传列表走 bizs="N" 才生效
try:
......@@ -180,7 +195,12 @@ class EquityProcessor:
# Excel 门店名 → 业务表 merchant_name 模糊匹配
biz_data = fuzzy_match_store(store_name, biz_sql_map) or {}
# 主机厂交车:SAAS表"门店名" 模糊匹配 主机厂表"厅店名称"/"基础信息-门店名称"
# Excel 未匹配时,系统日报 scene_type=0 兜底
delivery_cnt = fuzzy_match_store(store_name, delivery_map) or 0
if delivery_cnt == 0 and system_delivery_map:
# system_delivery_map value 是 dict{delivery_cnt, equity_to_shop_count, ...}
_sys_entry = fuzzy_match_store(store_name, system_delivery_map) or {}
delivery_cnt = _sys_entry.get('delivery_cnt', 0) if isinstance(_sys_entry, dict) else 0
# 指标系统取值
touch_cnt = int(Decimal(str(ind.get('A084', 0))))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!