Kaynağa Gözat

commit 优化若干

林海 1 ay önce
ebeveyn
işleme
521bfdb9ea
3 değiştirilmiş dosya ile 38 ekleme ve 9 silme
  1. 16 8
      app.py
  2. 6 0
      templates/member_detail.html
  3. 16 1
      templates/members.html

+ 16 - 8
app.py

@@ -1085,26 +1085,34 @@ def members():
             
             # 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
-            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:
                 variants = expand_name_search_variants(search_name)
                 where_parts = []
                 params = []
                 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}%"
                     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:
                     like = f"%{search_name}%"
                     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] Members SQL parameters: {params + [per_page, offset]}")
                 cursor.execute(sql, tuple(params + [per_page, offset]))
             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] Members SQL parameters: {[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'))
             
-            # 获取关系(包含子类型)
+            # 获取关系(包含子类型和第几子
             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 
                 JOIN family_member_info m ON r.parent_mid = m.id 
                 WHERE r.child_mid = %s

+ 6 - 0
templates/member_detail.html

@@ -297,6 +297,7 @@
                 <div class="section-title">家族关系</div>
                 
                 <h6 class="fw-bold mb-3"><i class="bi bi-arrow-up-circle me-1"></i> 尊辈/关联人</h6>
+                {% set child_order_labels = {1: '长子', 2: '次子', 3: '三子', 4: '四子', 5: '五子', 6: '六子', 7: '七子', 8: '八子', 9: '九子', 10: '十子'} %}
                 {% for p in parents %}
                 <div class="relation-card">
                     <div class="d-flex justify-content-between align-items-center">
@@ -308,6 +309,11 @@
                                 {% set rel_map = {1: '父亲', 2: '母亲', 10: '配偶', 11: '兄弟', 12: '姐妹'} %}
                                 {{ rel_map.get(p.relation_type, '关联人') }}
                             </span>
+                            {% if p.relation_type == 1 and p.child_order %}
+                            <span class="badge bg-info small">
+                                {{ child_order_labels.get(p.child_order, '第' ~ p.child_order ~ '子') }}
+                            </span>
+                            {% endif %}
                             {% if p.sub_relation_type %}
                             <span class="badge bg-warning small">
                                 {% set sub_rel_map = {0: '亲生', 1: '养父', 2: '出继', 3: '入继', 10: '妾', 11: '外室'} %}

+ 16 - 1
templates/members.html

@@ -54,6 +54,7 @@
                         <th class="px-4">序号</th>
                         <th>基本信息</th>
                         <th>世系世代</th>
+                        <th>父亲</th>
                         <th>职业背景</th>
                         <th>堂内排行</th>
                         <th>分房 / 堂号</th>
@@ -90,6 +91,20 @@
                             <span class="text-muted small">-</span>
                             {% endif %}
                         </td>
+                        <td>
+                            {% if member.father_id %}
+                            {% set co_labels = {1: '长子', 2: '次子', 3: '三子', 4: '四子', 5: '五子', 6: '六子', 7: '七子', 8: '八子', 9: '九子', 10: '十子'} %}
+                            <a href="{{ url_for('member_detail', member_id=member.father_id) }}"
+                               target="_blank" class="text-decoration-none small fw-medium">
+                                {{ member.father_name }}{% if member.father_simplified_name %}({{ member.father_simplified_name }}){% endif %}
+                                {% if member.child_order_to_father %}
+                                <span class="text-muted">{{ co_labels.get(member.child_order_to_father, '第' ~ member.child_order_to_father ~ '子') }}</span>
+                                {% endif %}
+                            </a>
+                            {% else %}
+                            <span class="text-muted small">-</span>
+                            {% endif %}
+                        </td>
                         <td>
                             {% if member.occupation %}
                             <div class="small" style="max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" title="{{ member.occupation }}">
@@ -143,7 +158,7 @@
                     {% endfor %}
                     {% if not members %}
                     <tr>
-                        <td colspan="8" class="text-center py-5 text-muted">
+                        <td colspan="9" class="text-center py-5 text-muted">
                             <i class="bi bi-person-x fs-1 d-block mb-2"></i>
                             暂无成员数据
                         </td>