Merge branch 'mysql' into dev

Resolved merge conflict in utils/material_status_validator.py by keeping
both deduplication statistics and error messages for empty results.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-02-24 20:44:52 +08:00
14 changed files with 1998 additions and 76 deletions

View File

@@ -3,6 +3,6 @@
"""
from .excel_converter import ExcelConverter
from .离散备料计划维护数据提取 import DiscreteMaterialPlanExtractor
from .discrete_material_plan_extractor import DiscreteMaterialPlanExtractor
__all__ = ["ExcelConverter", "DiscreteMaterialPlanExtractor"]

View File

@@ -113,56 +113,62 @@ class DiscreteMaterialPlanCleaner:
detail_status = re.search(r"备料状态:(.+)$", status_text.replace("\n", "")).group(1)
# 6. 执行清理逻辑
if detail_count > 0 and detail_status == "审批通过":
# --- 点击修改并等待状态切换 (保留原逻辑) ---
detail_inner_frame.get_by_role("button", name="修改").click()
# 关键判断:等待保存按钮出现,确认进入编辑模式
save_button_locator = detail_inner_frame.get_by_role("button", name="保存")
save_button_locator.wait_for(state="visible", timeout=10000)
self._log("已进入编辑模式(保存按钮已就绪)")
# ---------------------------------------
detail_inner_frame.get_by_text("展开").first.click()
child_form = detail_inner_frame.locator(".card-table-side-box")
button_wrapper = child_form.locator(".button-wrapper")
delete_row_btn = button_wrapper.get_by_role("button", name="删行")
next_btn = button_wrapper.locator(".icon-jiantouyou")
collapse_btn = button_wrapper.locator(".icon-celashouqi")
last_row_number = None
while True:
# 稳定性检查:等待行号更新
current_row = self._get_input_value(child_form, r"^行号$")
if current_row == last_row_number:
time.sleep(0.5)
material_code = self._get_input_value(child_form, r"^材料编码")
material_name = self._get_input_value(child_form, r"^材料名称")
pending_qty = self._get_input_value(child_form, r"^累计待发数量$")
if material_code in self.to_delete_set:
self._log(f"发现匹配物料: {material_name} ({material_code})")
if not pending_qty or float(pending_qty) == 0:
delete_row_btn.click()
self._log(f"✅ 已点击删行")
continue
else:
self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn")
if detail_status == "审批通过":
if detail_count >0:
# --- 点击修改并等待状态切换 (保留原逻辑) ---
detail_inner_frame.get_by_role("button", name="修改").click()
if self._is_button_enabled(next_btn):
last_row_number = current_row
next_btn.click()
else:
break
# 关键判断:等待保存按钮出现,确认进入编辑模式
save_button_locator = detail_inner_frame.get_by_role("button", name="保存")
save_button_locator.wait_for(state="visible", timeout=10000)
self._log("已进入编辑模式(保存按钮已就绪)")
# ---------------------------------------
collapse_btn.click()
# 执行最终保存逻辑(如业务需要)
# save_button_locator.click()
detail_inner_frame.get_by_text("展开").first.click()
child_form = detail_inner_frame.locator(".card-table-side-box")
button_wrapper = child_form.locator(".button-wrapper")
delete_row_btn = button_wrapper.get_by_role("button", name="删行")
next_btn = button_wrapper.locator(".icon-jiantouyou")
collapse_btn = button_wrapper.locator(".icon-celashouqi")
last_row_number = None
while True:
# 稳定性检查:等待行号更新
current_row = self._get_input_value(child_form, r"^行号$")
if current_row == last_row_number:
time.sleep(0.5)
material_code = self._get_input_value(child_form, r"^材料编码")
material_name = self._get_input_value(child_form, r"^材料名称")
pending_qty = self._get_input_value(child_form, r"^累计待发数量$")
if material_code in self.to_delete_set:
self._log(f"发现匹配物料: {material_name} ({material_code})")
if not pending_qty or float(pending_qty) != 0:
delete_row_btn.click()
self._log(f"✅ 已点击删行")
continue
else:
self._log(f"⚠️ 待发数量为 {pending_qty},跳过删除", "warn")
else:
self._log(f"物料 {material_name} ({material_code}) 不在删除列表中,不做处理")
if self._is_button_enabled(next_btn):
last_row_number = current_row
next_btn.click()
else:
break
collapse_btn.click()
# 执行最终保存逻辑(如业务需要)
# save_button_locator.click()
else:
self._log("订单无备料计划数据,无需处理")
elif detail_status == "完成":
self._log("订单已完成,无需处理")
else:
self._log(f"订单状态为 [{detail_status}],不符合处理条件", "warn")
page2.close()
def setup_query_interface(self, inner_frame):

View File

@@ -11,7 +11,7 @@ import os
import pandas as pd
from typing import List, Dict, Any, Optional, Set
from dataclasses import dataclass
from utils.离散备料计划维护数据提取 import DiscreteMaterialPlanExtractor
from utils.discrete_material_plan_extractor import DiscreteMaterialPlanExtractor
from db.materials_to_delete import get_all_materials_to_delete
from db.production_contract_data_dao import ProductionContractDataDAO
from db.discrete_material_plan_dao import DiscreteMaterialPlanDAO
@@ -446,10 +446,18 @@ class MaterialStatusValidator:
# Get material records (complete records, not just MaterialName)
if full_table:
self._print("\n模式: 全表校验")
self._print("[INFO] 查询 DiscreteMaterialPlanData 表中的所有完整记录...")
self._print("[INFO] 查询 DiscreteMaterialPlanData 表中的所有完整记录(启用 MaterialCode 去重)...")
dao = DiscreteMaterialPlanDAO()
material_records = dao.query_all()
# Get original count for deduplication statistics
original_count = dao.count_all()
material_records = dao.query_all_distinct_by_material_code()
dedup_count = original_count - len(material_records)
self._print(f"[INFO] 获取到 {len(material_records)} 条记录")
if dedup_count > 0:
self._print(f"[INFO] 基于 MaterialCode 去重:移除了 {dedup_count} 条重复记录")
elif production_id_file:
self._print("\n模式: ProductionID 过滤校验")
self._print(f"[INFO] 读取 ProductionID 文件: {production_id_file}")
@@ -461,12 +469,21 @@ class MaterialStatusValidator:
# 2. Query SourceNumbers
source_numbers = self._get_source_numbers_from_production_ids(production_ids)
# 3. Get complete material records
self._print(f"[INFO] 查询 {len(source_numbers)} 个生产订单对应的完整物料记录...")
# 3. Get complete material records with deduplication
self._print(f"[INFO] 查询 {len(source_numbers)} 个生产订单对应的完整物料记录(启用 MaterialCode 去重)...")
dao = DiscreteMaterialPlanDAO()
material_records = dao.query_by_source_numbers(source_numbers)
# Get original count for deduplication statistics
original_records = dao.query_by_source_numbers(source_numbers)
material_records = dao.query_by_source_numbers_distinct(source_numbers)
dedup_count = len(original_records) - len(material_records)
self._print(f"[INFO] 获取到 {len(material_records)} 条记录")
if dedup_count > 0:
self._print(f"[INFO] 基于 MaterialCode 去重:移除了 {dedup_count} 条重复记录")
# 如果没有找到物料记录,给出友好提示
if not material_records:
self._print("\n[ERROR] 校验失败:未找到物料记录")