refactor(fudai): 抽 _handle_in_fudai_detail 中"状态分发"和"保存详情"两块到 helper

将两个相邻的独立逻辑抽到 helper:
- dispatch_last_fudai_detail_status:根据 _last_fudai_detail_status 分发到 4 个 helper(coupon_popup/watch_task/validation_failed/error)
- save_first_open_detail:筛选通过后保存详情数据并写日志

douyin_fudai.py: 1468 → 1412 行 (-56)
fudai_detail_helpers.py: 2567 → 2640 行

douyin_fudai.py 跌破 1500 行(4121 → 1412,本会话累计削减 2709 行 = -66%)

验证:
- pytest 1013 passed
- compile OK

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
CodexandClaude Opus 4.7 committed 2026-05-22 12:29:02 +08:00
1 parent 0b3d69d28b
commit e3372fa51d
2 files changed
+83 -66

No files matched your search

+10 -66
View File
@@ -1224,25 +1224,11 @@ class fudai_analyse:
pass
# 筛选通过,保存详情数据并标记为已读取
try:
self._last_fudai_detail_tuple = detail
self._fudai_detail_first_read = True
from douyin.core.fudai_modules.fudai_detail_helpers import (
save_first_open_detail,
)
# 设置当前福袋的内容标识(从 detail tuple 的第一个元素获取)
if detail and isinstance(detail, tuple) and len(detail) >= 1:
self._current_fudai_content = str(
detail[0] if detail[0] else ""
)
# 映射表已在并行OCR中记录,这里不再重复记录
self._log_kv(
"流程",
"_handle_in_fudai_detail:福袋详情识别成功",
fudai_content=(detail[0] if len(detail) > 0 else "")[:50],
prize_value_yuan=float(detail[4] if len(detail) > 4 else 0.0),
)
except Exception:
pass
save_first_open_detail(self, detail)
else:
# 详情数据无效,不保存,不标记为已读取
try:
@@ -1254,55 +1240,13 @@ class fudai_analyse:
pass
return
# 检查是否是优惠券弹窗、观看任务或识别错误:如果检测到,应该直接跳过,不继续处理
try:
last_status = getattr(self, "_last_fudai_detail_status", "")
if last_status == "coupon_popup":
from douyin.core.fudai_modules.fudai_detail_helpers import (
handle_simple_skip_status,
)
# 检查是否是优惠券弹窗、观看任务或识别错误:根据 _last_fudai_detail_status 分发到对应处理
from douyin.core.fudai_modules.fudai_detail_helpers import (
dispatch_last_fudai_detail_status,
)
handle_simple_skip_status(
self,
start_time,
"_handle_in_fudai_detail:检测到优惠券弹窗,已关闭,跳过后续处理",
"优惠券弹窗",
)
return
elif last_status == "watch_task":
from douyin.core.fudai_modules.fudai_detail_helpers import (
handle_simple_skip_status,
)
handle_simple_skip_status(
self,
start_time,
"_handle_in_fudai_detail:检测到'观看X分钟'任务,已在OCR阶段跳过,无需后续处理",
"观看任务",
)
return
elif last_status == "validation_failed":
from douyin.core.fudai_modules.fudai_detail_helpers import (
handle_simple_skip_status,
)
handle_simple_skip_status(
self,
start_time,
"_handle_in_fudai_detail:福袋详情数据验证失败,识别出错,跳过后续处理",
"验证失败",
)
return
elif last_status == "error":
# 检查是否是任务数量为0的错误
from douyin.core.fudai_modules.fudai_detail_helpers import (
handle_task_count_zero_error,
)
if handle_task_count_zero_error(self, start_time):
return
except Exception:
pass
if dispatch_last_fudai_detail_status(self, start_time):
return
# 如果成功读取,重置失败计数
try:
@@ -42,6 +42,79 @@ def log_screenshot_failed(
pass
def dispatch_last_fudai_detail_status(analyser, start_time: float) -> bool:
"""_handle_in_fudai_detail 中根据 _last_fudai_detail_status 分发到对应处理 helper。
分发规则:
- "coupon_popup" → handle_simple_skip_status(优惠券弹窗)
- "watch_task" → handle_simple_skip_status(观看任务)
- "validation_failed" → handle_simple_skip_status(验证失败)
- "error" → handle_task_count_zero_error
返回:
True:命中并已处理(调用方应直接 return)
False:未命中或异常,调用方继续后续流程
"""
try:
last_status = getattr(analyser, "_last_fudai_detail_status", "")
if last_status == "coupon_popup":
handle_simple_skip_status(
analyser,
start_time,
"_handle_in_fudai_detail:检测到优惠券弹窗,已关闭,跳过后续处理",
"优惠券弹窗",
)
return True
elif last_status == "watch_task":
handle_simple_skip_status(
analyser,
start_time,
"_handle_in_fudai_detail:检测到'观看X分钟'任务,已在OCR阶段跳过,无需后续处理",
"观看任务",
)
return True
elif last_status == "validation_failed":
handle_simple_skip_status(
analyser,
start_time,
"_handle_in_fudai_detail:福袋详情数据验证失败,识别出错,跳过后续处理",
"验证失败",
)
return True
elif last_status == "error":
if handle_task_count_zero_error(analyser, start_time):
return True
except Exception:
pass
return False
def save_first_open_detail(analyser, detail) -> None:
"""_handle_in_fudai_detail 步骤2:筛选通过后保存详情数据并标记为已读取。
流程:
- _last_fudai_detail_tuple = detail
- _fudai_detail_first_read = True
- 设置 _current_fudai_content
- 写"福袋详情识别成功"日志
"""
try:
analyser._last_fudai_detail_tuple = detail
analyser._fudai_detail_first_read = True
if detail and isinstance(detail, tuple) and len(detail) >= 1:
analyser._current_fudai_content = str(detail[0] if detail[0] else "")
analyser._log_kv(
"流程",
"_handle_in_fudai_detail:福袋详情识别成功",
fudai_content=(detail[0] if len(detail) > 0 else "")[:50],
prize_value_yuan=float(detail[4] if len(detail) > 4 else 0.0),
)
except Exception:
pass
def validate_detail_or_skip(analyser, detail, start_time: float) -> bool:
"""_handle_in_fudai_detail 中的"额外验证 + 兜底检查"组合块。