style: apply code formatting to discrete_material_plan_cleaner.py

Apply consistent code formatting including:
- Single quotes to double quotes for string literals
- Multi-line formatting for long expressions
- Trailing whitespace cleanup
- Blank line adjustments for PEP 8 compliance

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-02-24 22:23:34 +08:00
parent a520c9a05c
commit de25841364

View File

@@ -24,11 +24,12 @@ from db.materials_to_delete import get_materials_to_delete
# --- 日志配置 --- # --- 日志配置 ---
logging.basicConfig( logging.basicConfig(
level=logging.INFO, level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s', format="%(asctime)s [%(levelname)s] %(message)s",
datefmt='%Y-%m-%d %H:%M:%S' datefmt="%Y-%m-%d %H:%M:%S",
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DiscreteMaterialPlanCleaner: class DiscreteMaterialPlanCleaner:
"""离散备料计划维护数据清理器""" """离散备料计划维护数据清理器"""
@@ -44,9 +45,12 @@ class DiscreteMaterialPlanCleaner:
def _log(self, message, level="info"): def _log(self, message, level="info"):
"""统一日志输出控制""" """统一日志输出控制"""
if self.verbose: if self.verbose:
if level == "info": logger.info(message) if level == "info":
elif level == "warn": logger.warning(message) logger.info(message)
elif level == "error": logger.error(message) elif level == "warn":
logger.warning(message)
elif level == "error":
logger.error(message)
def _is_button_enabled(self, button_locator): def _is_button_enabled(self, button_locator):
"""判定按钮是否可用""" """判定按钮是否可用"""
@@ -58,9 +62,12 @@ class DiscreteMaterialPlanCleaner:
def _get_input_value(self, container, label_regex): def _get_input_value(self, container, label_regex):
"""通用辅助函数:根据 Label 正则获取 Input 的值""" """通用辅助函数:根据 Label 正则获取 Input 的值"""
return container.locator("div").filter( return (
has_text=re.compile(label_regex, re.MULTILINE) container.locator("div")
).locator("input").first.input_value() .filter(has_text=re.compile(label_regex, re.MULTILINE))
.locator("input")
.first.input_value()
)
def preload_data(self): def preload_data(self):
"""批量预取数据库数据""" """批量预取数据库数据"""
@@ -74,7 +81,9 @@ class DiscreteMaterialPlanCleaner:
"""读取文件并查询生产订单号""" """读取文件并查询生产订单号"""
production_ids = read_production_ids(production_id_file) production_ids = read_production_ids(production_id_file)
order_ids = query_production_order_numbers(production_ids) order_ids = query_production_order_numbers(production_ids)
self._log(f"读取到 {len(production_ids)} 个总排号 -> 匹配到 {len(order_ids)} 个生产订单号") self._log(
f"读取到 {len(production_ids)} 个总排号 -> 匹配到 {len(order_ids)} 个生产订单号"
)
return order_ids return order_ids
def process_order(self, inner_frame, order_id, order_index, page1): def process_order(self, inner_frame, order_id, order_index, page1):
@@ -103,14 +112,22 @@ class DiscreteMaterialPlanCleaner:
detail_inner_frame = detail_main_frame.locator("#mainiframe").content_frame detail_inner_frame = detail_main_frame.locator("#mainiframe").content_frame
# 5. 提取订单状态信息 # 5. 提取订单状态信息
plan_code_locator = detail_inner_frame.get_by_text(re.compile(r"^离散备料计划维护:")) plan_code_locator = detail_inner_frame.get_by_text(
re.compile(r"^离散备料计划维护:")
)
plan_code_locator.wait_for(state="visible", timeout=15000) plan_code_locator.wait_for(state="visible", timeout=15000)
detail_count_text = detail_inner_frame.get_by_text(re.compile(r"^详细信息 \(\d+\)$")).inner_text() detail_count_text = detail_inner_frame.get_by_text(
re.compile(r"^详细信息 \(\d+\)$")
).inner_text()
detail_count = int(re.search(r"\((\d+)\)", detail_count_text).group(1)) detail_count = int(re.search(r"\((\d+)\)", detail_count_text).group(1))
status_text = detail_inner_frame.get_by_text(re.compile(r"^备料状态:.+$")).inner_text() status_text = detail_inner_frame.get_by_text(
detail_status = re.search(r"备料状态:(.+)$", status_text.replace("\n", "")).group(1) re.compile(r"^备料状态:.+$")
).inner_text()
detail_status = re.search(
r"备料状态:(.+)$", status_text.replace("\n", "")
).group(1)
# 6. 执行清理逻辑 # 6. 执行清理逻辑
if detail_status == "审批通过": if detail_status == "审批通过":
@@ -119,7 +136,9 @@ class DiscreteMaterialPlanCleaner:
detail_inner_frame.get_by_role("button", name="修改").click() detail_inner_frame.get_by_role("button", name="修改").click()
# 关键判断:等待保存按钮出现,确认进入编辑模式 # 关键判断:等待保存按钮出现,确认进入编辑模式
save_button_locator = detail_inner_frame.get_by_role("button", name="保存") save_button_locator = detail_inner_frame.get_by_role(
"button", name="保存"
)
save_button_locator.wait_for(state="visible", timeout=10000) save_button_locator.wait_for(state="visible", timeout=10000)
self._log("已进入编辑模式(保存按钮已就绪)") self._log("已进入编辑模式(保存按钮已就绪)")
# --------------------------------------- # ---------------------------------------
@@ -153,7 +172,9 @@ class DiscreteMaterialPlanCleaner:
else: else:
self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn") self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn")
else: else:
self._log(f"物料 {material_name} ({material_code}) 不在删除列表中,不做处理") self._log(
f"物料 {material_name} ({material_code}) 不在删除列表中,不做处理"
)
if self._is_button_enabled(next_btn): if self._is_button_enabled(next_btn):
last_row_number = current_row last_row_number = current_row
next_btn.click() next_btn.click()
@@ -207,7 +228,9 @@ class DiscreteMaterialPlanCleaner:
# 定位主 Iframe # 定位主 Iframe
work_main_frame = page1.locator("#forwardFrame").content_frame work_main_frame = page1.locator("#forwardFrame").content_frame
inner_frame = work_main_frame.locator("#mainiframe").content_frame inner_frame = work_main_frame.locator("#mainiframe").content_frame
inner_frame.locator("#hot-key-head_list").wait_for(state="visible", timeout=15000) inner_frame.locator("#hot-key-head_list").wait_for(
state="visible", timeout=15000
)
self.setup_query_interface(inner_frame) self.setup_query_interface(inner_frame)
order_ids = self.get_production_order_numbers(production_id_file) order_ids = self.get_production_order_numbers(production_id_file)
@@ -227,6 +250,7 @@ class DiscreteMaterialPlanCleaner:
browser.close() browser.close()
self._log("=" * 30 + " 任务全部完成 " + "=" * 30) self._log("=" * 30 + " 任务全部完成 " + "=" * 30)
def main(): def main():
# 路径配置 # 路径配置
base_dir = os.path.dirname(__file__) base_dir = os.path.dirname(__file__)
@@ -236,11 +260,12 @@ def main():
username="BLDpengqiangqiang", username="BLDpengqiangqiang",
password="your_password_here", password="your_password_here",
manager_name="彭羽", manager_name="彭羽",
headless=False headless=False,
) )
cleaner.clean(id_file) cleaner.clean(id_file)
input("执行完毕,按回车键退出程序...") input("执行完毕,按回车键退出程序...")
if __name__ == "__main__": if __name__ == "__main__":
main() main()