修改切换风格接口, 添加新的参数robot_role_id, 修改数据库更新语句

This commit is contained in:
haotian 2025-08-25 17:09:59 +08:00
parent 85641967f0
commit 106a7417ff
5 changed files with 32 additions and 17 deletions

View File

@ -20,22 +20,22 @@ from utils.response_util import ResponseUtil
explanation_style_robot_pairController = APIRouter(prefix='/system/explanation_style_robot_pair', dependencies=[Depends(LoginService.get_current_user)])
@explanation_style_robot_pairController.get(
'/list', response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:list'))]
)
async def get_system_explanation_style_robot_pair_list(
request: Request,
robot_id: int,
# explanation_style_robot_pair_page_query: Explanation_style_robot_pairPageQueryModel = Depends(Explanation_style_robot_pairPageQueryModel.as_query),
query_db: AsyncSession = Depends(get_db),
):
# 获取分页数据
# explanation_style_robot_pair_page_query_result = await Explanation_style_robot_pairService.get_explanation_style_robot_pair_list_services(query_db, explanation_style_robot_pair_page_query, is_page=False)
# @explanation_style_robot_pairController.get(
# '/list', response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:list'))]
# )
# async def get_system_explanation_style_robot_pair_list(
# request: Request,
# robot_id: int,
# # explanation_style_robot_pair_page_query: Explanation_style_robot_pairPageQueryModel = Depends(Explanation_style_robot_pairPageQueryModel.as_query),
# query_db: AsyncSession = Depends(get_db),
# ):
# # 获取分页数据
# # explanation_style_robot_pair_page_query_result = await Explanation_style_robot_pairService.get_explanation_style_robot_pair_list_services(query_db, explanation_style_robot_pair_page_query, is_page=False)
explanation_style_robot_pair_query_result = await Explanation_style_robot_pairService.get_style_robot_pair_list_services(query_db, robot_id)
logger.info('获取成功')
# explanation_style_robot_pair_query_result = await Explanation_style_robot_pairService.get_style_robot_pair_list_services(query_db, robot_id)
# logger.info('获取成功')
return ResponseUtil.success(data=explanation_style_robot_pair_query_result)
# return ResponseUtil.success(data=explanation_style_robot_pair_query_result)
# 切换风格
@explanation_style_robot_pairController.post('/switch_style')

View File

@ -17,6 +17,16 @@ class Explanation_style_robot_pairDao:
@classmethod
async def get_robot_role_style(cls, db: AsyncSession, robot_id: int, role_id: int):
"""根据机器人id和角色id获取机器人角色样式
Args:
db (AsyncSession): 数据库会话
robot_id (int): 机器人id
role_id (int): 角色id
Returns:
_type_: _description_
"""
stmt = (
select(ExplanationStyleRobotPairing.pairing_id, ExplanationStyleRobotPairing.explanation_style_id, ExplanationStyle.name, ExplanationStyle.detail, ExplanationStyleRobotPairing.status)
@ -31,7 +41,7 @@ class Explanation_style_robot_pairDao:
@classmethod
async def switch_explanation_style(cls, db: AsyncSession, robot_id: int = None, pairing_id: int = None, status:str = '0', update_by: str = None):
async def switch_explanation_style(cls, db: AsyncSession, robot_id: int = None, pairing_id: int = None, robot_role_id: str = None ,status:str = '0', update_by: str = None):
condition = list()
@ -39,6 +49,8 @@ class Explanation_style_robot_pairDao:
condition.append(ExplanationStyleRobotPairing.robot_id == robot_id)
if pairing_id:
condition.append(ExplanationStyleRobotPairing.pairing_id == pairing_id)
if robot_role_id:
condition.append(ExplanationStyleRobotPairing.robot_role_id == robot_role_id)
query = (
update(ExplanationStyleRobotPairing)

View File

@ -12,6 +12,7 @@ class SwitchExplanationStyleModel(BaseModel):
pairing_id: int = Field(default=None, description='主键ID')
robot_id: int = Field(default=None, description='机器人ID关联robot_info表')
robot_role_id: int = Field(default=None, description='机器人角色ID关联robot_role表')
update_by: Optional[str] = Field(default=None, description='修改者')

View File

@ -19,9 +19,9 @@ class Explanation_style_robot_pairService:
async def switch_explanation_style_services(cls, query_db: AsyncSession, switch_explanation_style: SwitchExplanationStyleModel):
try:
# 现将所有风格都置为0
result1 = await Explanation_style_robot_pairDao.switch_explanation_style(query_db, switch_explanation_style.robot_id, None, "0", switch_explanation_style.update_by)
result1 = await Explanation_style_robot_pairDao.switch_explanation_style(query_db, switch_explanation_style.robot_id, None, switch_explanation_style.robot_role_id ,"0", switch_explanation_style.update_by)
# 再将选择的风格置为1
result2 = await Explanation_style_robot_pairDao.switch_explanation_style(query_db, None, switch_explanation_style.pairing_id, "1", switch_explanation_style.update_by)
result2 = await Explanation_style_robot_pairDao.switch_explanation_style(query_db, None, switch_explanation_style.pairing_id,None ,"1", switch_explanation_style.update_by)
count = result2.rowcount
await query_db.commit()

View File

@ -36,9 +36,11 @@ class PairingService:
pairing_list = await PairingDao.get_role_pairing_list(query_db, robot_id)
style = None
# print(pairing_list)
for pairing in pairing_list:
if pairing["status"] == '1':
# print(pairing)
style = await Explanation_style_robot_pairDao.get_robot_role_style(query_db, robot_id, pairing["robot_role_id"])