|
@@ -1085,26 +1085,34 @@ def members():
|
|
|
|
|
|
|
|
# 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
|
|
|
- order_clause = "ORDER BY COALESCE(modified_time, create_time) DESC"
|
|
|
|
|
-
|
|
|
|
|
|
|
+ order_clause = "ORDER BY COALESCE(fmi.modified_time, fmi.create_time) DESC"
|
|
|
|
|
+
|
|
|
|
|
+ # 父亲信息 JOIN(取亲生/普通父亲,排除入继关系)
|
|
|
|
|
+ father_join = """
|
|
|
|
|
+ LEFT JOIN family_relation_info fri
|
|
|
|
|
+ ON fmi.id = fri.child_mid AND fri.relation_type = 1 AND COALESCE(fri.sub_relation_type, 0) != 3
|
|
|
|
|
+ LEFT JOIN family_member_info father ON fri.parent_mid = father.id
|
|
|
|
|
+ """
|
|
|
|
|
+ father_cols = ", father.id as father_id, father.name as father_name, father.simplified_name as father_simplified_name, fri.child_order as child_order_to_father"
|
|
|
|
|
+
|
|
|
if search_name:
|
|
if search_name:
|
|
|
variants = expand_name_search_variants(search_name)
|
|
variants = expand_name_search_variants(search_name)
|
|
|
where_parts = []
|
|
where_parts = []
|
|
|
params = []
|
|
params = []
|
|
|
for v in variants:
|
|
for v in variants:
|
|
|
- where_parts.append("(name LIKE %s OR simplified_name LIKE %s)")
|
|
|
|
|
|
|
+ where_parts.append("(fmi.name LIKE %s OR fmi.simplified_name LIKE %s)")
|
|
|
like = f"%{v}%"
|
|
like = f"%{v}%"
|
|
|
params.extend([like, like])
|
|
params.extend([like, like])
|
|
|
- where_clause = " OR ".join(where_parts) if where_parts else "(name LIKE %s OR simplified_name LIKE %s)"
|
|
|
|
|
|
|
+ where_clause = " OR ".join(where_parts) if where_parts else "(fmi.name LIKE %s OR fmi.simplified_name LIKE %s)"
|
|
|
if not where_parts:
|
|
if not where_parts:
|
|
|
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 fmi.id, fmi.name, fmi.simplified_name, fmi.sex, fmi.name_word_generation, fmi.birthday, fmi.occupation, fmi.family_rank, fmi.branch_family_hall, fmi.residential_address, fmi.is_pass_away, fmi.create_time, fmi.modified_time{father_cols} FROM family_member_info fmi {father_join} WHERE {where_clause} {order_clause} LIMIT %s OFFSET %s"
|
|
|
print(f"[Members List] Executing members SQL: {sql}")
|
|
print(f"[Members List] Executing members SQL: {sql}")
|
|
|
print(f"[Members List] Members SQL parameters: {params + [per_page, offset]}")
|
|
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 fmi.id, fmi.name, fmi.simplified_name, fmi.sex, fmi.name_word_generation, fmi.birthday, fmi.occupation, fmi.family_rank, fmi.branch_family_hall, fmi.residential_address, fmi.is_pass_away, fmi.create_time, fmi.modified_time{father_cols} FROM family_member_info fmi {father_join} {order_clause} LIMIT %s OFFSET %s"
|
|
|
print(f"[Members List] Executing members SQL: {sql}")
|
|
print(f"[Members List] Executing members SQL: {sql}")
|
|
|
print(f"[Members List] Members SQL parameters: {[per_page, offset]}")
|
|
print(f"[Members List] Members SQL parameters: {[per_page, offset]}")
|
|
|
cursor.execute(sql, (per_page, offset))
|
|
cursor.execute(sql, (per_page, offset))
|
|
@@ -2490,9 +2498,9 @@ def member_detail(member_id):
|
|
|
|
|
|
|
|
member['birthday_str'] = format_timestamp(member.get('birthday'))
|
|
member['birthday_str'] = format_timestamp(member.get('birthday'))
|
|
|
|
|
|
|
|
- # 获取关系(包含子类型)
|
|
|
|
|
|
|
+ # 获取关系(包含子类型和第几子)
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
|
- SELECT m.id, m.name, r.relation_type, r.sub_relation_type
|
|
|
|
|
|
|
+ SELECT m.id, m.name, r.relation_type, r.sub_relation_type, r.child_order
|
|
|
FROM family_relation_info r
|
|
FROM family_relation_info r
|
|
|
JOIN family_member_info m ON r.parent_mid = m.id
|
|
JOIN family_member_info m ON r.parent_mid = m.id
|
|
|
WHERE r.child_mid = %s
|
|
WHERE r.child_mid = %s
|