启动与授权-初步优化
This commit is contained in:
@@ -4,12 +4,12 @@ from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.core.deps import get_current_user, get_db_session
|
||||
from app.crud import audit as audit_crud
|
||||
from app.crud import contract_fee as contract_fee_crud
|
||||
from app.crud import contract_fee_payment as payment_crud
|
||||
from app.crud import fee_attachment as fee_attachment_crud
|
||||
from app.crud import member as member_crud
|
||||
from app.crud import site as site_crud
|
||||
from app.crud import user as user_crud
|
||||
@@ -23,6 +23,7 @@ from app.schemas.contract_fee_payment import (
|
||||
from app.schemas.fee_common import FeeApiResponse
|
||||
from app.schemas.fee_attachment import FeeAttachmentRead
|
||||
from app.schemas.user import UserDisplay
|
||||
from app.models.attachment import Attachment
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -123,7 +124,15 @@ async def get_contract_fee(
|
||||
await _ensure_project_access(db, contract.project_id, current_user, write=False)
|
||||
|
||||
payments = await payment_crud.list_payments(db, contract.id)
|
||||
attachments = await fee_attachment_crud.list_attachments(db, entity_type="contract_fee", entity_id=contract.id)
|
||||
attachment_types = ["contract_fee_contract", "contract_fee_voucher", "contract_fee_invoice"]
|
||||
result = await db.execute(
|
||||
select(Attachment).where(
|
||||
Attachment.entity_id == contract.id,
|
||||
Attachment.entity_type.in_(attachment_types),
|
||||
Attachment.is_deleted.is_(False),
|
||||
)
|
||||
)
|
||||
attachments = result.scalars().all()
|
||||
user_ids = {a.uploaded_by for a in attachments if a.uploaded_by}
|
||||
users_map = await user_crud.get_users_by_ids(db, user_ids)
|
||||
|
||||
@@ -133,20 +142,20 @@ async def get_contract_fee(
|
||||
"invoice": [],
|
||||
}
|
||||
for attachment in attachments:
|
||||
key = attachment.file_type
|
||||
key = attachment.entity_type.replace("contract_fee_", "", 1)
|
||||
attachments_map.setdefault(key, [])
|
||||
user = users_map.get(attachment.uploaded_by)
|
||||
attachments_map[key].append(
|
||||
FeeAttachmentRead(
|
||||
id=attachment.id,
|
||||
entity_type=attachment.entity_type,
|
||||
entity_type="contract_fee",
|
||||
entity_id=attachment.entity_id,
|
||||
file_type=attachment.file_type,
|
||||
file_type=key,
|
||||
filename=attachment.filename,
|
||||
mime_type=attachment.mime_type,
|
||||
size=attachment.size,
|
||||
storage_key=attachment.storage_key,
|
||||
url=attachment.url,
|
||||
mime_type=attachment.content_type,
|
||||
size=attachment.file_size,
|
||||
storage_key=attachment.file_path,
|
||||
url=None,
|
||||
uploaded_by_id=attachment.uploaded_by,
|
||||
uploaded_by=UserDisplay.model_validate(user) if user else None,
|
||||
uploaded_at=attachment.uploaded_at,
|
||||
|
||||
Reference in New Issue
Block a user