refactor(shipping-notice): 移除废弃的履约策略模型与相关逻辑
- 删除 `ShippingFulfillmentPolicy` 模型及其依赖,简化字段治理逻辑 - 更新相关服务与 API,确保自动建单策略通过 Schema 草稿管理 - 调整文档与代码注释,反映新的固定履约契约逻辑 - 增强事件审计功能,记录任务状态变化与操作人信息
This commit is contained in:
1 parent
aa8fb2616c
commit
c85997884b
81 files changed
+2625
-1965
No files matched your search
+18
-12
@@ -156,6 +156,7 @@ class CoordinateProfileLogicalRow(CoordinateReconstructionModel):
|
||||
|
||||
fields: dict[str, str] = Field(default_factory=dict)
|
||||
source_row_indices: list[int] = Field(min_length=1)
|
||||
role: Literal['data', 'deleted'] = 'data'
|
||||
issues: list[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
@@ -228,13 +229,15 @@ def reconstruct_coordinate_profile_rows(
|
||||
exclusion_regions: list[dict[str, Any]] | None = None,
|
||||
initial_fields: dict[str, str] | None = None,
|
||||
initial_next_offset: int = 0,
|
||||
include_deleted: bool = False,
|
||||
) -> list[CoordinateProfileLogicalRow]:
|
||||
"""
|
||||
按 v2 物理行和字段区域合并逻辑明细,不使用 MinerU 的行列结果。
|
||||
|
||||
主行必须在其已绑定 ``line_no`` 区域中出现有效行号才启动明细;未满足此条件的
|
||||
视觉行不会被猜测为新行。随后只按连续 ``row_offset`` 消费 continuation,避免描述
|
||||
换行、合计或相邻无关表区静默混入当前订单行。
|
||||
换行、合计或相邻无关表区静默混入当前订单行。``include_deleted`` 仅供标注预览
|
||||
返回删除行证据;正式解析保持默认值,删除行不会进入业务结果。
|
||||
"""
|
||||
bbox = table_bbox if isinstance(table_bbox, LayoutBBox) else LayoutBBox.model_validate(table_bbox)
|
||||
ordered_layouts = sorted((item for item in line_layouts if isinstance(item, dict)), key=lambda item: item.get('row_offset', -1))
|
||||
@@ -287,6 +290,7 @@ def reconstruct_coordinate_profile_rows(
|
||||
ordered_layouts=ordered_layouts,
|
||||
termination_rules=termination_rules or [],
|
||||
initial_fields=initial_fields,
|
||||
include_deleted=include_deleted,
|
||||
)
|
||||
if relative_y_rows is not None:
|
||||
return relative_y_rows
|
||||
@@ -323,10 +327,12 @@ def reconstruct_coordinate_profile_rows(
|
||||
next_offset = initial_next_offset if current is not None else 0
|
||||
current_issues: list[str] = []
|
||||
|
||||
def flush() -> None:
|
||||
def flush(*, role: Literal['data', 'deleted'] = 'data') -> None:
|
||||
nonlocal current, sources, next_offset, current_issues
|
||||
if current is not None and (sources or initial_fields):
|
||||
results.append(CoordinateProfileLogicalRow(fields=current, source_row_indices=sources, issues=current_issues))
|
||||
results.append(CoordinateProfileLogicalRow(
|
||||
fields=current, source_row_indices=sources, role=role, issues=current_issues,
|
||||
))
|
||||
current, sources, next_offset, current_issues = None, [], 0, []
|
||||
|
||||
for row_index, band in enumerate(_group_visual_rows(glyphs)):
|
||||
@@ -335,10 +341,9 @@ def reconstruct_coordinate_profile_rows(
|
||||
flush()
|
||||
break
|
||||
if _DELETED_PATTERN.fullmatch(re.sub(r'\s+', '', text)):
|
||||
# Deletion markers apply only to the immediately preceding started record.
|
||||
# Do not emit it as a partial row and do not guess an association when no
|
||||
# main row is active.
|
||||
current, sources, next_offset, current_issues = None, [], 0, []
|
||||
# Preserve deleted evidence for the annotator; downstream consumers use
|
||||
# the role to exclude it rather than silently losing the document row.
|
||||
flush(role='deleted')
|
||||
continue
|
||||
main_values, main_issues = values_for(band, ordered_layouts[0])
|
||||
line_no = re.sub(r'\s+', '', main_values.get('line_no', ''))
|
||||
@@ -370,7 +375,7 @@ def reconstruct_coordinate_profile_rows(
|
||||
current_issues.extend(continuation_issues)
|
||||
next_offset += 1
|
||||
flush()
|
||||
return results
|
||||
return results if include_deleted else [row for row in results if row.role != 'deleted']
|
||||
|
||||
|
||||
def _reconstruct_relative_y_profile_rows(
|
||||
@@ -380,6 +385,7 @@ def _reconstruct_relative_y_profile_rows(
|
||||
ordered_layouts: list[dict[str, Any]],
|
||||
termination_rules: list[dict[str, Any]],
|
||||
initial_fields: dict[str, str] | None,
|
||||
include_deleted: bool,
|
||||
) -> list[CoordinateProfileLogicalRow] | None:
|
||||
"""
|
||||
将单个多视觉行物理框按父行内相对 Y 投影到每条重复明细。
|
||||
@@ -429,10 +435,9 @@ def _reconstruct_relative_y_profile_rows(
|
||||
for anchor_index, start in enumerate(anchors):
|
||||
end = anchors[anchor_index + 1] if anchor_index + 1 < len(anchors) else len(usable_bands)
|
||||
record = usable_bands[start:end]
|
||||
if any(_DELETED_PATTERN.fullmatch(re.sub(
|
||||
deleted = any(_DELETED_PATTERN.fullmatch(re.sub(
|
||||
r'\s+', '', ''.join(glyph.text for _, glyph in sorted(band, key=lambda item: item[1].bbox.x0)),
|
||||
)) for _, band in record):
|
||||
continue
|
||||
)) for _, band in record)
|
||||
values: dict[str, str] = {}
|
||||
issues: list[str] = []
|
||||
matched_bands, alignment_issues = _match_field_band_groups(
|
||||
@@ -467,9 +472,10 @@ def _reconstruct_relative_y_profile_rows(
|
||||
results.append(CoordinateProfileLogicalRow(
|
||||
fields=values,
|
||||
source_row_indices=[row_index for row_index, _ in record],
|
||||
role='deleted' if deleted else 'data',
|
||||
issues=issues,
|
||||
))
|
||||
return results
|
||||
return results if include_deleted else [row for row in results if row.role != 'deleted']
|
||||
|
||||
|
||||
def _matches_termination_rule(
|
||||
|
||||
@@ -126,7 +126,7 @@ def _extract_layout(
|
||||
# intent, but it must remain review-only until the label is fixed.
|
||||
results.append(_read_value_region(
|
||||
layout=layout, config=config, glyphs=glyphs, page_no=page_no, source=source,
|
||||
region=_absolute_anchor_region(layout.value_region, reference_anchor),
|
||||
region=_absolute_value_region(layout=layout, anchor=reference_anchor, width=width, height=height),
|
||||
anchor_bbox=reference_anchor, fallback=False,
|
||||
review_issue='order_field_anchor_text_mismatch',
|
||||
))
|
||||
@@ -142,7 +142,7 @@ def _extract_layout(
|
||||
anchor_bbox, _indices = matches[0]
|
||||
results.append(_read_value_region(
|
||||
layout=layout, config=config, glyphs=glyphs, page_no=page_no, source=source,
|
||||
region=_absolute_anchor_region(layout.value_region, anchor_bbox), anchor_bbox=anchor_bbox, fallback=False,
|
||||
region=_absolute_value_region(layout=layout, anchor=anchor_bbox, width=width, height=height), anchor_bbox=anchor_bbox, fallback=False,
|
||||
))
|
||||
usable = [item for item in results if item.status != 'unavailable']
|
||||
if len(usable) == 1:
|
||||
@@ -165,16 +165,12 @@ def _read_value_region(
|
||||
source: str, region: LayoutBBox, anchor_bbox: LayoutBBox | None, fallback: bool,
|
||||
review_issue: str | None = None,
|
||||
) -> OrderFieldExtraction:
|
||||
"""按视觉行合并值区文字,多行模式先以停止标签截断,再执行 Schema 规范化与校验。
|
||||
"""按管理员值框读取文字,多行模式先以停止标签截断,再执行 Schema 规范化与校验。
|
||||
|
||||
``right_of_anchor`` 使用锚点右侧的同一连续文本段,而不是严格依赖值框的
|
||||
左边界;这能避免标签后的冒号进入值,也能容忍框选末尾少量字符。
|
||||
值框是字段边界的主证据。即使 ``right_of_anchor`` 也不跨出该边界补字,
|
||||
以免相邻字段的临界字符混入当前字段并与画布标注不一致。
|
||||
"""
|
||||
selected = (
|
||||
_inline_right_of_anchor_glyphs(glyphs=glyphs, anchor_bbox=anchor_bbox, region=region)
|
||||
if layout.value_mode == 'right_of_anchor' and anchor_bbox is not None
|
||||
else [(index, item) for index, item in enumerate(glyphs) if _glyph_center_inside(item, region)]
|
||||
)
|
||||
selected = [(index, item) for index, item in enumerate(glyphs) if _glyph_center_inside(item, region)]
|
||||
if layout.value_mode == 'multi_line':
|
||||
selected = _stop_before_anchor(
|
||||
selected, glyphs=glyphs, stop_anchors=layout.stop_anchors, anchor_bbox=anchor_bbox,
|
||||
@@ -449,6 +445,13 @@ def _absolute_anchor_region(region: AnchorRelativeRegion | None, anchor: LayoutB
|
||||
)
|
||||
|
||||
|
||||
def _absolute_value_region(*, layout: OrderFieldLayout, anchor: LayoutBBox, width: float, height: float) -> LayoutBBox:
|
||||
"""优先使用管理员画布绝对值框;旧模板才按锚点偏移投影。"""
|
||||
if layout.absolute_value_region is not None:
|
||||
return _absolute_relative_region(layout.absolute_value_region, width=width, height=height)
|
||||
return _absolute_anchor_region(layout.value_region, anchor)
|
||||
|
||||
|
||||
def _glyph_bbox(glyph: dict[str, Any]) -> LayoutBBox:
|
||||
"""严格解析一枚冻结 glyph 的 bbox;坏坐标不会被修正后参与提取。"""
|
||||
return LayoutBBox.model_validate(glyph.get('bbox'))
|
||||
|
||||
@@ -110,9 +110,11 @@ class OrderFieldLayout(OrderProfileModel):
|
||||
page_scope: Literal['first_page', 'all_pages', 'exact_page'] = 'first_page'
|
||||
page_no: int | None = Field(default=None, ge=1)
|
||||
anchor: AnchorRule | None = None
|
||||
# Anchored values use offsets relative to the anchor bbox; fixed-position
|
||||
# fallback values are stored separately so they cannot be mistaken for anchors.
|
||||
# ``absolute_value_region`` is the authoritative administrator-drawn page box.
|
||||
# ``value_region`` remains only for legacy profiles whose values were stored as
|
||||
# offsets relative to the anchor bbox.
|
||||
value_region: AnchorRelativeRegion | None = None
|
||||
absolute_value_region: RelativeRegion | None = None
|
||||
fallback_value_region: RelativeRegion | None = None
|
||||
value_mode: Literal['single_line', 'multi_line', 'right_of_anchor', 'below_anchor'] = 'single_line'
|
||||
stop_anchors: list[AnchorRule] = Field(default_factory=list)
|
||||
@@ -132,8 +134,11 @@ class OrderFieldLayout(OrderProfileModel):
|
||||
raise ValueError('value-only order field must have a bounded page scope')
|
||||
if self.value_region is not None or self.fallback_value_region is None:
|
||||
raise ValueError('value-only order field requires one fallback value region')
|
||||
elif self.value_region is None or self.fallback_value_region is not None:
|
||||
raise ValueError('anchored order field requires one anchor-relative value region')
|
||||
elif (
|
||||
(self.value_region is None) == (self.absolute_value_region is None)
|
||||
or self.fallback_value_region is not None
|
||||
):
|
||||
raise ValueError('anchored order field requires one value region')
|
||||
if self.value_mode == 'multi_line' and not self.stop_anchors:
|
||||
raise ValueError('multi-line order field requires stop anchors')
|
||||
return self
|
||||
@@ -226,6 +231,7 @@ class DraftUnboundOrderFieldLayout(OrderProfileModel):
|
||||
page_no: int | None = Field(default=None, ge=1)
|
||||
anchor: AnchorRule | None = None
|
||||
value_region: AnchorRelativeRegion | None = None
|
||||
absolute_value_region: RelativeRegion | None = None
|
||||
fallback_value_region: RelativeRegion | None = None
|
||||
value_mode: Literal['single_line', 'multi_line', 'right_of_anchor', 'below_anchor'] = 'single_line'
|
||||
stop_anchors: list[AnchorRule] = Field(default_factory=list)
|
||||
@@ -237,7 +243,8 @@ class DraftUnboundOrderFieldLayout(OrderProfileModel):
|
||||
OrderFieldLayout(
|
||||
layout_id=self.layout_id, field_id='draft_unbound', field_code='draft_unbound',
|
||||
page_scope=self.page_scope, page_no=self.page_no, anchor=self.anchor,
|
||||
value_region=self.value_region, fallback_value_region=self.fallback_value_region,
|
||||
value_region=self.value_region, absolute_value_region=self.absolute_value_region,
|
||||
fallback_value_region=self.fallback_value_region,
|
||||
value_mode=self.value_mode, stop_anchors=self.stop_anchors,
|
||||
minimum_evidence_level=self.minimum_evidence_level,
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user