Commit f5e85b4e by zhouhaibao

feat(data-process): 优化市场费2.3→2.1归属规则

- 预构建所有有2.1业务记录的流量方集合,提升匹配效率
- 修改2.3→2.1归属规则,增加流量方存在2.1业务记录的判断条件
- 添加标准化名称匹配逻辑,确保流量方名称一致性
- 更新日志输出格式,提供更详细的归属处理信息
- 优化代码结构,将标准化名称计算提前并统一处理
1 parent 9aaa43b4
...@@ -1878,6 +1878,17 @@ class DataProcessor: ...@@ -1878,6 +1878,17 @@ class DataProcessor:
if settlement_map is None: if settlement_map is None:
settlement_map = {} settlement_map = {}
# 预构建:从 settlement_map 收集所有有 2.1 业务记录的流量方
has_2_1_biz = set()
for (flow_n, bt, brand) in settlement_map.keys():
if bt == BIZ_TYPE_2_1 and flow_n:
has_2_1_biz.add(flow_n)
# 同时添加标准化后的名称(用于匹配)
std_flow = to_standard(flow_n, '4s')
if std_flow:
has_2_1_biz.add(std_flow)
logger.info(f"[市场费][2.3→2.1归属] 预构建完成: {len(has_2_1_biz)} 个流量方有 2.1 业务")
xls = pd.ExcelFile(file_path) xls = pd.ExcelFile(file_path)
all_results = [] all_results = []
total_skipped = 0 # 统计被跳过的行数 total_skipped = 0 # 统计被跳过的行数
...@@ -2102,14 +2113,20 @@ class DataProcessor: ...@@ -2102,14 +2113,20 @@ class DataProcessor:
model_str = str(vehicle_model).strip() if pd.notna(vehicle_model) else "NaN/空" model_str = str(vehicle_model).strip() if pd.notna(vehicle_model) else "NaN/空"
logger.info(f"[市场费诊断] 恒为行#{row_idx}: flow='{flow_name}', fee={fee}, model='{model_str}', brand={brand or '未知品牌'}, biz_type={biz_type}") logger.info(f"[市场费诊断] 恒为行#{row_idx}: flow='{flow_name}', fee={fee}, model='{model_str}', brand={brand or '未知品牌'}, biz_type={biz_type}")
# 2.3→2.1 归属规则:商品类别=权益服务/延保-原厂权益 归属2.1 # 2.3→2.1 归属规则:流量方存在 2.1 业务记录 且 商品类别=权益服务/延保-原厂权益
if biz_type == BIZ_TYPE_2_3 and col_category: if biz_type == BIZ_TYPE_2_3:
category = str(row[col_category]).strip() if pd.notna(row[col_category]) else "" # 先计算标准化名称(后续也需要使用)
if category in ["权益服务", "延保-原厂权益"]: std_flow_name = to_standard(flow_name, '4s')
# 判断流量方是否存在 2.1 业务记录
has_2_1 = flow_name in has_2_1_biz or std_flow_name in has_2_1_biz
# 获取商品类别
category = str(row[col_category]).strip() if col_category and pd.notna(row[col_category]) else ""
# 两个条件都满足才归属到 2.1
if has_2_1 and category in ["权益服务", "延保-原厂权益"]:
biz_type = BIZ_TYPE_2_1 biz_type = BIZ_TYPE_2_1
logger.debug(f"[市场费] 2.3→2.1 归属: flow={flow_name}, category={category}") logger.info(f"[市场费][2.3→2.1归属] flow={flow_name}, category={category}, 原因=存在2.1业务记录+商品类别匹配")
else:
# 使用标准名映射 # 使用标准名映射(非 2.3 业务时在此计算)
std_flow_name = to_standard(flow_name, '4s') std_flow_name = to_standard(flow_name, '4s')
result_row = { result_row = {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!