|
|
@@ -14,24 +14,108 @@ import zipfile
|
|
|
import base64
|
|
|
import uuid
|
|
|
from decimal import Decimal
|
|
|
+import sys
|
|
|
+import configparser
|
|
|
+
|
|
|
+# ========== 配置文件加载 ==========
|
|
|
+# exe / 脚本同目录下的 config.ini,首次运行自动生成,用记事本即可修改
|
|
|
+if getattr(sys, 'frozen', False):
|
|
|
+ BASE_DIR = os.path.dirname(sys.executable)
|
|
|
+else:
|
|
|
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
+
|
|
|
+CONFIG_FILE = os.path.join(BASE_DIR, 'config.ini')
|
|
|
+
|
|
|
+DEFAULT_CONFIG = """# ============================================
|
|
|
+# 沪武档案同步玄海 - 运行配置
|
|
|
+# 修改本文件后重新运行程序即可生效,无需重新生成 exe
|
|
|
+# ============================================
|
|
|
+
|
|
|
+[mysql]
|
|
|
+# 业务数据库连接(连接失败请检查 VPN 或修改以下地址/账号)
|
|
|
+host = 172.16.10.152
|
|
|
+port = 15606
|
|
|
+user = root
|
|
|
+password = 84853032
|
|
|
+database = dnn202500200jy
|
|
|
+connect_timeout = 10
|
|
|
+
|
|
|
+[api]
|
|
|
+# 档案系统上传接口
|
|
|
+api_url = http://218.94.73.106:8081/api/eps9/tyjk/api/data/asip/HWKJLZF
|
|
|
+# 附件文件下载地址前缀(数据库中为相对路径时自动拼接)
|
|
|
+file_base_url = https://oss.dnnbuild.com
|
|
|
+
|
|
|
+[archive]
|
|
|
+# 归档单位(默认值,数据缺失时使用)
|
|
|
+archive_unit = 无锡至宜兴高速公路雪堰枢纽至西坞枢纽段扩建工程
|
|
|
+# 文件目录署名单位
|
|
|
+catalog_signing_unit = 沪武高速公路太仓至常州段扩建工程苏州段
|
|
|
+
|
|
|
+[local]
|
|
|
+# 本地 SQLite 缓存文件名(放在 exe 同目录)
|
|
|
+sqlite_db = measure_data_cache.db
|
|
|
+# EEP 包输出目录(放在 exe 同目录)
|
|
|
+output_dir = eep_packages
|
|
|
+"""
|
|
|
|
|
|
-# 数据库配置 (从 application-dev.yml 获取)
|
|
|
-# 如果连接失败,请检查 VPN 或修改此处的 host/port/user/password
|
|
|
-DB_CONFIG = {
|
|
|
- 'user': 'root',
|
|
|
- 'password': '84853032',
|
|
|
- 'host': '172.16.10.152',
|
|
|
- 'port': 15606,
|
|
|
- 'database': 'dnn202500200jy',
|
|
|
- 'use_pure': True,
|
|
|
- 'connect_timeout': 10
|
|
|
-}
|
|
|
|
|
|
-# 目标API配置
|
|
|
-API_URL = "http://218.94.73.106:8081/api/eps9/tyjk/api/data/asip/HWKJLZF"
|
|
|
-FILE_BASE_URL = "https://oss.dnnbuild.com"
|
|
|
-ARCHIVE_UNIT = "无锡至宜兴高速公路雪堰枢纽至西坞枢纽段扩建工程"
|
|
|
-CATALOG_SIGNING_UNIT = "沪武高速公路太仓至常州段扩建工程苏州段"
|
|
|
+def load_config():
|
|
|
+ """加载 config.ini;不存在时自动写入默认配置。返回 (DB_CONFIG, API_URL, FILE_BASE_URL, ARCHIVE_UNIT, CATALOG_SIGNING_UNIT, SQLITE_DB, OUTPUT_DIR)。"""
|
|
|
+ if not os.path.exists(CONFIG_FILE):
|
|
|
+ try:
|
|
|
+ with open(CONFIG_FILE, 'w', encoding='utf-8') as f:
|
|
|
+ f.write(DEFAULT_CONFIG)
|
|
|
+ print(f"[配置] 未找到配置文件,已自动生成: {CONFIG_FILE}")
|
|
|
+ print("[配置] 可关闭程序,用记事本修改该文件后重新运行。")
|
|
|
+ print()
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[配置][警告] 无法写入配置文件 {CONFIG_FILE}: {e},改用内置默认配置。")
|
|
|
+
|
|
|
+ # interpolation=None:密码中出现 % 等特殊字符也不会报错
|
|
|
+ cfg = configparser.ConfigParser(interpolation=None)
|
|
|
+ cfg.optionxform = str # 保留键名大小写
|
|
|
+ try:
|
|
|
+ cfg.read(CONFIG_FILE, encoding='utf-8-sig')
|
|
|
+ except Exception as e:
|
|
|
+ print(f"[配置][警告] 读取配置文件失败({e}),改用内置默认配置。")
|
|
|
+ cfg = configparser.ConfigParser(interpolation=None)
|
|
|
+ cfg.optionxform = str
|
|
|
+ cfg.read_string(DEFAULT_CONFIG)
|
|
|
+
|
|
|
+ def get(section, key, fallback):
|
|
|
+ try:
|
|
|
+ value = cfg.get(section, key)
|
|
|
+ return value if value != '' else fallback
|
|
|
+ except Exception:
|
|
|
+ return fallback
|
|
|
+
|
|
|
+ db_config = {
|
|
|
+ 'user': get('mysql', 'user', 'root'),
|
|
|
+ 'password': get('mysql', 'password', '84853032'),
|
|
|
+ 'host': get('mysql', 'host', '172.16.10.152'),
|
|
|
+ 'port': int(get('mysql', 'port', '15606')),
|
|
|
+ 'database': get('mysql', 'database', 'dnn202500200jy'),
|
|
|
+ 'use_pure': True,
|
|
|
+ 'connect_timeout': int(get('mysql', 'connect_timeout', '10')),
|
|
|
+ }
|
|
|
+ api_url = get('api', 'api_url', "http://218.94.73.106:8081/api/eps9/tyjk/api/data/asip/HWKJLZF")
|
|
|
+ file_base_url = get('api', 'file_base_url', "https://oss.dnnbuild.com")
|
|
|
+ archive_unit = get('archive', 'archive_unit', "无锡至宜兴高速公路雪堰枢纽至西坞枢纽段扩建工程")
|
|
|
+ catalog_signing_unit = get('archive', 'catalog_signing_unit', "沪武高速公路太仓至常州段扩建工程苏州段")
|
|
|
+ sqlite_db = get('local', 'sqlite_db', 'measure_data_cache.db')
|
|
|
+ output_dir = get('local', 'output_dir', 'eep_packages')
|
|
|
+
|
|
|
+ if not os.path.isabs(sqlite_db):
|
|
|
+ sqlite_db = os.path.join(BASE_DIR, sqlite_db)
|
|
|
+ if not os.path.isabs(output_dir):
|
|
|
+ output_dir = os.path.join(BASE_DIR, output_dir)
|
|
|
+
|
|
|
+ return db_config, api_url, file_base_url, archive_unit, catalog_signing_unit, sqlite_db, output_dir
|
|
|
+
|
|
|
+
|
|
|
+(DB_CONFIG, API_URL, FILE_BASE_URL, ARCHIVE_UNIT, CATALOG_SIGNING_UNIT,
|
|
|
+ SQLITE_DB, OUTPUT_DIR) = load_config()
|
|
|
|
|
|
# XML 模板
|
|
|
XML_DESC_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
|
|
|
@@ -308,9 +392,6 @@ XML_PERSON_RELATION_TEMPLATE = """ <机构人员实体关系 name="M231">
|
|
|
<关系描述 name="M79" />
|
|
|
</机构人员实体关系>"""
|
|
|
|
|
|
-# 本地缓存文件
|
|
|
-SQLITE_DB = 'measure_data_cache.db'
|
|
|
-
|
|
|
# 流程节点 operateType -> 审核结论 映射 (参考 FlowProcessServiceImpl.resolveHisActivityStatus)
|
|
|
OPERATE_TYPE_CONCLUSION = {
|
|
|
'pass': '通过',
|
|
|
@@ -590,6 +671,9 @@ def build_metadata_entities(order_data, file_id):
|
|
|
|
|
|
|
|
|
def init_sqlite():
|
|
|
+ db_parent = os.path.dirname(SQLITE_DB)
|
|
|
+ if db_parent and not os.path.exists(db_parent):
|
|
|
+ os.makedirs(db_parent)
|
|
|
conn = sqlite3.connect(SQLITE_DB)
|
|
|
cursor = conn.cursor()
|
|
|
# 计量单表
|
|
|
@@ -1163,7 +1247,7 @@ def sync_to_external_system(sqlite_conn):
|
|
|
print(f"Syncing {len(rows)} records to external system...")
|
|
|
|
|
|
# Create output directory
|
|
|
- output_dir = 'eep_packages'
|
|
|
+ output_dir = OUTPUT_DIR
|
|
|
if not os.path.exists(output_dir):
|
|
|
os.makedirs(output_dir)
|
|
|
|
|
|
@@ -1199,6 +1283,10 @@ def sync_to_external_system(sqlite_conn):
|
|
|
print("Sync completed.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
+ print(f"配置文件: {CONFIG_FILE}")
|
|
|
+ print(f"MySQL: {DB_CONFIG['user']}@{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}")
|
|
|
+ print(f"本地缓存: {SQLITE_DB}")
|
|
|
+ print()
|
|
|
sqlite_conn = init_sqlite()
|
|
|
print("Fetching data from MySQL...")
|
|
|
data = fetch_from_mysql()
|