mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 09:17:06 +08:00
fix(Terminology Configuration): Term name, synonyms cannot be repeated
This commit is contained in:
@@ -13,7 +13,8 @@ router = APIRouter(tags=["Terminology"], prefix="/system/terminology")
|
||||
@router.get("/page/{current_page}/{page_size}")
|
||||
async def pager(session: SessionDep, current_user: CurrentUser, current_page: int, page_size: int,
|
||||
word: Optional[str] = Query(None, description="搜索术语(可选)")):
|
||||
current_page, page_size, total_count, total_pages, _list = page_terminology(session, current_page, page_size, word, current_user.oid)
|
||||
current_page, page_size, total_count, total_pages, _list = page_terminology(session, current_page, page_size, word,
|
||||
current_user.oid)
|
||||
|
||||
return {
|
||||
"current_page": current_page,
|
||||
@@ -30,7 +31,7 @@ async def create_or_update(session: SessionDep, current_user: CurrentUser, trans
|
||||
if info.id:
|
||||
return update_terminology(session, info, oid, trans)
|
||||
else:
|
||||
return create_terminology(session, info, oid)
|
||||
return create_terminology(session, info, oid, trans)
|
||||
|
||||
|
||||
@router.delete("")
|
||||
|
||||
@@ -62,7 +62,6 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
|
||||
if current_page > total_pages:
|
||||
current_page = 1
|
||||
|
||||
|
||||
# 步骤3:获取分页后的父节点ID
|
||||
paginated_parent_ids = (
|
||||
parent_ids_subquery
|
||||
@@ -147,10 +146,22 @@ def page_terminology(session: SessionDep, current_page: int = 1, page_size: int
|
||||
return current_page, page_size, total_count, total_pages, _list
|
||||
|
||||
|
||||
def create_terminology(session: SessionDep, info: TerminologyInfo, oid: int):
|
||||
def create_terminology(session: SessionDep, info: TerminologyInfo, oid: int, trans: Trans):
|
||||
create_time = datetime.datetime.now()
|
||||
parent = Terminology(word=info.word, create_time=create_time, description=info.description, oid=oid)
|
||||
|
||||
words = [info.word]
|
||||
for child in info.other_words:
|
||||
if child in words:
|
||||
raise Exception(trans("i18n_terminology.cannot_be_repeated"))
|
||||
else:
|
||||
words.append(child)
|
||||
|
||||
exists = session.query(
|
||||
session.query(Terminology).filter(and_(Terminology.word.in_(words), Terminology.oid == oid)).exists()).scalar()
|
||||
if exists:
|
||||
raise Exception(trans("i18n_terminology.exists_in_db"))
|
||||
|
||||
result = Terminology(**parent.model_dump())
|
||||
|
||||
session.add(parent)
|
||||
@@ -185,6 +196,26 @@ def update_terminology(session: SessionDep, info: TerminologyInfo, oid: int, tra
|
||||
if count == 0:
|
||||
raise Exception(trans('i18n_terminology.terminology_not_exists'))
|
||||
|
||||
words = [info.word]
|
||||
for child in info.other_words:
|
||||
if child in words:
|
||||
raise Exception(trans("i18n_terminology.cannot_be_repeated"))
|
||||
else:
|
||||
words.append(child)
|
||||
|
||||
exists = session.query(
|
||||
session.query(Terminology).filter(
|
||||
Terminology.word.in_(words),
|
||||
Terminology.oid == oid,
|
||||
or_(
|
||||
Terminology.pid != info.id,
|
||||
and_(Terminology.pid.is_(None), Terminology.id != info.id)
|
||||
),
|
||||
Terminology.id != info.id
|
||||
).exists()).scalar()
|
||||
if exists:
|
||||
raise Exception(trans("i18n_terminology.exists_in_db"))
|
||||
|
||||
stmt = update(Terminology).where(and_(Terminology.id == info.id)).values(
|
||||
word=info.word,
|
||||
description=info.description,
|
||||
@@ -211,7 +242,6 @@ def update_terminology(session: SessionDep, info: TerminologyInfo, oid: int, tra
|
||||
# embedding
|
||||
run_save_embeddings([info.id])
|
||||
|
||||
|
||||
return info.id
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
"invalid_origin": "Domain verification failed [{origin}]"
|
||||
},
|
||||
"i18n_terminology": {
|
||||
"terminology_not_exists": "Terminology does not exists"
|
||||
"terminology_not_exists": "Terminology does not exists",
|
||||
"cannot_be_repeated": "Term name, synonyms cannot be repeated",
|
||||
"exists_in_db": "Term name, synonyms exists"
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,8 @@
|
||||
"invalid_origin": "域名校验失败【{origin}】"
|
||||
},
|
||||
"i18n_terminology": {
|
||||
"terminology_not_exists": "该术语不存在"
|
||||
"terminology_not_exists": "该术语不存在",
|
||||
"cannot_be_repeated": "术语名称,同义词不能重复",
|
||||
"exists_in_db": "术语名称,同义词已存在"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user