AI实验室后端
This commit is contained in:
@@ -583,6 +583,7 @@ def patch_user_db(id: str, data: dict) -> int:
|
||||
sql = f"UPDATE sys_users SET {', '.join(fields)} WHERE id = %s"
|
||||
params.append(id)
|
||||
cursor.execute(sql, tuple(params))
|
||||
updated_count = cursor.rowcount # 保存这次的结果
|
||||
|
||||
# ------------------------
|
||||
# 2. roles 单独处理
|
||||
@@ -597,7 +598,7 @@ def patch_user_db(id: str, data: dict) -> int:
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
return cursor.rowcount
|
||||
return updated_count
|
||||
|
||||
|
||||
# 删除用户
|
||||
@@ -954,14 +955,24 @@ def get_dept_id_by_user_id(user_id: str) -> str:
|
||||
return str(dept_id)
|
||||
|
||||
|
||||
def get_dept_name_by_dept_id(user_id: str) -> str:
|
||||
with pg_pool.getConn() as conn:
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("SELECT name FROM sys_dept WHERE id = %s", (user_id,))
|
||||
dept_id = cursor.fetchone()
|
||||
dept_id = dept_id[0]
|
||||
return str(dept_id)
|
||||
|
||||
|
||||
def get_dept_id_by_iot_user_name(user_id: str) -> str:
|
||||
# 通过 iot_user_id 查找其所属的 dept_id
|
||||
with pg_pool.getConn() as conn:
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("SELECT dept_id FROM iot_users WHERE name = %s", (user_id,))
|
||||
dept_id = cursor.fetchone()
|
||||
dept_id = str(dept_id[0])
|
||||
return dept_id
|
||||
row = cursor.fetchone()
|
||||
if row is None:
|
||||
return None # 或者抛出自定义异常
|
||||
return str(row[0])
|
||||
|
||||
|
||||
def get_device_type_by_iot_user_name(user_id: str) -> str:
|
||||
@@ -969,9 +980,10 @@ def get_device_type_by_iot_user_name(user_id: str) -> str:
|
||||
with pg_pool.getConn() as conn:
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute("SELECT type FROM iot_users WHERE name = %s", (user_id,))
|
||||
type = cursor.fetchone()
|
||||
type = str(type[0])
|
||||
return type
|
||||
row = cursor.fetchone()
|
||||
if row is None:
|
||||
return None # 或者抛出自定义异常
|
||||
return str(row[0])
|
||||
|
||||
|
||||
from typing import List
|
||||
|
||||
Reference in New Issue
Block a user