Commit 31f35605 by zhouhaibao

fix(data-process): 更新装修摊销逻辑中的服务商过滤条件

- 在查询结果中新增 service_provider 字段用于服务商筛选
- 将服务商过滤条件从"深圳嘀加"改为"嘀加"以匹配实际数据库值
- 更新日志输出中的服务商名称显示
- 修正装修摊销和耗材分摊中的服务商过滤逻辑
- 添加服务商过滤说明注释(嘀加自营/嘀加直营)
1 parent ce59bee5
...@@ -324,10 +324,10 @@ def query_task_biz_rows(conn, task_id, stat_month, business_type): ...@@ -324,10 +324,10 @@ def query_task_biz_rows(conn, task_id, stat_month, business_type):
"""查询本任务下指定业务类型的预算达成结果行(用于装修摊销的 GMV 占比分摊)。 """查询本任务下指定业务类型的预算达成结果行(用于装修摊销的 GMV 占比分摊)。
Returns: Returns:
list[dict]: {id, traffic_name, park_store, gmv, gmv_ratio_park} list[dict]: {id, traffic_name, park_store, gmv, gmv_ratio_park, service_provider}
""" """
sql = ( sql = (
'SELECT id, traffic_name, park_store, gmv, gmv_ratio_park ' 'SELECT id, traffic_name, park_store, gmv, gmv_ratio_park, service_provider '
'FROM biz_budget_achieve ' 'FROM biz_budget_achieve '
'WHERE task_id = %s AND stat_month = %s AND business_type = %s' 'WHERE task_id = %s AND stat_month = %s AND business_type = %s'
) )
...@@ -436,14 +436,14 @@ def compute_renovation_amounts(detail_rows, biz_rows, stat_month, n_months=RENOV ...@@ -436,14 +436,14 @@ def compute_renovation_amounts(detail_rows, biz_rows, stat_month, n_months=RENOV
if total == 0: if total == 0:
continue continue
rows = row_map[key] rows = row_map[key]
# --- 服务商过滤:只保留 service_provider 含"深圳嘀加"的行 --- # --- 服务商过滤:只保留 service_provider 含"嘀加"的行(嘀加自营/嘀加直营) ---
dijia_rows = [r for r in rows if _is_dijia_row(r)] dijia_rows = [r for r in rows if _is_dijia_row(r)]
if not dijia_rows: if not dijia_rows:
# 全是非嘀加 → 不分摊(费用=0),跳过 # 全是非嘀加 → 不分摊(费用=0),跳过
continue continue
if len(dijia_rows) < len(rows): if len(dijia_rows) < len(rows):
logger.info(f"[装修分摊] key={key}: {len(rows)} 行中有 {len(dijia_rows)} 行" logger.info(f"[装修摊销] key={key}: {len(rows)} 行中有 {len(dijia_rows)} 行"
f" 服务商=深圳嘀加,参与分摊;跳过 {len(rows)-len(dijia_rows)} 行") f" 服务商=嘀加,参与分摊;跳过 {len(rows)-len(dijia_rows)} 行")
rows = dijia_rows rows = dijia_rows
if field == 'mgv_ratio_park': if field == 'mgv_ratio_park':
...@@ -662,15 +662,13 @@ def query_all_biz_rows(conn, task_id, stat_month): ...@@ -662,15 +662,13 @@ def query_all_biz_rows(conn, task_id, stat_month):
return cur.fetchall() return cur.fetchall()
_DIJIA_SPIDER = '%深圳嘀加%' # 匹配服务商含"深圳嘀加"的行 _DIJIA_SPIDER = '%嘀加%' # 匹配服务商含"嘀加"的行(DB 实际值:嘀加自营/嘀加直营)
def _is_dijia_row(row): def _is_dijia_row(row):
"""判断 biz_budget_achieve 行的 service_provider 是否含"深圳嘀加"。 """判断 biz_budget_achieve 行的 service_provider 是否含"嘀加"(嘀加自营/嘀加直营)。"""
row 可以是 dict(query_all_biz_rows 返回)或 sqlalchemy Row / pymysql dict。
"""
sp = (row.get('service_provider') or row.get('serviceProvider') or '').strip() sp = (row.get('service_provider') or row.get('serviceProvider') or '').strip()
return '深圳嘀加' in sp return '嘀加' in sp
def compute_consumables_amounts(detail_rows, biz_rows, stat_month): def compute_consumables_amounts(detail_rows, biz_rows, stat_month):
...@@ -772,14 +770,14 @@ def compute_consumables_amounts(detail_rows, biz_rows, stat_month): ...@@ -772,14 +770,14 @@ def compute_consumables_amounts(detail_rows, biz_rows, stat_month):
if total == 0: if total == 0:
continue # 净额为 0 才跳过;净负池同样分配成负摊消(冲减) continue # 净额为 0 才跳过;净负池同样分配成负摊消(冲减)
rows = row_map[key] rows = row_map[key]
# --- 服务商过滤:只保留 service_provider 含"深圳嘀加"的行 --- # --- 服务商过滤:只保留 service_provider 含"嘀加"的行(嘀加自营/嘀加直营) ---
dijia_rows = [r for r in rows if _is_dijia_row(r)] dijia_rows = [r for r in rows if _is_dijia_row(r)]
if not dijia_rows: if not dijia_rows:
# 全是非嘀加 → 不分摊(费用=0),跳过 # 全是非嘀加 → 不分摊(费用=0),跳过
continue continue
if len(dijia_rows) < len(rows): if len(dijia_rows) < len(rows):
logger.info(f"[耗材分摊] key={key}: {len(rows)} 行中有 {len(dijia_rows)} 行" logger.info(f"[耗材分摊] key={key}: {len(rows)} 行中有 {len(dijia_rows)} 行"
f" 服务商=深圳嘀加,参与分摊;跳过 {len(rows)-len(dijia_rows)} 行") f" 服务商=嘀加,参与分摊;跳过 {len(rows)-len(dijia_rows)} 行")
rows = dijia_rows rows = dijia_rows
if field == 'mgv_ratio_park': if field == 'mgv_ratio_park':
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!