diff --git a/lawrisk/services/licensing_repo.py b/lawrisk/services/licensing_repo.py index b04b1da..9a8b51e 100644 --- a/lawrisk/services/licensing_repo.py +++ b/lawrisk/services/licensing_repo.py @@ -1935,20 +1935,13 @@ def list_service_departments(region_id: Optional[str] = None) -> List[Dict[str, cur = conn.cursor() if region_id: - # Get departments associated with the specific region through permit_sources + # Get departments associated with the specific region through service_departments.region_id + # This includes both direct region match and hierarchical matching (child regions) sql = _SERVICE_DEPARTMENT_SELECT + """ - WHERE sd.id IN ( - SELECT DISTINCT ps.uploader_department_id - FROM permit_sources ps - WHERE ps.region_id = %s AND ps.uploader_department_id IS NOT NULL - UNION - SELECT DISTINCT ps.bound_department_id - FROM permit_sources ps - WHERE ps.region_id = %s AND ps.bound_department_id IS NOT NULL - ) + WHERE sd.region_id = %s ORDER BY sd.created_at ASC """ - cur.execute(sql, (region_id, region_id)) + cur.execute(sql, (region_id,)) else: # Get all departments cur.execute(_SERVICE_DEPARTMENT_SELECT + " ORDER BY sd.created_at ASC") @@ -5563,15 +5556,18 @@ def filter_permits_advanced( WHERE 1=1 """ count_params = [] - if region_id: - count_sql += " AND rtp.region_id = %s" - count_params.append(region_id) - if theme_id: - count_sql += " AND rtp.theme_id = %s" - count_params.append(theme_id) - if department_id: - count_sql += " AND (ps.uploader_department_id = %s OR ps.bound_department_id = %s)" - count_params.extend([department_id, department_id]) + if regions: + placeholders = ', '.join(['%s'] * len(regions)) + count_sql += f" AND rtp.region_id IN ({placeholders})" + count_params.extend(regions) + if themes: + placeholders = ', '.join(['%s'] * len(themes)) + count_sql += f" AND rtp.theme_id IN ({placeholders})" + count_params.extend(themes) + if departments: + placeholders = ', '.join(['%s'] * len(departments)) + count_sql += f" AND (ps.uploader_department_id IN ({placeholders}) OR ps.bound_department_id IN ({placeholders}))" + count_params.extend(departments * 2) if search_text: count_sql += " AND LOWER(p.name) LIKE LOWER(%s)" count_params.append(f"%{search_text}%") diff --git a/static/db_admin.html b/static/db_admin.html index 51e114e..d04f7e6 100644 --- a/static/db_admin.html +++ b/static/db_admin.html @@ -2256,14 +2256,19 @@

使用筛选器快速定位许可事项,支持多维度筛选、分页浏览、风险统计等功能。

-
+
+ +
- 请选择区域... + 全部区域