130 lines
5.1 KiB
Python
130 lines
5.1 KiB
Python
from datetime import datetime
|
|
from typing import Annotated
|
|
|
|
from fastapi import Path, Query, Request, Response
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from common.annotation.log_annotation import Log
|
|
from common.aspect.db_seesion import DBSessionDependency
|
|
from common.aspect.interface_auth import UserInterfaceAuthDependency
|
|
from common.aspect.pre_auth import CurrentUserDependency, PreAuthDependency
|
|
from common.enums import BusinessType
|
|
from common.router import APIRouterPro
|
|
from common.vo import DataResponseModel, PageResponseModel, ResponseBaseModel
|
|
from module_admin.entity.vo.user_vo import CurrentUserModel
|
|
from module_business.dependency.test_batch_dependency import TestBatchScopeDependency
|
|
from module_business.domain.test_batch_scope import TestBatchScope
|
|
from module_business.entity.vo.master_vo import DeleteStrainModel, StrainModel, StrainPageQueryModel
|
|
from module_business.service.master_service import MasterService
|
|
from utils.response_util import ResponseUtil
|
|
|
|
strain_controller = APIRouterPro(
|
|
prefix='/master/strain', tags=['基础资料-菌种管理'], dependencies=[PreAuthDependency()]
|
|
)
|
|
|
|
|
|
@strain_controller.get(
|
|
'/list',
|
|
summary='获取菌种分页列表接口',
|
|
description='用于获取菌种分页列表',
|
|
response_model=PageResponseModel[StrainModel],
|
|
dependencies=[UserInterfaceAuthDependency('master:strain:list')],
|
|
)
|
|
async def get_master_strain_list(
|
|
request: Request,
|
|
strain_page_query: Annotated[StrainPageQueryModel, Query()],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
strain_page_query_result = await MasterService.list_strain(query_db, strain_page_query, scope, is_page=True)
|
|
|
|
return ResponseUtil.success(model_content=strain_page_query_result)
|
|
|
|
|
|
@strain_controller.get(
|
|
'/{strain_id}',
|
|
summary='获取菌种详情接口',
|
|
description='用于获取指定菌种的详细信息',
|
|
response_model=DataResponseModel[StrainModel],
|
|
dependencies=[UserInterfaceAuthDependency('master:strain:query')],
|
|
)
|
|
async def query_detail_master_strain(
|
|
request: Request,
|
|
strain_id: Annotated[int, Path(gt=0, description='菌种ID')],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
strain_detail_result = await MasterService.detail_strain(query_db, strain_id, scope)
|
|
|
|
return ResponseUtil.success(data=strain_detail_result)
|
|
|
|
|
|
@strain_controller.post(
|
|
'',
|
|
summary='新增菌种接口',
|
|
description='用于新增菌种',
|
|
response_model=ResponseBaseModel,
|
|
dependencies=[UserInterfaceAuthDependency('master:strain:add')],
|
|
)
|
|
@Log(title='菌种管理', business_type=BusinessType.INSERT)
|
|
async def add_master_strain(
|
|
request: Request,
|
|
add_strain: StrainModel,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
|
|
) -> Response:
|
|
current_time = datetime.now()
|
|
add_strain.create_by = current_user.user.user_name
|
|
add_strain.create_time = current_time
|
|
add_strain.update_by = current_user.user.user_name
|
|
add_strain.update_time = current_time
|
|
add_strain_result = await MasterService.add_strain(query_db, add_strain, current_user, scope)
|
|
|
|
return ResponseUtil.success(msg=add_strain_result.message)
|
|
|
|
|
|
@strain_controller.put(
|
|
'',
|
|
summary='编辑菌种接口',
|
|
description='用于编辑菌种',
|
|
response_model=ResponseBaseModel,
|
|
dependencies=[UserInterfaceAuthDependency('master:strain:edit')],
|
|
)
|
|
@Log(title='菌种管理', business_type=BusinessType.UPDATE)
|
|
async def edit_master_strain(
|
|
request: Request,
|
|
edit_strain: StrainModel,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
|
|
) -> Response:
|
|
edit_strain.update_by = current_user.user.user_name
|
|
edit_strain.update_time = datetime.now()
|
|
edit_strain_result = await MasterService.edit_strain(query_db, edit_strain, current_user, scope)
|
|
|
|
return ResponseUtil.success(msg=edit_strain_result.message)
|
|
|
|
|
|
@strain_controller.delete(
|
|
'/{strain_ids}',
|
|
summary='删除菌种接口',
|
|
description='用于删除菌种',
|
|
response_model=ResponseBaseModel,
|
|
dependencies=[UserInterfaceAuthDependency('master:strain:remove')],
|
|
)
|
|
@Log(title='菌种管理', business_type=BusinessType.DELETE)
|
|
async def delete_master_strain(
|
|
request: Request,
|
|
strain_ids: Annotated[
|
|
str,
|
|
Path(pattern=r'^[1-9]\d*(,[1-9]\d*)*$', description='需要删除的菌种ID'),
|
|
],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
) -> Response:
|
|
delete_strain = DeleteStrainModel(strainIds=[int(strain_id) for strain_id in strain_ids.split(',')])
|
|
delete_strain_result = await MasterService.remove_strain(query_db, delete_strain)
|
|
|
|
return ResponseUtil.success(msg=delete_strain_result.message)
|