|
|
@@ -37,6 +37,7 @@ from app.schemas.menu_favorite import (
|
|
|
)
|
|
|
from app.services.web_auth_roles import _map_role_name_to_web
|
|
|
from app.utils.excel_export import (
|
|
|
+ EXPORT_MAX_ROWS,
|
|
|
ExportColumn,
|
|
|
ExportValidationError,
|
|
|
export_rows_to_xlsx_response,
|
|
|
@@ -174,6 +175,55 @@ def list_tenants(
|
|
|
)
|
|
|
|
|
|
|
|
|
+
|
|
|
+TENANT_EXPORT_COLUMNS = [
|
|
|
+ ExportColumn(title="租户编号", field="tenantNo"),
|
|
|
+ ExportColumn(title="租户名称", field="tenantName"),
|
|
|
+ ExportColumn(title="联系人", field="contactName"),
|
|
|
+ ExportColumn(title="联系电话", field="contactPhone"),
|
|
|
+ ExportColumn(title="创建时间", field="createTime"),
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+class TenantExportBody(BaseModel):
|
|
|
+ keyword: Optional[str] = None
|
|
|
+ ids: Optional[List[str]] = None
|
|
|
+ columns: Optional[List[str]] = None
|
|
|
+
|
|
|
+
|
|
|
+@router.post("/tenants/export")
|
|
|
+def export_tenants(
|
|
|
+ body: TenantExportBody,
|
|
|
+ _user: dict = Depends(require_admin_or_super_admin),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ """导出租户列表(当前筛选全量,或 ids 已选)。"""
|
|
|
+ try:
|
|
|
+ items, _ = tenant_svc.list_tenants(
|
|
|
+ db,
|
|
|
+ page=1,
|
|
|
+ page_size=EXPORT_MAX_ROWS,
|
|
|
+ keyword=body.keyword,
|
|
|
+ ids=body.ids,
|
|
|
+ max_page_size=EXPORT_MAX_ROWS,
|
|
|
+ user_info=_user,
|
|
|
+ )
|
|
|
+ cols = filter_export_columns(TENANT_EXPORT_COLUMNS, body.columns)
|
|
|
+ date_str = datetime.now().strftime("%Y%m%d")
|
|
|
+ return export_rows_to_xlsx_response(
|
|
|
+ db,
|
|
|
+ tenant_no=None,
|
|
|
+ sheet_title="租户列表",
|
|
|
+ columns=cols,
|
|
|
+ rows=items,
|
|
|
+ filename_stem=f"租户列表_{date_str}",
|
|
|
+ )
|
|
|
+ except ExportValidationError as e:
|
|
|
+ return error_response(400, str(e))
|
|
|
+ except Exception as e:
|
|
|
+ return error_response(500, str(e))
|
|
|
+
|
|
|
+
|
|
|
@router.post("/tenants")
|
|
|
def create_tenant(
|
|
|
body: TenantCreateBody,
|
|
|
@@ -1001,6 +1051,60 @@ def list_sites(
|
|
|
return success_response({"list": items, "total": total, "page": page, "pageSize": pageSize, "totalPages": tp})
|
|
|
|
|
|
|
|
|
+
|
|
|
+SITE_EXPORT_COLUMNS = [
|
|
|
+ ExportColumn(title="站点名称", field="siteName"),
|
|
|
+ ExportColumn(title="站点编码", field="siteCode"),
|
|
|
+ ExportColumn(title="站点类型", field="siteType"),
|
|
|
+ ExportColumn(title="状态", field="status", dict_type="sys_status"),
|
|
|
+ ExportColumn(title="地址", field="address"),
|
|
|
+ ExportColumn(title="联系人", field="contactName"),
|
|
|
+ ExportColumn(title="联系电话", field="contactPhone"),
|
|
|
+ ExportColumn(title="创建时间", field="createTime"),
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+class SiteExportBody(BaseModel):
|
|
|
+ keyword: Optional[str] = None
|
|
|
+ ids: Optional[List[str]] = None
|
|
|
+ columns: Optional[List[str]] = None
|
|
|
+
|
|
|
+
|
|
|
+@router.post("/sites/export")
|
|
|
+def export_sites(
|
|
|
+ body: SiteExportBody,
|
|
|
+ user: dict = Depends(require_menu_code("system:site:list")),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ """导出站点列表(当前筛选全量,或 ids 已选)。"""
|
|
|
+ try:
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ items, _ = site_svc.list_sites(
|
|
|
+ db,
|
|
|
+ page=1,
|
|
|
+ page_size=EXPORT_MAX_ROWS,
|
|
|
+ keyword=body.keyword,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ ids=body.ids,
|
|
|
+ max_page_size=EXPORT_MAX_ROWS,
|
|
|
+ user_info=user,
|
|
|
+ )
|
|
|
+ cols = filter_export_columns(SITE_EXPORT_COLUMNS, body.columns)
|
|
|
+ date_str = datetime.now().strftime("%Y%m%d")
|
|
|
+ return export_rows_to_xlsx_response(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ sheet_title="站点列表",
|
|
|
+ columns=cols,
|
|
|
+ rows=items,
|
|
|
+ filename_stem=f"站点列表_{date_str}",
|
|
|
+ )
|
|
|
+ except ExportValidationError as e:
|
|
|
+ return error_response(400, str(e))
|
|
|
+ except Exception as e:
|
|
|
+ return error_response(500, str(e))
|
|
|
+
|
|
|
+
|
|
|
@router.post("/sites")
|
|
|
def create_site(
|
|
|
body: SiteCreateBody,
|
|
|
@@ -1110,6 +1214,56 @@ def list_posts(
|
|
|
return success_response({"list": items, "total": total, "page": page, "pageSize": pageSize, "totalPages": tp})
|
|
|
|
|
|
|
|
|
+
|
|
|
+POST_EXPORT_COLUMNS = [
|
|
|
+ ExportColumn(title="职位名称", field="postName"),
|
|
|
+ ExportColumn(title="职位编码", field="postCode"),
|
|
|
+ ExportColumn(title="状态", field="status", dict_type="sys_status"),
|
|
|
+ ExportColumn(title="创建时间", field="createTime"),
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+class PostExportBody(BaseModel):
|
|
|
+ keyword: Optional[str] = None
|
|
|
+ ids: Optional[List[str]] = None
|
|
|
+ columns: Optional[List[str]] = None
|
|
|
+
|
|
|
+
|
|
|
+@router.post("/posts/export")
|
|
|
+def export_posts(
|
|
|
+ body: PostExportBody,
|
|
|
+ user: dict = Depends(require_menu_code("system:post:list")),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ """导出职位列表(当前筛选全量,或 ids 已选)。"""
|
|
|
+ try:
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ items, _ = post_svc.list_posts(
|
|
|
+ db,
|
|
|
+ page=1,
|
|
|
+ page_size=EXPORT_MAX_ROWS,
|
|
|
+ keyword=body.keyword,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ ids=body.ids,
|
|
|
+ max_page_size=EXPORT_MAX_ROWS,
|
|
|
+ user_info=user,
|
|
|
+ )
|
|
|
+ cols = filter_export_columns(POST_EXPORT_COLUMNS, body.columns)
|
|
|
+ date_str = datetime.now().strftime("%Y%m%d")
|
|
|
+ return export_rows_to_xlsx_response(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ sheet_title="职位列表",
|
|
|
+ columns=cols,
|
|
|
+ rows=items,
|
|
|
+ filename_stem=f"职位列表_{date_str}",
|
|
|
+ )
|
|
|
+ except ExportValidationError as e:
|
|
|
+ return error_response(400, str(e))
|
|
|
+ except Exception as e:
|
|
|
+ return error_response(500, str(e))
|
|
|
+
|
|
|
+
|
|
|
@router.post("/posts")
|
|
|
def create_post(
|
|
|
body: PostCreateBody,
|
|
|
@@ -1380,6 +1534,56 @@ def list_role_management(
|
|
|
return success_response({"list": items, "total": total, "page": page, "pageSize": pageSize, "totalPages": tp})
|
|
|
|
|
|
|
|
|
+
|
|
|
+ROLE_EXPORT_COLUMNS = [
|
|
|
+ ExportColumn(title="角色名称", field="roleName"),
|
|
|
+ ExportColumn(title="数据权限", field="dataScope", dict_type="sys_data_scope"),
|
|
|
+ ExportColumn(title="状态", field="status", dict_type="sys_status"),
|
|
|
+ ExportColumn(title="创建时间", field="createTime"),
|
|
|
+]
|
|
|
+
|
|
|
+
|
|
|
+class RoleExportBody(BaseModel):
|
|
|
+ keyword: Optional[str] = None
|
|
|
+ ids: Optional[List[str]] = None
|
|
|
+ columns: Optional[List[str]] = None
|
|
|
+
|
|
|
+
|
|
|
+@router.post("/role-management/export")
|
|
|
+def export_role_management(
|
|
|
+ body: RoleExportBody,
|
|
|
+ user: dict = Depends(require_menu_code("system:role:list")),
|
|
|
+ db: Session = Depends(get_db),
|
|
|
+):
|
|
|
+ """导出角色列表(当前筛选全量,或 ids 已选)。"""
|
|
|
+ try:
|
|
|
+ tenant_no = _get_tenant_no(db, user)
|
|
|
+ items, _ = role_svc.list_roles(
|
|
|
+ db,
|
|
|
+ page=1,
|
|
|
+ page_size=EXPORT_MAX_ROWS,
|
|
|
+ keyword=body.keyword,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ ids=body.ids,
|
|
|
+ max_page_size=EXPORT_MAX_ROWS,
|
|
|
+ user_info=user,
|
|
|
+ )
|
|
|
+ cols = filter_export_columns(ROLE_EXPORT_COLUMNS, body.columns)
|
|
|
+ date_str = datetime.now().strftime("%Y%m%d")
|
|
|
+ return export_rows_to_xlsx_response(
|
|
|
+ db,
|
|
|
+ tenant_no=tenant_no,
|
|
|
+ sheet_title="角色列表",
|
|
|
+ columns=cols,
|
|
|
+ rows=items,
|
|
|
+ filename_stem=f"角色列表_{date_str}",
|
|
|
+ )
|
|
|
+ except ExportValidationError as e:
|
|
|
+ return error_response(400, str(e))
|
|
|
+ except Exception as e:
|
|
|
+ return error_response(500, str(e))
|
|
|
+
|
|
|
+
|
|
|
@router.post("/role-management")
|
|
|
def create_role_management(
|
|
|
body: RoleCreateBody,
|