Files
ShiErFeng/shierfeng-fastapi-backend/module_business/controller/line_controller.py
T

128 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 DeleteLineModel, LineModel, LinePageQueryModel
from module_business.service.master_service import MasterService
from utils.response_util import ResponseUtil
line_controller = APIRouterPro(prefix='/master/line', tags=['基础资料-生产线管理'], dependencies=[PreAuthDependency()])
@line_controller.get(
'/list',
summary='获取生产线分页列表接口',
description='用于获取生产线分页列表',
response_model=PageResponseModel[LineModel],
dependencies=[UserInterfaceAuthDependency('master:line:list')],
)
async def get_master_line_list(
request: Request,
line_page_query: Annotated[LinePageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
line_page_query_result = await MasterService.list_line(query_db, line_page_query, scope, is_page=True)
return ResponseUtil.success(model_content=line_page_query_result)
@line_controller.get(
'/{line_id}',
summary='获取生产线详情接口',
description='用于获取指定生产线的详细信息',
response_model=DataResponseModel[LineModel],
dependencies=[UserInterfaceAuthDependency('master:line:query')],
)
async def query_detail_master_line(
request: Request,
line_id: Annotated[int, Path(gt=0, description='生产线ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
line_detail_result = await MasterService.detail_line(query_db, line_id, scope)
return ResponseUtil.success(data=line_detail_result)
@line_controller.post(
'',
summary='新增生产线接口',
description='用于新增生产线',
response_model=ResponseBaseModel,
dependencies=[UserInterfaceAuthDependency('master:line:add')],
)
@Log(title='生产线管理', business_type=BusinessType.INSERT)
async def add_master_line(
request: Request,
add_line: LineModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
current_time = datetime.now()
add_line.create_by = current_user.user.user_name
add_line.create_time = current_time
add_line.update_by = current_user.user.user_name
add_line.update_time = current_time
add_line_result = await MasterService.add_line(query_db, add_line, current_user, scope)
return ResponseUtil.success(msg=add_line_result.message)
@line_controller.put(
'',
summary='编辑生产线接口',
description='用于编辑生产线',
response_model=ResponseBaseModel,
dependencies=[UserInterfaceAuthDependency('master:line:edit')],
)
@Log(title='生产线管理', business_type=BusinessType.UPDATE)
async def edit_master_line(
request: Request,
edit_line: LineModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
edit_line.update_by = current_user.user.user_name
edit_line.update_time = datetime.now()
edit_line_result = await MasterService.edit_line(query_db, edit_line, current_user, scope)
return ResponseUtil.success(msg=edit_line_result.message)
@line_controller.delete(
'/{line_ids}',
summary='兼容旧接口,固定拒绝,请使用测试数据批次清理',
description='兼容旧接口,固定拒绝单条物理删除,请使用测试数据批次清理',
response_model=ResponseBaseModel,
dependencies=[UserInterfaceAuthDependency('master:line:list')],
)
@Log(title='生产线管理', business_type=BusinessType.DELETE)
async def delete_master_line(
request: Request,
line_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_line = DeleteLineModel(lineIds=[int(line_id) for line_id in line_ids.split(',')])
delete_line_result = await MasterService.remove_line(query_db, delete_line)
return ResponseUtil.success(msg=delete_line_result.message)