Commit 2769193a by zhouhaibao

feat(data-process): 添加轻改店中店和园区店处理器

- 新增 LightReformInshopProcessor 处理器用于轻改店中店数据处理
- 新增 LightReformParkProcessor 处理器用于轻改园区店数据处理
- 实现店中店和园区店的独立数据扫描和处理流程
- 添加 Excel 文件解析和业务数据计算功能
- 实现双优先级数据取值策略(Excel 优先,SQL 回退)
- 添加园区店专用的反过滤解析方法 parse_saas_base_sheet2_exclude
- 实现批量数据入库和排名计算功能
1 parent dbc4d0cc
......@@ -586,6 +586,68 @@ def parse_saas_base_sheet2(file_path):
return result
def parse_saas_base_sheet2_exclude(file_path):
"""
解析 SAAS门店预算分解表 sheet2,按品牌关键字**反过滤**(不包含关键字的保留)。
用于轻改园区店。
返回 list[dict]:同 parse_saas_base_sheet2,额外带 est_delivery_cnt / est_output_value / est_output_value_original
"""
logger.info(f"[SAAS预算分解-sheet2-exclude] 解析 {file_path}")
df_raw = pd.read_excel(file_path, sheet_name=1, header=None)
header_row = find_header_row(df_raw)
df = pd.read_excel(file_path, sheet_name=1, header=header_row)
df.columns = [str(c).strip() if c else '' for c in df.columns]
col_map = match_columns(df.columns, {
'park_name': ['园区名称', '园区'],
'store_name': ['门店名称', '门店名', '厅店名称', 'store_name'],
'brand': ['品牌', 'brand'],
'province': ['省份', '省'],
'city': ['城市', '市'],
'park_type': ['园区类型'],
'operate_type': ['驻店类型', '经营属性', '驻店'],
'region_manager': ['区域经理', '区域运营'],
'avg_price_target': ['预估平均客单价', '平客目标值'],
'est_delivery_cnt': ['预估交车数'],
'est_output_value': ['预估产值纠偏', '预估产值(纠偏)', '预估总产值'],
})
if 'store_name' not in col_map:
logger.error("[SAAS预算分解-sheet2-exclude] 未找到门店名列")
return []
brand_col = col_map.get('brand')
store_col = col_map['store_name']
result = []
for _, row in df.iterrows():
brand_val = str(row.get(brand_col, '')).strip() if brand_col else ''
brand_text = (brand_val + ' ' + str(row.get(store_col, ''))).strip()
# 反过滤:包含关键字 → 跳过
if brand_val and any(kw in brand_text for kw in LIGHT_REFORM_BRAND_KEYWORDS):
continue
sn = str(row.get(store_col, '')).strip()
if not sn or sn in ('nan', 'None', ''):
continue
result.append({
'park_name': str(row.get(col_map.get('park_name', ''), '')).strip() if col_map.get('park_name') else '',
'store_name': sn,
'brand': brand_val,
'province': str(row.get(col_map.get('province', ''), '')).strip() if col_map.get('province') else '',
'city': str(row.get(col_map.get('city', ''), '')).strip() if col_map.get('city') else '',
'park_type': str(row.get(col_map.get('park_type', ''), '')).strip() if col_map.get('park_type') else '园区店',
'operate_type': str(row.get(col_map.get('operate_type', ''), '')).strip() if col_map.get('operate_type') else '',
'region_manager': str(row.get(col_map.get('region_manager', ''), '')).strip() if col_map.get('region_manager') else '',
'avg_price_target': _to_decimal(row.get(col_map.get('avg_price_target', ''), '')) if col_map.get('avg_price_target') else Decimal('0'),
'est_delivery_cnt': _to_int(row.get(col_map.get('est_delivery_cnt', ''), 0)) if col_map.get('est_delivery_cnt') else 0,
'est_output_value': _to_decimal(row.get(col_map.get('est_output_value', ''), '')) if col_map.get('est_output_value') else Decimal('0'),
})
logger.info(f"[SAAS预算分解-sheet2-exclude] 反过滤后共 {len(result)} 条")
return result
def _to_decimal(val):
"""安全转 Decimal"""
if val is None or (isinstance(val, float) and pd.isna(val)) or str(val).strip() in ('', 'nan', 'None'):
......@@ -806,3 +868,75 @@ def is_luxury_brand(brand_name):
if row and row.is_luxury == 1:
return '豪华'
return '非豪华'
def parse_park_delivery_touch(file_path):
"""
解析园区店交车触客表(区域运营填写)。
返回 dict[store_name] = {delivery_cnt, arrival_cnt, arrival_invalid_cnt, purchase_indicator}
"""
logger.info(f"[园区店交车触客表] 解析 {file_path}")
try:
df = pd.read_excel(file_path)
except Exception:
logger.warning(f"[园区店交车触客表] 读取失败 {file_path}")
return {}
df.columns = [str(c).strip() if c else '' for c in df.columns]
col_map = match_columns(df.columns, {
'store_name': ['门店名称', '门店名'],
'delivery_cnt': ['交车数', '交车', '新车交付'],
'arrival_cnt': ['到店数', '到店'],
'arrival_invalid_cnt': ['到店无效', '无效客户数', '到店无效客户'],
'purchase_indicator': ['采买', '兜底指标', '采买兜底'],
})
if 'store_name' not in col_map:
logger.warning("[园区店交车触客表] 未找到门店名列")
return {}
result = {}
for _, row in df.iterrows():
sn = str(row.get(col_map['store_name'], '')).strip()
if not sn or sn in ('nan', 'None', ''):
continue
result[sn] = {
'delivery_cnt': _to_int(row.get(col_map.get('delivery_cnt', ''), 0)),
'arrival_cnt': _to_int(row.get(col_map.get('arrival_cnt', ''), 0)),
'arrival_invalid_cnt': _to_int(row.get(col_map.get('arrival_invalid_cnt', ''), 0)),
'purchase_indicator': str(row.get(col_map.get('purchase_indicator', ''), '')).strip() if col_map.get('purchase_indicator') else '',
}
logger.info(f"[园区店交车触客表] {len(result)} 个门店")
return result
def parse_commerce_policy_park(file_path):
"""
解析商务政策表(园区店处理版)。
返回 dict[store_name] = {traffic_fee_per_car, ...} —— 门店分成参考(按单台计算流量/台)
"""
logger.info(f"[商务政策-园区店] 解析 {file_path}")
try:
df = pd.read_excel(file_path)
except Exception:
logger.warning(f"[商务政策-园区店] 读取失败 {file_path}")
return {}
df.columns = [str(c).strip() if c else '' for c in df.columns]
col_map = match_columns(df.columns, {
'store_name': ['门店名称', '门店名'],
'traffic_fee_per_car': ['门店分成参考', '按单台计算流量', '流量费/台', '单台流量费'],
})
if 'store_name' not in col_map:
logger.warning("[商务政策-园区店] 未找到门店名列")
return {}
result = {}
for _, row in df.iterrows():
sn = str(row.get(col_map['store_name'], '')).strip()
if not sn or sn in ('nan', 'None', ''):
continue
result[sn] = {
'traffic_fee_per_car': _to_decimal(row.get(col_map.get('traffic_fee_per_car', ''), 0)),
}
logger.info(f"[商务政策-园区店] {len(result)} 个门店")
return result
......@@ -282,12 +282,12 @@ class NewReportScheduler:
from earnings_report_processor import WarrantyProcessor
from equity_processor import EquityProcessor
from light_reform_inshop_processor import LightReformInshopProcessor
# 轻改园区店后续创建,暂时用占位
from light_reform_park_processor import LightReformParkProcessor
_CATEGORY_CLS = {
'warranty': WarrantyProcessor,
'equity': EquityProcessor,
'inshop': LightReformInshopProcessor,
'park': WarrantyProcessor, # TODO: 后续创建 light_reform_park_processor.py
'park': LightReformParkProcessor,
}
cls = _CATEGORY_CLS.get(self.OUTPUT_CATEGORY)
if not cls:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!