feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程

清理废弃的shipping xfa ocr automark相关代码和job配置
新增收料报表管理的前端页面、路由和侧边栏入口
新增后端收料报表配置接口、数据库模型和RPA脚本
优化发货通知流程的重试策略,将shipping相关job默认不自动重试
移除废弃的库存源确认相关逻辑,更新流程门禁规则
重构订单模板的值适配器模块,新增坐标OCR值适配器
清理前端shipping菜单和action的废弃选项
更新相关文档和测试用例,调整.gitignore忽略规则
This commit is contained in:
hugo committed 2026-08-20 20:23:10 +08:00
1 parent 260465b72d
commit 1b6483a4ea
466 files changed
+32115 -33796

No files matched your search

@@ -33,6 +33,19 @@ _SIGNATURE_LOGO_NAME_RE = re.compile(
)
_HTML_TABLE_TAGS = frozenset({'table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td'})
_HTML_DROP_TAGS = frozenset({'script', 'style', 'img', 'svg', 'object', 'embed', 'iframe', 'template'})
_EML_PREVIEW_TAGS = frozenset({
'html', 'body', 'div', 'p', 'span', 'br', 'hr', 'blockquote', 'pre',
'table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'strong', 'b', 'em', 'i', 'u',
})
_EML_PREVIEW_STYLE_PROPERTIES = frozenset({
'background',
'background-color', 'border', 'border-bottom', 'border-collapse', 'border-color', 'border-style',
'border-width', 'color', 'font-family', 'font-size', 'font-style', 'font-weight', 'line-height',
'margin', 'margin-bottom', 'margin-left', 'margin-right', 'margin-top', 'padding', 'padding-bottom',
'padding-left', 'padding-right', 'padding-top', 'text-align', 'text-decoration', 'vertical-align',
'white-space', 'width',
})
@dataclass
@@ -260,6 +273,11 @@ def _part_as_text(part: Message) -> str:
return text.strip()
def _part_as_raw_html(part: Message) -> str:
"""按 MIME charset 解码 HTML 原文,供视觉预览使用;不得经过 HTML 转文本。"""
return _decode_part_text(part, _read_part_payload(part))
def _is_attached_multipart(part: Message) -> bool:
"""
判定 multipart 是否应视为「文件附件容器」(而非可选正文结构)。
@@ -380,6 +398,86 @@ def _extract_body_html_tables(msg: Message) -> list[str]:
return result
def sanitize_eml_preview_html(html: str) -> str:
"""
清洗 EML 正文 HTML 为可在 sandbox iframe 中展示的有限视觉快照。
核心逻辑:仅保留邮件阅读必需的文字/表格标签与有限内联样式;图片、链接、脚本、
事件属性和定位/URL 样式全部剥离,避免邮件主动内容影响 HXOPS 页面。
Args:
html: EML 的单个 text/html 正文部件,不得传入附件或嵌套邮件正文。
Returns:
安全 HTML 片段;没有可展示内容时返回空字符串。
"""
soup = BeautifulSoup(str(html or ''), 'html.parser')
for comment in soup.find_all(string=lambda value: isinstance(value, Comment)):
comment.extract()
for tag in list(soup.find_all(True)):
name = str(tag.name or '').lower()
if name == 'style':
css = str(tag.string or '')
css = re.sub(r'(?is)@import[^;]*;', '', css)
css = re.sub(r'(?is)url\s*\([^)]*\)', '', css)
css = re.sub(r'(?is)expression\s*\([^)]*\)', '', css)
tag.string = css
continue
if name in _HTML_DROP_TAGS or name in {'form', 'input', 'button', 'textarea', 'select', 'option', 'base'}:
tag.decompose()
continue
# 邮件 CSS 由隔离 iframe 自己消费;只禁止外部资源和主动导航,不重写布局属性。
for key in list(tag.attrs):
key_name = str(key).lower()
if key_name.startswith('on') or key_name in {'action', 'formaction', 'src', 'srcset', 'href', 'xlink:href'}:
tag.attrs.pop(key, None)
if name == 'meta' and str(tag.attrs.get('http-equiv') or '').lower() == 'refresh':
tag.decompose()
continue
inline_styles = [
f'{property_name}: {value}'
for property_name, value in _parse_inline_style(str(tag.attrs.get('style') or ''))
if property_name in _EML_PREVIEW_STYLE_PROPERTIES
]
if inline_styles:
tag.attrs['style'] = '; '.join(inline_styles)
else:
tag.attrs.pop('style', None)
return str(soup).strip()
def _parse_inline_style(value: str) -> list[tuple[str, str]]:
"""解析有限 CSS 声明,拒绝 URL、表达式与控制字符等主动样式值。"""
result: list[tuple[str, str]] = []
for item in str(value or '').split(';'):
property_name, separator, raw_value = item.partition(':')
name = property_name.strip().lower()
normalized = re.sub(r'\s+', ' ', raw_value).strip()
if not separator or not name or not normalized:
continue
if any(token in normalized.lower() for token in ('url(', 'expression(', '@import', '\x00')):
continue
result.append((name, normalized[:256]))
return result
def extract_eml_preview_html(data: bytes) -> str:
"""
从原始 EML 提取根消息首个 HTML 正文并生成安全视觉快照。
Args:
data: 原始 EML 字节;禁止传入附件展开后的任意子文件。
Returns:
已清洗 HTML;邮件无 HTML 正文时返回空字符串。
"""
message = BytesParser(policy=policy.default).parsebytes(data or b'')
for part in _iter_local_body_candidates(message):
if str(part.get_content_type() or '').lower() == 'text/html':
return sanitize_eml_preview_html(_part_as_raw_html(part))
return ''
def _is_collectible_text_leaf(msg: Message) -> bool:
"""判定部件是否可作为附件容器内的可落库文本叶子(非 filename 附件)。"""
ctype = str(msg.get_content_type() or "").lower()