# AGENTS.md — 沪武档案同步玄海 ## Project Overview Python scripts that sync construction measurement orders (施工计量单) from a MySQL database to an external archive system. The pipeline: fetch from MySQL → cache in SQLite → generate EEP packages (DA/T 48-2009 standard) → upload to external API. ## Commands No formal test/lint/build framework exists. Run scripts directly: ```bash # Full pipeline: fetch → cache → generate EEP → upload python sync_measure_data.py # Debug: check database schema python check_schema.py # Debug: check BQ (变清单) table for a specific order python check_bq.py # Debug: check attachment file IDs for a specific order python debug_db_files.py ``` ## Architecture - `sync_measure_data.py` — main pipeline (MySQL → SQLite → EEP → API upload) - `check_schema.py` — inspects MySQL table schemas (`mp_measure_order`, `mp_construction_measure_others`, `mp_contract`) - `check_bq.py` — inspects `mp_construction_measure_bq` table - `debug_db_files.py` — inspects attachment records in `mp_measure_attachments` and `tb_file` - `dangan/` — sample/reference archive XML outputs - `eep_packages/` — generated EEP output directory - `measure_data_cache.db` — local SQLite cache (auto-created) ## Key MySQL Tables - `mp_measure_order` — main measure orders (status: 2=审计完成, 4=also completed) - `mp_construction_measure_others` — other payment items (价格调整, 扣回材料设备预付款, etc.) - `mp_contract` — contract info (section_id, employer, contractor_dept, jl_section) - `mp_measure_attachments` — attachment links - `mp_construction_measure_bq` — BQ (变清单) items - `tb_file` — file storage (path = download URL) - `blade_user` — user info (real_name) ## Dependencies - `mysql.connector` — MySQL access - `requests` — HTTP uploads - `sqlite3`, `json`, `hashlib`, `zipfile`, `base64` — stdlib No `requirements.txt` or `pyproject.toml`. Install manually: `pip install mysql-connector-python requests` ## Conventions - XML templates follow DA/T 48-2009 (基于XML的电子文件封装规范) for EEP packages - Section name filter: only syncs orders with section containing 'CS', 'ZJG', or 'TC' - File download uses `FILE_BASE_URL = "https://oss.dnnbuild.com"` for relative paths - SQLite cache (`measure_data_cache.db`) persists across runs; new orders only (skips existing) - EEP packages are zip files with structure: `{order_id}/说明文件.xml`, `{order_id}/文件目录.xml`, `{year}/{order_id}/文件元数据.xml` ## Gotchas - DB credentials are hardcoded in scripts (not env vars) — check `DB_CONFIG` dict - `sync_measure_data.py` has a `LIMIT 1000` on the MySQL query for testing — remove for production - The upload payload includes full Base64-encoded EEP file — can be very large for orders with many attachments - `debug_db_files.py` has a hardcoded `TARGET_ID` — change it before running - `eep_packages/` directory is created at runtime; `dangan/` is reference data