feat: add demo report import workflow
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import logging
|
||||
|
||||
from apps.core.report_uploads import ReportUploadService
|
||||
from apps.core.upload_contracts import (
|
||||
build_upload_error_response,
|
||||
build_upload_success_payload,
|
||||
@@ -50,13 +51,20 @@ class FormF5UploadView(APIView):
|
||||
report_year = serializer.validated_data["report_year"]
|
||||
|
||||
report_quarter = serializer.validated_data.get("report_quarter")
|
||||
report_upload = ReportUploadService.create(
|
||||
uploaded_file=file,
|
||||
form="f5",
|
||||
user=request.user,
|
||||
)
|
||||
|
||||
if file.size > BACKGROUND_THRESHOLD:
|
||||
ReportUploadService.mark_queued(report_upload.id)
|
||||
task = process_form_f5_file.delay(
|
||||
file.read(),
|
||||
file.name,
|
||||
report_year,
|
||||
report_quarter,
|
||||
str(report_upload.id),
|
||||
)
|
||||
return Response(
|
||||
build_upload_success_payload(
|
||||
@@ -64,6 +72,7 @@ class FormF5UploadView(APIView):
|
||||
report_year=report_year,
|
||||
status="queued",
|
||||
job_id=task.id,
|
||||
upload_id=str(report_upload.id),
|
||||
),
|
||||
status=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
@@ -74,16 +83,19 @@ class FormF5UploadView(APIView):
|
||||
report_year=report_year,
|
||||
report_quarter=report_quarter,
|
||||
)
|
||||
ReportUploadService.finalize(report_upload.id, result)
|
||||
return Response(
|
||||
build_upload_success_payload(
|
||||
form="f5",
|
||||
report_year=report_year,
|
||||
status="done",
|
||||
result=FormF5ParseResultSerializer(result).data,
|
||||
upload_id=str(report_upload.id),
|
||||
),
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
except Exception as e:
|
||||
ReportUploadService.mark_failed(report_upload.id)
|
||||
logger.exception("Ошибка обработки файла Ф-5")
|
||||
return build_upload_error_response(
|
||||
error_code="processing_error",
|
||||
|
||||
Reference in New Issue
Block a user