feat: 添加仪表板路由和响应数据脱敏功能 - 添加了仪表板模块路由并集成到主路由器中 - 实现了敏感数据响应脱敏配置和功能 - 增加了 Feishu 审批卡片操作处理功能 - 支持通过任务队列异步推送日常简报和项目周报 - 添加了风险事件生成的任务队列支持 - 在 smoke 测试中增加了相关功能验证 refactor: 格式化模型注册模块导入列表 - 将单行导入列表改为多行格式以提高可读性 ```
101 lines
3.2 KiB
Python
101 lines
3.2 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query
|
|
from fastapi import status as http_status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.masking import mask_configured
|
|
from app.core.security import ApiPrincipal, require_api_key
|
|
from app.modules.business.constants import BusinessField, BusinessResponseKey
|
|
from app.modules.business.registry import supported_domain_values
|
|
from app.modules.business.schemas import DomainListRead, DomainRecordCreate, DomainRecordUpdate
|
|
from app.modules.business.service import BusinessService
|
|
|
|
router = APIRouter(dependencies=[Depends(require_api_key)])
|
|
|
|
|
|
@router.get("/domains")
|
|
def list_domains() -> dict[str, list[str]]:
|
|
return {BusinessResponseKey.DOMAINS: supported_domain_values()}
|
|
|
|
|
|
@router.get("/{domain}", response_model=DomainListRead)
|
|
def list_records(
|
|
domain: str,
|
|
limit: int = Query(default=50, ge=1, le=500),
|
|
offset: int = Query(default=0, ge=0),
|
|
status_filter: str | None = Query(default=None, alias=BusinessField.STATUS),
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
try:
|
|
total, items = BusinessService(db).list_records(domain, limit, offset, status_filter)
|
|
except KeyError as exc:
|
|
raise HTTPException(status_code=http_status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
|
return {
|
|
BusinessResponseKey.DOMAIN: domain,
|
|
BusinessResponseKey.TOTAL: total,
|
|
BusinessResponseKey.ITEMS: mask_configured(items),
|
|
}
|
|
|
|
|
|
@router.get("/{domain}/{record_id}")
|
|
def get_record(
|
|
domain: str,
|
|
record_id: int,
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
try:
|
|
return {
|
|
BusinessResponseKey.DOMAIN: domain,
|
|
BusinessResponseKey.DATA: mask_configured(
|
|
BusinessService(db).get_record(domain, record_id)
|
|
),
|
|
}
|
|
except KeyError as exc:
|
|
raise HTTPException(status_code=http_status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post("/{domain}")
|
|
def create_record(
|
|
domain: str,
|
|
payload: DomainRecordCreate,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
try:
|
|
data = BusinessService(db).create_record(
|
|
domain,
|
|
payload.data,
|
|
principal.actor,
|
|
payload.approval_ticket_id,
|
|
)
|
|
except KeyError as exc:
|
|
raise HTTPException(status_code=http_status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
|
return {
|
|
BusinessResponseKey.DOMAIN: domain,
|
|
BusinessResponseKey.DATA: mask_configured(data),
|
|
}
|
|
|
|
|
|
@router.patch("/{domain}/{record_id}")
|
|
def update_record(
|
|
domain: str,
|
|
record_id: int,
|
|
payload: DomainRecordUpdate,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
try:
|
|
data = BusinessService(db).update_record(
|
|
domain,
|
|
record_id,
|
|
payload.data,
|
|
actor=principal.actor,
|
|
approval_ticket_id=payload.approval_ticket_id,
|
|
)
|
|
except KeyError as exc:
|
|
raise HTTPException(status_code=http_status.HTTP_404_NOT_FOUND, detail=str(exc)) from exc
|
|
return {
|
|
BusinessResponseKey.DOMAIN: domain,
|
|
BusinessResponseKey.DATA: mask_configured(data),
|
|
}
|