chore: fork from IRIS track 供 LICA 部门独立运行
- 复制来源: /home/yueli/track @ 192c8ee (feature/ai-audit-update) - 组织隔离目标: LICA - 端口规划: 前端 8030 / 后端 8031 / 数据库 8032 - 已排除 deploy.sh、deploy_full.sh、docker-compose.prod.yml(IRIS 生产发布脚本) - 已排除工作区未提交改动,取干净的 192c8ee 状态
This commit is contained in:
44
backend/app/services/print_config.py
Normal file
44
backend/app/services/print_config.py
Normal file
@ -0,0 +1,44 @@
|
||||
"""打印机配置管理 — JSON 文件持久化"""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
CONFIG_DIR = Path(__file__).resolve().parent.parent.parent / "data"
|
||||
CONFIG_FILE = CONFIG_DIR / "printer_config.json"
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"label_printer": {
|
||||
"ip": "192.168.9.221",
|
||||
"port": 9100,
|
||||
"enabled": False,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class PrintConfigManager:
|
||||
"""打印机 IP/端口 配置读写"""
|
||||
|
||||
@staticmethod
|
||||
def _ensure_file() -> None:
|
||||
if not CONFIG_DIR.exists():
|
||||
CONFIG_DIR.mkdir(parents=True)
|
||||
if not CONFIG_FILE.exists():
|
||||
PrintConfigManager.save_config(DEFAULT_CONFIG)
|
||||
|
||||
@staticmethod
|
||||
def get_config() -> dict:
|
||||
PrintConfigManager._ensure_file()
|
||||
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
@staticmethod
|
||||
def save_config(config: dict) -> None:
|
||||
if not CONFIG_DIR.exists():
|
||||
CONFIG_DIR.mkdir(parents=True)
|
||||
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=2, ensure_ascii=False)
|
||||
|
||||
@staticmethod
|
||||
def get_printer(name: str = "label_printer") -> dict:
|
||||
config = PrintConfigManager.get_config()
|
||||
return config.get(name, DEFAULT_CONFIG.get("label_printer", {}))
|
||||
Reference in New Issue
Block a user