Commit 72c02e7e by zhouhaibao

refactor(data-process): 移除模糊匹配逻辑并优化SQL查询

- 移除了inshop和park处理器中的fuzzy_match_store模糊匹配功能
- 保留精确匹配和Excel原值兜底策略
- 优化report_utils中商户门店信息查询的SQL语句
- 使用表连接替代原有的单表查询方式
- 统一使用别名简化复杂查询结构
1 parent db5cea5e
...@@ -214,9 +214,8 @@ class LightReformInshopProcessor: ...@@ -214,9 +214,8 @@ class LightReformInshopProcessor:
for rec in base_records: for rec in base_records:
sn = rec.get('store_name', '') sn = rec.get('store_name', '')
store_to_park[sn] = ( store_to_park[sn] = (
park_name_sys_map.get(sn) park_name_sys_map.get(sn) # 精确匹配
or fuzzy_match_store(sn, park_name_sys_map) or rec.get('park_name', '') # Excel 原值兜底
or rec.get('park_name', '')
) )
_hit = sum(1 for v in store_to_park.values() if v) _hit = sum(1 for v in store_to_park.values() if v)
logger.info(f"[park_name-inshop] store_to_park 映射 {_hit}/{len(store_to_park)} 有值, " logger.info(f"[park_name-inshop] store_to_park 映射 {_hit}/{len(store_to_park)} 有值, "
......
...@@ -210,9 +210,8 @@ class LightReformParkProcessor: ...@@ -210,9 +210,8 @@ class LightReformParkProcessor:
for rec in base_records: for rec in base_records:
sn = rec.get('store_name', '') sn = rec.get('store_name', '')
store_to_park[sn] = ( store_to_park[sn] = (
park_name_sys_map.get(sn) park_name_sys_map.get(sn) # 精确匹配
or fuzzy_match_store(sn, park_name_sys_map) or rec.get('park_name', '') # Excel 原值兜底
or rec.get('park_name', '')
) )
_hit = sum(1 for v in store_to_park.values() if v) _hit = sum(1 for v in store_to_park.values() if v)
logger.info(f"[park_name] store_to_park 映射 {_hit}/{len(store_to_park)} 有值, " logger.info(f"[park_name] store_to_park 映射 {_hit}/{len(store_to_park)} 有值, "
......
...@@ -2025,14 +2025,17 @@ def fetch_est_delivery_count(base_scene_code='100101'): ...@@ -2025,14 +2025,17 @@ def fetch_est_delivery_count(base_scene_code='100101'):
return {} return {}
sql = f""" sql = f"""
SELECT traffic_party_name, SELECT t3.merchant_name AS traffic_party_name,
IF(estimated_delivery_count_per_month IS NULL, IF(t1.estimated_delivery_count_per_month IS NULL,
delivery_count, t1.delivery_count,
estimated_delivery_count_per_month) AS final_delivery_count t1.estimated_delivery_count_per_month) AS final_delivery_count
FROM dj_car_life_merchant_store_info FROM dj_car_life_merchant_store_info t1
WHERE base_scene_code = '{base_scene_code}' LEFT JOIN dj_car_life_service_merchant t3
AND deleted_flag = 'N' ON t1.traffic_party_id = t3.merchant_id
ORDER BY created_date DESC AND t3.deleted_flag = 'N'
WHERE t1.base_scene_code = '{base_scene_code}'
AND t1.deleted_flag = 'N'
ORDER BY t1.created_date DESC
""" """
out = {} out = {}
...@@ -2081,13 +2084,20 @@ def fetch_park_name_map(base_scene_code='100101'): ...@@ -2081,13 +2084,20 @@ def fetch_park_name_map(base_scene_code='100101'):
return {} return {}
sql = f""" sql = f"""
SELECT traffic_party_name, parking_store_name SELECT t3.merchant_name AS traffic_party_name,
FROM dj_car_life_merchant_store_info t2.merchant_name AS parking_store_name
WHERE base_scene_code = '{base_scene_code}' FROM dj_car_life_merchant_store_info t1
AND deleted_flag = 'N' LEFT JOIN dj_car_life_service_merchant t2
AND traffic_party_name IS NOT NULL ON t1.parking_store_id = t2.merchant_id
AND parking_store_name IS NOT NULL AND t2.deleted_flag = 'N'
ORDER BY created_date DESC LEFT JOIN dj_car_life_service_merchant t3
ON t1.traffic_party_id = t3.merchant_id
AND t3.deleted_flag = 'N'
WHERE t1.base_scene_code = '{base_scene_code}'
AND t1.deleted_flag = 'N'
AND t2.merchant_name IS NOT NULL
AND t3.merchant_name IS NOT NULL
ORDER BY t1.created_date DESC
""" """
out = {} out = {}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!