Files
playwrite/services/deletion_checker.py
Misaka_Company 5024384c73 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>
2026-02-10 14:17:37 +08:00

46 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
删除判断服务实现
基于数据库查询判断物料是否需要删除
"""
from interfaces.i_deletion_checker import IDeletionChecker
from models.material_info import MaterialInfo
from db.materials_to_delete import should_delete_material
class DatabaseDeletionChecker(IDeletionChecker):
"""基于数据库的删除判断实现"""
def __init__(self, manager_name: str, verbose: bool = True):
"""
初始化删除检查器
Args:
manager_name: 负责人姓名
verbose: 是否打印详细日志
"""
self.manager_name = manager_name
self.verbose = verbose
def _print(self, *args, **kwargs):
"""打印日志(如果 verbose=True"""
if self.verbose:
print(*args, **kwargs)
def should_delete(self, material: MaterialInfo) -> bool:
"""
通过查询数据库判断是否需要删除
Args:
material: 物料信息对象
Returns:
是否需要删除
"""
result = should_delete_material(self.manager_name, material.code)
if self.verbose and result:
self._print(f">>> 需要清理:{material.name}{material.code}")
elif self.verbose and not result:
self._print(f"保留:{material.name}{material.code}】无需清理")
return result