1.SRM数据库驱动调整

2.新增MSDS文件检核逻辑
This commit is contained in:
hugo committed 2026-05-19 19:32:18 +08:00
1 parent fb8189ef13
commit 09b5e62861
5 files changed
+530 -116

No files matched your search

+67 -21
View File
@@ -1,4 +1,4 @@
from __future__ import annotations
from __future__ import annotations
import json
from pathlib import Path
@@ -13,40 +13,86 @@ def _flatten_value(v: Any) -> Any:
return v
def export_schedule_result_excel(*, run_no: str, summary: dict, details: list[dict], root_dir: str) -> tuple[str | None, str | None, int]:
def export_schedule_result_excel(
*,
run_no: str,
summary: dict,
details: list[dict],
root_dir: str,
header_order: list[str] | None = None,
header_labels: dict[str, str] | None = None,
) -> tuple[str | None, str | None, int]:
if not details:
return None, None, 0
out_root = Path(root_dir)
out_root.mkdir(parents=True, exist_ok=True)
rows: list[dict[str, Any]] = []
for row in details:
output = row.get('dify_output')
if not isinstance(output, dict):
output = {}
entry = {k: _flatten_value(v) for k, v in output.items()}
for k in ('writeback_ok', 'error', 'judgement', 'reason'):
if k in row:
entry[k] = row[k]
rows.append(entry)
header_order = header_order or []
header_labels = header_labels or {}
headers: list[str] = []
for row in rows:
for k in row:
if k not in headers:
headers.append(k)
rows: list[dict[str, Any]] = []
sql_headers: list[str] = []
json_headers: list[str] = []
exec_result_headers: list[str] = []
exec_result_order = ["dify_result", "dify_message", "writeback_srm", "writeback_err"]
def _append_unique(target: list[str], key: str) -> None:
if key not in target:
target.append(key)
def _collect_json_headers(obj: Any) -> None:
if isinstance(obj, dict):
for k in obj.keys():
_append_unique(json_headers, str(k))
for row in details:
if not isinstance(row, dict):
continue
flat_row: dict[str, Any] = {}
for k, v in row.items():
key = str(k)
if key in {"dify_output", "json_output", "output"}:
_collect_json_headers(v)
if isinstance(v, dict):
for json_key, json_val in v.items():
flat_row[str(json_key)] = _flatten_value(json_val)
continue
flat_row[key] = _flatten_value(v)
if key in exec_result_order:
_append_unique(exec_result_headers, key)
else:
_append_unique(sql_headers, key)
rows.append(flat_row)
if not rows:
return None, None, 0
ordered_exec_headers = [k for k in exec_result_order if k in exec_result_headers]
other_exec_headers = [k for k in exec_result_headers if k not in exec_result_order]
ordered_sql_headers = [k for k in header_order if k in sql_headers]
other_sql_headers = [k for k in sql_headers if k not in header_order]
headers = (
ordered_sql_headers
+ other_sql_headers
+ [k for k in json_headers if k not in sql_headers and k not in exec_result_headers]
+ ordered_exec_headers
+ other_exec_headers
)
wb = Workbook()
ws = wb.active
ws.title = 'result'
ws.append(headers)
ws.title = "result"
ws.append([header_labels.get(k, k) for k in headers])
for row in rows:
ws.append([row.get(k, '') for k in headers])
ws.append([row.get(k, "") for k in headers])
file_name = f'schedule_{run_no}.xlsx'
file_name = f"schedule_{run_no}.xlsx"
file_path = out_root / file_name
wb.save(file_path)
size = file_path.stat().st_size
return str(file_path), file_name, int(size)