fix: bugs-04

This commit is contained in:
2026-03-17 22:39:05 +08:00
parent 143a1b4507
commit cdc2c4ead6
50 changed files with 1694 additions and 1916 deletions

View File

@@ -16,6 +16,7 @@ from app.schemas.assessment import (
InquirySuggestionOut,
)
from app.services.assessment_service import generate_inquiry_suggestions
from app.services.case_service import recalculate_case_total
router = APIRouter()
@@ -48,6 +49,7 @@ async def review_assessment(
"reviewed_by": body.reviewed_by,
"reviewed_at": datetime.now(timezone.utc),
})
await recalculate_case_total(assessment.case_id, db)
# eager-load the transaction relationship to avoid lazy-load in async context
result = await db.execute(

View File

@@ -15,11 +15,13 @@ from app.schemas.image import (
ImageOut,
ImageDetailOut,
OcrFieldCorrection,
OcrBlockUpdateIn,
CaseOcrStartIn,
CaseImagesDeleteIn,
)
from app.utils.hash import sha256_file
from app.utils.file_storage import save_upload
from app.models.ocr_block import OcrBlock
router = APIRouter()
@@ -149,6 +151,50 @@ async def correct_ocr(
return {"message": "修正已保存", "corrections": len(corrections)}
@router.patch("/images/{image_id}/ocr-blocks")
async def update_ocr_blocks(
image_id: UUID,
blocks: list[OcrBlockUpdateIn],
db: AsyncSession = Depends(get_db),
):
repo = ImageRepository(db)
image = await repo.get(image_id)
if not image:
raise HTTPException(404, "截图不存在")
existing = sorted(list(image.ocr_blocks), key=lambda b: b.seq_order)
total = len(blocks)
if total == 0:
return {"message": "未提交可保存内容", "updated": 0}
# Update existing blocks first.
min_len = min(len(existing), total)
for idx in range(min_len):
existing[idx].content = blocks[idx].content
existing[idx].confidence = blocks[idx].confidence
existing[idx].seq_order = idx
# Create extra blocks if payload has more.
for idx in range(min_len, total):
db.add(
OcrBlock(
image_id=image_id,
content=blocks[idx].content,
bbox={},
seq_order=idx,
confidence=blocks[idx].confidence,
)
)
# Remove extra old blocks if payload has fewer.
for idx in range(total, len(existing)):
await db.delete(existing[idx])
await db.flush()
await db.commit()
return {"message": f"已保存 {total} 条OCR内容", "updated": total}
@router.get("/images/{image_id}/file")
async def get_image_file(image_id: UUID, db: AsyncSession = Depends(get_db)):
repo = ImageRepository(db)

View File

@@ -5,7 +5,12 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import get_db
from app.repositories.transaction_repo import TransactionRepository
from app.schemas.transaction import TransactionOut, TransactionListOut, FlowGraphOut
from app.schemas.transaction import (
TransactionOut,
TransactionListOut,
FlowGraphOut,
TransactionUpdateIn,
)
from app.services.flow_service import build_flow_graph
router = APIRouter()
@@ -31,6 +36,23 @@ async def get_transaction(tx_id: UUID, db: AsyncSession = Depends(get_db)):
return tx
@router.patch("/transactions/{tx_id}", response_model=TransactionOut)
async def update_transaction(
tx_id: UUID,
body: TransactionUpdateIn,
db: AsyncSession = Depends(get_db),
):
repo = TransactionRepository(db)
tx = await repo.get(tx_id)
if not tx:
raise HTTPException(404, "交易不存在")
update_data = body.model_dump(exclude_unset=True)
tx = await repo.update(tx, update_data)
await db.commit()
return tx
@router.get("/cases/{case_id}/flows", response_model=FlowGraphOut)
async def get_fund_flows(case_id: UUID, db: AsyncSession = Depends(get_db)):
return await build_flow_graph(case_id, db)