feat: add contract template v3 api and legacy oss migration
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
"""合同模板控制器。"""
|
||||
|
||||
from fastapi import Depends, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from fastapi_common.fastapi_common_security.security import verify_access_token
|
||||
from fastapi_common.fastapi_common_web.controller import BaseController
|
||||
from fastapi_modules.fastapi_leaudit.domian.Dto.contractTemplateDto import (
|
||||
ContractTemplateListQueryDTO,
|
||||
ContractTemplateSearchQueryDTO,
|
||||
)
|
||||
from fastapi_modules.fastapi_leaudit.services.contractTemplateService import IContractTemplateService
|
||||
from fastapi_modules.fastapi_leaudit.services.impl.contractTemplateServiceImpl import ContractTemplateServiceImpl
|
||||
from fastapi_modules.fastapi_leaudit.services.impl.permissionServiceImpl import PermissionServiceImpl
|
||||
from fastapi_modules.fastapi_leaudit.services.permissionService import IPermissionService
|
||||
|
||||
|
||||
class ContractTemplateController(BaseController):
|
||||
"""合同模板控制器。"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(prefix="/v3/contract-templates", tags=["合同模板"])
|
||||
self.ContractTemplateService: IContractTemplateService = ContractTemplateServiceImpl()
|
||||
self.PermissionService: IPermissionService = PermissionServiceImpl()
|
||||
|
||||
@self.router.get("/categories")
|
||||
async def ListContractTemplateCategories(
|
||||
include_disabled: bool = Query(False, description="是否包含禁用分类"),
|
||||
with_template_count: bool = Query(True, description="是否附带模板数量"),
|
||||
payload: dict = Depends(verify_access_token),
|
||||
):
|
||||
if not await self._check_permission(int(payload["user_id"]), ["contract_template:list:read", "contract_template:search:read"]):
|
||||
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有查看合同模板分类权限", "data": None})
|
||||
data = await self.ContractTemplateService.ListCategories(include_disabled, with_template_count)
|
||||
return JSONResponse(status_code=200, content={"code": 200, "message": "ok", "data": [item.model_dump() for item in data]})
|
||||
|
||||
@self.router.get("")
|
||||
async def ListContractTemplates(
|
||||
keyword: str | None = Query(None, description="关键词"),
|
||||
category_id: int | None = Query(None, description="分类ID"),
|
||||
category_name: str | None = Query(None, description="分类名称"),
|
||||
file_format: str | None = Query(None, description="文件格式"),
|
||||
is_featured: bool | None = Query(None, description="是否推荐"),
|
||||
page: int = Query(1, ge=1, description="页码"),
|
||||
page_size: int = Query(12, ge=1, le=200, description="分页大小"),
|
||||
sort_by: str = Query("updated_at", description="排序字段"),
|
||||
sort_order: str = Query("desc", description="排序方向"),
|
||||
payload: dict = Depends(verify_access_token),
|
||||
):
|
||||
if not await self._check_permission(int(payload["user_id"]), ["contract_template:list:read"]):
|
||||
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有查看合同模板列表权限", "data": None})
|
||||
query = ContractTemplateListQueryDTO(
|
||||
keyword=keyword,
|
||||
category_id=category_id,
|
||||
category_name=category_name,
|
||||
file_format=file_format,
|
||||
is_featured=is_featured,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
)
|
||||
data = await self.ContractTemplateService.ListTemplates(query)
|
||||
return JSONResponse(status_code=200, content={"code": 200, "message": "ok", "data": data.model_dump()})
|
||||
|
||||
@self.router.get("/search")
|
||||
async def SearchContractTemplates(
|
||||
q: str = Query(..., min_length=1, description="搜索关键词"),
|
||||
category_id: int | None = Query(None, description="分类ID"),
|
||||
category_name: str | None = Query(None, description="分类名称"),
|
||||
page: int = Query(1, ge=1, description="页码"),
|
||||
page_size: int = Query(12, ge=1, le=200, description="分页大小"),
|
||||
sort_by: str = Query("updated_at", description="排序字段"),
|
||||
sort_order: str = Query("desc", description="排序方向"),
|
||||
payload: dict = Depends(verify_access_token),
|
||||
):
|
||||
if not await self._check_permission(int(payload["user_id"]), ["contract_template:search:read"]):
|
||||
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有搜索合同模板权限", "data": None})
|
||||
query = ContractTemplateSearchQueryDTO(
|
||||
q=q,
|
||||
category_id=category_id,
|
||||
category_name=category_name,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
)
|
||||
data = await self.ContractTemplateService.SearchTemplates(query)
|
||||
return JSONResponse(status_code=200, content={"code": 200, "message": "ok", "data": data.model_dump()})
|
||||
|
||||
@self.router.get("/{TemplateId}")
|
||||
async def GetContractTemplateDetail(
|
||||
TemplateId: int,
|
||||
payload: dict = Depends(verify_access_token),
|
||||
):
|
||||
if not await self._check_permission(int(payload["user_id"]), ["contract_template:detail:read", "contract_template:list:read"]):
|
||||
return JSONResponse(status_code=403, content={"code": 403, "msg": "当前用户没有查看合同模板详情权限", "data": None})
|
||||
data = await self.ContractTemplateService.GetTemplateDetail(TemplateId)
|
||||
if not data:
|
||||
return JSONResponse(status_code=404, content={"code": 404, "msg": "合同模板不存在", "data": None})
|
||||
return JSONResponse(status_code=200, content={"code": 200, "message": "ok", "data": data.model_dump()})
|
||||
|
||||
async def _check_permission(self, user_id: int, permission_keys: list[str]) -> bool:
|
||||
for permission_key in permission_keys:
|
||||
if await self.PermissionService.CheckPermission(user_id, permission_key):
|
||||
return True
|
||||
return False
|
||||
@@ -0,0 +1,27 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class ContractTemplateListQueryDTO(BaseModel):
|
||||
"""合同模板列表查询参数。"""
|
||||
|
||||
keyword: str | None = Field(None, description="关键词")
|
||||
category_id: int | None = Field(None, description="分类ID")
|
||||
category_name: str | None = Field(None, description="分类名称")
|
||||
file_format: str | None = Field(None, description="文件格式")
|
||||
is_featured: bool | None = Field(None, description="是否推荐")
|
||||
page: int = Field(1, ge=1, description="页码")
|
||||
page_size: int = Field(12, ge=1, le=200, description="分页大小")
|
||||
sort_by: str = Field("updated_at", description="排序字段")
|
||||
sort_order: str = Field("desc", description="排序方向")
|
||||
|
||||
|
||||
class ContractTemplateSearchQueryDTO(BaseModel):
|
||||
"""合同模板搜索参数。"""
|
||||
|
||||
q: str = Field(..., min_length=1, description="搜索关键词")
|
||||
category_id: int | None = Field(None, description="分类ID")
|
||||
category_name: str | None = Field(None, description="分类名称")
|
||||
page: int = Field(1, ge=1, description="页码")
|
||||
page_size: int = Field(12, ge=1, le=200, description="分页大小")
|
||||
sort_by: str = Field("updated_at", description="排序字段")
|
||||
sort_order: str = Field("desc", description="排序方向")
|
||||
@@ -0,0 +1,67 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class ContractTemplateCategoryVO(BaseModel):
|
||||
"""合同模板分类。"""
|
||||
|
||||
id: int = Field(..., description="分类ID")
|
||||
name: str = Field(..., description="分类名称")
|
||||
icon: str | None = Field(None, description="分类图标")
|
||||
description: str | None = Field(None, description="分类描述")
|
||||
sort_order: int = Field(0, description="排序")
|
||||
template_count: int = Field(0, description="分类下模板数量")
|
||||
is_enabled: bool = Field(True, description="是否启用")
|
||||
|
||||
|
||||
class ContractTemplateListItemVO(BaseModel):
|
||||
"""合同模板列表项。"""
|
||||
|
||||
id: int = Field(..., description="模板ID")
|
||||
template_code: str = Field(..., description="模板编码")
|
||||
title: str = Field(..., description="模板标题")
|
||||
category_id: int = Field(..., description="分类ID")
|
||||
category_name: str | None = Field(None, description="分类名称")
|
||||
category_icon: str | None = Field(None, description="分类图标")
|
||||
description: str | None = Field(None, description="模板简介")
|
||||
file_path: str | None = Field(None, description="原始模板文件路径")
|
||||
pdf_file_path: str | None = Field(None, description="PDF 预览文件路径")
|
||||
file_format: str = Field(..., description="文件格式")
|
||||
is_featured: bool = Field(False, description="是否推荐")
|
||||
created_at: str | None = Field(None, description="创建时间")
|
||||
updated_at: str | None = Field(None, description="更新时间")
|
||||
|
||||
|
||||
class ContractTemplatePageVO(BaseModel):
|
||||
"""合同模板分页结果。"""
|
||||
|
||||
total: int = Field(..., description="总数")
|
||||
page: int = Field(..., description="当前页")
|
||||
page_size: int = Field(..., description="分页大小")
|
||||
total_pages: int = Field(..., description="总页数")
|
||||
templates: list[ContractTemplateListItemVO] = Field(default_factory=list, description="模板列表")
|
||||
|
||||
|
||||
class ContractTemplateDetailVO(ContractTemplateListItemVO):
|
||||
"""合同模板详情。"""
|
||||
|
||||
category_description: str | None = Field(None, description="分类描述")
|
||||
placeholder_schema: dict | None = Field(None, description="模板占位符结构")
|
||||
|
||||
|
||||
class ContractTemplateSearchCategoryVO(BaseModel):
|
||||
"""搜索结果分类统计。"""
|
||||
|
||||
id: int = Field(..., description="分类ID")
|
||||
name: str = Field(..., description="分类名称")
|
||||
search_count: int = Field(0, description="当前关键词命中的模板数")
|
||||
|
||||
|
||||
class ContractTemplateSearchResultVO(BaseModel):
|
||||
"""合同模板搜索结果。"""
|
||||
|
||||
total: int = Field(..., description="总数")
|
||||
page: int = Field(..., description="当前页")
|
||||
page_size: int = Field(..., description="分页大小")
|
||||
total_pages: int = Field(..., description="总页数")
|
||||
templates: list[ContractTemplateListItemVO] = Field(default_factory=list, description="模板列表")
|
||||
category_stats: list[ContractTemplateSearchCategoryVO] = Field(default_factory=list, description="分类统计")
|
||||
@@ -0,0 +1,32 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from fastapi_modules.fastapi_leaudit.domian.Dto.contractTemplateDto import (
|
||||
ContractTemplateListQueryDTO,
|
||||
ContractTemplateSearchQueryDTO,
|
||||
)
|
||||
from fastapi_modules.fastapi_leaudit.domian.vo.contractTemplateVo import (
|
||||
ContractTemplateCategoryVO,
|
||||
ContractTemplateDetailVO,
|
||||
ContractTemplatePageVO,
|
||||
ContractTemplateSearchResultVO,
|
||||
)
|
||||
|
||||
|
||||
class IContractTemplateService(ABC):
|
||||
"""合同模板服务接口。"""
|
||||
|
||||
@abstractmethod
|
||||
async def ListCategories(self, IncludeDisabled: bool, WithTemplateCount: bool) -> list[ContractTemplateCategoryVO]:
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def ListTemplates(self, Query: ContractTemplateListQueryDTO) -> ContractTemplatePageVO:
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def SearchTemplates(self, Query: ContractTemplateSearchQueryDTO) -> ContractTemplateSearchResultVO:
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def GetTemplateDetail(self, TemplateId: int) -> ContractTemplateDetailVO | None:
|
||||
...
|
||||
@@ -0,0 +1,317 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import bindparam, text
|
||||
|
||||
from fastapi_common.fastapi_common_sqlalchemy.database import GetAsyncSession
|
||||
from fastapi_modules.fastapi_leaudit.domian.Dto.contractTemplateDto import (
|
||||
ContractTemplateListQueryDTO,
|
||||
ContractTemplateSearchQueryDTO,
|
||||
)
|
||||
from fastapi_modules.fastapi_leaudit.domian.vo.contractTemplateVo import (
|
||||
ContractTemplateCategoryVO,
|
||||
ContractTemplateDetailVO,
|
||||
ContractTemplateListItemVO,
|
||||
ContractTemplatePageVO,
|
||||
ContractTemplateSearchCategoryVO,
|
||||
ContractTemplateSearchResultVO,
|
||||
)
|
||||
from fastapi_modules.fastapi_leaudit.services.contractTemplateService import IContractTemplateService
|
||||
|
||||
_ALLOWED_SORT_FIELDS = {
|
||||
"id": "t.id",
|
||||
"title": "t.title",
|
||||
"created_at": "t.created_at",
|
||||
"updated_at": "t.updated_at",
|
||||
}
|
||||
|
||||
|
||||
class ContractTemplateServiceImpl(IContractTemplateService):
|
||||
"""合同模板服务实现。"""
|
||||
|
||||
async def ListCategories(self, IncludeDisabled: bool, WithTemplateCount: bool) -> list[ContractTemplateCategoryVO]:
|
||||
count_select = "COUNT(t.id)::int AS template_count" if WithTemplateCount else "0::int AS template_count"
|
||||
sql = text(
|
||||
f"""
|
||||
SELECT
|
||||
c.id,
|
||||
c.name,
|
||||
c.icon,
|
||||
c.description,
|
||||
COALESCE(c.sort_order, 0) AS sort_order,
|
||||
{count_select},
|
||||
TRUE AS is_enabled
|
||||
FROM contract_categories c
|
||||
LEFT JOIN contract_templates t
|
||||
ON t.category_id = c.id
|
||||
WHERE 1=1
|
||||
GROUP BY c.id, c.name, c.icon, c.description, c.sort_order
|
||||
ORDER BY COALESCE(c.sort_order, 0) ASC, c.name ASC
|
||||
"""
|
||||
)
|
||||
|
||||
async with GetAsyncSession() as session:
|
||||
rows = (await session.execute(sql)).mappings().all()
|
||||
|
||||
return [self._to_category_vo(row) for row in rows]
|
||||
|
||||
async def ListTemplates(self, Query: ContractTemplateListQueryDTO) -> ContractTemplatePageVO:
|
||||
where_clause, params, needs_category_name_filter = self._build_template_filters(
|
||||
keyword=Query.keyword,
|
||||
category_id=Query.category_id,
|
||||
category_name=Query.category_name,
|
||||
file_format=Query.file_format,
|
||||
is_featured=Query.is_featured,
|
||||
)
|
||||
order_sql = self._build_order_clause(Query.sort_by, Query.sort_order, default_field="updated_at", default_order="desc")
|
||||
offset = max(Query.page - 1, 0) * Query.page_size
|
||||
params.update({"limit": Query.page_size, "offset": offset})
|
||||
|
||||
from_sql = self._build_template_from_sql(needs_category_name_filter)
|
||||
|
||||
count_sql = text(
|
||||
f"""
|
||||
SELECT COUNT(*)
|
||||
{from_sql}
|
||||
WHERE {where_clause}
|
||||
"""
|
||||
)
|
||||
list_sql = text(
|
||||
f"""
|
||||
SELECT
|
||||
t.id,
|
||||
t.template_code,
|
||||
t.title,
|
||||
t.category_id,
|
||||
c.name AS category_name,
|
||||
c.icon AS category_icon,
|
||||
c.description AS category_description,
|
||||
t.description,
|
||||
t.file_path,
|
||||
t.pdf_file_path,
|
||||
t.file_format,
|
||||
COALESCE(t.is_featured, FALSE) AS is_featured,
|
||||
t.created_at,
|
||||
t.updated_at
|
||||
{from_sql}
|
||||
WHERE {where_clause}
|
||||
ORDER BY {order_sql}
|
||||
LIMIT :limit OFFSET :offset
|
||||
"""
|
||||
)
|
||||
count_sql, list_sql = self._bind_expanding(count_sql, list_sql, params)
|
||||
|
||||
async with GetAsyncSession() as session:
|
||||
total = int((await session.execute(count_sql, params)).scalar_one())
|
||||
rows = (await session.execute(list_sql, params)).mappings().all()
|
||||
|
||||
return ContractTemplatePageVO(
|
||||
total=total,
|
||||
page=Query.page,
|
||||
page_size=Query.page_size,
|
||||
total_pages=max((total + Query.page_size - 1) // Query.page_size, 1) if total else 0,
|
||||
templates=[self._to_list_item_vo(row) for row in rows],
|
||||
)
|
||||
|
||||
async def SearchTemplates(self, Query: ContractTemplateSearchQueryDTO) -> ContractTemplateSearchResultVO:
|
||||
list_query = ContractTemplateListQueryDTO(
|
||||
keyword=Query.q,
|
||||
category_id=Query.category_id,
|
||||
category_name=Query.category_name,
|
||||
page=Query.page,
|
||||
page_size=Query.page_size,
|
||||
sort_by=Query.sort_by,
|
||||
sort_order=Query.sort_order,
|
||||
)
|
||||
page_result = await self.ListTemplates(list_query)
|
||||
category_stats = await self._load_search_category_stats(Query.q)
|
||||
|
||||
return ContractTemplateSearchResultVO(
|
||||
total=page_result.total,
|
||||
page=page_result.page,
|
||||
page_size=page_result.page_size,
|
||||
total_pages=page_result.total_pages,
|
||||
templates=page_result.templates,
|
||||
category_stats=category_stats,
|
||||
)
|
||||
|
||||
async def GetTemplateDetail(self, TemplateId: int) -> ContractTemplateDetailVO | None:
|
||||
sql = text(
|
||||
"""
|
||||
SELECT
|
||||
t.id,
|
||||
t.template_code,
|
||||
t.title,
|
||||
t.category_id,
|
||||
c.name AS category_name,
|
||||
c.icon AS category_icon,
|
||||
c.description AS category_description,
|
||||
t.description,
|
||||
t.file_path,
|
||||
t.pdf_file_path,
|
||||
t.file_format,
|
||||
COALESCE(t.is_featured, FALSE) AS is_featured,
|
||||
t.created_at,
|
||||
t.updated_at
|
||||
FROM contract_templates t
|
||||
LEFT JOIN contract_categories c ON c.id = t.category_id
|
||||
WHERE t.id = :template_id
|
||||
LIMIT 1
|
||||
"""
|
||||
)
|
||||
|
||||
async with GetAsyncSession() as session:
|
||||
row = (await session.execute(sql, {"template_id": TemplateId})).mappings().first()
|
||||
|
||||
if not row:
|
||||
return None
|
||||
return self._to_detail_vo(row)
|
||||
|
||||
async def _load_search_category_stats(
|
||||
self,
|
||||
keyword: str,
|
||||
) -> list[ContractTemplateSearchCategoryVO]:
|
||||
clean_keyword = (keyword or "").strip()
|
||||
if not clean_keyword:
|
||||
return []
|
||||
|
||||
filters = [
|
||||
"("
|
||||
"t.title ILIKE :keyword "
|
||||
"OR COALESCE(t.description, '') ILIKE :keyword "
|
||||
"OR COALESCE(t.template_code, '') ILIKE :keyword "
|
||||
"OR COALESCE(c.name, '') ILIKE :keyword"
|
||||
")"
|
||||
]
|
||||
params: dict[str, Any] = {"keyword": f"%{clean_keyword}%"}
|
||||
|
||||
sql = text(
|
||||
f"""
|
||||
SELECT
|
||||
c.id,
|
||||
c.name,
|
||||
COUNT(t.id)::int AS search_count
|
||||
FROM contract_categories c
|
||||
LEFT JOIN contract_templates t ON t.category_id = c.id
|
||||
WHERE {' AND '.join(filters)}
|
||||
GROUP BY c.id, c.name
|
||||
ORDER BY c.name ASC
|
||||
"""
|
||||
)
|
||||
|
||||
async with GetAsyncSession() as session:
|
||||
rows = (await session.execute(sql, params)).mappings().all()
|
||||
|
||||
return [
|
||||
ContractTemplateSearchCategoryVO(
|
||||
id=int(row["id"]),
|
||||
name=str(row["name"] or ""),
|
||||
search_count=int(row["search_count"] or 0),
|
||||
)
|
||||
for row in rows
|
||||
if row.get("id") is not None
|
||||
]
|
||||
|
||||
def _build_template_filters(
|
||||
self,
|
||||
keyword: str | None,
|
||||
category_id: int | None,
|
||||
category_name: str | None,
|
||||
file_format: str | None,
|
||||
is_featured: bool | None,
|
||||
) -> tuple[str, dict[str, Any], bool]:
|
||||
filters = ["1=1"]
|
||||
params: dict[str, Any] = {}
|
||||
needs_category_name_filter = False
|
||||
|
||||
if category_id is not None:
|
||||
filters.append("t.category_id = :category_id")
|
||||
params["category_id"] = category_id
|
||||
elif category_name:
|
||||
filters.append("c.name = :category_name")
|
||||
params["category_name"] = category_name.strip()
|
||||
needs_category_name_filter = True
|
||||
|
||||
if file_format:
|
||||
filters.append("t.file_format = :file_format")
|
||||
params["file_format"] = file_format.strip().lower()
|
||||
|
||||
if is_featured is not None:
|
||||
filters.append("COALESCE(t.is_featured, FALSE) = :is_featured")
|
||||
params["is_featured"] = is_featured
|
||||
|
||||
clean_keyword = (keyword or "").strip()
|
||||
if clean_keyword:
|
||||
filters.append(
|
||||
"("
|
||||
"t.title ILIKE :keyword "
|
||||
"OR COALESCE(t.description, '') ILIKE :keyword "
|
||||
"OR COALESCE(t.template_code, '') ILIKE :keyword "
|
||||
"OR COALESCE(c.name, '') ILIKE :keyword"
|
||||
")"
|
||||
)
|
||||
params["keyword"] = f"%{clean_keyword}%"
|
||||
needs_category_name_filter = True
|
||||
|
||||
return " AND ".join(filters), params, needs_category_name_filter
|
||||
|
||||
def _build_template_from_sql(self, needs_category_name_filter: bool) -> str:
|
||||
_ = needs_category_name_filter
|
||||
return """
|
||||
FROM contract_templates t
|
||||
LEFT JOIN contract_categories c ON c.id = t.category_id
|
||||
"""
|
||||
|
||||
def _build_order_clause(self, sort_by: str | None, sort_order: str | None, default_field: str, default_order: str) -> str:
|
||||
field = _ALLOWED_SORT_FIELDS.get(str(sort_by or "").strip().lower(), _ALLOWED_SORT_FIELDS[default_field])
|
||||
direction = "DESC" if str(sort_order or default_order).strip().lower() == "desc" else "ASC"
|
||||
return f"{field} {direction}, t.id ASC"
|
||||
|
||||
def _bind_expanding(self, *sql_objects_and_params: Any):
|
||||
sql_objects = list(sql_objects_and_params[:-1])
|
||||
params = sql_objects_and_params[-1]
|
||||
if "category_ids" in params:
|
||||
sql_objects = [sql.bindparams(bindparam("category_ids", expanding=True)) for sql in sql_objects]
|
||||
return tuple(sql_objects)
|
||||
|
||||
def _to_category_vo(self, row: Any) -> ContractTemplateCategoryVO:
|
||||
return ContractTemplateCategoryVO(
|
||||
id=int(row["id"]),
|
||||
name=str(row["name"] or ""),
|
||||
icon=row.get("icon"),
|
||||
description=row.get("description"),
|
||||
sort_order=int(row.get("sort_order") or 0),
|
||||
template_count=int(row.get("template_count") or 0),
|
||||
is_enabled=bool(row.get("is_enabled", True)),
|
||||
)
|
||||
|
||||
def _to_list_item_vo(self, row: Any) -> ContractTemplateListItemVO:
|
||||
return ContractTemplateListItemVO(
|
||||
id=int(row["id"]),
|
||||
template_code=str(row.get("template_code") or ""),
|
||||
title=str(row.get("title") or ""),
|
||||
category_id=int(row.get("category_id") or 0),
|
||||
category_name=row.get("category_name"),
|
||||
category_icon=row.get("category_icon"),
|
||||
description=row.get("description"),
|
||||
file_path=row.get("file_path"),
|
||||
pdf_file_path=row.get("pdf_file_path"),
|
||||
file_format=str(row.get("file_format") or ""),
|
||||
is_featured=bool(row.get("is_featured", False)),
|
||||
created_at=self._stringify_time(row.get("created_at")),
|
||||
updated_at=self._stringify_time(row.get("updated_at")),
|
||||
)
|
||||
|
||||
def _to_detail_vo(self, row: Any) -> ContractTemplateDetailVO:
|
||||
base = self._to_list_item_vo(row)
|
||||
return ContractTemplateDetailVO(
|
||||
**base.model_dump(),
|
||||
category_description=row.get("category_description"),
|
||||
placeholder_schema=None,
|
||||
)
|
||||
|
||||
def _stringify_time(self, value: Any) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
return str(value)
|
||||
@@ -222,6 +222,9 @@ class RbacAdminServiceImpl(IRbacAdminService):
|
||||
{"permission_key": "usage_stats:departments:read", "display_name": "查看部门统计", "module": "usage_stats", "resource": "departments", "action": "read", "api_method": "GET", "api_path": "/api/v3/usage-stats/by-departments", "route_path": "/usage-stats"},
|
||||
{"permission_key": "usage_stats:areas:read", "display_name": "查看地区统计", "module": "usage_stats", "resource": "areas", "action": "read", "api_method": "GET", "api_path": "/api/v3/usage-stats/by-areas", "route_path": "/usage-stats"},
|
||||
{"permission_key": "usage_stats:details:read", "display_name": "查看统计明细", "module": "usage_stats", "resource": "details", "action": "read", "api_method": "GET", "api_path": "/api/v3/usage-stats/details", "route_path": "/usage-stats"},
|
||||
{"permission_key": "contract_template:list:read", "display_name": "查看合同模板列表", "module": "contract_template", "resource": "list", "action": "read", "api_method": "GET", "api_path": "/api/v3/contract-templates", "route_path": "/contract-template/list"},
|
||||
{"permission_key": "contract_template:search:read", "display_name": "搜索合同模板", "module": "contract_template", "resource": "search", "action": "read", "api_method": "GET", "api_path": "/api/v3/contract-templates/search", "route_path": "/contract-template/search"},
|
||||
{"permission_key": "contract_template:detail:read", "display_name": "查看合同模板详情", "module": "contract_template", "resource": "detail", "action": "read", "api_method": "GET", "api_path": "/api/v3/contract-templates/{id}", "route_path": "/contract-template/list"},
|
||||
{"permission_key": "evaluation_group:list:read", "display_name": "评查点分组列表", "module": "evaluation_group", "resource": "list", "action": "read", "api_method": "GET", "api_path": "/api/v3/evaluation-point-groups", "route_path": "/rule-groups"},
|
||||
{"permission_key": "evaluation_group:create:write", "display_name": "创建评查点分组", "module": "evaluation_group", "resource": "create", "action": "write", "api_method": "POST", "api_path": "/api/v3/evaluation-point-groups", "route_path": "/rule-groups"},
|
||||
{"permission_key": "evaluation_group:update:write", "display_name": "更新评查点分组与绑定", "module": "evaluation_group", "resource": "update", "action": "write", "api_method": "PUT", "api_path": "/api/v3/evaluation-point-groups/{id}", "route_path": "/rule-groups"},
|
||||
|
||||
Reference in New Issue
Block a user