jiateng_ws/dao/login_dao.py
2025-06-07 10:45:09 +08:00

52 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from db.pgsql import PostgreSQL
from db.system_config_dao import SystemConfigDAO
def check_user_login(user_id: str, password: str) -> bool:
db = PostgreSQL()
try:
db.connect()
sql = "SELECT 1 FROM sys_user WHERE user_id=%s AND password=md5(%s)"
result = db.execute_query(sql, (user_id, password))
return bool(len(result) > 0)
finally:
db.disconnect()
def get_user_info(user_id: str):
db = PostgreSQL()
try:
db.connect()
sql = """
SELECT user_id, nick_name AS user_name, position_id,
f_getname('GETCORPEXP', '', '', org_id) AS corp_name,
org_id AS corp_id, default_org_id
FROM sys_user
WHERE user_id = %s
"""
result = db.execute_query(sql, (user_id,))
if result:
user_name = result[0]['user_name']
corp_name = result[0]['corp_name']
corp_id = result[0]['corp_id']
position_id = result[0]['position_id']
default_org_id = result[0]['default_org_id']
# 如果有默认账套ID使用默认账套ID替代登录账套ID
if default_org_id:
corp_id = default_org_id
# 查询默认账套的名称
corp_name_sql = """
SELECT corp_exp
FROM sys_org
WHERE org_id = %s
"""
corp_result = db.execute_query(corp_name_sql, (corp_id,))
if corp_result:
corp_name = corp_result[0]['corp_exp']
# 将用户的当前账套ID保存到内存中
SystemConfigDAO.save_user_selected_corp(user_id, corp_id)
return user_name, corp_name, corp_id, position_id
return None, None, None, None
finally:
db.disconnect()