|
|
@@ -551,24 +551,12 @@ async def ingest_docx_entries(entries: list[dict], engine, start_idx: int = 0):
|
|
|
|
|
|
|
|
|
async def dedup_old_versions(engine):
|
|
|
- """覆盖性新增:同名药品如果存在非 2025 版的旧记录,标记为 inactive"""
|
|
|
- async with engine.begin() as conn:
|
|
|
- result = await conn.execute(
|
|
|
- text("""
|
|
|
- UPDATE drugs
|
|
|
- SET is_active = FALSE, updated_at = NOW()
|
|
|
- WHERE is_active = TRUE
|
|
|
- AND source_version != '2025年版'
|
|
|
- AND name IN (
|
|
|
- SELECT name FROM drugs
|
|
|
- WHERE source_version = '2025年版' AND is_active = TRUE
|
|
|
- )
|
|
|
- """)
|
|
|
- )
|
|
|
- # asyncpg 不支持 rowcount,用另一种方式
|
|
|
- count = getattr(result, 'rowcount', 0)
|
|
|
- if count > 0:
|
|
|
- print(f" 🧹 去重: 标记 {count} 个旧版药品为 inactive")
|
|
|
+ """2025 版为主,2020 版保留为补充数据。
|
|
|
+ 不在数据库层面标记 inactive,由检索层通过 source_version 优先级(+0.05)
|
|
|
+ 自动将 2025 版排在前面,2020 版作为降级补充。
|
|
|
+ """
|
|
|
+ print(" 📋 版本共存:2025 版(优先)+ 2020 版(补充),均保持 active")
|
|
|
+ # 不再自动标记旧版为 inactive
|
|
|
|
|
|
|
|
|
async def main():
|