|
@@ -1845,10 +1845,18 @@ def get_lineage(member_id):
|
|
|
else:
|
|
else:
|
|
|
# 香火传承(默认):入继养父优先
|
|
# 香火传承(默认):入继养父优先
|
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
|
- # 若走入继路径,在当事人卡片标注"出继自xx"
|
|
|
|
|
|
|
+ # 若走入继路径,在当事人卡片标注"出继自xx,入继至yy"
|
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
|
- bio_name = (bio_parent.get('simplified_name') or bio_parent.get('name')) if bio_parent else None
|
|
|
|
|
- adopt_label = f"出继自{bio_name}" if bio_name else "出继"
|
|
|
|
|
|
|
+ # bio 父:sub_type=2 优先,否则取 normal (sub_type=0)
|
|
|
|
|
+ _bio_src = bio_parent or normal_parent
|
|
|
|
|
+ bio_name = (_bio_src.get('simplified_name') or _bio_src.get('name')) if _bio_src else None
|
|
|
|
|
+ adop_name = adoptive_parent.get('simplified_name') or adoptive_parent.get('name')
|
|
|
|
|
+ if bio_name and adop_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name},入继至{adop_name}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ adopt_label = "出继"
|
|
|
if depth == 0:
|
|
if depth == 0:
|
|
|
center['adoption_label'] = adopt_label
|
|
center['adoption_label'] = adopt_label
|
|
|
elif generations:
|
|
elif generations:
|
|
@@ -1984,21 +1992,29 @@ def get_lineage(member_id):
|
|
|
""", (member_id,))
|
|
""", (member_id,))
|
|
|
children = cursor.fetchall()
|
|
children = cursor.fetchall()
|
|
|
|
|
|
|
|
- # 香火模式:对入继子女标注"出继自xx";血脉模式:对出继子女标注"入继至xx"
|
|
|
|
|
|
|
+ # 香火模式:对入继子女标注"出继自xx,入继至yy";血脉模式:对出继子女同样双标
|
|
|
|
|
+ center_display = center.get('simplified_name') or center.get('name') or ''
|
|
|
for child in children:
|
|
for child in children:
|
|
|
if mode == 'incense' and child['sub_relation_type'] == 3:
|
|
if mode == 'incense' and child['sub_relation_type'] == 3:
|
|
|
|
|
+ # 亲生父:可能是 sub_type=2(出继标记)或 sub_type=0(普通关系)
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
|
SELECT p.simplified_name, p.name
|
|
SELECT p.simplified_name, p.name
|
|
|
FROM family_relation_info r
|
|
FROM family_relation_info r
|
|
|
JOIN family_member_info p ON r.parent_mid = p.id
|
|
JOIN family_member_info p ON r.parent_mid = p.id
|
|
|
- WHERE r.child_mid = %s AND r.sub_relation_type = 2 LIMIT 1
|
|
|
|
|
|
|
+ WHERE r.child_mid = %s AND r.sub_relation_type != 3
|
|
|
|
|
+ ORDER BY r.sub_relation_type DESC
|
|
|
|
|
+ LIMIT 1
|
|
|
""", (child['id'],))
|
|
""", (child['id'],))
|
|
|
bio_p = cursor.fetchone()
|
|
bio_p = cursor.fetchone()
|
|
|
- child['adoption_label'] = (
|
|
|
|
|
- f"出继自{bio_p['simplified_name'] or bio_p['name']}" if bio_p else "出继"
|
|
|
|
|
- )
|
|
|
|
|
- elif mode == 'blood' and child['sub_relation_type'] == 2:
|
|
|
|
|
- # 血脉模式下标注出继子女的去向(养父)
|
|
|
|
|
|
|
+ bio_name = (bio_p['simplified_name'] or bio_p['name']) if bio_p else None
|
|
|
|
|
+ if bio_name and center_display:
|
|
|
|
|
+ child['adoption_label'] = f"出继自{bio_name},入继至{center_display}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ child['adoption_label'] = f"出继自{bio_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ child['adoption_label'] = "出继"
|
|
|
|
|
+ elif mode == 'blood' and child['sub_relation_type'] in (0, 2):
|
|
|
|
|
+ # 血脉模式:找养父(sub_type=3)标注去向
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
|
SELECT p.simplified_name, p.name
|
|
SELECT p.simplified_name, p.name
|
|
|
FROM family_relation_info r
|
|
FROM family_relation_info r
|
|
@@ -2006,9 +2022,13 @@ def get_lineage(member_id):
|
|
|
WHERE r.child_mid = %s AND r.sub_relation_type = 3 LIMIT 1
|
|
WHERE r.child_mid = %s AND r.sub_relation_type = 3 LIMIT 1
|
|
|
""", (child['id'],))
|
|
""", (child['id'],))
|
|
|
adop_p = cursor.fetchone()
|
|
adop_p = cursor.fetchone()
|
|
|
- if adop_p:
|
|
|
|
|
- child['adoption_label'] = f"入继至{adop_p['simplified_name'] or adop_p['name']}"
|
|
|
|
|
- child['sub_relation_type'] = 2 # 保持供前端显示 adopted-out 样式
|
|
|
|
|
|
|
+ adop_name = (adop_p['simplified_name'] or adop_p['name']) if adop_p else None
|
|
|
|
|
+ if adop_name:
|
|
|
|
|
+ if center_display:
|
|
|
|
|
+ child['adoption_label'] = f"出继自{center_display},入继至{adop_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ child['adoption_label'] = f"入继至{adop_name}"
|
|
|
|
|
+ child['sub_relation_type'] = 2 # 保持供前端显示 adopted-out 样式
|
|
|
|
|
|
|
|
# Initialize children array
|
|
# Initialize children array
|
|
|
for child in children:
|
|
for child in children:
|
|
@@ -2043,18 +2063,25 @@ def get_lineage(member_id):
|
|
|
LIMIT 30
|
|
LIMIT 30
|
|
|
""", (parent_id, member_id))
|
|
""", (parent_id, member_id))
|
|
|
siblings = cursor.fetchall()
|
|
siblings = cursor.fetchall()
|
|
|
- # 为入继兄弟补充"出继自xx"标注
|
|
|
|
|
|
|
+ # 为入继兄弟补充"出继自xx,入继至yy"标注
|
|
|
|
|
+ parent_display = (generations[0]['ancestor'].get('simplified_name') or
|
|
|
|
|
+ generations[0]['ancestor'].get('name') or '') if generations else ''
|
|
|
for sib in siblings:
|
|
for sib in siblings:
|
|
|
if sib.get('sub_relation_type') == 3:
|
|
if sib.get('sub_relation_type') == 3:
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
|
SELECT p.simplified_name, p.name
|
|
SELECT p.simplified_name, p.name
|
|
|
FROM family_relation_info r
|
|
FROM family_relation_info r
|
|
|
JOIN family_member_info p ON r.parent_mid = p.id
|
|
JOIN family_member_info p ON r.parent_mid = p.id
|
|
|
- WHERE r.child_mid = %s AND r.sub_relation_type = 2 LIMIT 1
|
|
|
|
|
|
|
+ WHERE r.child_mid = %s AND r.sub_relation_type != 3
|
|
|
|
|
+ ORDER BY r.sub_relation_type DESC
|
|
|
|
|
+ LIMIT 1
|
|
|
""", (sib['id'],))
|
|
""", (sib['id'],))
|
|
|
sbp = cursor.fetchone()
|
|
sbp = cursor.fetchone()
|
|
|
- if sbp:
|
|
|
|
|
- sib['adoption_label'] = f"出继自{sbp['simplified_name'] or sbp['name']}"
|
|
|
|
|
|
|
+ bio_name = (sbp['simplified_name'] or sbp['name']) if sbp else None
|
|
|
|
|
+ if bio_name and parent_display:
|
|
|
|
|
+ sib['adoption_label'] = f"出继自{bio_name},入继至{parent_display}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ sib['adoption_label'] = f"出继自{bio_name}"
|
|
|
else:
|
|
else:
|
|
|
sib['adoption_label'] = "出继"
|
|
sib['adoption_label'] = "出继"
|
|
|
print(f"[Lineage Query] Step 4 - Get siblings ({len(siblings)}): {time.time() - step_start:.3f}s")
|
|
print(f"[Lineage Query] Step 4 - Get siblings ({len(siblings)}): {time.time() - step_start:.3f}s")
|
|
@@ -2117,15 +2144,25 @@ def get_ancestors_above(ancestor_id):
|
|
|
""", (ancestor_id,))
|
|
""", (ancestor_id,))
|
|
|
anchor_parents = cursor.fetchall()
|
|
anchor_parents = cursor.fetchall()
|
|
|
anchor_bio = None
|
|
anchor_bio = None
|
|
|
- has_adoptive = False
|
|
|
|
|
|
|
+ anchor_adop = None
|
|
|
|
|
+ anchor_normal = None
|
|
|
for ap in anchor_parents:
|
|
for ap in anchor_parents:
|
|
|
if ap['sub_relation_type'] == 3:
|
|
if ap['sub_relation_type'] == 3:
|
|
|
- has_adoptive = True
|
|
|
|
|
|
|
+ anchor_adop = ap
|
|
|
elif ap['sub_relation_type'] == 2:
|
|
elif ap['sub_relation_type'] == 2:
|
|
|
anchor_bio = ap
|
|
anchor_bio = ap
|
|
|
- if has_adoptive and anchor_bio:
|
|
|
|
|
- bio_name = anchor_bio.get('simplified_name') or anchor_bio.get('name')
|
|
|
|
|
- anchor_adoption_label = f"出继自{bio_name}" if bio_name else "出继"
|
|
|
|
|
|
|
+ else:
|
|
|
|
|
+ anchor_normal = ap
|
|
|
|
|
+ if anchor_adop:
|
|
|
|
|
+ _bio_src = anchor_bio or anchor_normal
|
|
|
|
|
+ bio_name = (_bio_src.get('simplified_name') or _bio_src.get('name')) if _bio_src else None
|
|
|
|
|
+ adop_name = anchor_adop.get('simplified_name') or anchor_adop.get('name')
|
|
|
|
|
+ if bio_name and adop_name:
|
|
|
|
|
+ anchor_adoption_label = f"出继自{bio_name},入继至{adop_name}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ anchor_adoption_label = f"出继自{bio_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ anchor_adoption_label = "出继"
|
|
|
|
|
|
|
|
for depth in range(max_depth):
|
|
for depth in range(max_depth):
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
@@ -2157,10 +2194,17 @@ def get_ancestors_above(ancestor_id):
|
|
|
parent = normal_parent or bio_parent or adoptive_parent
|
|
parent = normal_parent or bio_parent or adoptive_parent
|
|
|
else:
|
|
else:
|
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
|
- # 若走入继路径,在 current_id 对应的人物上标注"出继自xx"
|
|
|
|
|
|
|
+ # 若走入继路径,在 current_id 对应的人物上标注"出继自xx,入继至yy"
|
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
|
- bio_name = (bio_parent.get('simplified_name') or bio_parent.get('name')) if bio_parent else None
|
|
|
|
|
- adopt_label = f"出继自{bio_name}" if bio_name else "出继"
|
|
|
|
|
|
|
+ _bio_src = bio_parent or normal_parent
|
|
|
|
|
+ bio_name = (_bio_src.get('simplified_name') or _bio_src.get('name')) if _bio_src else None
|
|
|
|
|
+ adop_name = adoptive_parent.get('simplified_name') or adoptive_parent.get('name')
|
|
|
|
|
+ if bio_name and adop_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name},入继至{adop_name}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ adopt_label = "出继"
|
|
|
if depth == 0:
|
|
if depth == 0:
|
|
|
anchor_adoption_label = adopt_label
|
|
anchor_adoption_label = adopt_label
|
|
|
elif generations:
|
|
elif generations:
|
|
@@ -6115,8 +6159,15 @@ def api_get_lineage(member_id):
|
|
|
else:
|
|
else:
|
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
|
- bio_name = (bio_parent.get('simplified_name') or bio_parent.get('name')) if bio_parent else None
|
|
|
|
|
- adopt_label = f"出继自{bio_name}" if bio_name else "出继"
|
|
|
|
|
|
|
+ _bio_src = bio_parent or normal_parent
|
|
|
|
|
+ bio_name = (_bio_src.get('simplified_name') or _bio_src.get('name')) if _bio_src else None
|
|
|
|
|
+ adop_name = adoptive_parent.get('simplified_name') or adoptive_parent.get('name')
|
|
|
|
|
+ if bio_name and adop_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name},入继至{adop_name}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ adopt_label = "出继"
|
|
|
if depth == 0:
|
|
if depth == 0:
|
|
|
center['adoption_label'] = adopt_label
|
|
center['adoption_label'] = adopt_label
|
|
|
elif generations:
|
|
elif generations:
|
|
@@ -6202,19 +6253,24 @@ def api_get_lineage(member_id):
|
|
|
LIMIT 20
|
|
LIMIT 20
|
|
|
""", (member_id,))
|
|
""", (member_id,))
|
|
|
children = cursor.fetchall()
|
|
children = cursor.fetchall()
|
|
|
|
|
+ center_display_wx = center.get('simplified_name') or center.get('name') or ''
|
|
|
for c in children:
|
|
for c in children:
|
|
|
c['has_children'] = bool(c['has_children'])
|
|
c['has_children'] = bool(c['has_children'])
|
|
|
- # 入继子女:附加生父母信息,生成"出继自xx"标注
|
|
|
|
|
|
|
+ # 入继子女:附加生父信息,生成"出继自xx,入继至yy"标注
|
|
|
if c['sub_relation_type'] == 3:
|
|
if c['sub_relation_type'] == 3:
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
|
SELECT p.name, p.simplified_name
|
|
SELECT p.name, p.simplified_name
|
|
|
FROM family_relation_info r
|
|
FROM family_relation_info r
|
|
|
JOIN family_member_info p ON r.parent_mid = p.id
|
|
JOIN family_member_info p ON r.parent_mid = p.id
|
|
|
- WHERE r.child_mid = %s AND r.sub_relation_type = 2 LIMIT 1
|
|
|
|
|
|
|
+ WHERE r.child_mid = %s AND r.sub_relation_type != 3
|
|
|
|
|
+ ORDER BY r.sub_relation_type DESC
|
|
|
|
|
+ LIMIT 1
|
|
|
""", (c['id'],))
|
|
""", (c['id'],))
|
|
|
bp = cursor.fetchone()
|
|
bp = cursor.fetchone()
|
|
|
- if bp:
|
|
|
|
|
- bio_name = bp['simplified_name'] or bp['name']
|
|
|
|
|
|
|
+ bio_name = (bp['simplified_name'] or bp['name']) if bp else None
|
|
|
|
|
+ if bio_name and center_display_wx:
|
|
|
|
|
+ c['adoption_label'] = f"出继自{bio_name},入继至{center_display_wx}"
|
|
|
|
|
+ elif bio_name:
|
|
|
c['adoption_label'] = f"出继自{bio_name}"
|
|
c['adoption_label'] = f"出继自{bio_name}"
|
|
|
else:
|
|
else:
|
|
|
c['adoption_label'] = "出继"
|
|
c['adoption_label'] = "出继"
|
|
@@ -6302,15 +6358,25 @@ def api_get_ancestors_above(ancestor_id):
|
|
|
""", (ancestor_id,))
|
|
""", (ancestor_id,))
|
|
|
anchor_parents_wx = cursor.fetchall()
|
|
anchor_parents_wx = cursor.fetchall()
|
|
|
anchor_bio_wx = None
|
|
anchor_bio_wx = None
|
|
|
- has_adoptive_wx = False
|
|
|
|
|
|
|
+ anchor_adop_wx = None
|
|
|
|
|
+ anchor_normal_wx = None
|
|
|
for ap in anchor_parents_wx:
|
|
for ap in anchor_parents_wx:
|
|
|
if ap['sub_relation_type'] == 3:
|
|
if ap['sub_relation_type'] == 3:
|
|
|
- has_adoptive_wx = True
|
|
|
|
|
|
|
+ anchor_adop_wx = ap
|
|
|
elif ap['sub_relation_type'] == 2:
|
|
elif ap['sub_relation_type'] == 2:
|
|
|
anchor_bio_wx = ap
|
|
anchor_bio_wx = ap
|
|
|
- if has_adoptive_wx and anchor_bio_wx:
|
|
|
|
|
- bio_name_wx = anchor_bio_wx.get('simplified_name') or anchor_bio_wx.get('name')
|
|
|
|
|
- anchor_adoption_label_wx = f"出继自{bio_name_wx}" if bio_name_wx else "出继"
|
|
|
|
|
|
|
+ else:
|
|
|
|
|
+ anchor_normal_wx = ap
|
|
|
|
|
+ if anchor_adop_wx:
|
|
|
|
|
+ _bio_src_wx = anchor_bio_wx or anchor_normal_wx
|
|
|
|
|
+ bio_name_wx = (_bio_src_wx.get('simplified_name') or _bio_src_wx.get('name')) if _bio_src_wx else None
|
|
|
|
|
+ adop_name_wx = anchor_adop_wx.get('simplified_name') or anchor_adop_wx.get('name')
|
|
|
|
|
+ if bio_name_wx and adop_name_wx:
|
|
|
|
|
+ anchor_adoption_label_wx = f"出继自{bio_name_wx},入继至{adop_name_wx}"
|
|
|
|
|
+ elif bio_name_wx:
|
|
|
|
|
+ anchor_adoption_label_wx = f"出继自{bio_name_wx}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ anchor_adoption_label_wx = "出继"
|
|
|
|
|
|
|
|
for depth in range(max_depth):
|
|
for depth in range(max_depth):
|
|
|
cursor.execute("""
|
|
cursor.execute("""
|
|
@@ -6339,10 +6405,17 @@ def api_get_ancestors_above(ancestor_id):
|
|
|
normal_parent = p
|
|
normal_parent = p
|
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
parent = adoptive_parent or normal_parent or bio_parent
|
|
|
|
|
|
|
|
- # 若走入继路径,在 current_id 对应的人物上标注"出继自xx"
|
|
|
|
|
|
|
+ # 若走入继路径,在 current_id 对应的人物上标注"出继自xx,入继至yy"
|
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
if parent is adoptive_parent and adoptive_parent is not None:
|
|
|
- bio_name = (bio_parent.get('simplified_name') or bio_parent.get('name')) if bio_parent else None
|
|
|
|
|
- adopt_label = f"出继自{bio_name}" if bio_name else "出继"
|
|
|
|
|
|
|
+ _bio_src = bio_parent or normal_parent
|
|
|
|
|
+ bio_name = (_bio_src.get('simplified_name') or _bio_src.get('name')) if _bio_src else None
|
|
|
|
|
+ adop_name = adoptive_parent.get('simplified_name') or adoptive_parent.get('name')
|
|
|
|
|
+ if bio_name and adop_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name},入继至{adop_name}"
|
|
|
|
|
+ elif bio_name:
|
|
|
|
|
+ adopt_label = f"出继自{bio_name}"
|
|
|
|
|
+ else:
|
|
|
|
|
+ adopt_label = "出继"
|
|
|
if depth == 0:
|
|
if depth == 0:
|
|
|
anchor_adoption_label_wx = adopt_label
|
|
anchor_adoption_label_wx = adopt_label
|
|
|
elif generations:
|
|
elif generations:
|