Files
37duAutomation/plugins/XQ0001-0100/XQ0033 门店管理及服务岗出勤积分更新/report/summary.py
T

58 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0033 插件 - 执行摘要组装(summary 文本 + detail 结构化数据)。"""
def build_summary(today, t2, target_path, stats, push_result=None):
"""按执行结果拼装 {summary, detail}。
stats: report_rows/selected/new/fix/del/gap/rejoin_new/rejoin_total/rejoin_skip/
rejoin_skipped_rows 计数;update=False 表示本轮仅推送(不展示更新计数)。
push_result: {label: {success, message}} 或 None(未执行推送)。
"""
if stats.get("update", True):
detail = {
"运行日": today.isoformat(),
"积分日期(T-2)": t2.isoformat(),
"报表月份": stats.get("report_month") or f"{t2.year}-{t2.month:02d}",
"工作簿": target_path,
"报表人数": stats.get("report_rows", 0),
"圈人命中": stats.get("selected", 0),
"新增积分行": stats.get("new", 0),
"补漏日期数": stats.get("gap", 0),
"修正补积分行": stats.get("fix", 0),
"修正删积分行": stats.get("del", 0),
"再入职新增行": stats.get("rejoin_new", 0),
"再入职台账人数": stats.get("rejoin_total", 0),
"再入职不操作段人数": stats.get("rejoin_skip", 0),
"再入职段跳过行数": stats.get("rejoin_skipped_rows", 0),
}
lines = [
f"XQ0033 完成(运行日 {today},积分日期 T-2={t2}):"
f"报表 {stats.get('report_rows', 0)} 人 / 圈人 {stats.get('selected', 0)} 人;"
f"积分导入新增 {stats.get('new', 0)} 行、修正补 {stats.get('fix', 0)} 行;"
f"积分删除 {stats.get('del', 0)} 行;当月再入职新增 {stats.get('rejoin_new', 0)} 行。",
f"工作簿:{target_path}",
]
if (t2.year, t2.month) != (today.year, today.month):
lines.insert(0, f"月初延续上月批次:积分日期 T-2={t2} 属 {t2.year}-{t2.month:02d},"
f"本轮报表与月首窗口按 {t2.year}-{t2.month:02d} 计算。")
if stats.get("rejoin_skip"):
desc = ";".join(stats.get("rejoin_skip_desc") or []) or f"{stats['rejoin_skip']} 人"
lines.append(f"离职当月再入职 {stats['rejoin_skip']} 人:再入职日之前的积分不操作"
f"(不导入、不删除),本轮跳过 {stats.get('rejoin_skipped_rows', 0)} 行——{desc}。")
if stats.get("gap"):
lines.append(f"检测到漏处理日期 {stats['gap']} 天,已按新增段口径全量补齐。")
else:
detail = {"运行日": today.isoformat(), "工作簿": target_path}
lines = [f"XQ0033 完成(运行日 {today},仅推送):工作簿 {target_path}"]
if push_result:
parts = []
for label, res in push_result.items():
if res.get("success") is None:
parts.append(f"{label}:{res.get('message') or '未上传'}")
else:
parts.append(f"{label}:{'成功' if res.get('success') else '失败'}({res.get('message')})")
lines.append("OPM 推送:" + ";".join(parts))
detail["OPM推送"] = push_result
return "\n".join(lines), detail