feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订
This commit is contained in:
1 parent
70f684b94a
commit
b595e157e9
83 files changed
+5857
-200
No files matched your search
@@ -25,8 +25,12 @@ from app.models import (
|
||||
User,
|
||||
)
|
||||
from app.services.shipping_notice.batch_from_intakes import create_shipping_batch_from_intakes
|
||||
from app.services.shipping_notice.business_fingerprint import build_business_fingerprint
|
||||
from app.services.shipping_notice.business_fingerprint import (
|
||||
build_business_fingerprint,
|
||||
build_content_fingerprint,
|
||||
)
|
||||
from app.services.shipping_notice.duplicate_detection import (
|
||||
apply_duplicate_result_to_candidate,
|
||||
detect_duplicates_for_candidate,
|
||||
detect_duplicates_for_intake,
|
||||
)
|
||||
@@ -86,6 +90,26 @@ def _seed_parsed_intake(
|
||||
return asset, intake
|
||||
|
||||
|
||||
def test_business_fingerprint_ignores_internal_hex_reservation_id():
|
||||
"""内部 32 位 hex 不得增强业务身份指纹,避免把数据库主键当成订单真值。"""
|
||||
summary = {
|
||||
'customer_name': 'ACME',
|
||||
'reservation_ids': ['1f1a682dfdc446a393415dee93eb36ce'],
|
||||
'lines': [
|
||||
{
|
||||
'sku': 'A001',
|
||||
'qty': 1,
|
||||
'reservation_id': '1f1a682dfdc446a393415dee93eb36ce',
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
fingerprint = build_business_fingerprint(summary)
|
||||
|
||||
assert fingerprint['strength'] == 'weak'
|
||||
assert 'reservation_ids' not in fingerprint['components']
|
||||
|
||||
|
||||
def test_fingerprint_stable_across_line_order():
|
||||
base = {
|
||||
'customer_code': 'C1',
|
||||
@@ -616,6 +640,7 @@ def test_candidate_duplicate_blocks_only_matching_candidate(app, dedup_user):
|
||||
candidate_no=f'SNC-{po}',
|
||||
intake_id=intake.id,
|
||||
primary_document_id=doc.id,
|
||||
candidate_key=f'test:SNC-{po}',
|
||||
po_number=po,
|
||||
structured_result_json={'business_summary': summary},
|
||||
business_fingerprint=fp.get('fingerprint'),
|
||||
@@ -725,6 +750,7 @@ def test_refresh_duplicate_updates_candidate_statuses(app, dedup_user):
|
||||
candidate_no='SNC-REFRESH-1',
|
||||
intake_id=intake.id,
|
||||
primary_document_id=doc.id,
|
||||
candidate_key='test:SNC-REFRESH-1',
|
||||
po_number='4510099999',
|
||||
structured_result_json={'business_summary': summary},
|
||||
business_fingerprint=fp.get('fingerprint'),
|
||||
@@ -748,3 +774,98 @@ def test_refresh_duplicate_updates_candidate_statuses(app, dedup_user):
|
||||
cand2 = db.session.query(ShippingNoticeCandidate).filter_by(candidate_no='SNC-REFRESH-1').one()
|
||||
assert cand2.duplicate_status != 'none'
|
||||
assert list(cand2.duplicate_matches_json or [])
|
||||
|
||||
|
||||
def test_candidate_content_fingerprint_distinguishes_same_content_and_revision(app, dedup_user):
|
||||
"""身份相同且内容相同应判重复内容;数量变化应判修订。"""
|
||||
with app.app_context():
|
||||
base = {
|
||||
'customer_code': 'C1',
|
||||
'po_number': '4510039227',
|
||||
'reservation_ids': ['2000485916'],
|
||||
'lines': [
|
||||
{
|
||||
'reservation_id': '2000485916',
|
||||
'sku': '504-006043-001',
|
||||
'qty': 30,
|
||||
'uom': 'EA',
|
||||
}
|
||||
],
|
||||
}
|
||||
identity = build_business_fingerprint(base)
|
||||
content = build_content_fingerprint(base)
|
||||
existing = ShippingTask(
|
||||
task_no='SN-CONTENT-EXISTING',
|
||||
user_id=dedup_user.id,
|
||||
source_type='manual',
|
||||
process_status='pending_review',
|
||||
business_fingerprint=identity['fingerprint'],
|
||||
fingerprint_version=identity['version'],
|
||||
content_fingerprint=content['fingerprint'],
|
||||
content_fingerprint_version=content['version'],
|
||||
)
|
||||
db.session.add(existing)
|
||||
parent, intake = _seed_parsed_intake(
|
||||
dedup_user.id,
|
||||
intake_no='SNI-CONTENT-CHECK',
|
||||
hash_value='content-parent-hash',
|
||||
business_summary=base,
|
||||
fingerprint=identity,
|
||||
)
|
||||
doc = ShippingNoticeDocument(
|
||||
intake_id=intake.id,
|
||||
attachment_key='att-content',
|
||||
document_type='attachment',
|
||||
filename='4510039227.pdf',
|
||||
content_hash='different-file-hash',
|
||||
classification='order_notice',
|
||||
parse_status='parsed',
|
||||
)
|
||||
db.session.add(doc)
|
||||
db.session.commit()
|
||||
|
||||
same = detect_duplicates_for_candidate(
|
||||
intake=intake,
|
||||
document=doc,
|
||||
business_summary=base,
|
||||
fingerprint_result=identity,
|
||||
content_fingerprint_result=content,
|
||||
)
|
||||
changed = {**base, 'lines': [{**base['lines'][0], 'qty': 25}]}
|
||||
revision = detect_duplicates_for_candidate(
|
||||
intake=intake,
|
||||
document=doc,
|
||||
business_summary=changed,
|
||||
fingerprint_result=identity,
|
||||
content_fingerprint_result=build_content_fingerprint(changed),
|
||||
)
|
||||
assert same['status'] == 'same_business_content'
|
||||
assert revision['status'] == 'possible_revision'
|
||||
candidate = ShippingNoticeCandidate(
|
||||
candidate_no='SNC-CONTENT-WRITEBACK',
|
||||
intake_id=intake.id,
|
||||
primary_document_id=doc.id,
|
||||
candidate_key='test:SNC-CONTENT-WRITEBACK',
|
||||
structured_result_json={'business_summary': changed},
|
||||
content_fingerprint=content['fingerprint'],
|
||||
content_fingerprint_version=content['version'],
|
||||
)
|
||||
db.session.add(candidate)
|
||||
apply_duplicate_result_to_candidate(candidate, revision)
|
||||
assert candidate.content_fingerprint == revision['content_fingerprint']
|
||||
assert candidate.content_fingerprint != content['fingerprint']
|
||||
|
||||
hub_changed = {
|
||||
**base,
|
||||
'lines': [{**base['lines'][0], 'hub_code': 'DUB'}],
|
||||
}
|
||||
assert build_content_fingerprint(hub_changed)['fingerprint'] != content['fingerprint']
|
||||
|
||||
header_date_changed = {**base, 'required_date': '2026-07-20'}
|
||||
assert build_content_fingerprint(header_date_changed)['fingerprint'] != content['fingerprint']
|
||||
|
||||
allocation_changed = {
|
||||
**base,
|
||||
'lines': [{**base['lines'][0], 'allocation_id': 'ALLOC-2'}],
|
||||
}
|
||||
assert build_content_fingerprint(allocation_changed)['fingerprint'] != content['fingerprint']
|
||||
Reference in new issue
Block a user