feat: 增加项目一键整理、打包及自动上传夸克/百度网盘功能
This commit is contained in:
@@ -77,7 +77,8 @@ class DatabaseManager:
|
||||
return True
|
||||
|
||||
def get_projects(self, page: int = 1, page_size: int = 20,
|
||||
search_name: Optional[str] = None) -> Tuple[List[ProjectOrder], int]:
|
||||
search_name: Optional[str] = None,
|
||||
zlzt: Optional[str] = None) -> Tuple[List[ProjectOrder], int]:
|
||||
"""
|
||||
获取项目列表(分页)
|
||||
|
||||
@@ -85,6 +86,7 @@ class DatabaseManager:
|
||||
page: 页码(从1开始)
|
||||
page_size: 每页数量
|
||||
search_name: 搜索名称(模糊匹配)
|
||||
zlzt: 整理状态
|
||||
|
||||
Returns:
|
||||
(项目列表, 总数量)
|
||||
@@ -96,11 +98,18 @@ class DatabaseManager:
|
||||
cursor = self.connection.cursor(dictionary=True)
|
||||
|
||||
# 构建查询条件
|
||||
where_clause = ""
|
||||
where_conditions = []
|
||||
params = []
|
||||
if search_name:
|
||||
where_clause = "WHERE name LIKE %s"
|
||||
where_conditions.append("name LIKE %s")
|
||||
params.append(f"%{search_name}%")
|
||||
if zlzt:
|
||||
where_conditions.append("zlzt = %s")
|
||||
params.append(zlzt)
|
||||
|
||||
where_clause = ""
|
||||
if where_conditions:
|
||||
where_clause = "WHERE " + " AND ".join(where_conditions)
|
||||
|
||||
# 获取总数
|
||||
count_sql = f"SELECT COUNT(*) as total FROM t_new_project_order_new {where_clause}"
|
||||
@@ -147,7 +156,7 @@ class DatabaseManager:
|
||||
更新整理状态
|
||||
|
||||
Args:
|
||||
name: 项目名称
|
||||
name: 项目名称 (匹配 name 或 name2)
|
||||
zlzt: 新的整理状态值
|
||||
|
||||
Returns:
|
||||
@@ -158,8 +167,9 @@ class DatabaseManager:
|
||||
|
||||
try:
|
||||
cursor = self.connection.cursor()
|
||||
sql = "UPDATE t_new_project_order_new SET zlzt = %s WHERE name = %s"
|
||||
cursor.execute(sql, (zlzt, name))
|
||||
# 尝试同时匹配 name 和 name2
|
||||
sql = "UPDATE t_new_project_order_new SET zlzt = %s WHERE name = %s OR name2 = %s"
|
||||
cursor.execute(sql, (zlzt, name, name))
|
||||
self.connection.commit()
|
||||
affected = cursor.rowcount
|
||||
cursor.close()
|
||||
@@ -211,6 +221,52 @@ class DatabaseManager:
|
||||
print(f"[DatabaseManager] 查询失败: {e}")
|
||||
return None
|
||||
|
||||
def get_project_by_path(self, path: str) -> Optional[ProjectOrder]:
|
||||
"""
|
||||
根据路径模糊获取项目
|
||||
|
||||
Args:
|
||||
path: 项目路径关键字
|
||||
|
||||
Returns:
|
||||
项目对象,如果找不到返回 None
|
||||
"""
|
||||
if not self.ensure_connected():
|
||||
return None
|
||||
|
||||
try:
|
||||
cursor = self.connection.cursor(dictionary=True)
|
||||
# 使用模糊匹配,因为路径可能包含反斜杠或斜杠差异
|
||||
sql = """
|
||||
SELECT name, paths, zlzt, sfxxm, name1, name2, bianhao,
|
||||
`desc`, sql_paths, error_message
|
||||
FROM t_new_project_order_new
|
||||
WHERE paths LIKE %s OR %s LIKE CONCAT('%', paths, '%')
|
||||
LIMIT 1
|
||||
"""
|
||||
search_path = f"%{path}%"
|
||||
cursor.execute(sql, (search_path, path))
|
||||
row = cursor.fetchone()
|
||||
cursor.close()
|
||||
|
||||
if row:
|
||||
return ProjectOrder(
|
||||
name=row.get('name'),
|
||||
paths=row.get('paths'),
|
||||
zlzt=row.get('zlzt'),
|
||||
sfxxm=row.get('sfxxm'),
|
||||
name1=row.get('name1'),
|
||||
name2=row.get('name2'),
|
||||
bianhao=row.get('bianhao'),
|
||||
desc=row.get('desc'),
|
||||
sql_paths=row.get('sql_paths'),
|
||||
error_message=row.get('error_message')
|
||||
)
|
||||
return None
|
||||
except Error as e:
|
||||
print(f"[DatabaseManager] 查询失败: {e}")
|
||||
return None
|
||||
|
||||
def delete_project(self, name: str) -> bool:
|
||||
"""
|
||||
删除项目
|
||||
|
||||
Reference in New Issue
Block a user