perf(shipping-notice): 优化发货任务性能,修复上传流程与终态问题
This commit is contained in:
1 parent
434c04ed2d
commit
bcdd8285ae
29 files changed
+1074
-128
No files matched your search
@@ -440,6 +440,69 @@ def test_freight_notice_groups_reads_frozen_snapshot_po_when_extraction_projecti
|
||||
assert [item['business_no'] for item in result['items']] == ['WYC26082411', 'WYC26082412']
|
||||
|
||||
|
||||
def test_freight_notice_groups_upload_mode_reads_attempt_not_stale_column(app):
|
||||
"""通知完成面的上传方式必须取自 ShippingUploadAttempt,而非恒为 None 的 Notice.upload_mode。
|
||||
|
||||
回归点:denormalized Notice.upload_mode 从未被写入真实值;人工确认/RPA 的成功事实
|
||||
只保存在 ShippingUploadAttempt.mode。聚合投影若直接读列会导致「通知完成」卡片拿不到
|
||||
「人工確認 vs RPA 上传」的徽标来源。
|
||||
"""
|
||||
with app.app_context():
|
||||
from app import db
|
||||
from app.models import (
|
||||
ShippingExportArtifact, ShippingExcelTemplate, ShippingInventoryParsingProfile,
|
||||
ShippingNotice, ShippingOrderExtraction, ShippingOrderSchema, ShippingOrderSchemaVersion,
|
||||
)
|
||||
from app.services.shipping_notice import query_service
|
||||
from app.services.shipping_notice.upload_attempt_service import record_manual_upload
|
||||
|
||||
notice = ShippingNotice(task_no='SN-GROUP-MODE-1', business_no='WYC26082501', source_type='manual', user_id=11)
|
||||
template = ShippingExcelTemplate(
|
||||
template_code='MODE', display_name='Mode', version=1, status='published', storage_bucket='test',
|
||||
storage_key='test/template.xlsx', original_filename='template.xlsx', file_checksum='a' * 64,
|
||||
definition_json={},
|
||||
)
|
||||
profile = ShippingInventoryParsingProfile(
|
||||
profile_code='MODE', display_name='Mode', version=1, status='published', file_format='xlsx',
|
||||
definition_json={},
|
||||
)
|
||||
schema = ShippingOrderSchema(schema_code='SHIPPING_ORDER', display_name='Order')
|
||||
db.session.add_all([notice, template, profile, schema]); db.session.flush()
|
||||
version = ShippingOrderSchemaVersion(schema_id=schema.id, version=1, status='published', definition_json={})
|
||||
db.session.add(version); db.session.flush()
|
||||
extraction = ShippingOrderExtraction(schema_version_id=version.id, input_snapshot_hash='a' * 64, status='accepted')
|
||||
db.session.add(extraction); db.session.flush()
|
||||
artifact = ShippingExportArtifact(
|
||||
artifact_no='ART-MODE-1', task_id=notice.id, template_id=template.id, order_schema_version_id=version.id,
|
||||
order_extraction_id=extraction.id, inventory_parsing_profile_id=profile.id, input_checksum='b' * 64,
|
||||
file_path='/tmp/notice.xlsx', file_name='notice.xlsx', file_checksum='c' * 64, file_size=100, status='ready',
|
||||
)
|
||||
db.session.add(artifact); db.session.flush()
|
||||
notice.export_file_name = 'notice.xlsx'
|
||||
notice.export_file_path = '/tmp/notice.xlsx'
|
||||
# 人为把陈旧列写成错误值,证明聚合不再消费它。
|
||||
notice.upload_mode = 'rpa'
|
||||
notice.upload_attempt = 99
|
||||
db.session.commit()
|
||||
|
||||
# 一条人工确认成功 Attempt = 唯一可信的来源。
|
||||
record_manual_upload(notice, artifact_id=artifact.id, operator_id=22)
|
||||
db.session.commit()
|
||||
|
||||
original_header_reader = query_service.current_header_field_values_or_empty
|
||||
query_service.current_header_field_values_or_empty = lambda _task: {'customer_po_number': 'PO-MODE'}
|
||||
try:
|
||||
result = list_freight_notice_groups_for_task(notice, user_id=11)
|
||||
finally:
|
||||
query_service.current_header_field_values_or_empty = original_header_reader
|
||||
|
||||
item = result['items'][0]
|
||||
assert item['business_no'] == 'WYC26082501'
|
||||
# 权威事实:人工确认成功 → manual;不读陈旧列('rpa')或恒 0/99 的 attempt 计数。
|
||||
assert item['upload_mode'] == 'manual'
|
||||
assert item['upload_attempt'] == 1
|
||||
|
||||
|
||||
def test_list_my_todos_and_count_buckets(app):
|
||||
"""list_my_todos 按 bucket 分类;count 徽标与 pending 一致。"""
|
||||
with app.app_context():
|
||||
@@ -848,3 +911,36 @@ def test_todo_category_lightweight_matches_orm_and_count(app):
|
||||
assert counts["done"] == 1
|
||||
assert counts["processing"] == 1
|
||||
assert counts["total_pending_badge"] == 3
|
||||
|
||||
|
||||
def test_serialize_task_detail_workbench_view_drops_editor_fields(app):
|
||||
"""工作台 view=workbench 剔除复核编辑器重字段,保留 ui_state/产物/行摘要,全量视图不受影响。"""
|
||||
with app.app_context():
|
||||
from app import db
|
||||
from app.services.shipping_notice.query_service import serialize_task_detail
|
||||
|
||||
task = ShippingNotice(
|
||||
task_no="SN-WORKBENCH-VIEW", source_type="manual", user_id=11,
|
||||
export_file_name="n.xlsx", export_file_path="/tmp/n.xlsx",
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.commit()
|
||||
|
||||
full = serialize_task_detail(task, viewer_user_id=11, include_stage_context=True)
|
||||
wb = serialize_task_detail(
|
||||
task, viewer_user_id=11, include_stage_context=True, view="workbench",
|
||||
)
|
||||
|
||||
# full 保留编辑器重字段;workbench 剔除它们,显著缩小响应体。
|
||||
for key in (
|
||||
"lines", "order_header", "order_header_fields", "order_line_fields",
|
||||
"events", "field_conflicts",
|
||||
):
|
||||
assert key in full
|
||||
assert key not in wb
|
||||
# workbench 仍保留工作台所需字段(ui_state/stage_context、产物、行摘要)。
|
||||
assert wb["ui_state"]["task_no"] == "SN-WORKBENCH-VIEW"
|
||||
assert wb["ui_state"]["stage_context"] is not None
|
||||
assert wb["artifact_summary"]["export_file_name"] == "n.xlsx"
|
||||
assert "notice_line_summary" in wb
|
||||
assert "export_artifacts" in wb
|
||||
Reference in new issue
Block a user