待补平差检查和上传逻辑

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

@@ -325,7 +325,8 @@ def get_work_conditions_by_linecode(linecode: str) -> Optional[Dict[str, Dict]]:
while retry_count < max_retries:
try:
# 准备请求参数
payload = {"linecode": linecode}
account_id = global_variable.GLOBAL_ACCOUNT_ID
payload = {"linecode": linecode, "account_id": account_id}
headers = {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
@@ -422,7 +423,8 @@ def get_user_max_variation(username: str) -> Optional[int]:
# 1. 准备请求参数与头部
# 接口要求的POST参数JSON格式
payload = {"username": username}
account_id = global_variable.GLOBAL_ACCOUNT_ID
payload = {"username": username, "account_id": account_id}
# 请求头部指定JSON格式模拟浏览器UA避免被接口拦截
headers = {
"Content-Type": "application/json",

View File

@@ -17,8 +17,12 @@ from urllib3.connection import port_by_scheme
def run_command(command):
"""执行系统命令并返回输出"""
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return result.stdout.strip()
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, encoding='utf-8', errors='ignore')
return result.stdout.strip()
except Exception:
result = subprocess.run(command, shell=True, capture_output=True, text=True, errors='ignore')
return result.stdout.strip()
# =======================
@@ -131,18 +135,39 @@ def cleanup_wireless_connections(target_device_ip=None, target_port=4723):
def start_appium():
appium_port = 4723
print(f"🚀 启动 Appium Server端口 {appium_port}...")
subprocess.Popen(
["appium.cmd", "-a", "127.0.0.1", "-p", str(appium_port)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
# 检查端口是否就绪替代固定sleep
# 先检查端口是否已被占用
try:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex(("127.0.0.1", appium_port))
sock.close()
if result == 0:
print(f"✅ Appium Server 已在运行(端口 {appium_port}")
return True
except Exception:
pass
# 启动 Appium Server
try:
subprocess.Popen(
["appium.cmd", "-a", "127.0.0.1", "-p", str(appium_port)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
except FileNotFoundError:
print("❌ 未找到 appium.cmd请确认 Appium 已正确安装")
return False
except Exception as e:
print(f"❌ Appium Server 启动失败: {str(e)}")
return False
# 检查端口是否就绪
max_wait = 30 # 最大等待30秒
start_time = time.time()
while time.time() - start_time < max_wait:
try:
# 尝试连接Appium端口验证是否就绪
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex(("127.0.0.1", appium_port))
@@ -190,7 +215,7 @@ def setup_adb_wireless():
if not usb_devices:
print("❌ 未检测到 USB 设备")
return
return None
for serial in usb_devices:
print(f"\n🔎 处理设备: {serial}")
@@ -261,7 +286,10 @@ def setup_adb_wireless():
# print("🔄 关闭Appium连接...")
# driver.quit()
break # 处理完第一个设备后退出,如需处理多个设备可移除此行
return wireless_id # 返回无线连接的设备ID
print("❌ 未能成功建立无线连接")
return None
# =======================

View File

@@ -547,6 +547,10 @@ def grant_appium_permissions(device_id: str, require_all: bool = False) -> bool:
"""
修复版:为 Appium 授予权限(使用正确的方法)
"""
if not device_id:
logging.error("设备 ID 为空,无法授予 Appium 权限")
return False
logging.info(f"设备 {device_id}开始设置Appium权限")
# 1. 使用系统设置命令替代原来的pm grant尝试
@@ -1084,6 +1088,11 @@ def go_main_click_tabber_button(driver, device_id, tabber_button_text, max_retri
返回:
bool: 成功返回True失败返回False
"""
# 检查沉降观测应用是否已启动
if not is_app_launched(driver):
logging.warning(f"设备 {device_id} 沉降观测应用未启动")
return False
retry_count = 0
while retry_count < max_retries:

View File

@@ -1,11 +1,12 @@
# 全局变量
GLOBAL_DEVICE_ID = "" # 设备ID
GLOBAL_USERNAME = "czyuzongwen" # 用户名
GLOBAL_ACCOUNT_ID = "" # 账号ID
GLOBAL_CURRENT_PROJECT_NAME = "" # 当前测试项目名称
GLOBAL_LINE_NUM = "" # 线路编码
GLOBAL_BREAKPOINT_STATUS_CODES = [0,3] # 要获取的断点状态码列表
GLOBAL_UPLOAD_BREAKPOINT_LIST = []
GLOBAL_UPLOAD_BREAKPOINT_DICT = {}
GLOBAL_UPLOAD_BREAKPOINT_DICT = {}
GLOBAL_TESTED_BREAKPOINT_LIST = [] # 测量结束的断点列表
LINE_TIME_MAPPING_DICT = {} # 存储所有线路编码和对应的时间的全局字典
GLOBAL_BREAKPOINT_DICT = {} # 存储测量结束的断点名称和对应的线路编码的全局字典