101 lines
3.7 KiB
Python
101 lines
3.7 KiB
Python
"""场外基金运营接口。"""
|
|||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
from fastapi import APIRouter, Depends
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
|
|
||
|
|
from app.api.dependencies.auth import build_request_context
|
||
|
|
from app.api.dependencies.database import get_session
|
||
|
|
from app.api.schemas.offsite_fund import (
|
||
|
|
OffsiteConfirmRequest,
|
||
|
|
OffsiteMailRecognizeRequest,
|
||
|
|
OffsiteNotificationRequest,
|
||
|
|
OffsiteNotificationSendRequest,
|
||
|
|
OffsiteRecalculateRequest,
|
||
|
|
OffsiteTriggerNl2SqlRequest,
|
||
|
|
)
|
||
|
|
from app.core.contracts import RequestContext
|
||
|
|
from app.service.offsite_fund_service import OffsiteFundService
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/api/v1/offsite-fund", tags=["offsite-fund"])
|
||
|
|
operation_router = APIRouter(prefix="/api", tags=["offsite-fund"])
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/recognized-mails")
|
||
|
|
async def receive_recognized_mail(
|
||
|
|
payload: OffsiteMailRecognizeRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).receive_recognized_mail(payload, context)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/documents/{task_id}/confirmations")
|
||
|
|
async def confirm_document(
|
||
|
|
task_id: str,
|
||
|
|
payload: OffsiteConfirmRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).confirm_document(
|
||
|
|
task_id, payload.decision, payload.operator_id, context)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/documents/{task_id}/notifications")
|
||
|
|
async def create_notification(
|
||
|
|
task_id: str,
|
||
|
|
payload: OffsiteNotificationRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).create_notification(
|
||
|
|
task_id, payload.notification_type, payload.operator_id, context)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/notifications/{notification_id}/send")
|
||
|
|
async def send_notification(
|
||
|
|
notification_id: int,
|
||
|
|
payload: OffsiteNotificationSendRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).send_notification(
|
||
|
|
notification_id,
|
||
|
|
payload.operator_id,
|
||
|
|
payload.operator_confirmed,
|
||
|
|
payload.final_content,
|
||
|
|
context,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/settlement-statistics/recalculate")
|
||
|
|
async def recalculate_statistics(
|
||
|
|
payload: OffsiteRecalculateRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).recalculate_statistics(
|
||
|
|
payload.fund_code, payload.application_date, context)
|
||
|
|
|
||
|
|
|
||
|
|
@operation_router.post("/tasks/{task_id}/trigger-agent-nl2sql")
|
||
|
|
async def trigger_agent_nl2sql(
|
||
|
|
task_id: str,
|
||
|
|
payload: OffsiteTriggerNl2SqlRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).trigger_agent_nl2sql(
|
||
|
|
task_id, payload.operator_id, payload.manual_confirmed, context)
|
||
|
|
|
||
|
|
|
||
|
|
@operation_router.post("/settlement-statistics/recalculate")
|
||
|
|
async def recalculate_statistics_compat(
|
||
|
|
payload: OffsiteRecalculateRequest,
|
||
|
|
context: RequestContext = Depends(build_request_context), # noqa: B008
|
||
|
|
session: AsyncSession = Depends(get_session), # noqa: B008
|
||
|
|
) -> dict[str, Any]:
|
||
|
|
return await OffsiteFundService(session).recalculate_statistics(
|
||
|
|
payload.fund_code, payload.application_date, context)
|