fix: 扩大x坐标范围1200-2600 + code_map优先保留含横杠的完整名

1. x坐标范围从1500-2600扩大到1200-2600
   修复第二个2203.01(x=1297)被过滤导致错过完整名的问题

2. code_map更新逻辑:inline文本含横杠→用新名覆盖旧名
   让2203.01第二次出现(含完整三级名)覆盖第一次(仅一级名)
This commit is contained in:
2026-06-23 00:50:36 +08:00
parent d8d54581c3
commit 1484e72c35
+6 -4
View File
@@ -163,8 +163,8 @@ class K3VoucherParser:
if cy < y_lower - 100 or cy > y_debit_val:
continue
# x坐标:科目代码通常在表格中间区域
if cx < 1500 or cx > 2600:
# x坐标:科目代码通常在表格中间偏左区域
if cx < 1200 or cx > 2600:
continue
t = text.strip()
@@ -185,6 +185,8 @@ class K3VoucherParser:
# 提取名称 — 按用户规则:取最后一个横杠之后的文字
name = t[m.end():].lstrip('--—= ')
# 记录原始inline文本是否含横杠(判断完整性用)
inline_has_dash = max(name.rfind('-'), name.rfind('-'), name.rfind('—')) >= 0
name = re.sub(r'[\d.\-—=]+$', '', name).strip()
name = name.lstrip('-—-=')
@@ -198,8 +200,8 @@ class K3VoucherParser:
# 去重:优先保留带完整名称的行
if code_part in code_map:
existing = codes[code_map[code_part]]
# 已有名称为空,而新行有名称 → 更新
if (not existing['name'] or len(existing['name']) < 2) and len(name) >= 2:
# 新名称的原文本含横杠(更完整)→ 更新
if inline_has_dash or ((not existing['name'] or len(existing['name']) < 2) and len(name) >= 2):
existing['name'] = name
existing['y_pos'] = cy
existing['x_pos'] = cx