feat(shipping-notice): 添加识别定义和规则集管理功能,支持客户和站点的可配置识别规则

This commit is contained in:
hugo committed 2026-07-20 19:28:17 +08:00
1 parent 88408490d7
commit 34d489a2d1
167 files changed
+10365 -7978

No files matched your search

@@ -113,6 +113,70 @@ def test_order_schema_publish_keeps_history_when_field_code_changes(app):
assert getattr(exc_info.value, 'code', None) == 'SHIPPING.ORDER_FIELD_IMMUTABLE'
def test_order_schema_business_purposes_bind_stable_line_field_ids(app):
"""业务用途只存在于不可变版本快照,字段改名后仍由原 field_id 供下游定位。"""
with app.app_context():
service.initialize_schema({'display_name': '发货订单字段'}, actor_id=None)
reservation = service.save_field({
'field_code': 'reservation_id', 'scope': 'line', 'value_type': 'string',
}, actor_id=None)
source_hint = service.save_field({
'field_code': 'inventory_source_hint', 'scope': 'line', 'value_type': 'string',
}, actor_id=None)
draft = service.create_draft({}, actor_id=None)
reservation_config = _field_config(reservation['id'], name='预定单号')
reservation_config.update({
'normalizer_key': 'uppercase_trim', 'validator_keys': ['reservation_id'],
'comparator_key': 'normalized_text', 'business_purpose': 'reservation_id',
})
source_hint_config = _field_config(source_hint['id'], name='库存源线索')
source_hint_config.update({
'normalizer_key': 'uppercase_trim', 'validator_keys': [],
'comparator_key': 'normalized_text', 'business_purpose': 'inventory_source_hint',
})
_save_draft(draft['id'], [reservation_config, source_hint_config])
published = _publish_draft(draft['id'])
purposes = {
item['business_purpose']: item['field_id']
for item in service.get_published_contract()['fields']
}
assert purposes == {
'reservation_id': reservation['id'],
'inventory_source_hint': source_hint['id'],
}
service.save_field({
'field_code': 'reservation_number', 'scope': 'line', 'value_type': 'string',
}, actor_id=None, field_id=reservation['id'])
assert next(
item for item in published['definition']['fields'] if item['field_id'] == reservation['id']
)['business_purpose'] == 'reservation_id'
def test_order_schema_rejects_duplicate_or_incompatible_business_purposes(app):
"""用途必须唯一且符合行级类型约束,防止路由与门禁在运行期读取错误字段。"""
with app.app_context():
service.initialize_schema({'display_name': '发货订单字段'}, actor_id=None)
first = service.save_field({'field_code': 'first_hint', 'scope': 'line', 'value_type': 'string'}, actor_id=None)
second = service.save_field({'field_code': 'second_hint', 'scope': 'line', 'value_type': 'string'}, actor_id=None)
header = service.save_field({'field_code': 'header_hint', 'scope': 'header', 'value_type': 'string'}, actor_id=None)
draft = service.create_draft({}, actor_id=None)
first_config = _field_config(first['id'], name='线索一')
first_config.update({'normalizer_key': 'trim', 'validator_keys': [], 'comparator_key': 'normalized_text', 'business_purpose': 'inventory_source_hint'})
second_config = _field_config(second['id'], name='线索二')
second_config.update({'normalizer_key': 'trim', 'validator_keys': [], 'comparator_key': 'normalized_text', 'business_purpose': 'inventory_source_hint'})
with pytest.raises(Exception) as duplicate_exc:
_save_draft(draft['id'], [first_config, second_config])
assert getattr(duplicate_exc.value, 'code', None) == 'SHIPPING.ORDER_SCHEMA_VERSION_INVALID'
header_config = _field_config(header['id'], name='订单头线索')
header_config.update({'normalizer_key': 'trim', 'validator_keys': [], 'comparator_key': 'normalized_text', 'business_purpose': 'reservation_id'})
with pytest.raises(Exception) as scope_exc:
_save_draft(draft['id'], [header_config])
assert getattr(scope_exc.value, 'code', None) == 'SHIPPING.ORDER_SCHEMA_VERSION_INVALID'
def test_order_schema_excluded_field_config_is_saved_but_not_published(app):
"""未纳入字段仍保存版本显示名称和规则,但发布契约不得包含该字段。"""
with app.app_context():