Commit 8d30c816 authored by 于飞's avatar 于飞

添加敏感词的时候,加入过滤列表中

parent 234a6ad2
...@@ -143,6 +143,15 @@ class SensitiveDal(DalBase): ...@@ -143,6 +143,15 @@ class SensitiveDal(DalBase):
""" """
return list(queryset.all()) return list(queryset.all())
async def get_sensitive_byid(self, uid:int)-> Any:
sql = select(models.sensitive.VadminWordSensitive).where(models.sensitive.VadminWordSensitive.id == uid)
queryset = await self.db.scalars(sql)
"""
for row in dataqs:
print(f"编号:{row.id} 词条:{row.word_name} ")
"""
return queryset.first()
async def update_sensitives(self, ids: [], data: SensitiveUpdate): async def update_sensitives(self, ids: [], data: SensitiveUpdate):
""" """
修改敏感词 修改敏感词
......
...@@ -14,7 +14,7 @@ from dbgpt.app.apps.vadmin.word.schemas.sensitive import SensitiveSchemas, Sensi ...@@ -14,7 +14,7 @@ from dbgpt.app.apps.vadmin.word.schemas.sensitive import SensitiveSchemas, Sensi
from dbgpt.app.apps.vadmin.word.params.sensitive import SensitiveParams from dbgpt.app.apps.vadmin.word.params.sensitive import SensitiveParams
from dbgpt.app.apps.vadmin.word import crud from dbgpt.app.apps.vadmin.word import crud
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
from dbgpt.app.apps.utils.filter import mydfafiter, mydfafiter_picture, mydfafiter_question, mydfafiter_video
from ...core.dependencies import IdList from ...core.dependencies import IdList
router = APIRouter() router = APIRouter()
...@@ -82,6 +82,10 @@ async def create_sensitive(qdata: Request, auth: Auth = Depends(FullAdminAuth()) ...@@ -82,6 +82,10 @@ async def create_sensitive(qdata: Request, auth: Auth = Depends(FullAdminAuth())
Sensit_data = SensitiveSchemas() Sensit_data = SensitiveSchemas()
Sensit_data.word_name = qdata.query_params['word_name'] Sensit_data.word_name = qdata.query_params['word_name']
# 向敏感词字典中新加一条敏感词
mydfafiter.add(Sensit_data.word_name)
return SuccessResponse(await crud.SensitiveDal(auth.db).create_data(data=Sensit_data)) return SuccessResponse(await crud.SensitiveDal(auth.db).create_data(data=Sensit_data))
@router.get("/get_sensitives", summary="获取敏感词列表") @router.get("/get_sensitives", summary="获取敏感词列表")
...@@ -103,10 +107,16 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAut ...@@ -103,10 +107,16 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAut
print(f"word_id:{data.query_params['id']} req词条:{data.query_params['word_name']} ") print(f"word_id:{data.query_params['id']} req词条:{data.query_params['word_name']} ")
data_id = data.query_params['id'] data_id = data.query_params['id']
sdata = SensitiveUpdate sdata = SensitiveUpdate
sdata.word_name = data.query_params['word_name'] sdata.word_name = data.query_params['word_name']
sensitive_datas = await crud.SensitiveDal(auth.db).get_sensitive_byid(data_id)
if sensitive_datas != None:
print(f"------编辑时要删除旧的敏感词------>:{sensitive_datas.word_name}")
mydfafiter.remove(sensitive_datas.word_name)
print(f"------编辑时要添加新的敏感词------>:{sdata.word_name}")
mydfafiter.add(sdata.word_name)
sensitiveids = [] sensitiveids = []
sensitiveids.append(data_id) sensitiveids.append(data_id)
...@@ -116,4 +126,8 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAut ...@@ -116,4 +126,8 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAut
@router.post("/delete_sensitives", summary="根据id删除敏感词") @router.post("/delete_sensitives", summary="根据id删除敏感词")
async def delete_sensitives(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())): async def delete_sensitives(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())):
await crud.SensitiveDal(auth.db).delete_datas(ids=ids.ids, v_soft=True) await crud.SensitiveDal(auth.db).delete_datas(ids=ids.ids, v_soft=True)
sensitive_datas = await crud.SensitiveDal(auth.db).get_sensitive_byid(ids.ids[0])
if sensitive_datas != None:
print(f"------要删除的敏感词------>:{sensitive_datas}")
mydfafiter.remove(sensitive_datas.word_name)
return SuccessResponse("删除成功") return SuccessResponse("删除成功")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment