Signed-off-by: 南通一次元科技有限公司 <guwangtu@icimeta.com>
This commit is contained in:
commit
b91954df4a
106 files changed
+43359
No files matched your search
@@ -0,0 +1,6 @@
|
||||
# 构建上下文不需要代码和数据(运行时通过 volume 挂载)
|
||||
app/
|
||||
# 文档与打包脚本不需要进镜像
|
||||
部署说明.md
|
||||
打包.py
|
||||
.env
|
||||
@@ -0,0 +1,5 @@
|
||||
# 登录账号密码(必填;留空则首次启动生成随机管理员密码并打印在容器日志中)
|
||||
AUTH_USER=
|
||||
AUTH_PASSWORD=
|
||||
# 登录会话 Cookie 的签名密钥(必填;四个服务必须一致,建议随机 32 位以上)
|
||||
SESSION_SECRET=
|
||||
@@ -0,0 +1,31 @@
|
||||
# 医院审计科综合管理系统 - 运行时镜像
|
||||
# 说明:代码与数据不打进镜像,由 docker-compose 通过 ./app 目录挂载,
|
||||
# 这样更新文件、备份数据都直接在宿主机上完成。
|
||||
|
||||
FROM python:3.12-slim
|
||||
|
||||
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUTF8=1 \
|
||||
LANG=C.UTF-8 \
|
||||
LC_ALL=C.UTF-8 \
|
||||
TZ=Asia/Shanghai \
|
||||
PIP_INDEX_URL=${PIP_INDEX_URL}
|
||||
|
||||
# 安装 OCR 组件(扫描件 PDF 识别),apt 使用阿里云镜像源加速
|
||||
RUN sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g; s|http://security.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends tesseract-ocr tesseract-ocr-chi-sim \
|
||||
libreoffice-writer libreoffice-calc libreoffice-impress fonts-noto-cjk \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /tmp/requirements.txt
|
||||
RUN pip install --no-cache-dir -r /tmp/requirements.txt \
|
||||
&& rm -f /tmp/requirements.txt
|
||||
|
||||
# 实际启动命令由 docker-compose.yml 中每个服务的 command 指定
|
||||
CMD ["python", "--version"]
|
||||
@@ -0,0 +1,97 @@
|
||||
# 医院审计科综合管理系统 - Docker Compose 编排
|
||||
# 四个服务共用同一镜像,代码与数据统一放在 ./app 目录下挂载到容器的 /app
|
||||
#
|
||||
# 端口:门户 8080 / 审计 8000 / 风险 8001 / 合同 8090
|
||||
# 启动:docker compose up -d --build
|
||||
# 停止:docker compose down
|
||||
# 日志:docker compose logs -f <audit|risk|contract|portal>
|
||||
|
||||
x-common: &common
|
||||
image: hospital-audit-suite:1.0
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./app:/app
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
# 登录账号密码(在 .env 文件中配置)
|
||||
AUTH_USER: ${AUTH_USER:?请在 .env 中设置 AUTH_USER}
|
||||
AUTH_PASSWORD: ${AUTH_PASSWORD:?请在 .env 中设置 AUTH_PASSWORD}
|
||||
# Cookie 会话签名密钥(四个服务必须一致)
|
||||
SESSION_SECRET: ${SESSION_SECRET:?请在 .env 中设置 SESSION_SECRET}
|
||||
|
||||
services:
|
||||
# ===== 审计项目管理平台 :8000 =====
|
||||
audit:
|
||||
<<: *common
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: audit-suite-audit
|
||||
working_dir: /app/审计项目管理平台
|
||||
command: ["python", "start_audit_server.py"]
|
||||
ports:
|
||||
- "8000:8000"
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://127.0.0.1:8000/api/health', timeout=3)"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
|
||||
# ===== 风险管理项目 :8001 =====
|
||||
risk:
|
||||
<<: *common
|
||||
container_name: audit-suite-risk
|
||||
working_dir: /app/风险管理项目
|
||||
command: ["python", "main.py"]
|
||||
ports:
|
||||
- "8001:8001"
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://127.0.0.1:8001/api/health', timeout=3)"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
|
||||
# ===== 合同审核管理平台 :8090 =====
|
||||
contract:
|
||||
<<: *common
|
||||
container_name: audit-suite-contract
|
||||
working_dir: /app/合同审核管理平台
|
||||
command: ["python", "portal_server.py"]
|
||||
ports:
|
||||
- "8090:8090"
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://127.0.0.1:8090/api/health', timeout=3)"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
|
||||
# ===== 综合管理平台(门户) :8080 =====
|
||||
portal:
|
||||
<<: *common
|
||||
container_name: audit-suite-portal
|
||||
working_dir: /app/综合管理平台
|
||||
command: ["python", "portal_server.py"]
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
AUTH_USER: ${AUTH_USER:?请在 .env 中设置 AUTH_USER}
|
||||
AUTH_PASSWORD: ${AUTH_PASSWORD:?请在 .env 中设置 AUTH_PASSWORD}
|
||||
SESSION_SECRET: ${SESSION_SECRET:?请在 .env 中设置 SESSION_SECRET}
|
||||
# 容器内用服务名互相访问,门户的健康检查依赖这三个地址
|
||||
AUDIT_URL: http://audit:8000
|
||||
RISK_URL: http://risk:8001
|
||||
CONTRACT_URL: http://contract:8090
|
||||
depends_on:
|
||||
- audit
|
||||
- risk
|
||||
- contract
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request;urllib.request.urlopen('http://127.0.0.1:8080/api/health', timeout=3)"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
@@ -0,0 +1,11 @@
|
||||
fastapi==0.143.3
|
||||
uvicorn[standard]==0.54.0
|
||||
python-multipart==0.0.32
|
||||
python-docx==1.2.0
|
||||
pypdfium2==5.15.2
|
||||
Pillow
|
||||
openai==3.33.0
|
||||
openpyxl==3.1.5
|
||||
PyPDF2==3.0.1
|
||||
pytesseract==0.3.13
|
||||
mammoth==1.8.0
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""审计管理平台冒烟测试。
|
||||
|
||||
用法:
|
||||
python deploy/冒烟测试.py
|
||||
python deploy/冒烟测试.py --url http://your-server:8080 --user shenji --password '***'
|
||||
|
||||
检查:登录(可选)、核心页面、核心接口、静态资源。返回码 0 表示全部通过。
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
except Exception:
|
||||
pass
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
import http.cookiejar
|
||||
|
||||
|
||||
PAGES = [
|
||||
("统一入口", "/"),
|
||||
("数字化审计", "/digital-audit"),
|
||||
("知识库", "/knowledge"),
|
||||
("系统设置", "/settings"),
|
||||
("旧门户", "/portal"),
|
||||
]
|
||||
|
||||
APIS = [
|
||||
("健康检查", "/api/health"),
|
||||
("当前用户", "/api/me"),
|
||||
("平台状态", "/api/platform/status"),
|
||||
("驾驶舱", "/api/da/overview"),
|
||||
("待办中心", "/api/da/todo"),
|
||||
("规则库", "/api/da/rules"),
|
||||
("审计任务", "/api/da/tasks"),
|
||||
("整改统计", "/api/da/rectifications/stats"),
|
||||
("整改报表", "/api/da/rectifications/report?dimension=dept"),
|
||||
("整改组织分布", "/api/da/rectifications/map"),
|
||||
("OCR 任务", "/api/da/ocr/tasks"),
|
||||
("要素抽取任务", "/api/da/extract/tasks"),
|
||||
("审计作业统计", "/api/da/workflow/stats"),
|
||||
("解析记录", "/api/da/parsed"),
|
||||
("数据资源", "/api/da/datasources"),
|
||||
("分析模型", "/api/da/models"),
|
||||
]
|
||||
|
||||
STATIC = [
|
||||
("数字化审计 core.js", "/static/js/core.js"),
|
||||
("数字化审计 boot.js", "/static/js/boot.js"),
|
||||
("数字化审计 CSS", "/static/digital_audit.css"),
|
||||
]
|
||||
|
||||
|
||||
def build_opener():
|
||||
cj = http.cookiejar.CookieJar()
|
||||
return urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
||||
|
||||
|
||||
def login(opener, base, user, password):
|
||||
data = urllib.parse.urlencode({"username": user, "password": password, "next": "/"}).encode()
|
||||
req = urllib.request.Request(base + "/api/login", data=data, method="POST")
|
||||
try:
|
||||
resp = opener.open(req, timeout=15)
|
||||
return resp.status in (200, 303)
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code in (200, 303)
|
||||
|
||||
|
||||
def check(opener, url, expect_json=False):
|
||||
try:
|
||||
resp = opener.open(urllib.request.Request(url), timeout=20)
|
||||
body = resp.read()
|
||||
if resp.status != 200:
|
||||
return False, f"HTTP {resp.status}"
|
||||
if expect_json:
|
||||
try:
|
||||
json.loads(body.decode("utf-8"))
|
||||
except Exception:
|
||||
return False, "返回不是合法 JSON"
|
||||
return True, f"200 / {len(body)} bytes"
|
||||
except urllib.error.HTTPError as e:
|
||||
return False, f"HTTP {e.code}"
|
||||
except Exception as e:
|
||||
return False, str(e)[:80]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--url", default="http://127.0.0.1:8080")
|
||||
parser.add_argument("--user", default="")
|
||||
parser.add_argument("--password", default="")
|
||||
args = parser.parse_args()
|
||||
base = args.url.rstrip("/")
|
||||
opener = build_opener()
|
||||
failures = []
|
||||
|
||||
if args.user:
|
||||
ok = login(opener, base, args.user, args.password)
|
||||
print(("[OK]" if ok else "[FAIL]") + " 登录")
|
||||
if not ok:
|
||||
failures.append("登录")
|
||||
|
||||
print("\n== 页面 ==")
|
||||
for name, path in PAGES:
|
||||
ok, detail = check(opener, base + path)
|
||||
print(("[OK]" if ok else "[FAIL]") + f" {name}: {detail}")
|
||||
if not ok:
|
||||
failures.append(name)
|
||||
|
||||
print("\n== 接口 ==")
|
||||
for name, path in APIS:
|
||||
ok, detail = check(opener, base + path, expect_json=True)
|
||||
print(("[OK]" if ok else "[FAIL]") + f" {name}: {detail}")
|
||||
if not ok:
|
||||
failures.append(name)
|
||||
|
||||
print("\n== 静态资源 ==")
|
||||
for name, path in STATIC:
|
||||
ok, detail = check(opener, base + path)
|
||||
print(("[OK]" if ok else "[FAIL]") + f" {name}: {detail}")
|
||||
if not ok:
|
||||
failures.append(name)
|
||||
|
||||
print("\n" + "=" * 40)
|
||||
if failures:
|
||||
print(f"冒烟测试失败 {len(failures)} 项:{'、'.join(failures)}")
|
||||
return 1
|
||||
print("冒烟测试全部通过")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""公共模块同步工具
|
||||
|
||||
当前平台由四个独立 FastAPI 服务组成,公共模块统一放在 shared/ 目录维护,
|
||||
再同步到四个项目目录,避免出现“四份代码不一致”。
|
||||
|
||||
用法:
|
||||
python deploy/同步公共模块.py # 同步 shared/ 到四个项目
|
||||
python deploy/同步公共模块.py --check # 只检查是否一致,不写入
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
WORKSPACE = Path(__file__).resolve().parent.parent
|
||||
PROJECTS = ["综合管理平台", "审计项目管理平台", "风险管理项目", "合同审核管理平台"]
|
||||
SHARED_MODULES = ["auth_guard.py", "pdf_tools.py"]
|
||||
|
||||
|
||||
def md5(path: Path) -> str:
|
||||
return hashlib.md5(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--check", action="store_true", help="只检查不写入")
|
||||
args = parser.parse_args()
|
||||
|
||||
shared_dir = WORKSPACE / "shared"
|
||||
problems = 0
|
||||
for module in SHARED_MODULES:
|
||||
src = shared_dir / module
|
||||
if not src.exists():
|
||||
print(f"[错误] 缺少公共模块:shared/{module}")
|
||||
problems += 1
|
||||
continue
|
||||
src_hash = md5(src)
|
||||
for project in PROJECTS:
|
||||
dst = WORKSPACE / project / module
|
||||
if not dst.exists():
|
||||
if args.check:
|
||||
print(f"[缺失] {project}/{module}")
|
||||
problems += 1
|
||||
else:
|
||||
shutil.copy2(src, dst)
|
||||
print(f"[已创建] {project}/{module}")
|
||||
continue
|
||||
if md5(dst) == src_hash:
|
||||
print(f"[一致] {project}/{module}")
|
||||
continue
|
||||
if args.check:
|
||||
print(f"[不一致] {project}/{module}")
|
||||
problems += 1
|
||||
else:
|
||||
shutil.copy2(src, dst)
|
||||
print(f"[已同步] {project}/{module}")
|
||||
if problems:
|
||||
print(f"\n检查完成:发现 {problems} 处问题")
|
||||
return 1
|
||||
print("\n检查完成:公共模块全部一致")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,88 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""统一嵌入主题同步工具
|
||||
|
||||
把 shared/embed_theme.css 注入到各业务页面,替换原有的
|
||||
<style id="platform-embed-style"> 内容,避免主题散落在 6 个文件里各改一份。
|
||||
|
||||
用法:
|
||||
python deploy/同步统一主题.py # 写入
|
||||
python deploy/同步统一主题.py --check # 只检查是否需要更新
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
WORKSPACE = Path(__file__).resolve().parent.parent
|
||||
THEME_FILE = WORKSPACE / "shared" / "embed_theme.css"
|
||||
|
||||
# 页面级补充样式(只放页面特有的高度/布局修正)
|
||||
PAGE_EXTRAS = {
|
||||
"审计项目管理平台/templates/index.html": "",
|
||||
"风险管理项目/templates/index.html": "",
|
||||
"合同审核管理平台/index.html": "body.embedded { height:100vh !important; }",
|
||||
"综合管理平台/knowledge.html": "",
|
||||
"综合管理平台/settings.html": "",
|
||||
"综合管理平台/digital_audit.html": "",
|
||||
}
|
||||
|
||||
STYLE_RE = re.compile(r'<style id="platform-embed-style">.*?</style>', re.S)
|
||||
SCRIPT_MARKER = 'id="platform-embed-script"'
|
||||
|
||||
|
||||
def build_block(extra: str) -> str:
|
||||
theme = THEME_FILE.read_text(encoding="utf-8")
|
||||
if extra:
|
||||
theme += "\n/* 页面补充样式 */\n" + extra + "\n"
|
||||
return '<style id="platform-embed-style">\n' + theme + "</style>"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--check", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not THEME_FILE.exists():
|
||||
print("缺少 shared/embed_theme.css")
|
||||
return 1
|
||||
problems = 0
|
||||
for rel, extra in PAGE_EXTRAS.items():
|
||||
path = WORKSPACE / rel
|
||||
if not path.exists():
|
||||
print(f"[缺失] {rel}")
|
||||
problems += 1
|
||||
continue
|
||||
raw = path.read_bytes()
|
||||
bom = raw.startswith(b"\xef\xbb\xbf")
|
||||
text = raw.decode("utf-8-sig")
|
||||
if SCRIPT_MARKER not in text:
|
||||
print(f"[缺少嵌入脚本] {rel}")
|
||||
problems += 1
|
||||
new_block = build_block(extra)
|
||||
if STYLE_RE.search(text):
|
||||
new_text = STYLE_RE.sub(lambda m: new_block, text, count=1)
|
||||
else:
|
||||
idx = text.rfind("</body>")
|
||||
if idx < 0:
|
||||
print(f"[无法定位] {rel}")
|
||||
problems += 1
|
||||
continue
|
||||
new_text = text[:idx] + new_block + "\n" + text[idx:]
|
||||
if new_text == text:
|
||||
print(f"[已是最新] {rel}")
|
||||
continue
|
||||
if args.check:
|
||||
print(f"[需要更新] {rel}")
|
||||
problems += 1
|
||||
else:
|
||||
path.write_bytes(new_text.encode("utf-8-sig" if bom else "utf-8"))
|
||||
print(f"[已同步] {rel}")
|
||||
if problems:
|
||||
print(f"\n完成:发现 {problems} 处需要处理")
|
||||
return 1
|
||||
print("\n完成:统一嵌入主题全部一致")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,307 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""生成合成演示数据包(C 阶段)。
|
||||
|
||||
从现有数据库复制 schema,清空全部业务数据后写入虚构数据并 VACUUM,
|
||||
生成:
|
||||
dist/医院智能审计管理平台-v1.0.0-demo-data.zip
|
||||
|
||||
演示数据全部为虚构内容,不包含任何真实医院、患者、合同或人员信息。
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import shutil
|
||||
import sqlite3
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
WORKSPACE = Path(__file__).resolve().parent.parent
|
||||
DBS = {
|
||||
"审计项目管理平台": WORKSPACE / "审计项目管理平台" / "audit_data.db",
|
||||
"风险管理项目": WORKSPACE / "风险管理项目" / "risk_data.db",
|
||||
"合同审核管理平台": WORKSPACE / "合同审核管理平台" / "contract.db",
|
||||
"综合管理平台": WORKSPACE / "综合管理平台" / "digital_audit.db",
|
||||
}
|
||||
KEEP_TABLES = {
|
||||
"综合管理平台": {"da_rules", "da_rule_categories", "da_models", "da_workflows"},
|
||||
}
|
||||
NOW = "2026-12-05 09:00:00"
|
||||
|
||||
|
||||
def backup_copy(src: Path, dst: Path):
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
with sqlite3.connect(str(src), timeout=15) as s, sqlite3.connect(str(dst), timeout=15) as d:
|
||||
s.backup(d)
|
||||
|
||||
|
||||
def wipe(conn, keep_tables):
|
||||
tables = [r[0] for r in conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")]
|
||||
for t in tables:
|
||||
if t in keep_tables:
|
||||
continue
|
||||
conn.execute(f'DELETE FROM "{t}"')
|
||||
try:
|
||||
conn.execute("DELETE FROM sqlite_sequence")
|
||||
except sqlite3.Error:
|
||||
pass
|
||||
conn.commit()
|
||||
|
||||
|
||||
def insert(conn, table, **data):
|
||||
cols = ",".join(data.keys())
|
||||
marks = ",".join("?" for _ in data)
|
||||
cur = conn.execute(f'INSERT INTO "{table}" ({cols}) VALUES ({marks})', tuple(data.values()))
|
||||
return cur.lastrowid
|
||||
|
||||
|
||||
def seed_audit(conn):
|
||||
cat1 = insert(conn, "categories", name="财务审计", description="演示分类", status="启用", created_at=NOW)
|
||||
cat2 = insert(conn, "categories", name="采购审计", description="演示分类", status="启用", created_at=NOW)
|
||||
p1 = insert(conn, "persons", name="张演示", department="审计科", role="审计员", contact="", created_at=NOW)
|
||||
p2 = insert(conn, "persons", name="李示例", department="审计科", role="主审", contact="", created_at=NOW)
|
||||
y1 = insert(conn, "years", year=2026, name="2026 年度审计计划(演示)", goal="演示数据",
|
||||
budget=0, status="进行中", category_id=cat1, leader_id=p2, created_at=NOW)
|
||||
projs = []
|
||||
for i, (name, cat, status, leader) in enumerate([
|
||||
("示例市第一人民医院 2026 年度财务收支审计(演示)", cat1, "实施中", p2),
|
||||
("示例市第一人民医院 2026 年度采购专项审计(演示)", cat2, "进行中", p1),
|
||||
("示例医疗集团 2026 年度合同管理审计(演示)", cat1, "报告阶段", p2),
|
||||
], start=1):
|
||||
pid = insert(conn, "projects", name=name, description="虚构的演示项目,仅用于功能体验。",
|
||||
status=status, priority="P1", budget=0, risks="", start_date="2026-01-01T00:00:00.000+08:00",
|
||||
end_date="2026-12-31T00:00:00.000+08:00", year_id=y1, category_id=cat,
|
||||
leader_id=leader, created_at=NOW)
|
||||
projs.append(pid)
|
||||
insert(conn, "project_members", project_id=pid, person_id=leader)
|
||||
s1 = insert(conn, "steps", name=name.split("(")[0] + " + 审前调查", status="已完成", priority="P1",
|
||||
progress=100, deliverable="审前调查报告", remark="", start_date="2026-01-01T00:00:00.000+08:00",
|
||||
end_date="2026-02-01T00:00:00.000+08:00", project_id=pid, leader_id=leader, created_at=NOW)
|
||||
s2 = insert(conn, "steps", name=name.split("(")[0] + " + 现场实施", status="进行中", priority="P1",
|
||||
progress=60, deliverable="审计工作底稿", remark="", start_date="2026-02-01T00:00:00.000+08:00",
|
||||
end_date="2026-06-01T00:00:00.000+08:00", project_id=pid, leader_id=leader,
|
||||
prev_step_id=s1, created_at=NOW)
|
||||
docs = [
|
||||
("审计实施方案(演示)", "方案", "本方案为演示数据:审计目标、范围、重点、时间安排和人员分工。", "已完成", s2),
|
||||
("财务管理制度(演示)", "制度", "示例医院财务管理制度:预算、收支、采购、资产等内容均为虚构。", "已完成", s1),
|
||||
("采购合同样本(演示)", "合同", "示例采购合同:甲方向乙方采购医疗设备,合同金额为演示金额。", "已完成", s2),
|
||||
]
|
||||
doc_ids = []
|
||||
for title, dtype, content, status, step in docs:
|
||||
doc_ids.append(insert(conn, "audit_docs", title=title, doc_type=dtype, content=content,
|
||||
status=status, project_id=pid, step_id=step, created_at=NOW))
|
||||
insert(conn, "analysis_results", doc_id=doc_ids[0], analysis_type="风险识别",
|
||||
summary="演示分析结果:方案缺少后续跟踪安排,建议补充整改复查节点。",
|
||||
risk_level="中", findings="1. 演示问题一;2. 演示问题二。",
|
||||
suggestions="1. 补充整改复查;2. 明确责任人和时限。", raw_output="{}", created_at=NOW)
|
||||
insert(conn, "analysis_results", doc_id=doc_ids[2], analysis_type="合同风险",
|
||||
summary="演示分析结果:合同缺少验收条款,建议补充验收标准和付款节点。",
|
||||
risk_level="高", findings="1. 缺少验收标准;2. 付款节点不明确。",
|
||||
suggestions="补充验收条款和付款条件。", raw_output="{}", created_at=NOW)
|
||||
space = insert(conn, "knowledge_spaces", space_id="demo-space-001", name="审计制度与模板(演示)", description="演示知识库",
|
||||
space_type="内部", visibility="公开", created_at=NOW)
|
||||
for title, content in [
|
||||
("内部审计工作制度(演示)", "这是虚构的演示制度文本,用于展示知识库阅读与检索。"),
|
||||
("审计报告模板(演示)", "演示模板:标题、背景、审计发现、整改建议、附件。"),
|
||||
("整改台账填写说明(演示)", "演示说明:问题描述、责任部门、整改期限、反馈、验收。"),
|
||||
]:
|
||||
insert(conn, "knowledge_docs", space_id=space, space_name="审计制度与模板(演示)", title=title,
|
||||
content=content, obj_type="docx", has_child=0, created_at=NOW)
|
||||
insert(conn, "collection_items", url="https://example.com/demo-policy", title="演示政策文章",
|
||||
content="演示采集内容,不代表任何真实政策。", source_name="示例来源", source_type="web",
|
||||
category="政策法规", status="待整理", created_at=NOW, updated_at=NOW)
|
||||
conn.commit()
|
||||
|
||||
|
||||
def seed_risk(conn):
|
||||
depts = ["财务科", "采购管理科", "医学装备科"]
|
||||
for i, d in enumerate(depts, 1):
|
||||
insert(conn, "departments", dept_code=f"D{i:02d}", dept_name=d, created_at=NOW, updated_at=NOW)
|
||||
for code, name in [("C1", "合规目标"), ("C2", "运营目标")]:
|
||||
insert(conn, "coso_erm_categories", coso_code=code, coso_name=name, created_at=NOW, updated_at=NOW)
|
||||
for code, name in [("T1", "收入管理"), ("T2", "采购管理")]:
|
||||
insert(conn, "target_categories", cat_code=code, cat_name=name, created_at=NOW, updated_at=NOW)
|
||||
ver = insert(conn, "risk_versions", year=2026, version_name="2026 演示风险库", description="虚构演示数据",
|
||||
status="启用", created_at=NOW, updated_at=NOW)
|
||||
risks = [
|
||||
("R-DEMO-001", "财务科", "采购付款未按合同约定节点执行,存在提前付款风险。", "高风险", "采购管理"),
|
||||
("R-DEMO-002", "采购管理科", "供应商准入资料不完整,未定期复核资质。", "中风险", "采购管理"),
|
||||
("R-DEMO-003", "医学装备科", "设备验收记录缺失,可能导致资产账实不符。", "中风险", "资产管理"),
|
||||
("R-DEMO-004", "财务科", "合同台账与财务付款记录未定期核对。", "高风险", "合同管理"),
|
||||
("R-DEMO-005", "采购管理科", "单一来源采购缺少论证材料。", "低风险", "采购管理"),
|
||||
]
|
||||
item_ids = []
|
||||
for i, (code, dept, desc, level, framework) in enumerate(risks, 1):
|
||||
item_ids.append(insert(conn, "risk_items", version_id=ver, risk_code=f"{dept}/{code}",
|
||||
department=dept, risk_no=code, risk_desc=desc, is_economic="是",
|
||||
in_responsibility="是", has_regulation="是", probability_score=1,
|
||||
impact_score=1, risk_total_score=1, framework=framework, risk_level=level,
|
||||
risk_type="经济", target_category="运营", target_content=framework,
|
||||
coso_erm_category="合规目标", created_at=NOW, updated_at=NOW))
|
||||
insert(conn, "risk_assessments", risk_item_id=item_ids[-1], version_id=ver,
|
||||
subjective_score=0.7, objective_score=0.7, combined_score=0.7,
|
||||
final_risk_level=level, assessment_detail="演示评估", assessed_at=NOW)
|
||||
insert(conn, "risk_unique_points", risk_no=code, risk_desc=desc, business_level="院级",
|
||||
business_framework=framework, level_code=code, risk_number=i, created_at=NOW, updated_at=NOW)
|
||||
report = insert(conn, "inspection_reports", year=2026, report_name="2026 年度检查报告(演示)",
|
||||
report_date="2026-11-01", batch_no="DEMO-2026-001", total_identified=len(risks),
|
||||
new_risks=len(risks), existing_matches=0, status="已完成", created_at=NOW)
|
||||
for i, (code, dept, desc, level, framework) in enumerate(risks, 1):
|
||||
insert(conn, "inspection_risk_data", year=2026, report_id=report, risk_no=code,
|
||||
risk_desc=desc, department=dept, is_economic="是", survey_choice="B",
|
||||
occurrence_count=i, occurrence_amount=10000 * i, remark="演示检查发现",
|
||||
batch_no="DEMO-2026-001", report_name="2026 年度检查报告(演示)",
|
||||
report_date="2026-11-01", status="已入库", created_at=NOW, updated_at=NOW,
|
||||
subjective_score=0.7, combined_score=0.7, final_risk_level=level,
|
||||
assessment_detail="演示评估")
|
||||
insert(conn, "inspection_aggregated", year=2026, risk_no=code, risk_desc=desc, department=dept,
|
||||
is_economic="是", occurrence_count=i, occurrence_amount=10000 * i,
|
||||
final_risk_level=level, aggregated_at=NOW, subjective_score=0.7, combined_score=0.7)
|
||||
conn.commit()
|
||||
|
||||
|
||||
def seed_contract(conn):
|
||||
rows = [
|
||||
("医疗设备采购合同(演示).docx", "reviewed", "采购合同", "高",
|
||||
"合同缺少验收标准和付款节点,建议补充。"),
|
||||
("信息系统运维服务合同(演示).docx", "reviewed", "服务合同", "中",
|
||||
"服务范围描述较笼统,建议明确响应时限。"),
|
||||
("办公用品采购合同(演示).docx", "pending", "采购合同", "",
|
||||
"演示数据,尚未审核。"),
|
||||
]
|
||||
for i, (name, status, ctype, level, summary) in enumerate(rows, 1):
|
||||
issues = "[]"
|
||||
if level:
|
||||
issues = ('[{"dimension":"演示维度","severity":"%s",'
|
||||
'"description":"演示问题:条款描述不完整,仅用于功能演示。"}]' % level)
|
||||
insert(conn, "contracts", name=name, file_path="", upload_date=NOW, status=status,
|
||||
contract_type=ctype, risk_level=level, issues=issues, rectifications=None,
|
||||
report_path="", summary=summary, reviewed_at=NOW if status == "reviewed" else None,
|
||||
updated_at=NOW)
|
||||
conn.commit()
|
||||
|
||||
|
||||
def seed_digital(conn):
|
||||
# 清空任务/整改/日志/解析等演示数据;规则/分类/模型/流程保留
|
||||
for table in ("da_rectifications", "da_rect_history", "da_tasks", "da_task_hits", "da_parsed_docs",
|
||||
"da_ocr_tasks", "da_ocr_files", "da_extract_tasks", "da_extract_files",
|
||||
"da_extract_results", "da_logs"):
|
||||
conn.execute(f'DELETE FROM "{table}"')
|
||||
conn.commit()
|
||||
rects = [
|
||||
("DEMO-001", "采购合同缺少验收条款", "采购管理科", "高", "待派发", 30,
|
||||
"补充验收标准、验收流程和付款节点。", "总院区", "张演示"),
|
||||
("DEMO-002", "设备验收记录不完整", "医学装备科", "中", "整改中", 15,
|
||||
"补齐设备验收单,建立设备台账复核机制。", "东院区", "李示例"),
|
||||
("DEMO-003", "合同台账未定期核对", "财务科", "高", "已办结", -10,
|
||||
"建立月度合同台账与付款记录核对机制。", "总院区", "王演示"),
|
||||
]
|
||||
for i, (no, issue, dept, level, status, days, requirement, branch, owner) in enumerate(rects, 1):
|
||||
rid = insert(conn, "da_rectifications", work_no=no, issue=issue, dept=dept, owner=owner,
|
||||
level=level, priority=level, status=status, progress=100 if status == "已办结" else (50 if status == "整改中" else 0),
|
||||
deadline="2026-12-31", requirement=requirement, branch=branch,
|
||||
created_at=NOW, updated_at=NOW)
|
||||
insert(conn, "da_rect_history", rect_id=rid, action="创建工单", from_status="", to_status="待派发",
|
||||
comment="演示数据", operator="演示管理员", created_at=NOW)
|
||||
if status != "待派发":
|
||||
insert(conn, "da_rect_history", rect_id=rid, action="派发", from_status="待派发", to_status="整改中",
|
||||
comment="演示派发", operator="演示管理员", created_at=NOW)
|
||||
if status == "已办结":
|
||||
insert(conn, "da_rect_history", rect_id=rid, action="评估到位", from_status="待评估", to_status="已办结",
|
||||
comment="演示办结", operator="演示管理员", created_at=NOW)
|
||||
task = insert(conn, "da_tasks", name="演示审计任务", task_type="综合审计", project_id=None,
|
||||
project_name="示例市第一人民医院 2026 年度财务收支审计(演示)", rule_ids="[]",
|
||||
status="已完成", progress=100, doc_total=6, hit_total=3, mode="正式运行",
|
||||
created_at=NOW, finished_at=NOW, schedule_type="立即", run_count=1)
|
||||
for i in range(1, 4):
|
||||
insert(conn, "da_task_hits", task_id=task, rule_id=None, rule_name=f"演示规则 {i}",
|
||||
risk_level="中" if i < 3 else "高", doc_id=None, doc_title="演示资料",
|
||||
hit_type="keyword_exists", snippet="演示疑点片段", description="演示疑点:请结合真实业务复核。",
|
||||
created_at=NOW)
|
||||
insert(conn, "da_parsed_docs", filename="演示制度.txt", file_type="txt", mode="文本读取", status="已完成",
|
||||
pages=1, char_count=60, preview="演示制度内容", content="这是虚构的演示制度文本,仅用于展示解析结果。",
|
||||
created_at=NOW)
|
||||
insert(conn, "da_logs", action="演示初始化", detail="已导入合成演示数据", operator="演示管理员", created_at=NOW)
|
||||
conn.commit()
|
||||
|
||||
|
||||
SEEDS = {"审计项目管理平台": seed_audit, "风险管理项目": seed_risk,
|
||||
"合同审核管理平台": seed_contract, "综合管理平台": seed_digital}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--version", default="1.0.0")
|
||||
parser.add_argument("--out", default=str(WORKSPACE / "dist"))
|
||||
args = parser.parse_args()
|
||||
outdir = Path(args.out)
|
||||
outdir.mkdir(parents=True, exist_ok=True)
|
||||
stage = Path(tempfile.mkdtemp(prefix="demo_stage_"))
|
||||
demo_root = stage / f"医院智能审计管理平台-v{args.version}-demo-data"
|
||||
demo_root.mkdir(parents=True)
|
||||
|
||||
for project, src in DBS.items():
|
||||
if not src.exists():
|
||||
print(f"[跳过] 缺少数据库:{src}")
|
||||
continue
|
||||
dst = demo_root / project / src.name
|
||||
backup_copy(src, dst)
|
||||
conn = sqlite3.connect(str(dst))
|
||||
try:
|
||||
wipe(conn, KEEP_TABLES.get(project, set()))
|
||||
SEEDS[project](conn)
|
||||
conn.execute("VACUUM")
|
||||
ok = conn.execute("PRAGMA integrity_check").fetchone()[0]
|
||||
if ok != "ok":
|
||||
raise SystemExit(f"{project} 演示库校验失败:{ok}")
|
||||
finally:
|
||||
conn.close()
|
||||
print(f"[生成] {project}/{src.name} {dst.stat().st_size/1024:.0f} KB")
|
||||
|
||||
readme = """# 医院智能审计管理平台 · 合成演示数据
|
||||
|
||||
本目录内所有数据均为**虚构数据**,不包含任何真实医院、患者、合同或人员信息。
|
||||
|
||||
## 导入方式
|
||||
|
||||
1. 先备份现有数据库(生产环境务必先备份)。
|
||||
2. 停止服务。
|
||||
3. 把以下文件复制到对应目录(覆盖同名文件):
|
||||
- `审计项目管理平台/audit_data.db`
|
||||
- `风险管理项目/risk_data.db`
|
||||
- `合同审核管理平台/contract.db`
|
||||
- `综合管理平台/digital_audit.db`
|
||||
4. 启动服务。
|
||||
5. 首次启动后如提示用户库为空,按安装文档设置管理员账号。
|
||||
|
||||
注意:仅建议在演示/测试环境导入,不要覆盖生产数据。
|
||||
"""
|
||||
(demo_root / "README.md").write_text(readme, encoding="utf-8")
|
||||
|
||||
manifest = []
|
||||
for p in sorted(demo_root.rglob("*")):
|
||||
if p.is_file():
|
||||
manifest.append(f"{hashlib.sha256(p.read_bytes()).hexdigest()} {p.relative_to(demo_root).as_posix()}")
|
||||
(demo_root / "SHA256SUMS").write_text("\n".join(manifest) + "\n", encoding="utf-8")
|
||||
|
||||
zip_path = outdir / f"医院智能审计管理平台-v{args.version}-demo-data.zip"
|
||||
if zip_path.exists():
|
||||
zip_path.unlink()
|
||||
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
for p in sorted(demo_root.rglob("*")):
|
||||
if p.is_file():
|
||||
zf.write(p, p.relative_to(demo_root.parent).as_posix())
|
||||
digest = hashlib.sha256(zip_path.read_bytes()).hexdigest()
|
||||
(outdir / "SHA256SUMS-demo.txt").write_text(f"{digest} {zip_path.name}\n", encoding="utf-8")
|
||||
shutil.rmtree(stage, ignore_errors=True)
|
||||
print(f"已生成:{zip_path}")
|
||||
print(f"SHA256:{digest}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+257
@@ -0,0 +1,257 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""项目自检脚本:部署前/提交前统一检查,避免把低级错误带到线上。
|
||||
|
||||
检查项:
|
||||
1. 四个项目 + shared 的 Python 文件语法编译
|
||||
2. 公共模块(auth_guard.py)是否与 shared 一致
|
||||
3. 关键 HTML 页面是否包含统一嵌入样式、统一入口 shell.html 是否存在
|
||||
4. 前端内联 JS 语法检查(需要本机 node;没有则跳过并提示)
|
||||
5. 数据库文件是否存在、是否可打开
|
||||
6. 可选:--url 检查线上健康接口和统一入口
|
||||
|
||||
用法:
|
||||
python deploy/自检.py
|
||||
python deploy/自检.py --url http://your-server
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
WORKSPACE = Path(__file__).resolve().parent.parent
|
||||
PROJECTS = ["综合管理平台", "审计项目管理平台", "风险管理项目", "合同审核管理平台"]
|
||||
EMBED_PAGES = [
|
||||
"审计项目管理平台/templates/index.html",
|
||||
"风险管理项目/templates/index.html",
|
||||
"合同审核管理平台/index.html",
|
||||
"综合管理平台/knowledge.html",
|
||||
"综合管理平台/settings.html",
|
||||
"综合管理平台/digital_audit.html",
|
||||
]
|
||||
DATABASES = [
|
||||
"审计项目管理平台/audit_data.db",
|
||||
"风险管理项目/risk_data.db",
|
||||
"合同审核管理平台/contract.db",
|
||||
]
|
||||
SKIP_DIRS = {".venv", "__pycache__", "backups", "node_modules", ".git"}
|
||||
|
||||
failures = []
|
||||
warnings = []
|
||||
|
||||
|
||||
def fail(msg):
|
||||
failures.append(msg)
|
||||
print(f" [失败] {msg}")
|
||||
|
||||
|
||||
def warn(msg):
|
||||
warnings.append(msg)
|
||||
print(f" [提示] {msg}")
|
||||
|
||||
|
||||
def ok(msg):
|
||||
print(f" [通过] {msg}")
|
||||
|
||||
|
||||
def check_python_syntax():
|
||||
print("\n1. Python 语法检查")
|
||||
count = 0
|
||||
targets = list(WORKSPACE.glob("shared/*.py"))
|
||||
for project in PROJECTS:
|
||||
for path in (WORKSPACE / project).rglob("*.py"):
|
||||
if SKIP_DIRS.intersection(path.parts):
|
||||
continue
|
||||
targets.append(path)
|
||||
for path in targets:
|
||||
try:
|
||||
raw = path.read_bytes()
|
||||
source = None
|
||||
for enc in ("utf-8-sig", "utf-8", "gbk", "gb18030"):
|
||||
try:
|
||||
source = raw.decode(enc)
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
if source is None:
|
||||
warn(f"{path.relative_to(WORKSPACE)} 编码无法识别,跳过")
|
||||
continue
|
||||
compile(source, str(path), "exec")
|
||||
count += 1
|
||||
except SyntaxError as e:
|
||||
fail(f"{path.relative_to(WORKSPACE)} 语法错误:{e}")
|
||||
ok(f"{count} 个 Python 文件编译通过")
|
||||
|
||||
|
||||
def check_public_modules():
|
||||
print("\n2. 公共模块一致性")
|
||||
src = WORKSPACE / "shared" / "auth_guard.py"
|
||||
if not src.exists():
|
||||
fail("缺少 shared/auth_guard.py")
|
||||
return
|
||||
src_hash = hashlib.md5(src.read_bytes()).hexdigest()
|
||||
for project in PROJECTS:
|
||||
dst = WORKSPACE / project / "auth_guard.py"
|
||||
if not dst.exists():
|
||||
fail(f"{project}/auth_guard.py 缺失")
|
||||
elif hashlib.md5(dst.read_bytes()).hexdigest() != src_hash:
|
||||
fail(f"{project}/auth_guard.py 与 shared 不一致(执行 deploy/同步公共模块.py 修复)")
|
||||
else:
|
||||
ok(f"{project}/auth_guard.py 一致")
|
||||
|
||||
|
||||
def check_pages():
|
||||
print("\n3. 统一入口与嵌入页面")
|
||||
shell = WORKSPACE / "综合管理平台" / "shell.html"
|
||||
if shell.exists():
|
||||
ok("统一入口 shell.html 存在")
|
||||
else:
|
||||
fail("缺少综合管理平台/shell.html")
|
||||
for rel in EMBED_PAGES:
|
||||
path = WORKSPACE / rel
|
||||
if not path.exists():
|
||||
fail(f"缺少页面:{rel}")
|
||||
continue
|
||||
text = path.read_text(encoding="utf-8", errors="ignore")
|
||||
if "platform-embed-style" not in text:
|
||||
fail(f"{rel} 缺少统一嵌入样式(platform-embed-style)")
|
||||
elif "shared/embed_theme.css" not in text:
|
||||
fail(f"{rel} 嵌入样式不是统一主题来源(执行 deploy/同步统一主题.py)")
|
||||
elif "portalTopBack" not in text:
|
||||
warn(f"{rel} 未看到返回门户隐藏规则")
|
||||
else:
|
||||
ok(f"{rel} 统一嵌入主题正常")
|
||||
|
||||
|
||||
def node_path():
|
||||
for name in ("node", "node.exe"):
|
||||
path = shutil.which(name)
|
||||
if path:
|
||||
return path
|
||||
return None
|
||||
|
||||
|
||||
def check_js():
|
||||
print("\n4. 前端 JS 语法")
|
||||
node = node_path()
|
||||
if not node:
|
||||
warn("未找到 node,跳过 JS 语法检查")
|
||||
return
|
||||
temp = Path(tempfile.gettempdir()) / "_platform_js_check.js"
|
||||
checked = 0
|
||||
for rel in EMBED_PAGES + ["综合管理平台/shell.html"]:
|
||||
path = WORKSPACE / rel
|
||||
if not path.exists():
|
||||
continue
|
||||
html = path.read_text(encoding="utf-8", errors="ignore")
|
||||
for block in re.findall(r"<script[^>]*>(.*?)</script>", html, re.S):
|
||||
if not block.strip():
|
||||
continue
|
||||
temp.write_text(block, encoding="utf-8")
|
||||
r = subprocess.run([node, "--check", str(temp)], capture_output=True, text=True)
|
||||
if r.returncode != 0:
|
||||
fail(f"{rel} 内联 JS 语法错误:{r.stderr.strip()[:200]}")
|
||||
checked += 1
|
||||
ok(f"检查 {checked} 个内联脚本块")
|
||||
|
||||
|
||||
def check_static_assets():
|
||||
print("\n4.1 静态资源(数字化审计拆分后)")
|
||||
html_path = WORKSPACE / "综合管理平台" / "digital_audit.html"
|
||||
css_path = WORKSPACE / "综合管理平台" / "digital_audit.css"
|
||||
js_dir = WORKSPACE / "综合管理平台" / "js"
|
||||
for path in (css_path, html_path):
|
||||
if not path.exists():
|
||||
fail(f"缺少静态资源:{path.relative_to(WORKSPACE)}")
|
||||
else:
|
||||
ok(f"{path.relative_to(WORKSPACE)} 存在")
|
||||
if not js_dir.is_dir():
|
||||
fail("缺少静态资源目录:综合管理平台/js")
|
||||
return
|
||||
text = html_path.read_text(encoding="utf-8", errors="ignore")
|
||||
if "/static/digital_audit.css" not in text:
|
||||
fail("digital_audit.html 未引用 /static/digital_audit.css")
|
||||
modules = sorted(js_dir.glob("*.js"))
|
||||
if not modules:
|
||||
fail("综合管理平台/js 下没有前端模块")
|
||||
return
|
||||
for m in modules:
|
||||
if f"/static/js/{m.name}" not in text:
|
||||
fail(f"digital_audit.html 未引用前端模块 {m.name}")
|
||||
if "/static/digital_audit.js" in text:
|
||||
fail("digital_audit.html 仍引用已拆分旧文件 digital_audit.js")
|
||||
node = node_path()
|
||||
checked = 0
|
||||
if node:
|
||||
for m in modules:
|
||||
r = subprocess.run([node, "--check", str(m)], capture_output=True, text=True)
|
||||
if r.returncode != 0:
|
||||
fail(f"{m.name} 语法错误:{r.stderr.strip()[:200]}")
|
||||
else:
|
||||
checked += 1
|
||||
ok(f"{checked} 个前端模块语法通过")
|
||||
|
||||
|
||||
def check_databases():
|
||||
print("\n5. 数据库文件")
|
||||
for rel in DATABASES:
|
||||
path = WORKSPACE / rel
|
||||
if not path.exists():
|
||||
warn(f"{rel} 不存在(本地可能未下载数据,不影响代码自检)")
|
||||
continue
|
||||
try:
|
||||
conn = sqlite3.connect(f"file:{path.as_posix()}?mode=ro", uri=True)
|
||||
tables = conn.execute("SELECT COUNT(*) FROM sqlite_master WHERE type='table'").fetchone()[0]
|
||||
conn.close()
|
||||
ok(f"{rel} 可打开,{tables} 张表")
|
||||
except Exception as e:
|
||||
fail(f"{rel} 无法打开:{e}")
|
||||
|
||||
|
||||
def check_url(base):
|
||||
print(f"\n6. 线上检查:{base}")
|
||||
paths = ["/api/health", "/api/health/audit", "/api/health/risk", "/api/health/contract"]
|
||||
for p in paths:
|
||||
try:
|
||||
with urllib.request.urlopen(base.rstrip("/") + p, timeout=8) as resp:
|
||||
if resp.status == 200:
|
||||
ok(f"{p} 200")
|
||||
else:
|
||||
fail(f"{p} 返回 {resp.status}")
|
||||
except Exception as e:
|
||||
fail(f"{p} 无法访问:{e}")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--url", help="可选:线上服务根地址,如 http://your-server:8080")
|
||||
args = parser.parse_args()
|
||||
|
||||
print("=" * 60)
|
||||
print("审计管理平台 · 项目自检")
|
||||
print("=" * 60)
|
||||
check_python_syntax()
|
||||
check_public_modules()
|
||||
check_pages()
|
||||
check_js()
|
||||
check_static_assets()
|
||||
check_databases()
|
||||
if args.url:
|
||||
check_url(args.url)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
if failures:
|
||||
print(f"自检失败:{len(failures)} 项错误,{len(warnings)} 项提示")
|
||||
return 1
|
||||
print(f"自检通过:0 项错误,{len(warnings)} 项提示")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user