Files
Mutual_Fund/repositories/sensitive_word.py
T

29 lines
1.0 KiB
Python

"""sensitive_word 敏感词仓储:取启用态词库(发送终审合规拦截唯一来源,与 Agent 同源)。"""
from __future__ import annotations
from sqlalchemy import select
from model.sensitive_word import SensitiveWord
from repositories.base import BaseRepository
# 词库启用态(DDL:status 启用/停用;未入 common_const,与 schema 注释一致)
_ACTIVE_STATUS = "启用"
class SensitiveWordRepo(BaseRepository):
model = SensitiveWord
async def list_active(self) -> list[SensitiveWord]:
"""取全部启用态敏感词,供发送终审扫描。"""
return list(
(
await self.db.scalars(
select(SensitiveWord).where(SensitiveWord.status == _ACTIVE_STATUS)
)
).all()
)
async def list_active_words(self) -> list[str]:
"""Return enabled words as strings for Agent content scanning."""
return [item if isinstance(item, str) else item.word for item in await self.list_active()]