|
@@ -75,15 +75,19 @@ try:
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
def get_db_connection():
|
|
def get_db_connection():
|
|
|
- return pool.connection()
|
|
|
|
|
|
|
+ conn = pool.connection()
|
|
|
|
|
+ print(f"[Database] Got connection from pool: {id(conn)}")
|
|
|
|
|
+ return conn
|
|
|
|
|
|
|
|
- print("Database connection pool initialized successfully")
|
|
|
|
|
|
|
+ print("[Database] Database connection pool initialized successfully")
|
|
|
except ImportError:
|
|
except ImportError:
|
|
|
# 如果DBUtils不可用,使用普通连接
|
|
# 如果DBUtils不可用,使用普通连接
|
|
|
def get_db_connection():
|
|
def get_db_connection():
|
|
|
- return pymysql.connect(**DB_CONFIG)
|
|
|
|
|
|
|
+ conn = pymysql.connect(**DB_CONFIG)
|
|
|
|
|
+ print(f"[Database] Created new connection: {id(conn)}")
|
|
|
|
|
+ return conn
|
|
|
|
|
|
|
|
- print("DBUtils not available, using regular database connections")
|
|
|
|
|
|
|
+ print("[Database] DBUtils not available, using regular database connections")
|
|
|
|
|
|
|
|
def format_timestamp(ts):
|
|
def format_timestamp(ts):
|
|
|
if not ts: return '未知'
|
|
if not ts: return '未知'
|
|
@@ -985,6 +989,8 @@ def members():
|
|
|
per_page = 10
|
|
per_page = 10
|
|
|
offset = (page - 1) * per_page
|
|
offset = (page - 1) * per_page
|
|
|
|
|
|
|
|
|
|
+ print(f"[Members List] Fetching members page: {page}, search: '{search_name}', per_page: {per_page}")
|
|
|
|
|
+
|
|
|
conn = get_db_connection()
|
|
conn = get_db_connection()
|
|
|
try:
|
|
try:
|
|
|
with conn.cursor() as cursor:
|
|
with conn.cursor() as cursor:
|
|
@@ -1000,13 +1006,19 @@ def members():
|
|
|
where_clause = " OR ".join(where_parts) if where_parts else "name LIKE %s"
|
|
where_clause = " OR ".join(where_parts) if where_parts else "name LIKE %s"
|
|
|
if not where_parts:
|
|
if not where_parts:
|
|
|
params = [f"%{search_name}%"]
|
|
params = [f"%{search_name}%"]
|
|
|
- cursor.execute(f"SELECT COUNT(*) as count FROM family_member_info WHERE {where_clause}", tuple(params))
|
|
|
|
|
|
|
+ count_sql = f"SELECT COUNT(*) as count FROM family_member_info WHERE {where_clause}"
|
|
|
|
|
+ print(f"[Members List] Executing count SQL: {count_sql}")
|
|
|
|
|
+ print(f"[Members List] Count SQL parameters: {params}")
|
|
|
|
|
+ cursor.execute(count_sql, tuple(params))
|
|
|
else:
|
|
else:
|
|
|
- cursor.execute("SELECT COUNT(*) as count FROM family_member_info")
|
|
|
|
|
|
|
+ count_sql = "SELECT COUNT(*) as count FROM family_member_info"
|
|
|
|
|
+ print(f"[Members List] Executing count SQL: {count_sql}")
|
|
|
|
|
+ cursor.execute(count_sql)
|
|
|
|
|
|
|
|
result = cursor.fetchone()
|
|
result = cursor.fetchone()
|
|
|
total = result['count'] if result else 0
|
|
total = result['count'] if result else 0
|
|
|
total_pages = (total + per_page - 1) // per_page
|
|
total_pages = (total + per_page - 1) // per_page
|
|
|
|
|
+ print(f"[Members List] Total members: {total}, total pages: {total_pages}")
|
|
|
|
|
|
|
|
# 2. Get paginated results, ordered by modified_time DESC (or create_time if modified is null/same)
|
|
# 2. Get paginated results, ordered by modified_time DESC (or create_time if modified is null/same)
|
|
|
# Using COALESCE to ensure sort works even if modified_time is NULL
|
|
# Using COALESCE to ensure sort works even if modified_time is NULL
|
|
@@ -1025,12 +1037,17 @@ def members():
|
|
|
like = f"%{search_name}%"
|
|
like = f"%{search_name}%"
|
|
|
params = [like, like]
|
|
params = [like, like]
|
|
|
sql = f"SELECT id, name, simplified_name, sex, name_word_generation, birthday, occupation, family_rank, branch_family_hall, residential_address, is_pass_away, create_time, modified_time FROM family_member_info WHERE {where_clause} {order_clause} LIMIT %s OFFSET %s"
|
|
sql = f"SELECT id, name, simplified_name, sex, name_word_generation, birthday, occupation, family_rank, branch_family_hall, residential_address, is_pass_away, create_time, modified_time FROM family_member_info WHERE {where_clause} {order_clause} LIMIT %s OFFSET %s"
|
|
|
|
|
+ print(f"[Members List] Executing members SQL: {sql}")
|
|
|
|
|
+ print(f"[Members List] Members SQL parameters: {params + [per_page, offset]}")
|
|
|
cursor.execute(sql, tuple(params + [per_page, offset]))
|
|
cursor.execute(sql, tuple(params + [per_page, offset]))
|
|
|
else:
|
|
else:
|
|
|
sql = f"SELECT id, name, simplified_name, sex, name_word_generation, birthday, occupation, family_rank, branch_family_hall, residential_address, is_pass_away, create_time, modified_time FROM family_member_info {order_clause} LIMIT %s OFFSET %s"
|
|
sql = f"SELECT id, name, simplified_name, sex, name_word_generation, birthday, occupation, family_rank, branch_family_hall, residential_address, is_pass_away, create_time, modified_time FROM family_member_info {order_clause} LIMIT %s OFFSET %s"
|
|
|
|
|
+ print(f"[Members List] Executing members SQL: {sql}")
|
|
|
|
|
+ print(f"[Members List] Members SQL parameters: {[per_page, offset]}")
|
|
|
cursor.execute(sql, (per_page, offset))
|
|
cursor.execute(sql, (per_page, offset))
|
|
|
|
|
|
|
|
members = cursor.fetchall()
|
|
members = cursor.fetchall()
|
|
|
|
|
+ print(f"[Members List] Fetched {len(members)} members")
|
|
|
|
|
|
|
|
# 格式化日期
|
|
# 格式化日期
|
|
|
for m in members:
|
|
for m in members:
|
|
@@ -1042,6 +1059,7 @@ def members():
|
|
|
m['modified_time_str'] = m['modified_time'].strftime('%Y-%m-%d %H:%M')
|
|
m['modified_time_str'] = m['modified_time'].strftime('%Y-%m-%d %H:%M')
|
|
|
|
|
|
|
|
finally:
|
|
finally:
|
|
|
|
|
+ print(f"[Members List] Closing database connection")
|
|
|
conn.close()
|
|
conn.close()
|
|
|
|
|
|
|
|
return render_template('members.html', members=members, search_name=search_name, page=page, total_pages=total_pages, total=total)
|
|
return render_template('members.html', members=members, search_name=search_name, page=page, total_pages=total_pages, total=total)
|
|
@@ -1444,11 +1462,15 @@ def add_member():
|
|
|
# ... (rest of logic) ...
|
|
# ... (rest of logic) ...
|
|
|
|
|
|
|
|
with conn.cursor() as cursor:
|
|
with conn.cursor() as cursor:
|
|
|
|
|
+ print(f"[Add Member] Inserting member data: {data}")
|
|
|
fields = ", ".join(data.keys())
|
|
fields = ", ".join(data.keys())
|
|
|
placeholders = ", ".join(["%s"] * len(data))
|
|
placeholders = ", ".join(["%s"] * len(data))
|
|
|
sql = f"INSERT INTO family_member_info ({fields}) VALUES ({placeholders})"
|
|
sql = f"INSERT INTO family_member_info ({fields}) VALUES ({placeholders})"
|
|
|
|
|
+ print(f"[Add Member] Executing SQL: {sql}")
|
|
|
|
|
+ print(f"[Add Member] SQL parameters: {list(data.values())}")
|
|
|
cursor.execute(sql, list(data.values()))
|
|
cursor.execute(sql, list(data.values()))
|
|
|
member_id = cursor.lastrowid
|
|
member_id = cursor.lastrowid
|
|
|
|
|
+ print(f"[Add Member] Inserted member with ID: {member_id}")
|
|
|
|
|
|
|
|
# 录入关系
|
|
# 录入关系
|
|
|
if related_mid and relation_type:
|
|
if related_mid and relation_type:
|
|
@@ -1462,6 +1484,7 @@ def add_member():
|
|
|
(parent_mid, child_mid, relation_type, sub_relation_type, source_mid, generation_diff)
|
|
(parent_mid, child_mid, relation_type, sub_relation_type, source_mid, generation_diff)
|
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
|
"""
|
|
"""
|
|
|
|
|
+ print(f"[Add Member] Inserting relation: parent_mid={parent_mid}, child_mid={child_mid}, relation_type={rel_type}")
|
|
|
cursor.execute(sql_relation, (parent_mid, child_mid, rel_type, sub_relation_type, member_id, gen_diff))
|
|
cursor.execute(sql_relation, (parent_mid, child_mid, rel_type, sub_relation_type, member_id, gen_diff))
|
|
|
|
|
|
|
|
# Update AI Record Status if applicable
|
|
# Update AI Record Status if applicable
|
|
@@ -1471,6 +1494,7 @@ def add_member():
|
|
|
if source_record_id and source_index and source_index.isdigit():
|
|
if source_record_id and source_index and source_index.isdigit():
|
|
|
try:
|
|
try:
|
|
|
idx = int(source_index)
|
|
idx = int(source_index)
|
|
|
|
|
+ print(f"[Add Member] Updating AI record status: record_id={source_record_id}, index={idx}")
|
|
|
cursor.execute("SELECT ai_content FROM genealogy_records WHERE id = %s FOR UPDATE", (source_record_id,))
|
|
cursor.execute("SELECT ai_content FROM genealogy_records WHERE id = %s FOR UPDATE", (source_record_id,))
|
|
|
rec = cursor.fetchone()
|
|
rec = cursor.fetchone()
|
|
|
if rec and rec['ai_content']:
|
|
if rec and rec['ai_content']:
|
|
@@ -1491,10 +1515,13 @@ def add_member():
|
|
|
if updated:
|
|
if updated:
|
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
|
cursor.execute("UPDATE genealogy_records SET ai_content = %s WHERE id = %s", (new_content, source_record_id))
|
|
cursor.execute("UPDATE genealogy_records SET ai_content = %s WHERE id = %s", (new_content, source_record_id))
|
|
|
|
|
+ print(f"[Add Member] Updated AI record status")
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(f"Error updating AI content status: {e}")
|
|
|
|
|
|
|
+ print(f"[Add Member] Error updating AI content status: {e}")
|
|
|
|
|
|
|
|
|
|
+ print(f"[Add Member] Committing transaction")
|
|
|
conn.commit()
|
|
conn.commit()
|
|
|
|
|
+ print(f"[Add Member] Transaction committed successfully")
|
|
|
|
|
|
|
|
if request.headers.get('X-Requested-With') == 'XMLHttpRequest' or request.is_json:
|
|
if request.headers.get('X-Requested-With') == 'XMLHttpRequest' or request.is_json:
|
|
|
return jsonify({"success": True, "message": "成员录入成功", "member_id": member_id})
|
|
return jsonify({"success": True, "message": "成员录入成功", "member_id": member_id})
|
|
@@ -1607,13 +1634,18 @@ def edit_member(member_id):
|
|
|
sub_relation_type = request.form.get('sub_relation_type', 0)
|
|
sub_relation_type = request.form.get('sub_relation_type', 0)
|
|
|
|
|
|
|
|
with conn.cursor() as cursor:
|
|
with conn.cursor() as cursor:
|
|
|
|
|
+ print(f"[Edit Member] Updating member data: {data}")
|
|
|
update_parts = [f"{k} = %s" for k in data.keys()]
|
|
update_parts = [f"{k} = %s" for k in data.keys()]
|
|
|
sql = f"UPDATE family_member_info SET {', '.join(update_parts)} WHERE id = %s"
|
|
sql = f"UPDATE family_member_info SET {', '.join(update_parts)} WHERE id = %s"
|
|
|
|
|
+ print(f"[Edit Member] Executing SQL: {sql}")
|
|
|
|
|
+ print(f"[Edit Member] SQL parameters: {list(data.values()) + [member_id]}")
|
|
|
cursor.execute(sql, list(data.values()) + [member_id])
|
|
cursor.execute(sql, list(data.values()) + [member_id])
|
|
|
|
|
+ print(f"[Edit Member] Updated member with ID: {member_id}")
|
|
|
|
|
|
|
|
# 更新关系
|
|
# 更新关系
|
|
|
if related_mid and relation_type:
|
|
if related_mid and relation_type:
|
|
|
rel_type = int(relation_type)
|
|
rel_type = int(relation_type)
|
|
|
|
|
+ print(f"[Edit Member] Deleting existing relations for member ID: {member_id}")
|
|
|
cursor.execute("DELETE FROM family_relation_info WHERE source_mid = %s", (member_id,))
|
|
cursor.execute("DELETE FROM family_relation_info WHERE source_mid = %s", (member_id,))
|
|
|
|
|
|
|
|
parent_mid = int(related_mid)
|
|
parent_mid = int(related_mid)
|
|
@@ -1625,6 +1657,7 @@ def edit_member(member_id):
|
|
|
(parent_mid, child_mid, relation_type, sub_relation_type, source_mid, generation_diff)
|
|
(parent_mid, child_mid, relation_type, sub_relation_type, source_mid, generation_diff)
|
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
|
"""
|
|
"""
|
|
|
|
|
+ print(f"[Edit Member] Inserting relation: parent_mid={parent_mid}, child_mid={child_mid}, relation_type={rel_type}")
|
|
|
cursor.execute(sql_relation, (parent_mid, child_mid, rel_type, sub_relation_type, member_id, gen_diff))
|
|
cursor.execute(sql_relation, (parent_mid, child_mid, rel_type, sub_relation_type, member_id, gen_diff))
|
|
|
|
|
|
|
|
# Update AI Record Status if applicable
|
|
# Update AI Record Status if applicable
|
|
@@ -1634,6 +1667,7 @@ def edit_member(member_id):
|
|
|
if source_record_id and source_index and source_index.isdigit():
|
|
if source_record_id and source_index and source_index.isdigit():
|
|
|
try:
|
|
try:
|
|
|
idx = int(source_index)
|
|
idx = int(source_index)
|
|
|
|
|
+ print(f"[Edit Member] Updating AI record status: record_id={source_record_id}, index={idx}")
|
|
|
cursor.execute("SELECT ai_content FROM genealogy_records WHERE id = %s FOR UPDATE", (source_record_id,))
|
|
cursor.execute("SELECT ai_content FROM genealogy_records WHERE id = %s FOR UPDATE", (source_record_id,))
|
|
|
rec = cursor.fetchone()
|
|
rec = cursor.fetchone()
|
|
|
if rec and rec['ai_content']:
|
|
if rec and rec['ai_content']:
|
|
@@ -1653,10 +1687,13 @@ def edit_member(member_id):
|
|
|
if updated:
|
|
if updated:
|
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
new_content = json.dumps(content, ensure_ascii=False)
|
|
|
cursor.execute("UPDATE genealogy_records SET ai_content = %s WHERE id = %s", (new_content, source_record_id))
|
|
cursor.execute("UPDATE genealogy_records SET ai_content = %s WHERE id = %s", (new_content, source_record_id))
|
|
|
|
|
+ print(f"[Edit Member] Updated AI record status")
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(f"Error updating AI content status: {e}")
|
|
|
|
|
|
|
+ print(f"[Edit Member] Error updating AI content status: {e}")
|
|
|
|
|
|
|
|
|
|
+ print(f"[Edit Member] Committing transaction")
|
|
|
conn.commit()
|
|
conn.commit()
|
|
|
|
|
+ print(f"[Edit Member] Transaction committed successfully")
|
|
|
if request.headers.get('X-Requested-With') == 'XMLHttpRequest' or request.is_json:
|
|
if request.headers.get('X-Requested-With') == 'XMLHttpRequest' or request.is_json:
|
|
|
return jsonify({"success": True, "message": "成员信息更新成功"})
|
|
return jsonify({"success": True, "message": "成员信息更新成功"})
|
|
|
|
|
|