from datetime import datetime from fastapi import APIRouter, Depends, Form, Request from pydantic_validation_decorator import ValidateFields from sqlalchemy.ext.asyncio import AsyncSession from config.enums import BusinessType from config.get_db import get_db from module_admin.annotation.log_annotation import Log from module_admin.aspect.interface_auth import CheckUserInterfaceAuth from module_admin.entity.vo.user_vo import CurrentUserModel from module_admin.service.login_service import LoginService from module_admin.service.explanation_style_robot_pair_service import Explanation_style_robot_pairService from module_admin.entity.vo.explanation_style_robot_pair_vo import DeleteExplanation_style_robot_pairModel, \ Explanation_style_robot_pairModel, Explanation_style_robot_pairPageQueryModel, SwitchExplanationStyleModel from utils.common_util import bytes2file_response from utils.log_util import logger from utils.page_util import PageResponseModel 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_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) # 切换风格 @explanation_style_robot_pairController.post('/switch_style') async def switch_explanation_style( request: Request, switch_explanation_style: SwitchExplanationStyleModel, query_db: AsyncSession = Depends(get_db), current_user: CurrentUserModel = Depends(LoginService.get_current_user), ): switch_explanation_style.update_by = current_user.user.user_name switch_explanation_style_message = await Explanation_style_robot_pairService.switch_explanation_style_services(query_db, switch_explanation_style) if switch_explanation_style_message.is_success: logger.info(switch_explanation_style_message.message) return ResponseUtil.success(msg=switch_explanation_style_message.message) else: return ResponseUtil.error(msg=switch_explanation_style_message.message) # @explanation_style_robot_pairController.post('', dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:add'))]) # @ValidateFields(validate_model='add_explanation_style_robot_pair') # @Log(title='讲解风格--机器人配对', business_type=BusinessType.INSERT) # async def add_system_explanation_style_robot_pair( # request: Request, # add_explanation_style_robot_pair: Explanation_style_robot_pairModel, # query_db: AsyncSession = Depends(get_db), # current_user: CurrentUserModel = Depends(LoginService.get_current_user), # ): # add_explanation_style_robot_pair.create_time = datetime.now() # add_explanation_style_robot_pair.create_by = current_user.user.user_name # add_explanation_style_robot_pair.update_time = datetime.now() # add_explanation_style_robot_pair.update_by = current_user.user.user_name # add_explanation_style_robot_pair_result = await Explanation_style_robot_pairService.add_explanation_style_robot_pair_services(query_db, add_explanation_style_robot_pair) # logger.info(add_explanation_style_robot_pair_result.message) # # return ResponseUtil.success(msg=add_explanation_style_robot_pair_result.message) # @explanation_style_robot_pairController.put('', dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:edit'))]) # @ValidateFields(validate_model='edit_explanation_style_robot_pair') # @Log(title='讲解风格--机器人配对', business_type=BusinessType.UPDATE) # async def edit_system_explanation_style_robot_pair( # request: Request, # edit_explanation_style_robot_pair: Explanation_style_robot_pairModel, # query_db: AsyncSession = Depends(get_db), # current_user: CurrentUserModel = Depends(LoginService.get_current_user), # ): # edit_explanation_style_robot_pair.update_by = current_user.user.user_name # edit_explanation_style_robot_pair.update_time = datetime.now() # edit_explanation_style_robot_pair_result = await Explanation_style_robot_pairService.edit_explanation_style_robot_pair_services(query_db, edit_explanation_style_robot_pair) # logger.info(edit_explanation_style_robot_pair_result.message) # # return ResponseUtil.success(msg=edit_explanation_style_robot_pair_result.message) # @explanation_style_robot_pairController.delete('/{pairing_ids}', dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:remove'))]) # @Log(title='讲解风格--机器人配对', business_type=BusinessType.DELETE) # async def delete_system_explanation_style_robot_pair(request: Request, pairing_ids: str, query_db: AsyncSession = Depends(get_db)): # delete_explanation_style_robot_pair = DeleteExplanation_style_robot_pairModel(pairingIds=pairing_ids) # delete_explanation_style_robot_pair_result = await Explanation_style_robot_pairService.delete_explanation_style_robot_pair_services(query_db, delete_explanation_style_robot_pair) # logger.info(delete_explanation_style_robot_pair_result.message) # # return ResponseUtil.success(msg=delete_explanation_style_robot_pair_result.message) # @explanation_style_robot_pairController.get( # '/{pairing_id}', response_model=Explanation_style_robot_pairModel, dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:query'))] # ) # async def query_detail_system_explanation_style_robot_pair(request: Request, pairing_id: int, query_db: AsyncSession = Depends(get_db)): # explanation_style_robot_pair_detail_result = await Explanation_style_robot_pairService.explanation_style_robot_pair_detail_services(query_db, pairing_id) # logger.info(f'获取pairing_id为{pairing_id}的信息成功') # # return ResponseUtil.success(data=explanation_style_robot_pair_detail_result) # @explanation_style_robot_pairController.post('/export', dependencies=[Depends(CheckUserInterfaceAuth('system:explanation_style_robot_pair:export'))]) # @Log(title='讲解风格--机器人配对', business_type=BusinessType.EXPORT) # async def export_system_explanation_style_robot_pair_list( # request: Request, # explanation_style_robot_pair_page_query: Explanation_style_robot_pairPageQueryModel = Form(), # query_db: AsyncSession = Depends(get_db), # ): # # 获取全量数据 # explanation_style_robot_pair_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_export_result = await Explanation_style_robot_pairService.export_explanation_style_robot_pair_list_services(explanation_style_robot_pair_query_result) # logger.info('导出成功') # # return ResponseUtil.streaming(data=bytes2file_response(explanation_style_robot_pair_export_result))