fix: resolve missing preview data in permit import session and fix logging bug

This commit is contained in:
黄仁欢 2025-12-25 19:56:56 +08:00
parent 70e46a730e
commit 1595027679
1 changed files with 52 additions and 52 deletions

View File

@ -1710,9 +1710,9 @@ def commit_permit_import_session(
details={
"filename": workbook_filename,
"sheets_processed": len(sheet_names),
"created_count": result["created_count"],
"overwritten_count": result["overwritten_count"],
"skipped_count": result["skipped_count"],
"created_count": len(result["created_permits"]),
"overwritten_count": len(result["overwritten_permits"]),
"skipped_count": len(result["skipped_permits"]),
"snapshot_count": result["snapshot_count"]
}
)
@ -1798,60 +1798,60 @@ def describe_permit_import_session(session_id: str) -> Dict[str, Any]:
total_permits += len(permit_summaries)
theme_options: List[Dict[str, Any]] = []
seen_theme_labels: Set[str] = set()
theme_options: List[Dict[str, Any]] = []
seen_theme_labels: Set[str] = set()
theme_options.append(
{
"id": ALL_THEMES_SENTINEL,
"name": ALL_THEMES_DISPLAY_NAME,
"source": "virtual",
"description": "选择后将与当前及未来的新主题自动绑定",
"is_all": True,
}
)
seen_theme_labels.add(ALL_THEMES_SENTINEL.lower())
seen_theme_labels.add(ALL_THEMES_DISPLAY_NAME.lower())
theme_options.append(
{
"id": ALL_THEMES_SENTINEL,
"name": ALL_THEMES_DISPLAY_NAME,
"source": "virtual",
"description": "选择后将与当前及未来的新主题自动绑定",
"is_all": True,
}
)
seen_theme_labels.add(ALL_THEMES_SENTINEL.lower())
seen_theme_labels.add(ALL_THEMES_DISPLAY_NAME.lower())
candidate_theme_lists: List[List[Dict[str, str]]] = []
region_theme_options = region_theme_map.get(region_id)
if region_theme_options:
candidate_theme_lists.append(region_theme_options)
if all_theme_options:
candidate_theme_lists.append(all_theme_options)
candidate_theme_lists: List[List[Dict[str, str]]] = []
region_theme_options = region_theme_map.get(region_id)
if region_theme_options:
candidate_theme_lists.append(region_theme_options)
if all_theme_options:
candidate_theme_lists.append(all_theme_options)
for option_list in candidate_theme_lists:
for option in option_list:
label = option.get("name") or ""
normalized = label.lower()
if normalized in seen_theme_labels:
continue
seen_theme_labels.add(normalized)
theme_options.append(
{
"id": option.get("id") or "",
"name": label,
"source": "existing",
}
)
for option_list in candidate_theme_lists:
for option in option_list:
label = option.get("name") or ""
normalized = label.lower()
if normalized in seen_theme_labels:
continue
seen_theme_labels.add(normalized)
theme_options.append(
{
"id": option.get("id") or "",
"name": label,
"source": "existing",
}
)
# Workbook themes are no longer supported as the template has no theme column
pass
# Workbook themes are no longer supported as the template has no theme column
pass
preview_sheets.append(
{
"sheet_name": sheet_name,
"region_name": region_name,
"region_id": region_id,
"missing_region": not bool(region_id),
"theme_options": theme_options,
"permits": permit_summaries,
"duplicate_permits": list(duplicate_permits),
"new_permits": list(new_permits),
"permit_count": len(permit_summaries),
"risk_count": sheet_risk_total,
}
)
preview_sheets.append(
{
"sheet_name": sheet_name,
"region_name": region_name,
"region_id": region_id,
"missing_region": not bool(region_id),
"theme_options": theme_options,
"permits": permit_summaries,
"duplicate_permits": list(duplicate_permits),
"new_permits": list(new_permits),
"permit_count": len(permit_summaries),
"risk_count": sheet_risk_total,
}
)
return {
"session_id": session_id,