feat(shipping-notice): 添加订单抽取功能,支持异步运行和管理,优化相关数据模型和处理逻辑
This commit is contained in:
1 parent
34d489a2d1
commit
ce26d6d0c4
144 files changed
+12241
-4233
No files matched your search
@@ -3,7 +3,7 @@ backend/app/services/shipping_notice/identity_rules/service.py
|
||||
|
||||
用途:管理货代客户识别定义、规则集版本和新证据值。
|
||||
依赖:订单 Schema 字段目录、客户/站点主数据、customer_normalization、统一异常。
|
||||
逻辑:平台只提供受控来源适配器;所有定义由管理员创建,发布规则集冻结全量快照。
|
||||
逻辑:管理员只选择已发布且允许客户识别的 Header 字段;规则集冻结字段配置快照。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -40,32 +40,6 @@ from app.services.shipping_notice.customer_normalization import (
|
||||
|
||||
DEFINITION_CODE_RE = re.compile(r'^[a-z][a-z0-9_]{1,63}$')
|
||||
TARGET_TYPES = frozenset({'customer', 'site'})
|
||||
SOURCE_ADAPTERS = {
|
||||
'email_metadata': {
|
||||
'display_name': '邮件发件人',
|
||||
'description': '从来件的发件人读取完整邮箱或企业域名。',
|
||||
'selectors': {'attribute': 'email.from', 'projections': {'email', 'domain'}},
|
||||
'options': {
|
||||
'email': {'display_name': '发件人邮箱', 'normalizer_key': 'email', 'max_automation': 'conditional'},
|
||||
'domain': {'display_name': '企业域名', 'normalizer_key': 'domain', 'max_automation': 'conditional'},
|
||||
},
|
||||
},
|
||||
'document_template': {
|
||||
'display_name': '单据版式',
|
||||
'description': '根据主单据的固定版式特征识别。',
|
||||
'selectors': {'document': 'primary'},
|
||||
'options': {
|
||||
'template': {'display_name': '当前单据版式', 'normalizer_key': 'text_upper', 'max_automation': 'conditional'},
|
||||
},
|
||||
},
|
||||
'order_field': {
|
||||
'display_name': '已解析订单字段',
|
||||
'description': '读取已发布订单字段中已经确认的内容,仅供人工复核使用。',
|
||||
'options': {},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _copy(value: Any) -> Any:
|
||||
"""复制目录或快照值,并将集合规范化为稳定 JSON 数组避免 API 序列化失败。"""
|
||||
def _json_default(item: Any) -> list[Any]:
|
||||
@@ -82,8 +56,9 @@ def _iso(value: datetime | None) -> str | None:
|
||||
|
||||
|
||||
def _definition_payload(row: ShippingIdentityDefinition, *, field: ShippingOrderField | None = None) -> dict[str, Any]:
|
||||
"""序列化识别定义及其稳定订单字段引用,不依赖前端自行判定权限。"""
|
||||
field = field or (db.session.get(ShippingOrderField, row.order_field_id) if row.order_field_id else None)
|
||||
"""序列化识别定义及其已发布上下文字段引用。"""
|
||||
field = field or db.session.get(ShippingOrderField, row.context_field_id)
|
||||
field_config = _published_field_config(row.context_field_id)
|
||||
return {
|
||||
'id': row.id,
|
||||
'definition_code': row.definition_code,
|
||||
@@ -91,16 +66,13 @@ def _definition_payload(row: ShippingIdentityDefinition, *, field: ShippingOrder
|
||||
'description': row.description,
|
||||
'evidence_label': row.evidence_label or '识别证据',
|
||||
'target_type': row.target_type,
|
||||
'source_adapter_key': row.source_adapter_key,
|
||||
'source_selector': _copy(row.source_selector_json or {}),
|
||||
'attribute_key': row.attribute_key,
|
||||
'order_field_id': row.order_field_id,
|
||||
'order_field': ({
|
||||
'context_field_id': row.context_field_id,
|
||||
'context_field': ({
|
||||
'field_id': field.id, 'field_code': field.field_code, 'display_name': _field_catalog_item(field)['display_name'],
|
||||
'scope': field.scope, 'value_type': field.value_type, 'status': field.status,
|
||||
'field_category': field.field_category, 'collection_mode': field.collection_mode,
|
||||
} if field else None),
|
||||
'normalizer_key': row.normalizer_key,
|
||||
'comparator_key': row.comparator_key,
|
||||
'field_config': _copy(field_config) if field_config else None,
|
||||
'default_weight': row.default_weight,
|
||||
'max_automation': row.max_automation,
|
||||
'status': row.status,
|
||||
@@ -127,64 +99,35 @@ def _write_audit(
|
||||
))
|
||||
|
||||
|
||||
def _source_adapter_catalog() -> list[dict[str, Any]]:
|
||||
"""返回只读来源适配器目录;客户端只能选择受控参数,不能提交任意取值路径。"""
|
||||
return [
|
||||
{
|
||||
'key': key,
|
||||
'display_name': value['display_name'],
|
||||
'description': value['description'],
|
||||
'selectors': _copy(value.get('selectors') or {}),
|
||||
'options': _copy(value.get('options') or {}),
|
||||
}
|
||||
for key, value in SOURCE_ADAPTERS.items()
|
||||
]
|
||||
def _published_field_config(field_id: str) -> dict[str, Any] | None:
|
||||
"""读取当前发布版本中的字段配置;识别定义和证据标准化均使用同一快照。"""
|
||||
published = ShippingOrderSchemaVersion.query.filter_by(status='published').one_or_none()
|
||||
return next((
|
||||
item for item in ((published.definition_json if published else {}) or {}).get('fields', [])
|
||||
if str(item.get('field_id') or '') == field_id and item.get('enabled', True)
|
||||
), None)
|
||||
|
||||
|
||||
def _validate_source(
|
||||
*, adapter_key: str, selector: object, field_id: str, target_type: str,
|
||||
) -> tuple[dict[str, Any], ShippingOrderField | None, str, str, str]:
|
||||
"""校验受控来源并推导内部执行参数,业务端不能提交属性或自动化等级。"""
|
||||
adapter = SOURCE_ADAPTERS.get(adapter_key)
|
||||
if adapter is None or not isinstance(selector, dict):
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
if adapter_key == 'order_field':
|
||||
field = _published_header_field(field_id)
|
||||
expected = {'order_field_id': field.id}
|
||||
if selector != expected:
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
return expected, field, 'text_upper', 'order_field_value', 'none'
|
||||
if field_id:
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
if adapter_key == 'email_metadata':
|
||||
if target_type != 'customer':
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
projection = clean_text(selector.get('projection')).lower()
|
||||
if selector != {'attribute': 'email.from', 'projection': projection} or projection not in {'email', 'domain'}:
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
option = adapter['options'][projection]
|
||||
return {'attribute': 'email.from', 'projection': projection}, None, option['normalizer_key'], projection, option['max_automation']
|
||||
if adapter_key == 'document_template':
|
||||
if target_type != 'customer' or selector != {'document': 'primary'}:
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
option = adapter['options']['template']
|
||||
return {'document': 'primary'}, None, option['normalizer_key'], 'template', option['max_automation']
|
||||
raise ValidationError('Identity definition source is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
def _published_schema_snapshot() -> dict[str, Any]:
|
||||
"""返回识别规则发布所绑定的唯一订单 Schema 版本锚点。"""
|
||||
published = ShippingOrderSchemaVersion.query.filter_by(status='published').one_or_none()
|
||||
if published is None or not published.checksum:
|
||||
raise ConflictError(
|
||||
'Published order schema is required for identity rules',
|
||||
code='SHIPPING.IDENTITY_RULE_SET_CONFLICT',
|
||||
)
|
||||
return {'id': published.id, 'version': published.version, 'checksum': published.checksum}
|
||||
|
||||
|
||||
def _published_header_field(field_id: str) -> ShippingOrderField:
|
||||
"""验证业务来源字段已发布、启用且为可识别的 Header 文本字段。"""
|
||||
def _published_context_field(field_id: str) -> tuple[ShippingOrderField, dict[str, Any]]:
|
||||
"""验证字段已发布、启用、位于 Header 且明确允许用于客户识别。"""
|
||||
field = db.session.get(ShippingOrderField, field_id)
|
||||
if field is None or field.status != 'active' or field.scope != 'header' or field.value_type not in {'string', 'enum'}:
|
||||
raise ValidationError('Identity order field is invalid', code='SHIPPING.IDENTITY_ORDER_FIELD_INVALID')
|
||||
published = ShippingOrderSchemaVersion.query.filter_by(status='published').one_or_none()
|
||||
enabled_ids = {
|
||||
str(item.get('field_id')) for item in ((published.definition_json if published else {}) or {}).get('fields', [])
|
||||
if item.get('enabled', True)
|
||||
}
|
||||
if field.id not in enabled_ids:
|
||||
config = _published_field_config(field.id)
|
||||
if config is None or not config.get('available_for_customer_identity'):
|
||||
raise ValidationError('Identity order field is not published', code='SHIPPING.IDENTITY_ORDER_FIELD_INVALID')
|
||||
return field
|
||||
return field, config
|
||||
|
||||
|
||||
def list_definitions(*, target_type: str | None = None, active_only: bool = False) -> dict[str, Any]:
|
||||
@@ -199,11 +142,8 @@ def list_definitions(*, target_type: str | None = None, active_only: bool = Fals
|
||||
rows = query.order_by(ShippingIdentityDefinition.definition_code).all()
|
||||
return {
|
||||
'definitions': [_definition_payload(row) for row in rows],
|
||||
'order_fields': [_field_catalog_item(row) for row in _published_header_fields()],
|
||||
'catalog': {
|
||||
'target_types': sorted(TARGET_TYPES),
|
||||
'source_adapters': _source_adapter_catalog(),
|
||||
},
|
||||
'context_fields': [_field_catalog_item(row) for row in _published_header_fields()],
|
||||
'catalog': {'target_types': sorted(TARGET_TYPES)},
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +170,8 @@ def _published_header_fields() -> list[ShippingOrderField]:
|
||||
if version is None:
|
||||
return []
|
||||
ids = [str(item.get('field_id')) for item in (version.definition_json or {}).get('fields', [])
|
||||
if item.get('enabled', True) and item.get('scope') == 'header' and item.get('value_type') in {'string', 'enum'}]
|
||||
if item.get('enabled', True) and item.get('scope') == 'header'
|
||||
and item.get('value_type') in {'string', 'enum'} and item.get('available_for_customer_identity')]
|
||||
return ShippingOrderField.query.filter(ShippingOrderField.id.in_(ids), ShippingOrderField.status == 'active').all() if ids else []
|
||||
|
||||
|
||||
@@ -243,6 +184,7 @@ def _field_catalog_item(field: ShippingOrderField) -> dict[str, Any]:
|
||||
return {
|
||||
'field_id': field.id, 'field_code': field.field_code, 'display_name': display_name,
|
||||
'scope': field.scope, 'value_type': field.value_type,
|
||||
'field_category': field.field_category, 'collection_mode': field.collection_mode,
|
||||
}
|
||||
|
||||
|
||||
@@ -257,18 +199,27 @@ def save_definition(data: dict[str, Any], *, actor_id: int | None, request_id: s
|
||||
evidence_label = clean_text(data.get('evidence_label'))
|
||||
code = clean_text(data.get('definition_code')).lower() or f'identity_rule_{uuid.uuid4().hex[:12]}'
|
||||
target = clean_text(data.get('target_type')).lower()
|
||||
field_id = clean_text(data.get('order_field_id'))
|
||||
adapter_key = clean_text(data.get('source_adapter_key')).lower()
|
||||
selector = data.get('source_selector')
|
||||
field_id = clean_text(data.get('context_field_id'))
|
||||
if not DEFINITION_CODE_RE.fullmatch(code) or target not in TARGET_TYPES:
|
||||
raise ValidationError('Identity definition is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
# 兼容服务层既有调用;管理端新建规则始终提交业务名称与证据名称。
|
||||
display_name = display_name or code
|
||||
evidence_label = evidence_label or display_name
|
||||
selector, field, normalizer, attribute, automation = _validate_source(
|
||||
adapter_key=adapter_key, selector=selector, field_id=field_id, target_type=target,
|
||||
)
|
||||
comparator = 'normalized_exact'
|
||||
field, field_config = _published_context_field(field_id)
|
||||
if row and (row.definition_code, row.target_type, row.context_field_id) != (code, target, field.id):
|
||||
referenced = ShippingIdentityEvidence.query.filter_by(definition_id=row.id).count() > 0 or any(
|
||||
any(str(item.get('id') or '') == row.id for item in (rule_set.definition_json or {}).get('definitions', []))
|
||||
for rule_set in ShippingIdentityRuleSet.query.filter(
|
||||
ShippingIdentityRuleSet.status.in_(['draft', 'published'])
|
||||
).all()
|
||||
)
|
||||
if referenced:
|
||||
raise ConflictError(
|
||||
'Referenced identity definition binding is immutable',
|
||||
code='SHIPPING.IDENTITY_DEFINITION_CONFLICT',
|
||||
)
|
||||
source = field_config.get('context_source') if isinstance(field_config.get('context_source'), dict) else {}
|
||||
automation = 'conditional' if source.get('option_key') in {'from_email', 'from_domain'} and target == 'customer' else 'none'
|
||||
requested_automation = clean_text(data.get('max_automation')).lower() if 'max_automation' in data else automation
|
||||
if requested_automation not in {'none', automation}:
|
||||
raise ValidationError('Identity definition automation is invalid', code='SHIPPING.IDENTITY_AUTOMATION_FORBIDDEN')
|
||||
@@ -281,8 +232,7 @@ def save_definition(data: dict[str, Any], *, actor_id: int | None, request_id: s
|
||||
raise ValidationError('Identity definition weight is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
row = row or ShippingIdentityDefinition(
|
||||
definition_code=code, display_name=display_name, description=description, evidence_label=evidence_label,
|
||||
target_type=target, source_adapter_key=adapter_key, source_selector_json=selector,
|
||||
attribute_key=attribute, order_field_id=field.id if field else None, normalizer_key=normalizer, comparator_key=comparator,
|
||||
target_type=target, context_field_id=field.id,
|
||||
default_weight=weight, max_automation=automation,
|
||||
created_by_id=actor_id,
|
||||
)
|
||||
@@ -291,12 +241,7 @@ def save_definition(data: dict[str, Any], *, actor_id: int | None, request_id: s
|
||||
row.description = description
|
||||
row.evidence_label = evidence_label
|
||||
row.target_type = target
|
||||
row.source_adapter_key = adapter_key
|
||||
row.source_selector_json = selector
|
||||
row.attribute_key = attribute
|
||||
row.order_field_id = field.id if field else None
|
||||
row.normalizer_key = normalizer
|
||||
row.comparator_key = comparator
|
||||
row.context_field_id = field.id
|
||||
row.default_weight = weight
|
||||
row.max_automation = automation
|
||||
row.updated_by_id = actor_id
|
||||
@@ -396,7 +341,7 @@ def save_rule_set(rule_set_id: int, data: dict[str, Any], *, actor_id: int | Non
|
||||
|
||||
def publish_rule_set(rule_set_id: int, *, expected_lock_version: int | None, actor_id: int | None,
|
||||
request_id: str | None = None) -> dict[str, Any]:
|
||||
"""发布规则集并退役前一版本;发布快照 checksum 是运行期审计锚点。"""
|
||||
"""发布规则集并冻结订单 Schema 版本;双重 checksum 构成运行期审计锚点。"""
|
||||
row = db.session.get(ShippingIdentityRuleSet, rule_set_id)
|
||||
if row is None:
|
||||
raise NotFoundError('Identity rule set not found', code='SHIPPING.IDENTITY_RULE_SET_NOT_FOUND')
|
||||
@@ -405,9 +350,28 @@ def publish_rule_set(rule_set_id: int, *, expected_lock_version: int | None, act
|
||||
definitions = (row.definition_json or {}).get('definitions') or []
|
||||
if not definitions:
|
||||
raise ValidationError('Identity rule definitions are required', code='SHIPPING.IDENTITY_RULE_SET_INVALID')
|
||||
active_ids = {item.id for item in ShippingIdentityDefinition.query.filter_by(status='active').all()}
|
||||
if any(str(item.get('id') or '') not in active_ids for item in definitions):
|
||||
active_rows = {
|
||||
item.id: item for item in ShippingIdentityDefinition.query.filter_by(status='active').all()
|
||||
}
|
||||
definition_ids = [str(item.get('id') or '') for item in definitions]
|
||||
if any(definition_id not in active_rows for definition_id in definition_ids):
|
||||
raise ConflictError('Identity rule set references retired definitions', code='SHIPPING.IDENTITY_RULE_SET_CONFLICT')
|
||||
for definition_id in definition_ids:
|
||||
try:
|
||||
_published_context_field(active_rows[definition_id].context_field_id)
|
||||
except ValidationError as exc:
|
||||
raise ConflictError(
|
||||
'Identity rule set references an unavailable published field',
|
||||
code='SHIPPING.IDENTITY_RULE_SET_CONFLICT',
|
||||
) from exc
|
||||
# 发布边界必须重新编译当前 Schema 字段配置,禁止草稿携带陈旧 field_config 投产。
|
||||
row.definition_json = {
|
||||
'order_schema': _published_schema_snapshot(),
|
||||
'definitions': [
|
||||
_definition_snapshot(active_rows[definition_id])
|
||||
for definition_id in sorted(definition_ids, key=lambda item: active_rows[item].definition_code)
|
||||
],
|
||||
}
|
||||
current = ShippingIdentityRuleSet.query.filter_by(status='published').one_or_none()
|
||||
now = datetime.utcnow()
|
||||
if current:
|
||||
@@ -425,13 +389,18 @@ def list_rule_sets() -> dict[str, Any]:
|
||||
return {'items': [_rule_set_payload(row) for row in ShippingIdentityRuleSet.query.order_by(ShippingIdentityRuleSet.version.desc()).all()]}
|
||||
|
||||
|
||||
def _normalize_for_definition(definition: ShippingIdentityDefinition, value: object) -> str:
|
||||
"""按定义受控 normalizer 生成证据匹配键,禁止前端传入任意处理方式。"""
|
||||
if definition.normalizer_key == 'email':
|
||||
def _normalize_for_snapshot(definition: dict[str, Any], value: object) -> str:
|
||||
"""按已发布规则集冻结的字段配置生成证据匹配键。"""
|
||||
config = definition.get('field_config') if isinstance(definition.get('field_config'), dict) else {}
|
||||
if not config:
|
||||
raise ValidationError('Identity definition snapshot is invalid', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
source = config.get('context_source') if isinstance(config.get('context_source'), dict) else {}
|
||||
option_key = str(source.get('option_key') or '')
|
||||
if option_key == 'from_email':
|
||||
return normalize_email(value)
|
||||
if definition.normalizer_key == 'domain':
|
||||
if option_key == 'from_domain':
|
||||
return normalize_domain(value)
|
||||
if definition.normalizer_key == 'name':
|
||||
if config.get('normalizer_key') == 'name':
|
||||
return normalize_customer_name(value)
|
||||
result = clean_text(value).upper()
|
||||
if not result:
|
||||
@@ -458,15 +427,21 @@ def create_evidence(*, target_type: str, target_id: int, data: dict[str, Any], a
|
||||
customer = db.session.get(ShippingCustomer, int(target.customer_id))
|
||||
if customer is None or customer.status != 'active':
|
||||
raise ValidationError('Identity evidence target is invalid', code='SHIPPING.IDENTITY_TARGET_INVALID')
|
||||
published_definition = next(
|
||||
item for item in (published.definition_json or {}).get('definitions', [])
|
||||
if str(item.get('id') or '') == definition.id
|
||||
)
|
||||
raw = clean_text(data.get('raw_value') or data.get('identifier_value'))
|
||||
normalized = _normalize_for_definition(definition, raw)
|
||||
normalized = _normalize_for_snapshot(published_definition, raw)
|
||||
status = clean_text(data.get('status') or 'pending').lower()
|
||||
allowed = data.get('auto_match_allowed', False)
|
||||
if status not in {'pending', 'approved', 'disabled'} or not isinstance(allowed, bool):
|
||||
raise ValidationError('Identity evidence status is invalid', code='SHIPPING.IDENTITY_EVIDENCE_INVALID')
|
||||
if allowed and (status != 'approved' or definition.max_automation != 'conditional'):
|
||||
if allowed and (status != 'approved' or published_definition.get('max_automation') != 'conditional'):
|
||||
raise ValidationError('Identity evidence cannot auto confirm', code='SHIPPING.IDENTITY_AUTOMATION_FORBIDDEN')
|
||||
if allowed and definition.attribute_key == 'domain' and is_public_email_domain(normalized):
|
||||
config = published_definition.get('field_config') if isinstance(published_definition.get('field_config'), dict) else {}
|
||||
source = config.get('context_source') if isinstance(config.get('context_source'), dict) else {}
|
||||
if allowed and source.get('option_key') == 'from_domain' and is_public_email_domain(normalized):
|
||||
raise ValidationError('Public email domain cannot auto confirm', code='SHIPPING.CUSTOMER_PUBLIC_DOMAIN_AUTO_MATCH_FORBIDDEN')
|
||||
row = ShippingIdentityEvidence(
|
||||
definition_id=definition.id, customer_id=target_id if target_type == 'customer' else None,
|
||||
@@ -513,9 +488,18 @@ def update_evidence(evidence_id: int, data: dict[str, Any], *, actor_id: int | N
|
||||
raise ValidationError('Identity evidence status is invalid', code='SHIPPING.IDENTITY_EVIDENCE_INVALID')
|
||||
if next_status != 'approved':
|
||||
next_allowed = False
|
||||
if next_allowed and definition.max_automation != 'conditional':
|
||||
published = ShippingIdentityRuleSet.query.filter_by(status='published').one_or_none()
|
||||
published_definition = next((
|
||||
item for item in ((published.definition_json if published else {}) or {}).get('definitions', [])
|
||||
if str(item.get('id') or '') == definition.id
|
||||
), None)
|
||||
if published_definition is None:
|
||||
raise ValidationError('Identity definition is not published', code='SHIPPING.IDENTITY_DEFINITION_INVALID')
|
||||
if next_allowed and published_definition.get('max_automation') != 'conditional':
|
||||
raise ValidationError('Identity evidence cannot auto confirm', code='SHIPPING.IDENTITY_AUTOMATION_FORBIDDEN')
|
||||
if next_allowed and definition.attribute_key == 'domain' and is_public_email_domain(row.normalized_value):
|
||||
config = published_definition.get('field_config') if isinstance(published_definition.get('field_config'), dict) else {}
|
||||
source = config.get('context_source') if isinstance(config.get('context_source'), dict) else {}
|
||||
if next_allowed and source.get('option_key') == 'from_domain' and is_public_email_domain(row.normalized_value):
|
||||
raise ValidationError('Public email domain cannot auto confirm', code='SHIPPING.CUSTOMER_PUBLIC_DOMAIN_AUTO_MATCH_FORBIDDEN')
|
||||
next_remark = clean_text(data.get('remark')) or None if 'remark' in data else row.remark
|
||||
changed = (next_status, bool(next_allowed), next_remark) != (row.status, bool(row.auto_match_allowed), row.remark)
|
||||
@@ -560,12 +544,10 @@ def serialize_evidence(row: ShippingIdentityEvidence) -> dict[str, Any]:
|
||||
def active_definition_field_references(field_id: str) -> list[str]:
|
||||
"""供订单 Schema 退役/发布门禁查询仍被启用业务定义引用的稳定字段。"""
|
||||
references: list[str] = []
|
||||
if ShippingIdentityDefinition.query.filter_by(
|
||||
source_adapter_key='order_field', order_field_id=field_id, status='active',
|
||||
).count():
|
||||
if ShippingIdentityDefinition.query.filter_by(context_field_id=field_id, status='active').count():
|
||||
references.append('identity_definition')
|
||||
if any(
|
||||
any(str(item.get('order_field_id') or '') == field_id for item in (rule_set.definition_json or {}).get('definitions', []))
|
||||
any(str(item.get('context_field_id') or '') == field_id for item in (rule_set.definition_json or {}).get('definitions', []))
|
||||
for rule_set in ShippingIdentityRuleSet.query.filter(ShippingIdentityRuleSet.status.in_(['draft', 'published'])).all()
|
||||
):
|
||||
references.append('identity_rule_set')
|
||||
|
||||
Reference in new issue
Block a user