init: mini-erp-fabric-demo 迷你 ERP + 治理演示底座(FastAPI+MySQL+Docker,含业务/架构/数据字典文档与稽核脚本)

This commit is contained in:
admin committed 2026-11-24 22:43:39 +08:00
commit 509fd32518
38 files changed
+3920

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
"""数据质量稽核脚本(架构文档要求的 dq_check.py)。
运行方式:
docker compose exec erp python -m scripts.dq_check # 容器内
python -m scripts.dq_check # backend 目录下直连数据库
python -m scripts.dq_check --json # 机器可读输出(供 Dify/Agent 调用)
退出码:0 = 无 ERROR 级问题;1 = 存在 ERROR 级问题。
"""
import json
import sys
from app.database import SessionLocal
from app.services.dq import run_checks
def main():
as_json = "--json" in sys.argv
with SessionLocal() as db:
report = run_checks(db)
if as_json:
print(json.dumps(report, ensure_ascii=False, indent=2))
else:
print(f"数据质量稽核报告 {report['checked_at']}")
print("=" * 72)
for r in report["results"]:
mark = "PASS" if r["passed"] else ("WARN" if r["level"] == "WARN" else "FAIL")
print(f"[{mark}] {r['id']} {r['name']} 问题数={r['issue_count']}")
for s in r["samples"]:
print(f" - {s}")
print("=" * 72)
print(f"共 {report['total_rules']} 条规则:通过 {report['passed']},"
f"失败 {report['failed']},警告 {report['warned']}")
sys.exit(0 if report["healthy"] else 1)
if __name__ == "__main__":
main()