# -*- coding: utf-8 -*- """正式交付稿:去掉临时/注释性文字,另存新版本。""" from __future__ import annotations import re import shutil import sys import tempfile from pathlib import Path from docx import Document HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) from _add_req_func_codes import set_paragraph_text # noqa: E402 from _adjust_front_matter import remove_paragraph # noqa: E402 from _unify_ab_delivery_vnext import ( # noqa: E402 BASE, append_version_row, dest_name, ensure_version_page, find_p, iter_paras, open_via_temp, update_cover_version, version_table_after, ) from _gen_delivery_sys_docs import ( # noqa: E402 write_module_dds, write_module_um, write_sys_bbp, write_sys_brd, write_sys_dds, write_sys_um, ) from _gen_s9_diag_impr_int_delivery import write_bbp, write_brd # noqa: E402 from _gen_s9_modules_data import MODULES # noqa: E402 NOTE_OLD = "统一系统名与版本记录" NOTE_NEW = "统一系统名称与文档版式,并修订范围与用词。" DROP_RE = re.compile( r"更新域|按 F9|按F9|如目录未显示|请在 Word 中右键|" r"不再使用|统一系统名与版本记录|" r"AidopDemoShell|AllowAnonymous|仅占位|规划占位|" r"本批禁用占位|写动作禁用占位|禁用占位|" r"占位与演示边界|演示基线|数据待接入|" r"实现现状(对照实际系统)|完成度:|" r"MVP 不得伪称|列为后续|缺口(|本轮不单独立册" ) JOBS = [ ("S0", "S0-运营建模-业务需求描述-V0.7.docx", "V0.7", "V0.8"), ("S0", "S0-运营建模-业务蓝图设计方案-V0.7.docx", "V0.7", "V0.8"), ("S0", "S0运营建模模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S0", "S0-运营建模-用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S1", "S1产销协同业务需求描述-V0.3.docx", "V0.3", "V0.4"), ("S1", "S1产销协同模块蓝图设计方案-V2.1.docx", "V2.1", "V2.2"), ("S1", "S1产销协同模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S1", "S1产销协同模块用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S2", "S2制造协同业务需求描述-V0.3.docx", "V0.3", "V0.4"), ("S2", "S2制造协同模块蓝图设计方案-V0.3.docx", "V0.3", "V0.4"), ("S2", "S2制造协同模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S2", "S2制造协同模块用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S3", "S3供应协同业务需求描述-V0.3.docx", "V0.3", "V0.4"), ("S3", "S3供应协同模块蓝图设计方案-V0.3.docx", "V0.3", "V0.4"), ("S3", "S3供应协同模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S3", "S3供应协同模块用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S4", "S4采购执行业务需求描述-V0.3.docx", "V0.3", "V0.4"), ("S4", "S4采购执行模块蓝图设计方案-V0.3.docx", "V0.3", "V0.4"), ("S4", "S4采购执行模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S4", "S4采购执行模块用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S5", "S5-物料仓储-业务需求描述-V1.1.docx", "V1.1", "V1.2"), ("S5", "S5-物料仓储-业务蓝图设计方案-V0.2.docx", "V0.2", "V0.3"), ("S5", "S5物料仓储模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S5", "S5-物料仓储-用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S6", "S6-生产执行-业务需求描述-V1.1.docx", "V1.1", "V1.2"), ("S6", "S6-生产执行-业务蓝图设计方案-V0.2.docx", "V0.2", "V0.3"), ("S6", "S6生产执行模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S6", "S6-生产执行-用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S7", "S7-成品仓储-业务需求描述-V1.1.docx", "V1.1", "V1.2"), ("S7", "S7-成品仓储-业务蓝图设计方案-V0.2.docx", "V0.2", "V0.3"), ("S7", "S7成品仓储模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S7", "S7-成品仓储-用户操作手册-V1.1.docx", "V1.1", "V1.2"), ("S8", "S8-异常监控-业务需求描述-V1.1.docx", "V1.1", "V1.2"), ("S8", "S8-异常监控-业务蓝图设计方案-V0.2.docx", "V0.2", "V0.3"), ("S8", "S8异常监控模块详细设计说明书-V1.1.docx", "V1.1", "V1.2"), ("S8", "S8-异常监控-用户操作手册-V1.1.docx", "V1.1", "V1.2"), ] def drop_or_rewrite(doc: Document) -> int: n = 0 for p in list(doc.paragraphs): t = p.text.strip() if not t: continue if "临时加产" in t: continue if NOTE_OLD in t: set_paragraph_text(p, t.replace(t, NOTE_NEW) if t.startswith("统一系统名") else NOTE_NEW) n += 1 continue if DROP_RE.search(t): remove_paragraph(p) n += 1 for table in doc.tables: for row in table.rows: for cell in row.cells: for p in cell.paragraphs: raw = p.text if NOTE_OLD in raw or "不再使用「数据中台」" in raw: set_paragraph_text(p, NOTE_NEW) n += 1 elif DROP_RE.search(raw) and "版本" not in raw[:6]: if raw.strip() in {"文档编号", "版本", "密级", "编制单位", "编制日期"}: continue if re.match(r"^V\d", raw.strip()): continue set_paragraph_text(p, NOTE_NEW if "变更" in "".join(c.text for c in row.cells) else "") n += 1 return n def process_sxx(module: str, src_name: str, old_ver: str, new_ver: str) -> str: src = BASE / module / src_name if not src.exists(): return f"MISSING {src}" dest = BASE / module / dest_name(src_name, new_ver) doc, _ = open_via_temp(src) n = drop_or_rewrite(doc) update_cover_version(doc, old_ver, new_ver) heading = find_p(doc, "版本记录") if heading is not None: tbl = version_table_after(heading) if tbl is not None: append_version_row(tbl, new_ver) for row in tbl.rows: for cell in row.cells: if NOTE_OLD in cell.text: set_paragraph_text(cell.paragraphs[0], NOTE_NEW) else: ensure_version_page(doc, old_ver, new_ver) else: ensure_version_page(doc, old_ver, new_ver) tmp = Path(tempfile.gettempdir()) / "aidop_unify_ab" / f"formal_{dest.stem[:40]}.docx" tmp.parent.mkdir(parents=True, exist_ok=True) doc.save(str(tmp)) shutil.copy2(tmp, dest) return f"OK {dest.name} drop={n} {dest.stat().st_size // 1024}KB" def write_generated() -> list[str]: import _gen_delivery_sys_docs as sysgen msgs = [] orig = sysgen.save_doc def save_ver(doc, dest): dest = Path(dest) orig(doc, dest.with_name(f"{dest.stem}-V0.4{dest.suffix}")) sysgen.save_doc = save_ver try: write_sys_brd() write_sys_bbp() write_sys_dds() write_sys_um() for key in ("运营诊断", "运营改善", "ChatBI", "系统集成"): write_module_dds(key, MODULES[key]) write_module_um(key, MODULES[key]) finally: sysgen.save_doc = orig msgs.append("SYS+DDS/UM V0.4 written") for key in ("S9", "运营诊断", "运营改善", "ChatBI", "系统集成"): mod = MODULES[key] folder = BASE / mod["folder"] write_brd(mod, folder / f"{Path(mod['brd_name']).stem}-V0.4.docx") write_bbp(mod, folder / f"{Path(mod['bbp_name']).stem}-V0.4.docx") msgs.append(f"{key} BRD/BBP V0.4") return msgs def main() -> None: lines = [] for module, src_name, old_ver, new_ver in JOBS: print(f"formalize {module} {src_name}", flush=True) try: msg = process_sxx(module, src_name, old_ver, new_ver) except Exception as exc: msg = f"FAIL {module} {src_name}: {exc}" print(msg, flush=True) lines.append(msg) print("regenerate topic docs", flush=True) lines.extend(write_generated()) print("\n".join(lines), flush=True) if __name__ == "__main__": main()