待补平差检查和上传逻辑

This commit is contained in:
2026-05-26 14:40:04 +08:00
parent 19afa3d19b
commit 10db652cbc
18 changed files with 217 additions and 29 deletions

View File

@@ -3,6 +3,8 @@ import time
import requests
import pandas as pd
from io import BytesIO
from datetime import datetime
import os
import subprocess
import globals.global_variable as global_variable
import globals.driver_utils as driver_utils # 导入驱动工具模块
@@ -84,6 +86,7 @@ class CheckStation:
# return device_id
def get_measure_data(self):
# 模拟获取测量数据
pass
@@ -188,7 +191,14 @@ class CheckStation:
return result
def main_run(self):
return self.add_transition_point()
if not self.add_transition_point():
logging.error("添加转点失败")
return False
if not self.take_screenshot():
logging.error("截图失败")
return False
logging.info("检查站点成功")
return True
def run(self, station_num: int):
# last_station_num = 0
@@ -247,9 +257,123 @@ class CheckStation:
# 错误处理,可以继续循环或退出
print(f"已处理{over_station_num}个站点")
# 截图
self.driver.save_screenshot("check_station.png")
# # 截图
# self.driver.save_screenshot("check_station.png")
if not self.take_screenshot():
logging.error(f"设备 {device_id} 截图失败")
# 打完数据,截图完毕,点击平差处理按钮
if not self.click_adjustment_button(device_id):
self.logger.error(f"设备 {device_id} 点击平差处理按钮失败")
return False
return True
def click_adjustment_button(self, device_id):
"""
点击平差处理按钮
Args:
device_id: 设备ID
Returns:
bool: 是否成功点击
"""
try:
self.logger.info(f"设备 {device_id} 查找平差处理按钮")
# 查找平差处理按钮
adjustment_button = self.driver.find_element(AppiumBy.ID, "com.bjjw.cjgc:id/point_measure_btn")
# 验证按钮文本
button_text = adjustment_button.text
if "平差处理" not in button_text:
self.logger.warning(f"设备 {device_id} 按钮文本不匹配,期望'平差处理',实际: {button_text}")
if adjustment_button.is_displayed() and adjustment_button.is_enabled():
self.logger.info(f"设备 {device_id} 点击平差处理按钮")
adjustment_button.click()
time.sleep(3) # 等待平差处理完成
return True
else:
self.logger.error(f"设备 {device_id} 平差处理按钮不可点击")
return False
except NoSuchElementException:
self.logger.error(f"设备 {device_id} 未找到平差处理按钮")
return False
except Exception as e:
self.logger.error(f"设备 {device_id} 点击平差处理按钮时发生错误: {str(e)}")
return False
def take_screenshot(self):
"""
通过Appium驱动截取设备屏幕
参数:
filename_prefix: 断点名称
返回:
bool: 操作是否成功
"""
try:
# 获取项目名称
project_name = global_variable.GLOBAL_USERNAME or "用户名"
filename_prefix = global_variable.GLOBAL_CURRENT_PROJECT_NAME or "平差页面截图"
# 获取当前日期
date_str = datetime.now().strftime("%Y%m%d")
# if not date_str:
# date_str = datetime.now().strftime("%Y%m%d")
# 获取当前时间(如果没有提供),并确保格式合法(不含冒号)
time_str = datetime.now().strftime("%H%M%S")
# 创建D盘下的截图目录结构D:\uploadInfo\picture\项目名\年月日
screenshots_dir = os.path.join("D:\\", "uploadInfo", "picture", project_name, date_str)
# 确保目录存在
try:
os.makedirs(screenshots_dir, exist_ok=True)
logging.info(f"截图目录: {screenshots_dir}")
except Exception as dir_error:
logging.error(f"创建截图目录失败: {str(dir_error)}")
return False
line_code = global_variable.GLOBAL_LINE_NUM
if not line_code:
logging.error(f"未找到与断点名称 {filename_prefix} 对应的线路编码")
line_code = "unknown"
# 截图保存
screenshot_file = os.path.join(
screenshots_dir,
f"{line_code}_{filename_prefix}_{time_str}.png"
)
# 尝试保存截图
try:
success = self.driver.save_screenshot(screenshot_file)
if success:
logging.info(f"截图已保存: {screenshot_file}")
# 验证文件是否真的存在
if os.path.exists(screenshot_file):
logging.info(f"截图文件验证存在: {screenshot_file}")
else:
logging.warning(f"截图文件保存成功但验证不存在: {screenshot_file}")
return True
else:
logging.error(f"Appium截图保存失败: {screenshot_file}")
return False
except Exception as save_error:
logging.error(f"保存截图时发生错误: {str(save_error)}")
return False
except Exception as e:
logging.error(f"截图时发生错误: {str(e)}")
return False
def get_excel_from_url(url):
"""
从URL获取Excel文件并解析为字典