Files
pricing_review/CostReview/app/store/README.md
2026-10-11 10:52:01 +08:00

92 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Runtime Storage
The active application and offline comparison tools use `data/history.db`.
Projects and information/market prices share batch metadata, but have separate
detail tables (`bills`, `lmes`, `prices`). Attachments are linked through batches.
`data/session.db` contains audit sessions only.
## Price import sources (2026-10-06)
Two entry points, one pipeline — both land in `prices` with the same
`x_hash_exact` so HTML-imported and Excel-imported rows match each other:
* `core/price_html.py` — the 信息价 HTML (`const DATA = [...]`)
* `core/price_xlsx.py` — the standard Excel template (`/api/admin/price_template`)
⚠️ They share **one** `PARSER_VER` on purpose. `stale_batches()` has a single
price line, so a separate Excel version would make Excel batches report
"expired" forever. Change the 入库口径 → bump both → re-import both.
## Legacy (archived 2026-10-06, do not use)
`price_lib.db` / `price_lib.sql` / `parse/merge_price_lib.py` were moved to
`app/_deprecated/legacy_price_lib/` — the old parser used a different column set
(`x_period_m` single month) and a different hash normalisation, so its rows can
never match current data. Kept only as a read-only reference. Do not run
`merge_price_lib.py`: it writes legacy-shaped rows into the live database.
## 询价附件 (2026-10-06)
`inquiry_files` (one file per upload: pdf/zip/rar) + `lme_attach`
(`lme_id` is the PRIMARY KEY → a 工料机 can only ever point at ONE file;
a file can point at many). Change binding with `INSERT OR REPLACE` — the
primary-key conflict *is* the rebind. Project batches only: price batches
(info/market) have no `lmes` rows, so every entry point asserts `kind='project'`.
## 2026-10-06 changes
**`batches.x_rows_price` (new column).**
`x_rows_lme` used to carry *two* meanings: on `project` batches it was the
工料机 count, on `info` / `market` batches it was the 价格 count. Any code
asking `x_rows_lme > 0` to mean "this batch has 工料机" would wrongly match
price batches. Price counts now live in `x_rows_price`; `x_rows_lme` is
工料机-only. **To ask "does this batch have 工料机", test `kind='project'`,
never a row count.**
**`dict_region` / `dict_org` (new tables) — the 数据源 dictionary.**
Single source for the 地区 / 发布单位 / 建设单位 dropdowns, shared by the
admin UI and the workbench:
* entry dropdowns (import / edit / 打开工程) read **only** `/api/dict`
* filter dropdowns (list filters, area tree) read `/api/admin/filters`,
which is *dictionary ∪ values actually present in `batches`* — filtering
must still be able to reach historical rows, so it only ever widens
On first start the dictionary is seeded from existing `batches` values, so
nothing disappears when it is enabled.
## 2026-10-06 · 价格导入「一个块 = 一个批次」(取代「一个文件 = 一个批次」)
A price file usually carries **several markets** with **different periods**
(珠海市建材设备市场综合价 → 2026-07, 珠海市2026年4-6月园林苗木市场信息 →
2026-04~06, 横琴, 万山). One batch can hold only one period, so cramming all
markets into a single batch forced the period to be left empty — and
`ym2str('')` raises, which took the whole 信息价 list down with a 500
(defect DB-1). Now:
* `price_html.parse()` / `price_xlsx.parse()` return **one entry per block**
(HTML: per top-level object; Excel: **per sheet**), each carrying
`period_start_m` / `period_end_m` detected from the block name
(`guess_period`, e.g. "2026年4-6月" → 24316~24318)
* `api_import_price()` creates **one batch per block**; period precedence is
block name → file name → the value typed in the import dialog
* batch name = block name when there is more than one block
## 2026-10-06 · sessions.x_batch_id(会话 ↔ 后台项目批次)
The workbench opens a file straight into the session DB and never touched
`batches`, so it could not see 询价附件. `sessions.x_batch_id` now links the
two: `api_audit()` matches on the **same source file**
(`batches.x_src_hash` == `sessions.src_name`, both "<sha256>_<original name>").
⚠️ **Source-file match only** (2026-10-06, 主人定): the old "fall back to
project name" branch was removed from both `_link_batch()` and
`backfill_session_batch()`. Same-named projects would bind the wrong batch,
and a *wrong* 询价附件 is worse than none (it looks legitimate). Sessions left
`NULL` simply mean "this project was never imported in the admin UI" (or was
imported by an old build that stored sha1 — re-import once).
`backfill_session_batch()` backfills old sessions at startup. The workbench
reads attachments **read-only** (`GET /api/session/inq`); binding stays in the
admin UI.