feat: wire native leaudit upload flow
This commit is contained in:
@@ -12,7 +12,15 @@ from fastapi_common.fastapi_common_web.domain.responses import StatusCodeEnum
|
||||
from fastapi_common.fastapi_common_web.exception.LeauditException import LeauditException
|
||||
from sqlalchemy import select, text
|
||||
|
||||
from fastapi_modules.fastapi_leaudit.domian.vo.auditVo import AuditRunVO, AuditResultVO
|
||||
from fastapi_modules.fastapi_leaudit.domian.vo.auditVo import (
|
||||
AuditArtifactVO,
|
||||
AuditFieldResultVO,
|
||||
AuditMetricsVO,
|
||||
AuditRescueOutcomeVO,
|
||||
AuditResultVO,
|
||||
AuditRunErrorVO,
|
||||
AuditRunVO,
|
||||
)
|
||||
from fastapi_modules.fastapi_leaudit.leaudit_bridge.fileSourceResolver import FileSourceResolver
|
||||
from fastapi_modules.fastapi_leaudit.leaudit_bridge.tasks import dispatch_leaudit_task
|
||||
from fastapi_modules.fastapi_leaudit.models import (
|
||||
@@ -132,11 +140,18 @@ class AuditServiceImpl(IAuditService):
|
||||
runId=run.Id,
|
||||
documentId=run.documentId,
|
||||
runNo=run.runNo,
|
||||
documentFileId=run.documentFileId,
|
||||
status=run.status,
|
||||
phase=run.phase,
|
||||
resultStatus=run.resultStatus,
|
||||
ruleSetId=run.ruleSetId,
|
||||
ruleVersionId=run.ruleVersionId,
|
||||
ruleTypeId=run.ruleTypeId,
|
||||
rescueApplied=run.rescueApplied or False,
|
||||
totalScore=float(run.totalScore) if run.totalScore else None,
|
||||
passedCount=run.passedCount,
|
||||
failedCount=run.failedCount,
|
||||
skippedCount=run.skippedCount,
|
||||
startedAt=run.startedAt,
|
||||
finishedAt=run.finishedAt,
|
||||
)
|
||||
@@ -151,11 +166,18 @@ class AuditServiceImpl(IAuditService):
|
||||
runId=run.Id,
|
||||
documentId=run.documentId,
|
||||
runNo=run.runNo,
|
||||
documentFileId=run.documentFileId,
|
||||
status=run.status,
|
||||
phase=run.phase,
|
||||
resultStatus=run.resultStatus,
|
||||
ruleSetId=run.ruleSetId,
|
||||
ruleVersionId=run.ruleVersionId,
|
||||
ruleTypeId=run.ruleTypeId,
|
||||
rescueApplied=run.rescueApplied or False,
|
||||
totalScore=float(run.totalScore) if run.totalScore else None,
|
||||
passedCount=run.passedCount,
|
||||
failedCount=run.failedCount,
|
||||
skippedCount=run.skippedCount,
|
||||
startedAt=run.startedAt,
|
||||
finishedAt=run.finishedAt,
|
||||
)
|
||||
@@ -166,7 +188,7 @@ class AuditServiceImpl(IAuditService):
|
||||
run = await session.get(LeauditAuditRun, RunId)
|
||||
if not run:
|
||||
raise LeauditException(StatusCodeEnum.HTTP_404_NOT_FOUND, "评查运行记录不存在")
|
||||
result = await session.execute(
|
||||
ruleResult = await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
@@ -192,14 +214,204 @@ class AuditServiceImpl(IAuditService):
|
||||
),
|
||||
{"run_id": RunId},
|
||||
)
|
||||
rules = [dict(row) for row in result.mappings().all()]
|
||||
fieldResult = await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
field_name,
|
||||
field_type,
|
||||
value_text,
|
||||
confidence,
|
||||
grounding_method,
|
||||
fallback_value,
|
||||
raw_value_json,
|
||||
meta_json
|
||||
FROM leaudit_field_results
|
||||
WHERE run_id = :run_id
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
),
|
||||
{"run_id": RunId},
|
||||
)
|
||||
errorResult = await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
stage,
|
||||
level,
|
||||
error_code,
|
||||
message,
|
||||
detail_json,
|
||||
created_at
|
||||
FROM leaudit_run_errors
|
||||
WHERE run_id = :run_id
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
),
|
||||
{"run_id": RunId},
|
||||
)
|
||||
rescueResult = await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
rule_id,
|
||||
status,
|
||||
diagnosis,
|
||||
diagnosis_confidence,
|
||||
final_status,
|
||||
failure_reason,
|
||||
llm_calls,
|
||||
vlm_calls,
|
||||
duration_ms,
|
||||
requires_human_review,
|
||||
payload
|
||||
FROM leaudit_rescue_outcomes
|
||||
WHERE run_id = :run_id
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
),
|
||||
{"run_id": RunId},
|
||||
)
|
||||
metricResult = await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
ocr_seconds,
|
||||
normalize_seconds,
|
||||
extract_seconds,
|
||||
evaluate_seconds,
|
||||
rescue_seconds,
|
||||
total_seconds,
|
||||
page_count,
|
||||
sub_document_count,
|
||||
field_count,
|
||||
rule_count,
|
||||
llm_call_count,
|
||||
vlm_call_count,
|
||||
rescue_rule_count,
|
||||
artifact_count
|
||||
FROM leaudit_run_metrics
|
||||
WHERE run_id = :run_id
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
),
|
||||
{"run_id": RunId},
|
||||
)
|
||||
artifactResult = await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
artifact_type,
|
||||
artifact_role,
|
||||
file_name,
|
||||
file_ext,
|
||||
mime_type,
|
||||
file_size,
|
||||
oss_url,
|
||||
is_persisted
|
||||
FROM leaudit_artifacts
|
||||
WHERE run_id = :run_id
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
),
|
||||
{"run_id": RunId},
|
||||
)
|
||||
rules = [dict(row) for row in ruleResult.mappings().all()]
|
||||
fields = [
|
||||
AuditFieldResultVO(
|
||||
fieldName=row["field_name"],
|
||||
fieldType=row["field_type"],
|
||||
valueText=row["value_text"],
|
||||
confidence=float(row["confidence"]) if row["confidence"] is not None else None,
|
||||
groundingMethod=row["grounding_method"],
|
||||
fallbackValue=row["fallback_value"],
|
||||
rawValueJson=row["raw_value_json"],
|
||||
metaJson=row["meta_json"],
|
||||
)
|
||||
for row in fieldResult.mappings().all()
|
||||
]
|
||||
errors = [
|
||||
AuditRunErrorVO(
|
||||
stage=row["stage"],
|
||||
level=row["level"],
|
||||
errorCode=row["error_code"],
|
||||
message=row["message"],
|
||||
detailJson=row["detail_json"],
|
||||
createdAt=row["created_at"],
|
||||
)
|
||||
for row in errorResult.mappings().all()
|
||||
]
|
||||
rescueOutcomes = [
|
||||
AuditRescueOutcomeVO(
|
||||
ruleId=row["rule_id"],
|
||||
status=row["status"],
|
||||
diagnosis=row["diagnosis"],
|
||||
diagnosisConfidence=float(row["diagnosis_confidence"]) if row["diagnosis_confidence"] is not None else None,
|
||||
finalStatus=row["final_status"],
|
||||
failureReason=row["failure_reason"],
|
||||
llmCalls=row["llm_calls"],
|
||||
vlmCalls=row["vlm_calls"],
|
||||
durationMs=row["duration_ms"],
|
||||
requiresHumanReview=bool(row["requires_human_review"]),
|
||||
payload=row["payload"],
|
||||
)
|
||||
for row in rescueResult.mappings().all()
|
||||
]
|
||||
metricRow = metricResult.mappings().first()
|
||||
metrics = (
|
||||
AuditMetricsVO(
|
||||
ocrSeconds=float(metricRow["ocr_seconds"]) if metricRow["ocr_seconds"] is not None else None,
|
||||
normalizeSeconds=float(metricRow["normalize_seconds"]) if metricRow["normalize_seconds"] is not None else None,
|
||||
extractSeconds=float(metricRow["extract_seconds"]) if metricRow["extract_seconds"] is not None else None,
|
||||
evaluateSeconds=float(metricRow["evaluate_seconds"]) if metricRow["evaluate_seconds"] is not None else None,
|
||||
rescueSeconds=float(metricRow["rescue_seconds"]) if metricRow["rescue_seconds"] is not None else None,
|
||||
totalSeconds=float(metricRow["total_seconds"]) if metricRow["total_seconds"] is not None else None,
|
||||
pageCount=metricRow["page_count"],
|
||||
subDocumentCount=metricRow["sub_document_count"],
|
||||
fieldCount=metricRow["field_count"],
|
||||
ruleCount=metricRow["rule_count"],
|
||||
llmCallCount=metricRow["llm_call_count"],
|
||||
vlmCallCount=metricRow["vlm_call_count"],
|
||||
rescueRuleCount=metricRow["rescue_rule_count"],
|
||||
artifactCount=metricRow["artifact_count"],
|
||||
)
|
||||
if metricRow
|
||||
else None
|
||||
)
|
||||
artifacts = [
|
||||
AuditArtifactVO(
|
||||
artifactType=row["artifact_type"],
|
||||
artifactRole=row["artifact_role"],
|
||||
fileName=row["file_name"],
|
||||
fileExt=row["file_ext"],
|
||||
mimeType=row["mime_type"],
|
||||
fileSize=row["file_size"],
|
||||
ossUrl=row["oss_url"],
|
||||
isPersisted=row["is_persisted"],
|
||||
)
|
||||
for row in artifactResult.mappings().all()
|
||||
]
|
||||
return AuditResultVO(
|
||||
runId=run.Id,
|
||||
documentId=run.documentId,
|
||||
documentFileId=run.documentFileId,
|
||||
status=run.status,
|
||||
totalScore=float(run.totalScore) if run.totalScore else None,
|
||||
passedCount=run.passedCount or 0,
|
||||
failedCount=run.failedCount or 0,
|
||||
skippedCount=run.skippedCount or 0,
|
||||
phase=run.phase,
|
||||
resultStatus=run.resultStatus,
|
||||
rescueApplied=run.rescueApplied or False,
|
||||
ruleSetId=run.ruleSetId,
|
||||
ruleVersionId=run.ruleVersionId,
|
||||
startedAt=run.startedAt,
|
||||
finishedAt=run.finishedAt,
|
||||
rules=rules,
|
||||
fields=fields,
|
||||
errors=errors,
|
||||
rescueOutcomes=rescueOutcomes,
|
||||
metrics=metrics,
|
||||
artifacts=artifacts,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user