Commit 675d08ad authored by 林洋洋's avatar 林洋洋

Merge branch 'dev_1.0.0' of http://gitlab.solr.com.cn:10000/linyangyang/db_gpt into dev_1.0.0

parents 3016d7a4 e6f925b0
......@@ -155,6 +155,8 @@ logswebserver.log.*
# Ignore for now
thirdparty
/file/**
#web
# dependencies
/web/node_modules
......
......@@ -43,11 +43,10 @@ class MediaDal(DalBase):
await self.db.execute(sql)
async def get_count_by_groupIds(self, ids: list) -> int:
async with Session() as session:
stmt = select(func.count(self.model.id)).where(self.model.group_id.in_(ids))
result = await session.execute(stmt)
count = result.scalar()
return count
stmt = select(func.count(self.model.id)).where(self.model.group_id.in_(ids))
result = await self.db.execute(stmt)
count = result.scalar()
return count
class GroupDal(DalBase):
......@@ -80,11 +79,10 @@ class QuestionDal(DalBase):
await self.db.execute(sql)
class CorrelationDal(DalBase):
def __init__(self, db: AsyncSession):
super(CorrelationDal, self).__init__()
self.db = db
self.model = models.VadminCorrelation
self.schema = schemas.CorrelationOut
\ No newline at end of file
self.schema = schemas.CorrelationOut
......@@ -36,9 +36,9 @@ class GroupOut(Group):
class Question(BaseModel):
title: str
key_word: str
answer: str
title: str | None = None
key_word: str | None = None
answer: str | None = None
group_id: int | None = 0
......
......@@ -56,7 +56,7 @@ async def group_del(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth(
media_counts = await crud.MediaDal(auth.db).get_count_by_groupIds(ids.ids)
if media_counts > 0:
return ErrorResponse("分组内不为空,无法删除")
# await crud.GroupDal(auth.db).delete_datas(ids.ids, v_soft=True)
await crud.GroupDal(auth.db).delete_datas(ids.ids, v_soft=True)
return SuccessResponse("删除成功")
......
......@@ -21,6 +21,7 @@ class SensitiveSchemas(BaseModel):
class SensitiveInDic(SensitiveSchemas):
model_config = ConfigDict(from_attributes=True)
id :int
word_name: str | None = ""
class SensitiveIn(SensitiveSchemas):
......
......@@ -24,6 +24,7 @@ class SimilarInDic(SimilarSchemas):
"""
创建近义词
"""
id :int
word_name: str
similar_name: str | None = ""
......
......@@ -15,6 +15,8 @@ from dbgpt.app.apps.vadmin.word.params.sensitive import SensitiveParams
from dbgpt.app.apps.vadmin.word import crud
from fastapi.encoders import jsonable_encoder
from ...core.dependencies import IdList
router = APIRouter()
......@@ -22,7 +24,7 @@ router = APIRouter()
# 同义词管理
###########################################################
@router.get("/get_similars", summary="获取同义词列表")
async def get_similars(para: SimilarParams = Depends(), auth: Auth = Depends(OpenAuth())):
async def get_similars(para: SimilarParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
v_schema = schemas.similar.SimilarInDic
datas, count = await crud.SimilarDal(auth.db).get_datas(
**para.dict(),
......@@ -32,7 +34,7 @@ async def get_similars(para: SimilarParams = Depends(), auth: Auth = Depends(Ope
return SuccessResponse(datas, count=count)
@router.post("/create_similar", summary="创建同义词")
async def create_similar(qdata: Request, auth: Auth = Depends(OpenAuth())):
async def create_similar(qdata: Request, auth: Auth = Depends(FullAdminAuth())):
if qdata is None:
print('create_similar is None')
else:
......@@ -44,24 +46,19 @@ async def create_similar(qdata: Request, auth: Auth = Depends(OpenAuth())):
return SuccessResponse(await crud.SimilarDal(auth.db).create_data(data=simi_data))
@router.post("/delete_similars", summary="根据id删除同义词")
async def delete_similars(data: Request, auth: Auth = Depends(OpenAuth())):
if data is None:
return ErrorResponse("删除同义词请求参数为空!")
data_id = data.query_params['word_id']
similarids = [data_id]
await crud.SimilarDal(auth.db).delete_datas(ids=similarids, v_soft=True)
async def delete_similars(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())):
await crud.SimilarDal(auth.db).delete_datas(ids=ids.ids, v_soft=True)
return SuccessResponse("删除成功")
@router.post("/update_similar_byid", summary="根据id修改同义词")
async def update_similar_byid(data: Request, auth: Auth = Depends(OpenAuth())):
async def update_similar_byid(data: Request, auth: Auth = Depends(FullAdminAuth())):
if data is None:
print('SimilarIn is None')
return ErrorResponse("不能修改当前近义词")
else:
print(f"word_id:{data.query_params['word_id']} req词条:{data.query_params['word_name']} req近义词:{data.query_params['similar_name']} ")
print(f"word_id:{data.query_params['id']} req词条:{data.query_params['word_name']} req近义词:{data.query_params['similar_name']} ")
data_id = data.query_params['word_id']
data_id = data.query_params['id']
sdata = SimilarUpdate
sdata.word_name = data.query_params['word_name']
......@@ -77,7 +74,7 @@ async def update_similar_byid(data: Request, auth: Auth = Depends(OpenAuth())):
# 敏感词管理
###########################################################
@router.post("/create_sensitive", summary="创建敏感词")
async def create_sensitive(qdata: Request, auth: Auth = Depends(OpenAuth())):
async def create_sensitive(qdata: Request, auth: Auth = Depends(FullAdminAuth())):
if qdata is None:
print('create_sensitive is None')
else:
......@@ -88,7 +85,7 @@ async def create_sensitive(qdata: Request, auth: Auth = Depends(OpenAuth())):
return SuccessResponse(await crud.SensitiveDal(auth.db).create_data(data=Sensit_data))
@router.get("/get_sensitives", summary="获取敏感词列表")
async def get_sensitives(para: SensitiveParams = Depends(), auth: Auth = Depends(OpenAuth())):
async def get_sensitives(para: SensitiveParams = Depends(), auth: Auth = Depends(FullAdminAuth())):
v_schema = schemas.sensitive.SensitiveInDic
datas, count = await crud.SensitiveDal(auth.db).get_datas(
**para.dict(),
......@@ -98,14 +95,14 @@ async def get_sensitives(para: SensitiveParams = Depends(), auth: Auth = Depends
return SuccessResponse(datas, count=count)
@router.post("/update_sensitive_byid", summary="根据id修改敏感词")
async def update_sensitive_byid(data: Request, auth: Auth = Depends(OpenAuth())):
async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAuth())):
if data is None:
print('SimilarIn is None')
return ErrorResponse("不能修改当前敏感词")
else:
print(f"word_id:{data.query_params['word_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['word_id']
data_id = data.query_params['id']
sdata = SensitiveUpdate
sdata.word_name = data.query_params['word_name']
......@@ -117,14 +114,6 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(OpenAuth()))
return SuccessResponse("修改成功")
@router.post("/delete_sensitives", summary="根据id删除敏感词")
async def delete_sensitives(data: Request, auth: Auth = Depends(OpenAuth())):
if data is None:
print('sensitive request is None')
return ErrorResponse("不能删除当前敏感词")
else:
print(f"word_id:{data.query_params['word_id']} ")
data_id = data.query_params['word_id']
sensitiveids = [data_id]
await crud.SensitiveDal(auth.db).delete_datas(ids=sensitiveids, v_soft=True)
async def delete_sensitives(ids: IdList = Depends(), auth: Auth = Depends(FullAdminAuth())):
await crud.SensitiveDal(auth.db).delete_datas(ids=ids.ids, v_soft=True)
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