feat: 工参小区按制式拆成 CellData_4G、CellData_5G;即席查询补上页面必带参数

两张表列名沿用平台工参表,已有快照由迁移 0008 原样搬过去。即席查询的 result 补 tableParams、columnname,计数补 indexcount=0,缺这些服务端会返回 stat 0。
This commit is contained in:
2026-11-11 02:30:21 +08:00
parent dcd0a87cc3
commit 33d132d7b6
8 changed files with 304 additions and 76 deletions
+17 -5
View File
@@ -145,7 +145,6 @@ async def export_table(
if not columns:
raise NqiError("这张表没有可导出的字段")
title = str(columns[0].get("tablename_cn") or tablename)
selected = [_field(column) for column in columns]
where = _where(columns[0], start, end, city)
common = {
"geographicdimension": columns[0].get("geographicdimension") or "",
@@ -155,7 +154,7 @@ async def export_table(
"timeField": columns[0].get("time_field") or "starttime",
"cellField": columns[0].get("cell_field") or "",
"cityField": columns[0].get("city_field") or "city",
"result": json.dumps({"result": selected}, ensure_ascii=False),
"result": _result_json(columns[0], columns),
"where": json.dumps(where, ensure_ascii=False),
}
total, index_count = await _count(client, common)
@@ -222,7 +221,7 @@ async def export_day(
"timeField": head.get("time_field") or "starttime",
"cellField": head.get("cell_field") or "",
"cityField": head.get("city_field") or "city",
"result": json.dumps({"result": [_field(column) for column in selected]}, ensure_ascii=False),
"result": _result_json(head, selected),
"where": json.dumps(_where(head, _start(day), _end(day), city), ensure_ascii=False),
}
total, index_count = await _count(client, common)
@@ -266,14 +265,27 @@ def _first_choice(value: object) -> str:
async def _count(client: NqiClient, common: dict) -> tuple[int, str]:
"""平台出错时返回 {"stat":"0"},没有 count。不能当成 0 行。"""
counted = await _post_json(client, f"{PAGE}/getTableCount", common)
"""平台出错时返回 {"stat":"0"},没有 count。不能当成 0 行。页面第一次计数总是带 indexcount=0,缺了会报错。"""
counted = await _post_json(client, f"{PAGE}/getTableCount", {**common, "indexcount": "0"})
if not isinstance(counted, dict) or "count" not in counted:
message = counted.get("message") if isinstance(counted, dict) else ""
raise NqiError(f"即席查询没有返回行数{f':{message}' if message and message != 'null' else ''}")
return int(counted.get("count") or 0), str(counted.get("indexcount") or "0")
def _result_json(head: dict, columns: list[dict]) -> str:
"""页面在字段列表后还带 tableParams 和 columnname,缺了服务端返回 {"stat":"0","message":"null"}。"""
payload = {
"result": [_field(column) for column in columns],
"tableParams": {
"supporteddimension": head.get("supporteddimension"),
"supportedtimedimension": head.get("supportedtimedimension") or "",
},
"columnname": "",
}
return json.dumps(payload, ensure_ascii=False)
def _field(column: dict) -> dict:
return {
"feildtype": column.get("fieldtype") or "",