Commit 97f07f16 by zhouhaibao

feat(data-process): 实现轻改店中店和园区店SQL数据源集成

- 添加fetch_light_reform_goods_stats函数实现品类成交数和产值批量查询
- 添加fetch_est_delivery_count函数实现预估交车数静态配置查询
- 在店中店处理器中集成品类成交数和产值SQL数据源
- 在园区店处理器中集成品类成交数、产值和预估交车数SQL数据源
- 更新数据源文档说明包含dj_smartcarlife库查询功能
- 实现原厂和副厂商品分类统计逻辑
- 添加门店总产值、内部结算产值等财务指标计算
1 parent 7f4f7733
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
指标系统 biz 编码:2(轻改) 指标系统 biz 编码:2(轻改)
取值优先级:Excel 第一优先,SQL/指标系统第二优先(双优先模式)。 取值优先级:Excel 第一优先,SQL/指标系统第二优先(双优先模式)。
SQL 相关字段暂为 TODO 占位(biz_sql_data 默认空)。 SQL 数据源:dj_smartcarlife 库
- fetch_park_daily_report → 日报数据(交车数/交付触客/售后触客)
- fetch_light_reform_goods_stats → 品类成交数 + 产值(从 goods_sub_order 按 dj_order_type + AITO/HIMA 关键字条件聚合)
""" """
import logging import logging
import tempfile import tempfile
...@@ -23,7 +25,7 @@ from report_utils import ( ...@@ -23,7 +25,7 @@ from report_utils import (
parse_inshop_delivery_touch, parse_commerce_policy_inshop, parse_inshop_delivery_touch, parse_commerce_policy_inshop,
parse_labor_cost, is_luxury_brand, parse_labor_cost, is_luxury_brand,
parse_budget_achieve_excel, extract_budget_ratio, prorate_by_period, parse_budget_achieve_excel, extract_budget_ratio, prorate_by_period,
fetch_park_daily_report, fuzzy_match_store, fetch_park_daily_report, fetch_light_reform_goods_stats, fuzzy_match_store,
get_with_fallback, safe_div, safe_div_pct, safe_div_pct_decimal, get_with_fallback, safe_div, safe_div_pct, safe_div_pct_decimal,
) )
from models import ReportLightReformInshop, db from models import ReportLightReformInshop, db
...@@ -154,6 +156,8 @@ class LightReformInshopProcessor: ...@@ -154,6 +156,8 @@ class LightReformInshopProcessor:
# ========== Step2: 业务系统 SQL ========== # ========== Step2: 业务系统 SQL ==========
# 2a. 日报数据(scene_type=1 轻改,复用 park 的函数,3 字段全返回) # 2a. 日报数据(scene_type=1 轻改,复用 park 的函数,3 字段全返回)
daily_report_map = fetch_park_daily_report(period_start, period_end, scene_type=1) daily_report_map = fetch_park_daily_report(period_start, period_end, scene_type=1)
# 2c. 品类成交数 + 产值(店中店+园区店共用 SQL,按 dj_order_type + AITO/HIMA 关键字聚合)
goods_stats_map = fetch_light_reform_goods_stats(period_start, period_end)
# 2b. 模糊匹配到门店 → 组装 sql_data dict(get_with_fallback 双优先用) # 2b. 模糊匹配到门店 → 组装 sql_data dict(get_with_fallback 双优先用)
# 店中店:delivery_cnt→交车;equity→交付触客;after_sale→售后触客; # 店中店:delivery_cnt→交车;equity→交付触客;after_sale→售后触客;
# 售后首保/事故回厂数 → 无 SQL,默认 0 # 售后首保/事故回厂数 → 无 SQL,默认 0
...@@ -161,7 +165,9 @@ class LightReformInshopProcessor: ...@@ -161,7 +165,9 @@ class LightReformInshopProcessor:
for rec in base_records: for rec in base_records:
sn = rec.get('store_name', '') sn = rec.get('store_name', '')
dr = fuzzy_match_store(sn, daily_report_map) or {} dr = fuzzy_match_store(sn, daily_report_map) or {}
gs = fuzzy_match_store(sn, goods_stats_map) or {}
biz_sql_data[sn] = { biz_sql_data[sn] = {
# —— 日报类(来自 fetch_park_daily_report)——
'delivery_cnt': dr.get('delivery_cnt', 0), 'delivery_cnt': dr.get('delivery_cnt', 0),
'delivery_touch_cnt': dr.get('equity_to_shop_count', 0), 'delivery_touch_cnt': dr.get('equity_to_shop_count', 0),
'aftersales_touch_cnt': dr.get('after_sale_equity_to_shop_count', 0), 'aftersales_touch_cnt': dr.get('after_sale_equity_to_shop_count', 0),
...@@ -169,8 +175,20 @@ class LightReformInshopProcessor: ...@@ -169,8 +175,20 @@ class LightReformInshopProcessor:
'aftersales_shigu_cnt': 0, # 无 SQL 'aftersales_shigu_cnt': 0, # 无 SQL
'sales_order_cnt': 0, # 无 SQL(销售大定数) 'sales_order_cnt': 0, # 无 SQL(销售大定数)
'sales_touch_cnt': 0, # 无 SQL(销售触客数) 'sales_touch_cnt': 0, # 无 SQL(销售触客数)
# —— 品类成交数 + 产值(来自 fetch_inshop_goods_stats)——
'total_deal_cnt': gs.get('total_deal_cnt', 0),
'window_film_oe_cnt': gs.get('window_film_oe_cnt', 0),
'window_film_nonoe_cnt': gs.get('window_film_nonoe_cnt', 0),
'car_wrap_oe_cnt': gs.get('car_wrap_oe_cnt', 0),
'car_wrap_nonoe_cnt': gs.get('car_wrap_nonoe_cnt', 0),
'premium_oe_cnt': gs.get('premium_oe_cnt', 0),
'premium_nonoe_cnt': gs.get('premium_nonoe_cnt', 0),
'pedal_cnt': gs.get('pedal_cnt', 0),
'store_output_value': gs.get('store_output_value', Decimal('0')),
'internal_settle_value': gs.get('internal_settle_value', Decimal('0')),
'oe_output_value': gs.get('oe_output_value', Decimal('0')),
'nonoe_output_value': gs.get('nonoe_output_value', Decimal('0')),
} }
# 2c. 其他 SQL 字段(品类成交数、产值、成本、市场费、服务商分润等)后续接入,当前保持默认 0
# ========== Step3: 上月预算明细(已在 Step1 从 Excel 解析) ========== # ========== Step3: 上月预算明细(已在 Step1 从 Excel 解析) ==========
prev_budget_map = budget_achieve_map prev_budget_map = budget_achieve_map
...@@ -207,11 +225,11 @@ class LightReformInshopProcessor: ...@@ -207,11 +225,11 @@ class LightReformInshopProcessor:
dt_excel.get('aftersales_touch_cnt'), sql_data.get('aftersales_touch_cnt', 0)) dt_excel.get('aftersales_touch_cnt'), sql_data.get('aftersales_touch_cnt', 0))
purchase_indicator = dt_excel.get('purchase_indicator', '') purchase_indicator = dt_excel.get('purchase_indicator', '')
# —— 业务系统 SQL 取值(TODO 占位,后续补 SQL 映射)—— # —— 业务系统 SQL 取值(fetch_inshop_goods_stats 一次聚合返回)——
total_deal_cnt = int(Decimal(str(sql_data.get('total_deal_cnt', 0)))) total_deal_cnt = int(Decimal(str(sql_data.get('total_deal_cnt', 0))))
store_output_value = Decimal(str(sql_data.get('store_output_value', 0))) store_output_value = Decimal(str(sql_data.get('store_output_value', Decimal('0'))))
# —— 成交数/产值相关 SQL(TODO 占位,从 biz_sql_data 读)—— # —— 品类成交数 / 产值(来自 fetch_inshop_goods_stats 的条件聚合结果)——
window_film_oe_cnt = sql_data.get('window_film_oe_cnt', 0) window_film_oe_cnt = sql_data.get('window_film_oe_cnt', 0)
window_film_nonoe_cnt = sql_data.get('window_film_nonoe_cnt', 0) window_film_nonoe_cnt = sql_data.get('window_film_nonoe_cnt', 0)
car_wrap_oe_cnt = sql_data.get('car_wrap_oe_cnt', 0) car_wrap_oe_cnt = sql_data.get('car_wrap_oe_cnt', 0)
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
- 用"园区店交车触客表"和"商务政策表(园区店)" - 用"园区店交车触客表"和"商务政策表(园区店)"
- 施工成本是固定公式(窗膜×95 + 车衣×900 + 精品×60 + 无效×50) - 施工成本是固定公式(窗膜×95 + 车衣×900 + 精品×60 + 无效×50)
- 园区名称从 Excel park_name 列直接取 - 园区名称从 Excel park_name 列直接取
SQL 数据源:dj_smartcarlife 库
- fetch_park_daily_report → 日报数据(交车数/到店数)
- fetch_light_reform_goods_stats → 品类成交数(原厂+副厂聚合)+ 产值(与店中店共用 SQL)
- fetch_est_delivery_count → 预估交车数(dj_car_life_merchant_store_info 静态配置表)
""" """
import logging import logging
import tempfile import tempfile
...@@ -26,7 +31,8 @@ from report_utils import ( ...@@ -26,7 +31,8 @@ from report_utils import (
parse_park_delivery_touch, parse_commerce_policy_park, parse_park_delivery_touch, parse_commerce_policy_park,
parse_labor_cost, is_luxury_brand, parse_labor_cost, is_luxury_brand,
parse_budget_achieve_excel, extract_budget_ratio, prorate_by_period, parse_budget_achieve_excel, extract_budget_ratio, prorate_by_period,
fetch_indicator_data, fetch_park_daily_report, fuzzy_match_store, fetch_indicator_data, fetch_park_daily_report, fetch_light_reform_goods_stats,
fetch_est_delivery_count, fuzzy_match_store,
get_with_fallback, safe_div, safe_div_pct, safe_div_pct_decimal, get_with_fallback, safe_div, safe_div_pct, safe_div_pct_decimal,
) )
from models import ReportLightReformPark, db from models import ReportLightReformPark, db
...@@ -156,20 +162,36 @@ class LightReformParkProcessor: ...@@ -156,20 +162,36 @@ class LightReformParkProcessor:
# ========== Step3: 业务系统 SQL ========== # ========== Step3: 业务系统 SQL ==========
# 3a. 日报数据(scene_type=1 轻改,一次连接两次 GROUP BY,3 字段全返回) # 3a. 日报数据(scene_type=1 轻改,一次连接两次 GROUP BY,3 字段全返回)
daily_report_map = fetch_park_daily_report(period_start, period_end, scene_type=1) daily_report_map = fetch_park_daily_report(period_start, period_end, scene_type=1)
# 3b. 模糊匹配到门店 → 组装 sql_data dict(get_with_fallback 双优先用) # 3b. 品类成交数 + 产值(店中店+园区店共用 SQL,park 侧聚合 oe+nonoe)
goods_stats_map = fetch_light_reform_goods_stats(period_start, period_end)
# 3c. 预估交车数(静态配置表,无日期参数,traffic_party_name 即门店名)
est_delivery_map = fetch_est_delivery_count(base_scene_code='100101')
# 3d. 模糊匹配到门店 → 组装 sql_data dict
# 园区店:delivery_cnt → 交车;equity + after_sale → 到店数;无效到店无 SQL → 0 # 园区店:delivery_cnt → 交车;equity + after_sale → 到店数;无效到店无 SQL → 0
biz_sql_data = {} biz_sql_data = {}
for rec in base_records: for rec in base_records:
sn = rec.get('store_name', '') sn = rec.get('store_name', '')
dr = fuzzy_match_store(sn, daily_report_map) or {} dr = fuzzy_match_store(sn, daily_report_map) or {}
gs = fuzzy_match_store(sn, goods_stats_map) or {}
eq = dr.get('equity_to_shop_count', 0) eq = dr.get('equity_to_shop_count', 0)
af = dr.get('after_sale_equity_to_shop_count', 0) af = dr.get('after_sale_equity_to_shop_count', 0)
biz_sql_data[sn] = { biz_sql_data[sn] = {
# —— 日报类(来自 fetch_park_daily_report)——
'delivery_cnt': dr.get('delivery_cnt', 0), 'delivery_cnt': dr.get('delivery_cnt', 0),
'arrival_cnt': eq + af, 'arrival_cnt': eq + af,
'arrival_invalid_cnt': 0, # 无 SQL 'arrival_invalid_cnt': 0, # 无 SQL
# —— 品类成交数(原厂+副厂聚合,来自 fetch_light_reform_goods_stats)——
'deal_cnt': gs.get('total_deal_cnt', 0),
'window_film_cnt': gs.get('window_film_oe_cnt', 0) + gs.get('window_film_nonoe_cnt', 0),
'car_wrap_cnt': gs.get('car_wrap_oe_cnt', 0) + gs.get('car_wrap_nonoe_cnt', 0),
'premium_cnt': gs.get('premium_oe_cnt', 0) + gs.get('premium_nonoe_cnt', 0),
# —— 产值(来自 fetch_light_reform_goods_stats)——
'store_sales_output': gs.get('store_output_value', Decimal('0')),
'internal_settle_value': gs.get('internal_settle_value', Decimal('0')),
# —— 预估交车数(来自 fetch_est_delivery_count,traffic_party_name 即门店名)——
'est_delivery_cnt': fuzzy_match_store(sn, est_delivery_map) or 0,
} }
# 3c. 聚合 SQL(品类成交数、产值、成本等)后续接入,当前保持默认 0 # 3e. 其他聚合 SQL(成本/市场费/流量费等)后续接入,当前保持默认 0
# ========== Step4: 上月预算明细(已在 Step1 从 Excel 解析) ========== # ========== Step4: 上月预算明细(已在 Step1 从 Excel 解析) ==========
prev_budget_map = budget_achieve_map prev_budget_map = budget_achieve_map
...@@ -207,8 +229,8 @@ class LightReformParkProcessor: ...@@ -207,8 +229,8 @@ class LightReformParkProcessor:
ind = indicator_data.get(sn, {}) ind = indicator_data.get(sn, {})
deal_cnt = int(Decimal(str(ind.get('A075', sql_data.get('deal_cnt', 0))))) deal_cnt = int(Decimal(str(ind.get('A075', sql_data.get('deal_cnt', 0)))))
# —— SQL 取值(TODO 占位)—— # —— SQL 取值(来自 fetch_inshop_goods_stats,品类=原厂+副厂聚合)——
store_sales_output = Decimal(str(sql_data.get('store_sales_output', 0))) store_sales_output = Decimal(str(sql_data.get('store_sales_output', Decimal('0'))))
internal_settle_value = Decimal(str(sql_data.get('internal_settle_value', Decimal('0')))) internal_settle_value = Decimal(str(sql_data.get('internal_settle_value', Decimal('0'))))
window_film_cnt = sql_data.get('window_film_cnt', 0) window_film_cnt = sql_data.get('window_film_cnt', 0)
car_wrap_cnt = sql_data.get('car_wrap_cnt', 0) car_wrap_cnt = sql_data.get('car_wrap_cnt', 0)
...@@ -227,9 +249,10 @@ class LightReformParkProcessor: ...@@ -227,9 +249,10 @@ class LightReformParkProcessor:
# —— 人力成本 —— # —— 人力成本 ——
headcount = labor_map.get(sn, 0) headcount = labor_map.get(sn, 0)
# —— 预算目标 —— # —— 预算目标(预估交车数:Excel 第一优先,SQL 回退)——
avg_price_target = rec.get('avg_price_target', Decimal('0')) avg_price_target = rec.get('avg_price_target', Decimal('0'))
est_delivery_cnt = rec.get('est_delivery_cnt', 0) est_delivery_cnt = get_with_fallback(
rec.get('est_delivery_cnt', 0), sql_data.get('est_delivery_cnt', 0))
est_output_value_raw = rec.get('est_output_value', Decimal('0')) est_output_value_raw = rec.get('est_output_value', Decimal('0'))
# —— 预算达成 Excel(按周期天数摊销月度固定费用) —— # —— 预算达成 Excel(按周期天数摊销月度固定费用) ——
......
...@@ -1458,6 +1458,231 @@ def fetch_park_daily_report(start_date, end_date, scene_type=1): ...@@ -1458,6 +1458,231 @@ def fetch_park_daily_report(start_date, end_date, scene_type=1):
pass pass
def fetch_light_reform_goods_stats(start_date, end_date):
"""
轻改店中店 + 园区店 共用:品类成交数 + 产值批量查询(scene_type=1)。
**一条条件聚合 SQL** 一次性查出所有门店的:
- 品类成交数:窗膜/车衣/精品(各原厂+副厂)、踏板(带礼品排除 NOT LIKE '%(赠)%')
- 总产值:门店总产值 / 内部结算产值 / 原厂总产值 / 副厂总产值(不带礼品排除,按 dj_order_type + AITO/HIMA 关键字区分)
- 总成交数:COUNT(DISTINCT order_code) 排除内部结算订单(dj_order_type != 6)
数据源表:dj_car_life_goods_sub_order (t1) + dj_car_life_goods_order (t2) + dj_car_life_pay_order (t3)
过滤条件:t1.status=1, t2.status IN (4,6,12), t2.scene_type=1, t3.success_date BETWEEN start AND end
:param start_date: date 对象
:param end_date: date 对象
:return: dict[merchant_name] = {
'total_deal_cnt': int, # 总成交数(dj_order_type != 6 的门店有效订单数)
'window_film_oe_cnt': int, # 窗膜原厂成交数
'window_film_nonoe_cnt': int, # 窗膜副厂成交数
'car_wrap_oe_cnt': int, # 车衣原厂成交数
'car_wrap_nonoe_cnt': int, # 车衣副厂成交数
'premium_oe_cnt': int, # 精品原厂成交数
'premium_nonoe_cnt': int, # 精品副厂成交数
'pedal_cnt': int, # 踏板成交数
'store_output_value': Decimal, # 门店总产值(dj_order_type != 6)
'internal_settle_value': Decimal, # 内部结算产值(dj_order_type = 6)
'oe_output_value': Decimal, # 原厂总产值(dj_order_type != 6 AND 名称含 AITO/HIMA)
'nonoe_output_value': Decimal, # 副厂总产值(dj_order_type != 6 AND 名称不含 AITO/HIMA)
}
调用方说明:
- 店中店(inshop):直接用原厂+副厂拆分字段,以及全部产值字段
- 园区店(park):品类 = 原厂+副厂求和,产值映射 store_sales_output ← store_output_value
"""
from config import Config
if not Config.BIZ_SQL_ENABLED:
logger.warning("[BizSQL-店中店商品] BIZ_SQL_ENABLED=false,跳过查询")
return {}
conn = _get_biz_sql_conn()
if conn is None:
return {}
start_str = start_date.strftime('%Y-%m-%d 00:00:00') if start_date else ''
end_str = end_date.strftime('%Y-%m-%d 23:59:59') if end_date else ''
sql = f"""
SELECT
t2.merchant_name AS merchant_name,
-- 总成交数(门店有效订单数,dj_order_type != 6 排除内部结算,与 SQL #2 一致)
COUNT(DISTINCT CASE
WHEN t1.dj_order_type != 6
THEN t2.order_code END) AS total_deal_cnt,
-- 窗膜成交数(带礼品排除)
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name IN ('自建商品-太阳膜','天窗冰甲','太阳膜')
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
AND (t1.upgrade_goods_name LIKE '%AITO%' OR t1.upgrade_goods_name LIKE '%HIMA%')
THEN t2.order_code END) AS window_film_oe_cnt,
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name IN ('自建商品-太阳膜','天窗冰甲','太阳膜')
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
AND (t1.upgrade_goods_name NOT LIKE '%AITO%' AND t1.upgrade_goods_name NOT LIKE '%HIMA%')
THEN t2.order_code END) AS window_film_nonoe_cnt,
-- 车衣成交数(带礼品排除)
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name IN ('车衣','改色膜')
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
AND (t1.upgrade_goods_name LIKE '%AITO%' OR t1.upgrade_goods_name LIKE '%HIMA%')
THEN t2.order_code END) AS car_wrap_oe_cnt,
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name IN ('车衣','改色膜')
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
AND (t1.upgrade_goods_name NOT LIKE '%AITO%' AND t1.upgrade_goods_name NOT LIKE '%HIMA%')
THEN t2.order_code END) AS car_wrap_nonoe_cnt,
-- 踏板成交数(带礼品排除)
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name = '踏板'
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
THEN t2.order_code END) AS pedal_cnt,
-- 精品成交数(带礼品排除,排除已归类的品类)
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name NOT IN (
'自建商品-太阳膜','天窗冰甲','车衣','改色膜',
'踏板','充电桩','验收一级类目','太阳膜'
)
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
AND (t1.upgrade_goods_name LIKE '%AITO%' OR t1.upgrade_goods_name LIKE '%HIMA%')
THEN t2.order_code END) AS premium_oe_cnt,
COUNT(DISTINCT CASE
WHEN t1.upgrade_goods_type_name NOT IN (
'自建商品-太阳膜','天窗冰甲','车衣','改色膜',
'踏板','充电桩','验收一级类目','太阳膜'
)
AND t1.upgrade_goods_name NOT LIKE '%(赠)%'
AND (t1.upgrade_goods_name NOT LIKE '%AITO%' AND t1.upgrade_goods_name NOT LIKE '%HIMA%')
THEN t2.order_code END) AS premium_nonoe_cnt,
-- 门店总产值(dj_order_type != 6,不含礼品排除,与原 SQL 一致)
SUM(CASE WHEN t1.dj_order_type != 6
THEN IFNULL(t1.total_price, 0) - IFNULL(t1.refund_amount, 0)
ELSE 0 END) AS store_output_value,
-- 内部结算产值(dj_order_type = 6)
SUM(CASE WHEN t1.dj_order_type = 6
THEN IFNULL(t1.total_price, 0) - IFNULL(t1.refund_amount, 0)
ELSE 0 END) AS internal_settle_value,
-- 原厂总产值(dj_order_type != 6 AND 名称含 AITO/HIMA)
SUM(CASE WHEN t1.dj_order_type != 6
AND (t1.upgrade_goods_name LIKE '%AITO%' OR t1.upgrade_goods_name LIKE '%HIMA%')
THEN IFNULL(t1.total_price, 0) - IFNULL(t1.refund_amount, 0)
ELSE 0 END) AS oe_output_value,
-- 副厂总产值(dj_order_type != 6 AND 名称不含 AITO/HIMA)
SUM(CASE WHEN t1.dj_order_type != 6
AND (t1.upgrade_goods_name NOT LIKE '%AITO%' AND t1.upgrade_goods_name NOT LIKE '%HIMA%')
THEN IFNULL(t1.total_price, 0) - IFNULL(t1.refund_amount, 0)
ELSE 0 END) AS nonoe_output_value
FROM dj_car_life_goods_sub_order t1
LEFT JOIN dj_car_life_goods_order t2
ON t2.order_code = t1.order_code
AND t2.status IN (4,6,12)
LEFT JOIN dj_car_life_pay_order t3
ON t3.order_code = t1.order_code
WHERE t1.status = 1
AND t2.scene_type = 1
AND t3.success_date BETWEEN '{start_str}' AND '{end_str}'
GROUP BY t2.merchant_name
"""
out = {}
try:
from sqlalchemy import text as sa_text
from decimal import Decimal
for r in conn.execute(sa_text(sql)).mappings().all():
mn = r['merchant_name']
if not mn:
continue
out[mn] = {
'total_deal_cnt': int(r['total_deal_cnt'] or 0),
'window_film_oe_cnt': int(r['window_film_oe_cnt'] or 0),
'window_film_nonoe_cnt': int(r['window_film_nonoe_cnt'] or 0),
'car_wrap_oe_cnt': int(r['car_wrap_oe_cnt'] or 0),
'car_wrap_nonoe_cnt': int(r['car_wrap_nonoe_cnt'] or 0),
'premium_oe_cnt': int(r['premium_oe_cnt'] or 0),
'premium_nonoe_cnt': int(r['premium_nonoe_cnt'] or 0),
'pedal_cnt': int(r['pedal_cnt'] or 0),
'store_output_value': Decimal(str(r['store_output_value'] or 0)),
'internal_settle_value': Decimal(str(r['internal_settle_value'] or 0)),
'oe_output_value': Decimal(str(r['oe_output_value'] or 0)),
'nonoe_output_value': Decimal(str(r['nonoe_output_value'] or 0)),
}
logger.info(f"[BizSQL-店中店商品] 完成, {len(out)} 个门店")
return out
except Exception as e:
logger.error(f"[BizSQL-店中店商品] 查询异常: {e}")
import traceback
logger.error(traceback.format_exc())
return {}
finally:
try:
conn.close()
except Exception:
pass
def fetch_est_delivery_count(base_scene_code='100101'):
"""
预估交车数批量查询(静态配置表,无日期参数)。
数据源:dj_car_life_merchant_store_info(门店流量方配置表)
过滤条件:base_scene_code = '100101'(轻改), deleted_flag = 'N'
:param base_scene_code: 业务场景编码,默认 '100101' 轻改
:return: dict[traffic_party_name] = estimated_delivery_count_per_month (int)
"""
from config import Config
if not Config.BIZ_SQL_ENABLED:
logger.warning("[BizSQL-预估交车数] BIZ_SQL_ENABLED=false,跳过查询")
return {}
conn = _get_biz_sql_conn()
if conn is None:
return {}
sql = f"""
SELECT traffic_party_name, estimated_delivery_count_per_month
FROM dj_car_life_merchant_store_info
WHERE base_scene_code = '{base_scene_code}'
AND deleted_flag = 'N'
AND estimated_delivery_count_per_month IS NOT NULL
"""
out = {}
try:
from sqlalchemy import text as sa_text
for r in conn.execute(sa_text(sql)).mappings().all():
tn = r['traffic_party_name']
if tn:
out[tn] = int(r['estimated_delivery_count_per_month'] or 0)
logger.info(f"[BizSQL-预估交车数] 完成, {len(out)} 个门店")
return out
except Exception as e:
logger.error(f"[BizSQL-预估交车数] 查询异常: {e}")
import traceback
logger.error(traceback.format_exc())
return {}
finally:
try:
conn.close()
except Exception:
pass
def parse_saas_achieve_details(file_path, sheet_keywords, fallback_index=0): def parse_saas_achieve_details(file_path, sheet_keywords, fallback_index=0):
""" """
解析 SAAS门店预算分解表 的指定 sheet,返回门店明细列表。 解析 SAAS门店预算分解表 的指定 sheet,返回门店明细列表。
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!