Commit bc5e51f3 by 周立明

北汽专项-附件模板预填排除已闭店门店

1 parent 91be2fa4
...@@ -4,3 +4,10 @@ ...@@ -4,3 +4,10 @@
- baic_special_processor.py generate_result_excel(约1910行):上月段表头行(cur_prev_row+1) col15-18 用 _set_cell 置 None;数据行(_p_row) O~R 此前已清空(1928行原有逻辑保留)。 - baic_special_processor.py generate_result_excel(约1910行):上月段表头行(cur_prev_row+1) col15-18 用 _set_cell 置 None;数据行(_p_row) O~R 此前已清空(1928行原有逻辑保留)。
- 本月段表头+环比数据(data_row O~R = 本月-上月)与 DB 汇总表 *_mom_pp 回写均不变。 - 本月段表头+环比数据(data_row O~R = 本月-上月)与 DB 汇总表 *_mom_pp 回写均不变。
- 已 py_compile + grep 回读确认;生效需重启后端 PID 13536 + 重跑任务。 - 已 py_compile + grep 回读确认;生效需重启后端 PID 13536 + 重跑任务。
## 北汽专项-附件模板预填排除已闭店门店(2026-11-04)
- 需求:下载北汽附件模板时,预填门店排除已闭店门店。
- baic_special_processor.py:新增 BAIC_CLOSED_STORE_SQL(sale_close_store_record, deleted_flag='N' AND status=3,DISTINCT shop_merchant_id;status=3 不会回退,任一记录即已闭店;待关店 status=1 不排除)+ fetch_baic_closed_store_codes()(失败返回 set() 回退全量预填)。
- build_attachment_template:按 store_info[name]['store_code'] ∈ 闭店编码集合排除,日志打排除家数;store_code 缺失不误排除。
- 仅影响模板下载预填;fetch_baic_store_info 本身未改,结果表/基础信息匹配不受影响。
- 已 py_compile + mock 自测(排除/无闭店/编码不匹配/store_code缺失)全过;生效需重启后端 PID 13536。
...@@ -494,6 +494,16 @@ WHERE a.deleted_flag = 'N' ...@@ -494,6 +494,16 @@ WHERE a.deleted_flag = 'N'
AND b.group_name = :group_name AND b.group_name = :group_name
""" """
# 已关店记录(dj_smartcarlife.sale_close_store_record,口径与 common_equity_processor 一致):
# status=3 已关店 / status=1 待关店;已关店查全部历史记录(status=3 不会回退,任一记录即视为已闭店)。
# 附件模板预填门店时排除已闭店门店(用户 2026-11-04)。
BAIC_CLOSED_STORE_SQL = """
SELECT DISTINCT shop_merchant_id
FROM sale_close_store_record
WHERE deleted_flag = 'N'
AND status = 3
"""
def fetch_baic_store_info(group_name=BAIC_GROUP_NAME): def fetch_baic_store_info(group_name=BAIC_GROUP_NAME):
"""查询北汽项目组下门店的 D+ 基础信息(dj_smartcarlife 单次查询)。 """查询北汽项目组下门店的 D+ 基础信息(dj_smartcarlife 单次查询)。
...@@ -555,6 +565,21 @@ def fetch_baic_store_info(group_name=BAIC_GROUP_NAME): ...@@ -555,6 +565,21 @@ def fetch_baic_store_info(group_name=BAIC_GROUP_NAME):
return result return result
def fetch_baic_closed_store_codes():
"""查询 D+ 已关店门店编码集合(sale_close_store_record,status=3 已关店)。
返回 {shop_merchant_id(str)};查询失败返回 set()(不致命,调用方回退为全量预填)。
"""
engine = _get_biz_engine()
try:
with engine.connect() as conn:
rows = conn.execute(text(BAIC_CLOSED_STORE_SQL)).fetchall()
except Exception as e:
logger.warning(f"[北汽] 已闭店门店查询失败(回退为全量预填): {e}")
return set()
return {str(r[0]).strip() for r in rows if r[0] not in (None, '')}
# ---------- D+ 系统:截止目前产值(dj_smartcarlife) ---------- # ---------- D+ 系统:截止目前产值(dj_smartcarlife) ----------
# 用户提供口径(2026-09-21):按门店 merchant_id + 周期 success_date 区间汇总支付成功金额。 # 用户提供口径(2026-09-21):按门店 merchant_id + 周期 success_date 区间汇总支付成功金额。
# merchant_id <- 门店 D+ 编码(即 store_code,来自 pg_group_store_rel.merchant_id) # merchant_id <- 门店 D+ 编码(即 store_code,来自 pg_group_store_rel.merchant_id)
...@@ -1003,21 +1028,32 @@ class BaicSpecialProcessor: ...@@ -1003,21 +1028,32 @@ class BaicSpecialProcessor:
def build_attachment_template(self): def build_attachment_template(self):
"""基于附件模板预填门店名称(连续填充,自动扩展到全部门店),返回临时文件路径。 """基于附件模板预填门店名称(连续填充,自动扩展到全部门店),返回临时文件路径。
门店来源:fetch_baic_store_info() 全量(含闭店)。 门店来源:fetch_baic_store_info() 北汽项目组全量,**排除已闭店门店**
(sale_close_store_record status=3,用户 2026-11-04;闭店查询失败时回退为全量预填)。
布局:从 row3 起连续写门店名到 A 列(跳过 row1/2 表头);其余列及末尾汇总段示例值全部清空。 布局:从 row3 起连续写门店名到 A 列(跳过 row1/2 表头);其余列及末尾汇总段示例值全部清空。
末尾汇总段(北汽品牌汇总 / 售后门店数 / 售后场景开通率)随门店数动态下移,与门店列表之间 末尾汇总段(北汽品牌汇总 / 售后门店数 / 售后场景开通率)随门店数动态下移,与门店列表之间
保留一行空行作分隔,并复刻原模板汇总段样式(绿色标题行 + 黄色数据行,A-B 列填充、加粗、居中)。 保留一行空行作分隔,并复刻原模板汇总段样式(绿色标题行 + 黄色数据行,A-B 列填充、加粗、居中)。
⚠ D+ 不可达时 fetch_baic_store_info 返回 {},门店名列表为空(仅表头 + 空数据区 + 汇总段标签)。 ⚠ D+ 不可达时 fetch_baic_store_info 返回 {},门店名列表为空(仅表头 + 空数据区 + 汇总段标签)。
""" """
# 门店名称列表(D+ 北汽项目组全量,去重保序) # 门店名称列表(D+ 北汽项目组全量,排除已闭店,去重保序)
store_info = fetch_baic_store_info() store_info = fetch_baic_store_info()
closed_codes = fetch_baic_closed_store_codes()
seen = set() seen = set()
store_names = [] store_names = []
for name in store_info.keys(): excluded = 0
for name, info in store_info.items():
if name is None or name in seen: if name is None or name in seen:
continue continue
if closed_codes:
code = (info or {}).get('store_code')
if code is not None and str(code).strip() in closed_codes:
excluded += 1
continue
seen.add(name) seen.add(name)
store_names.append(name) store_names.append(name)
if excluded:
logger.info(f"[北汽] 附件模板预填:排除已闭店门店 {excluded} 家,"
f"实际预填 {len(store_names)} 家")
wb = openpyxl.load_workbook(BAIC_ATTACH_TEMPLATE_PATH) wb = openpyxl.load_workbook(BAIC_ATTACH_TEMPLATE_PATH)
ws = wb[wb.sheetnames[0]] ws = wb[wb.sheetnames[0]]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!