feat: 新增内网文件服务器离线监控,升级ERP报表导出插件适配新旧系统差异

1.  新增内网文件服务器心跳上报与离线监控功能:
    - 为文件服务器添加周期心跳上报到中心机的能力
    - 中心机新增文件服务器状态监控线程,超时自动判离线并钉钉告警管理员
    - 新增数据库表存储文件服务器状态,提供管理端API查看在线状态
2.  修复ERP物料收发汇总报表插件:
    - 调整插件版本到1.0.9,更新前端配置与UI适配新旧ERP系统
    - 重构组织与仓库默认值逻辑,区分新版/旧版ERP的默认配置
    - 统一所有场景下显式设置查询组织,移除旧版默认组织的兼容逻辑
    - 新增代管仓仓库编码适配旧版系统
3.  优化文件服务器打包脚本路径,更新文档示例命令
This commit is contained in:
2026-09-19 14:55:22 +08:00
parent c23c123fb8
commit b1ae4e5111
31 changed files with 39259 additions and 145 deletions
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,128 @@
This file lists modules PyInstaller was not able to find. This does not
necessarily mean these modules are required for running your program. Both
Python's standard library and 3rd-party Python packages often conditionally
import optional modules, some of which may be available only on certain
platforms.
Types of import:
* top-level: imported at the top-level - look at these first
* conditional: imported within an if-statement
* delayed: imported within a function
* optional: imported within a try-except-statement
IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
tracking down the missing module yourself. Thanks!
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional), zipimport (top-level)
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional), zipimport (top-level)
missing module named 'org.python' - imported by copy (optional), xml.sax (delayed, conditional)
missing module named posix - imported by os (conditional, optional), posixpath (optional), shutil (conditional), importlib._bootstrap_external (conditional)
missing module named resource - imported by posix (top-level)
missing module named grp - imported by shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional)
missing module named pwd - imported by posixpath (delayed, conditional, optional), shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional), webbrowser (delayed), getpass (delayed), netrc (delayed, conditional)
missing module named _posixsubprocess - imported by subprocess (conditional), multiprocessing.util (delayed)
missing module named fcntl - imported by subprocess (optional)
missing module named _posixshmem - imported by multiprocessing.resource_tracker (conditional), multiprocessing.shared_memory (conditional)
missing module named _scproxy - imported by urllib.request (conditional)
missing module named termios - imported by click._termui_impl (conditional), tty (top-level), getpass (optional)
missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
missing module named multiprocessing.BufferTooShort - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
missing module named multiprocessing.AuthenticationError - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
missing module named multiprocessing.get_context - imported by multiprocessing (top-level), multiprocessing.pool (top-level), multiprocessing.managers (top-level), multiprocessing.sharedctypes (top-level)
missing module named multiprocessing.TimeoutError - imported by multiprocessing (top-level), multiprocessing.pool (top-level)
missing module named org - imported by pickle (optional)
missing module named multiprocessing.set_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
missing module named multiprocessing.get_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
missing module named multiprocessing.Pipe - imported by multiprocessing (top-level), uvicorn.supervisors.multiprocess (top-level)
missing module named pyimod02_importers - imported by D:\work\code\37duAutomation\.venv\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py (delayed)
missing module named email_validator - imported by pydantic.networks (delayed, conditional, optional), pydantic.v1.networks (delayed, conditional, optional), fastapi.openapi.models (optional), D:\work\code\37duAutomation\desktop\fileserver\launch.py (top-level), pydantic.v1._hypothesis_plugin (optional)
missing module named asyncio.DefaultEventLoopPolicy - imported by asyncio (delayed, conditional), asyncio.events (delayed, conditional)
missing module named annotationlib - imported by typing_extensions (conditional), pydantic._internal._typing_extra (delayed, conditional), pydantic._internal._model_construction (delayed, conditional), pydantic.v1.main (delayed, conditional), fastapi.dependencies.utils (delayed, conditional, optional)
missing module named vms_lib - imported by platform (delayed, optional)
missing module named java - imported by platform (delayed)
missing module named _winreg - imported by platform (delayed, optional)
missing module named trio - imported by httpx._transports.asgi (delayed, conditional), httpcore._synchronization (optional), httpcore._backends.trio (top-level), websockets.trio.client (top-level), websockets.trio.connection (top-level), websockets.trio.messages (top-level), websockets.trio.utils (top-level), websockets.trio.router (top-level), websockets.trio.server (top-level)
missing module named sniffio - imported by anyio._core._eventloop (optional), httpx._transports.asgi (delayed, optional), httpcore._synchronization (delayed, optional)
missing module named socksio - imported by httpcore._sync.socks_proxy (top-level), httpcore._async.socks_proxy (top-level), httpx._transports.default (delayed, conditional, optional)
missing module named 'h2.settings' - imported by httpcore._sync.http2 (top-level), httpcore._async.http2 (top-level)
missing module named 'h2.exceptions' - imported by httpcore._sync.http2 (top-level), httpcore._async.http2 (top-level)
missing module named 'h2.events' - imported by httpcore._sync.http2 (top-level), httpcore._async.http2 (top-level)
missing module named 'h2.connection' - imported by httpcore._sync.http2 (top-level), httpcore._async.http2 (top-level)
missing module named h2 - imported by httpcore._sync.http2 (top-level), httpx._client (delayed, conditional, optional)
missing module named 'h2.config' - imported by httpcore._async.http2 (top-level)
missing module named 'rich.table' - imported by httpx._main (top-level)
missing module named 'rich.syntax' - imported by httpx._main (top-level)
missing module named 'rich.progress' - imported by httpx._main (top-level)
missing module named 'rich.markup' - imported by httpx._main (top-level)
missing module named 'rich.console' - imported by httpx._main (top-level)
missing module named 'pygments.util' - imported by httpx._main (top-level)
missing module named pygments - imported by httpx._main (top-level)
missing module named '_typeshed.wsgi' - imported by httpx._transports.wsgi (conditional)
missing module named _typeshed - imported by anyio.abc._eventloop (conditional), anyio._core._sockets (conditional), anyio._core._fileio (conditional), anyio._core._tempfile (conditional), pydantic_core._pydantic_core (top-level), pydantic._internal._dataclasses (conditional), httpx._transports.wsgi (conditional), anyio._backends._asyncio (conditional), anyio._core._asyncio_selector_thread (conditional), anyio._backends._trio (conditional)
missing module named zstandard - imported by httpx._decoders (optional)
missing module named brotlicffi - imported by httpx._decoders (optional)
missing module named brotli - imported by httpx._decoders (optional)
missing module named wsproto - imported by uvicorn.protocols.websockets.wsproto_impl (top-level), uvicorn.protocols.websockets.auto (optional), D:\work\code\37duAutomation\desktop\fileserver\launch.py (top-level)
missing module named 'trio.abc' - imported by websockets.trio.connection (top-level), websockets.trio.server (top-level)
missing module named 'werkzeug.routing' - imported by websockets.asyncio.router (optional), websockets.sync.router (optional), websockets.trio.router (optional)
missing module named 'werkzeug.exceptions' - imported by websockets.sync.router (optional), websockets.trio.router (optional)
missing module named 'python_socks.async_' - imported by websockets.asyncio.client (optional), websockets.trio.client (optional)
missing module named python_socks - imported by websockets.asyncio.client (optional), websockets.sync.client (optional), websockets.trio.client (optional)
missing module named 'python_socks.sync' - imported by websockets.sync.client (optional)
missing module named readline - imported by websockets.cli (delayed, optional)
missing module named werkzeug - imported by websockets.asyncio.router (optional)
missing module named httptools - imported by uvicorn.protocols.http.httptools_impl (top-level), uvicorn.protocols.http.auto (optional), D:\work\code\37duAutomation\desktop\fileserver\launch.py (top-level)
missing module named a2wsgi - imported by uvicorn.middleware.wsgi (optional)
missing module named zttp - imported by uvicorn.protocols.http.zttp_impl (top-level)
missing module named 'IPython.core' - imported by dotenv.ipython (top-level)
missing module named IPython - imported by dotenv.ipython (top-level)
excluded module named win32con - imported by win32evtlogutil (top-level)
excluded module named win32api - imported by win32evtlogutil (top-level)
missing module named 'wsproto.utilities' - imported by uvicorn.protocols.websockets.wsproto_impl (top-level)
missing module named 'wsproto.extensions' - imported by uvicorn.protocols.websockets.wsproto_impl (top-level)
missing module named 'wsproto.connection' - imported by uvicorn.protocols.websockets.wsproto_impl (top-level)
missing module named uvloop - imported by uvicorn.loops.auto (delayed, optional), uvicorn.loops.uvloop (top-level), anyio._backends._asyncio (delayed, conditional)
missing module named 'trio.testing' - imported by anyio._backends._trio (delayed)
missing module named exceptiongroup - imported by anyio._core._exceptions (conditional), anyio._core._sockets (conditional), starlette._utils (conditional, optional), anyio._backends._asyncio (conditional), anyio._backends._trio (conditional)
missing module named 'trio.to_thread' - imported by anyio._backends._trio (top-level)
missing module named 'trio.socket' - imported by anyio._backends._trio (top-level)
missing module named outcome - imported by anyio._backends._trio (top-level)
missing module named 'trio.lowlevel' - imported by anyio._backends._trio (top-level)
missing module named 'trio.from_thread' - imported by anyio._backends._trio (top-level)
missing module named '_pytest.outcomes' - imported by anyio._backends._asyncio (delayed)
missing module named _pytest - imported by anyio._backends._asyncio (delayed)
missing module named winloop - imported by anyio._backends._asyncio (delayed, conditional)
missing module named 'pathlib.types' - imported by anyio._core._fileio (conditional)
missing module named cython - imported by pydantic.v1.version (optional)
missing module named toml - imported by pydantic.v1.mypy (delayed, conditional, optional)
missing module named tomli - imported by pydantic.mypy (delayed, conditional, optional), pydantic.v1.mypy (delayed, conditional, optional)
missing module named 'mypy.version' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.util' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.typevars' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.types' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.server' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.semanal' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.plugins' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.plugin' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.options' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.nodes' - imported by pydantic.mypy (top-level), pydantic.v1.mypy (top-level)
missing module named 'mypy.errorcodes' - imported by pydantic.v1.mypy (top-level)
missing module named hypothesis - imported by pydantic.v1._hypothesis_plugin (top-level)
missing module named 'mypy.typeops' - imported by pydantic.mypy (top-level)
missing module named 'mypy.type_visitor' - imported by pydantic.mypy (top-level)
missing module named 'mypy.state' - imported by pydantic.mypy (top-level)
missing module named 'mypy.expandtype' - imported by pydantic.mypy (top-level)
missing module named mypy - imported by pydantic.mypy (top-level)
missing module named eval_type_backport - imported by pydantic._internal._typing_extra (delayed, optional)
missing module named 'rich.pretty' - imported by pydantic._internal._core_utils (delayed)
missing module named rich - imported by pydantic._internal._core_utils (conditional)
missing module named pydantic.PydanticSchemaGenerationError - imported by pydantic (delayed), pydantic.functional_validators (delayed), fastapi._compat.v2 (top-level)
missing module named pydantic.PydanticUserError - imported by pydantic (top-level), pydantic.root_model (top-level)
missing module named pydantic.BaseModel - imported by pydantic (conditional), pydantic._internal._typing_extra (conditional), pydantic._internal._core_utils (delayed), pydantic._internal._import_utils (delayed, conditional), pydantic.deprecated.copy_internals (delayed, conditional), fastapi.exceptions (top-level), fastapi.types (top-level), fastapi._compat.shared (top-level), fastapi._compat.v2 (top-level), fastapi.openapi.models (top-level), fastapi.security.http (top-level), fastapi.dependencies.utils (top-level), fastapi.encoders (top-level), fastapi.sse (top-level), fastapi.openapi.utils (top-level)
missing module named 'itsdangerous.exc' - imported by starlette.middleware.sessions (top-level)
missing module named itsdangerous - imported by starlette.middleware.sessions (top-level)
missing module named pydantic_extra_types - imported by fastapi.encoders (optional)
missing module named 'gunicorn.workers' - imported by uvicorn.workers (top-level)
missing module named gunicorn - imported by uvicorn.workers (top-level)
missing module named watchfiles - imported by uvicorn.supervisors.watchfilesreload (top-level)
File diff suppressed because it is too large Load Diff
+10
View File
@@ -27,6 +27,13 @@ TOKEN = os.getenv("FILESERVER_TOKEN", "") # 上传/删除/列表鉴权
DATA_DIR = Path(os.getenv("FILESERVER_DATA_DIR", "") or (APP_DIR / "data")).resolve()
# 对外下载根(生成 url 用,须内网机器可访问);未配时回退 本机 IP 端口 形式
BASE_URL = os.getenv("FILESERVER_BASE_URL", "").rstrip("/") or f"http://127.0.0.1:{PORT}"
# 中心机(控制面)上报:非空时后台线程周期上报心跳状态,中心机据此监控在线/离线。
# CONTROLPLANE_URL 中心机地址,如 http://117.72.191.188:8800
# CONTROLPLANE_TOKEN 与中心机 controlplane/.env 的 CONTROLPLANE_TOKEN 一致
CONTROLPLANE_URL = os.getenv("CONTROLPLANE_URL", "").rstrip("/")
CONTROLPLANE_TOKEN = os.getenv("CONTROLPLANE_TOKEN", "")
# 心跳上报间隔(秒)
HEARTBEAT_INTERVAL = int(os.getenv("FILESERVER_HEARTBEAT_INTERVAL", "60") or "60")
def load_dotenv() -> None:
@@ -51,6 +58,9 @@ PORT = int(os.getenv("FILESERVER_PORT", "8802") or "8802")
TOKEN = os.getenv("FILESERVER_TOKEN", "")
DATA_DIR = Path(os.getenv("FILESERVER_DATA_DIR", "") or (APP_DIR / "data")).resolve()
BASE_URL = os.getenv("FILESERVER_BASE_URL", "").rstrip("/") or f"http://127.0.0.1:{PORT}"
CONTROLPLANE_URL = os.getenv("CONTROLPLANE_URL", "").rstrip("/")
CONTROLPLANE_TOKEN = os.getenv("CONTROLPLANE_TOKEN", "")
HEARTBEAT_INTERVAL = int(os.getenv("FILESERVER_HEARTBEAT_INTERVAL", "60") or "60")
def default_token() -> str:
+88 -1
View File
@@ -14,9 +14,14 @@ from __future__ import annotations
import hashlib
import json
import logging
import re
import secrets
import socket
import threading
import time
import urllib.request
from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import FastAPI, Header, HTTPException, UploadFile
@@ -24,7 +29,7 @@ from fastapi.responses import FileResponse
from fileserver.core import config
app = FastAPI(title="37du 内网文件服务器")
log = logging.getLogger("fileserver.heartbeat")
_DATA_DIR = config.DATA_DIR
_DATA_DIR.mkdir(parents=True, exist_ok=True)
@@ -32,6 +37,9 @@ _DATA_DIR.mkdir(parents=True, exist_ok=True)
_STATUS_DIR = _DATA_DIR / ".meta"
_STATUS_DIR.mkdir(parents=True, exist_ok=True)
# 进程启动时间(心跳上报 uptime 用)
_START_TS = time.time()
def _require_token(x_api_token: str = "") -> None:
"""校验管理 token;未配置 token 时放行(纯开发模式)。"""
@@ -62,6 +70,85 @@ def _file_meta(fid: str) -> dict:
return {}
# ==================== 中心机心跳上报(主动上报状态,供中心机监控在线/离线) ====================
def _server_status() -> dict:
"""收集本服务器状态快照:文件数/占用/主机/IP/运行时长等。"""
meta_files = list(_STATUS_DIR.glob("*.json"))
total = 0
for mf in meta_files:
try:
m = json.loads(mf.read_text(encoding="utf-8"))
total += int(m.get("size") or 0)
except Exception: # noqa: BLE001
pass
hostname = socket.gethostname()
ip = ""
try:
ip = socket.gethostbyname(hostname)
except OSError: # noqa: BLE001
pass
return {
"host": config.BASE_URL, # 中心机以其唯一标识本服务器(默认=对外下载根)
"base_url": config.BASE_URL,
"hostname": hostname,
"ip": ip,
"port": config.PORT,
"file_count": len(meta_files),
"total_size": total,
"version": "37du-fileserver",
"uptime_sec": int(time.time() - _START_TS),
}
def _post_heartbeat() -> bool:
"""单次上报心跳到中心机;成功返回 True。"""
payload = json.dumps(_server_status(), ensure_ascii=False).encode("utf-8")
req = urllib.request.Request(
f"{config.CONTROLPLANE_URL}/api/fileserver/heartbeat",
data=payload, method="POST")
req.add_header("Content-Type", "application/json")
if config.CONTROLPLANE_TOKEN:
req.add_header("X-API-Token", config.CONTROLPLANE_TOKEN)
try:
with urllib.request.urlopen(req, timeout=10) as resp:
return resp.status < 400
except OSError as exc: # noqa: BLE001 网络/中心机异常按失败处理
log.warning("心跳上报失败:%s", exc)
return False
def _heartbeat_loop() -> None:
"""后台线程:周期向中心机上报心跳。未配置 CONTROLPLANE_URL 则直接退出。
每次上报最多重试 3 次(项目级重试约定),三次失败记错误日志;不阻塞文件服务。
"""
if not config.CONTROLPLANE_URL:
log.info("未配置 CONTROLPLANE_URL,跳过心跳上报")
return
while True:
try:
ok = False
for _i in range(3):
if _post_heartbeat():
ok = True
break
if not ok:
log.error("心跳上报连续失败(3 次):%s", config.CONTROLPLANE_URL)
except Exception: # noqa: BLE001 上报异常不拖垮文件服务
log.exception("心跳上报线程异常")
time.sleep(max(5, config.HEARTBEAT_INTERVAL))
@asynccontextmanager
async def _lifespan(_app: FastAPI):
threading.Thread(target=_heartbeat_loop, daemon=True,
name="fileserver-heartbeat").start()
yield
app = FastAPI(title="37du 内网文件服务器", lifespan=_lifespan)
@app.post("/api/upload")
async def api_upload(upload: UploadFile,
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
+18 -18
View File
@@ -1,31 +1,31 @@
@echo off
REM ===== 37du 内网文件服务器 打包脚本(在 Windows 本机执行)=====
REM 前置:desktop/.venv 已安装 fastapi uvicorn python-multipart pyinstaller
REM 用法:在 desktop\ 目录下用项目 .venv 执行本脚本
REM ===== 37du intranet file server build script (run on Windows) =====
REM prereq: desktop/.venv with fastapi uvicorn python-multipart pyinstaller
REM usage: run inside desktop\ directory with project .venv
setlocal
cd /d %~dp0\..\..
set PY=..\.venv\Scripts\python.exe
if not exist %PY% (
echo [err] 未找到 %PY% ,请确认在 desktop\ 目录且 .venv 存在
echo [err] PYTHON NOT FOUND: %PY% - run from desktop\ and ensure .venv exists
pause & exit /b 1
)
echo [1/3] 打包 exe ...
%PY% -m PyInstaller desktop\fileserver\tools\37du-fileserver.spec ^
--distpath desktop\fileserver\dist-exe ^
--workpath desktop\fileserver\build-exe ^
echo [1/3] building exe ...
%PY% -m PyInstaller fileserver\tools\37du-fileserver.spec ^
--distpath fileserver\dist-exe ^
--workpath fileserver\build-exe ^
--noconfirm
if errorlevel 1 (echo [err] 打包失败 & pause & exit /b 1)
if errorlevel 1 (echo [err] BUILD FAILED & pause & exit /b 1)
echo [2/3] 装配部署目录 ...
set DEP=desktop\fileserver\dist-exe\fileserver
echo [2/3] assembling deploy dir ...
set DEP=fileserver\dist-exe\fileserver
if not exist %DEP% mkdir %DEP%
REM 拷贝 .env 到 exe 同目录(含 FILESERVER_BASE_URL 指向内网)
copy /y desktop\fileserver\.env %DEP%\.env >nul
move /y desktop\fileserver\dist-exe\37du-fileserver.exe %DEP%\37du-fileserver.exe >nul
REM copy .env next to exe (contains FILESERVER_BASE_URL pointing to intranet)
copy /y fileserver\.env %DEP%\.env >nul
move /y fileserver\dist-exe\37du-fileserver.exe %DEP%\37du-fileserver.exe >nul
echo [3/3] 完成。
echo 部署目录: %DEP%
echo 部署到内网机器 172.30.35.135,先改该 .env 的 FILESERVER_BASE_URL/TOKEN 再运行 install_autostart.bat
pause
echo [3/3] done.
echo deploy dir: %DEP%
echo deploy to 172.30.35.135: adjust FILESERVER_BASE_URL/TOKEN in .env, then run install_autostart.bat
pause