| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/usr/bin/env python3
- """将 docs/sop-templates/SOP-CC-001-E01-01.html 写入工艺 SOP-CC-001-E01-01 的 sop_content。
- 生产环境请执行 docs/sql/2026-08-25-seed-sop-cc-001-content.sql,勿依赖本脚本。
- """
- from __future__ import annotations
- import sys
- from datetime import datetime
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[1]
- sys.path.insert(0, str(ROOT / "backend"))
- from sqlalchemy import create_engine, text # noqa: E402
- from app.core.config import settings # noqa: E402
- PROCESS_CODE = "SOP-CC-001-E01-01"
- HTML_PATH = ROOT / "docs" / "sop-templates" / "SOP-CC-001-E01-01.html"
- def main() -> None:
- html = HTML_PATH.read_text(encoding="utf-8")
- engine = create_engine(settings.DATABASE_URL)
- with engine.begin() as conn:
- result = conn.execute(
- text(
- """
- UPDATE biz_process
- SET sop_content = :html,
- update_time = :now
- WHERE process_code = :code
- AND del_flag = 0
- """
- ),
- {"html": html, "now": datetime.now(), "code": PROCESS_CODE},
- )
- if result.rowcount < 1:
- raise SystemExit(f"未找到工艺 process_code={PROCESS_CODE}")
- row = conn.execute(
- text(
- "SELECT id, process_name, LENGTH(sop_content) AS n "
- "FROM biz_process WHERE process_code=:code AND del_flag=0"
- ),
- {"code": PROCESS_CODE},
- ).fetchone()
- print(f"已更新 {PROCESS_CODE}({row[1]}),sop_content 长度 {row[2]}")
- if __name__ == "__main__":
- main()
|