feat(ext): Фаза 1 — скачивание и активация данных ФГИС ЦС

fgis_client: download_split_form/indices/salary (endpoints сняты с сервера). ext_pull:
скачивание в снапшоты по региону+кварталу (осознанный шаг, EXT_REGIONS, не все 85).
ext_apply: verify (openpyxl+кодов≥1000) → diff по кодам колонки A → ГЕЙТ аномалий (>30%
удалено → отказ без --force) → бэкап старого → атомарная подмена fgis_split_form.xlsx →
предупреждение о fgis_cache.pkl (удаление только --yes) → напоминание рестарта (сам НЕ
рестартит). 11 тестов (гейт red-green).
This commit is contained in:
anor
2026-07-18 01:29:45 +10:00
parent 8772948acc
commit 81fc7a203a
5 changed files with 481 additions and 0 deletions
+31
View File
@@ -76,3 +76,34 @@ def subject_id_by_name(name_substr: str, client: httpx.Client | None = None) ->
if name_substr.lower() in s["name"].lower():
return s["id"]
return None
# --- Выгрузки (проверено на сервере 2026-07: content-type spreadsheet, размеры реальны) ---
_SPREADSHEET = "spreadsheet" # часть application/vnd.openxmlformats-...spreadsheetml.sheet
def download_split_form(period_id: int, price_zone_id: int, dest, client=None) -> dict:
"""Сплит-форма: полный каталог текущих цен ресурсов зоны за квартал (~13.7 МБ xlsx).
Это то, чем питается движок (fgis_split_form.xlsx)."""
return ext_fetch.fetch_file(
f"{BASE}/api/EstimatedPrice/BuildingResources/ExportSplitForm", dest,
params={"periodId": period_id, "priceZoneId": price_zone_id},
expect_min_size=1_000_000, expected_content_type=_SPREADSHEET, client=client)
def download_indices(period_id: int, price_zone_id: int, dest, client=None) -> dict:
"""Индексы к группам однородных ресурсов (ГОСР) зоны за квартал (~2.2 МБ xlsx, РИМ)."""
return ext_fetch.fetch_file(
f"{BASE}/api/IndicesForResourcesGroups/GenerateCustomReport", dest,
params={"periodId": period_id, "priceZoneId": price_zone_id, "authorityId": "null"},
expect_min_size=50_000, expected_content_type=_SPREADSHEET, client=client)
def salary_registry(price_zone_id: int, period_id: int, client=None) -> dict:
"""Реестр оплаты труда рабочих по разрядам (JSON: {total, items:[...]})."""
data = ext_fetch.fetch_json(f"{BASE}/api/EstimatedPrice/RimWorkerSalaryRegistry",
params={"priceZoneId": price_zone_id, "periodId": period_id},
client=client)
if not (isinstance(data, dict) and "items" in data):
raise FgisFormatError("RimWorkerSalaryRegistry: нет ключа items")
return data