refactor: restructure main_clean.py with dependency injection and interfaces
Refactor discrete material cleaner to improve maintainability and testability: - Introduce dependency injection pattern for service components - Add interfaces (IPageNavigator, IMaterialExtractor, IDeletionChecker) - Extract PageNavigator service for page navigation logic - Extract MaterialExtractor service for data extraction - Extract DatabaseDeletionChecker service for deletion logic - Add MaterialInfo data model for structured data - Centralize configuration (CleanerConfig, UIConstants) - Implement separation of concerns across services layer Also includes comprehensive execution mechanism documentation. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
75
interfaces/i_page_navigator.py
Normal file
75
interfaces/i_page_navigator.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
页面导航接口
|
||||
定义页面导航和 iframe 操作的抽象接口
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from playwright.sync_api import Page, Frame
|
||||
from typing import Tuple, Optional
|
||||
|
||||
|
||||
class IPageNavigator(ABC):
|
||||
"""页面导航接口 - 处理 iframe 导航、页面切换"""
|
||||
|
||||
@abstractmethod
|
||||
def navigate_to_main_page(self, page: Page) -> Frame:
|
||||
"""
|
||||
导航到主页面 iframe
|
||||
|
||||
Args:
|
||||
page: 浏览器页面对象
|
||||
|
||||
Returns:
|
||||
主页面 iframe 的 Frame 对象
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def navigate_to_order_page(self, main_frame: Frame, page: Page) -> Tuple[Page, Frame]:
|
||||
"""
|
||||
导航到订单页面
|
||||
|
||||
Args:
|
||||
main_frame: 主 iframe
|
||||
page: 当前页面对象
|
||||
|
||||
Returns:
|
||||
(新页面, 内部 iframe)
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def navigate_to_material_plan_page(self, page: Page) -> Tuple[Page, Frame]:
|
||||
"""
|
||||
导航到备料计划页面
|
||||
|
||||
Args:
|
||||
page: 订单页面对象
|
||||
|
||||
Returns:
|
||||
(新页面, 内部 iframe)
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def setup_query_interface(self, frame: Frame) -> None:
|
||||
"""
|
||||
设置查询界面
|
||||
|
||||
Args:
|
||||
frame: 目标 iframe
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def wait_for_page_loaded(self, frame: Frame) -> bool:
|
||||
"""
|
||||
等待页面加载完成
|
||||
|
||||
Args:
|
||||
frame: 目标 iframe
|
||||
|
||||
Returns:
|
||||
是否加载成功
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user