为 Web 端改版提供名称、统计和看板数据。只新增只读查询、扩展列表与详情 返回字段;写接口、托盘状态机和幂等键规则均未改动,未新增权限标识。 - 基础资料:列表补充名称与汇总,客户详情返回现场树,托盘详情返回最近流转, 托盘列表支持按流转阶段筛选和二维码精确匹配;新增现场、产线、隧道的上级 资料选项接口;Excel 导入支持 preview 只校验不写入 - 发货出库:列表支持 keyword、receiptState 筛选并补充名称、托盘数、包数和 菌种构成;详情明细补充托盘号、菌种、批次 - 首次入库:列表与详情补充名称、托盘数、托盘当前状态;新增 /summary - 托盘退回:列表支持 keyword 并补充名称与托盘汇总,详情补充托盘号和隧道; 新增 /summary、/site-options - 工厂装填:列表支持 keyword 并补充托盘号、仓库、操作人;新增 /summary、 /batches、/batches/detail - 客户现场使用:列表支持 keyword、fifoSkipped 并补充名称和被跳过的先到托盘号; 新增 /site-options、/site-board 以及 usage-fifo 的 /queue - 先到先用 DAO 抽出公共候选条件与排序,建议查询生成的 SQL 与改动前一致 - 新增各汇总 DAO 的单元测试,同步更新路由权限与模型字段契约测试 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
150 lines
6.3 KiB
Python
150 lines
6.3 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_summary_vo import MasterParentOptionModel, TunnelListItemModel
|
|
from module_business.entity.vo.master_vo import DeleteTunnelModel, TunnelModel, TunnelPageQueryModel
|
|
from module_business.service.master_service import MasterService
|
|
from module_business.service.master_summary_service import MasterSummaryService
|
|
from utils.response_util import ResponseUtil
|
|
|
|
tunnel_controller = APIRouterPro(
|
|
prefix='/master/tunnel',
|
|
tags=['基础资料-隧道管理'],
|
|
dependencies=[PreAuthDependency()],
|
|
)
|
|
# 上级资料选项单独注册且排在详情路由之前,避免被 /{tunnel_id} 捕获
|
|
tunnel_option_controller = APIRouterPro(
|
|
prefix='/master/tunnel', order_num=99, tags=['基础资料-隧道管理'], dependencies=[PreAuthDependency()]
|
|
)
|
|
|
|
|
|
@tunnel_option_controller.get(
|
|
'/site-options',
|
|
summary='获取隧道可选现场接口',
|
|
description='新增或修改隧道时选择所属现场,只返回状态正常的现场',
|
|
response_model=DataResponseModel[list[MasterParentOptionModel]],
|
|
dependencies=[UserInterfaceAuthDependency('master:tunnel:list')],
|
|
)
|
|
async def get_master_tunnel_site_options(
|
|
request: Request,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
options = await MasterSummaryService.site_options(query_db, scope)
|
|
return ResponseUtil.success(data=options)
|
|
|
|
|
|
@tunnel_controller.get(
|
|
'/list',
|
|
summary='获取隧道分页列表接口',
|
|
description='用于获取客户现场隧道分页列表',
|
|
response_model=PageResponseModel[TunnelListItemModel],
|
|
dependencies=[UserInterfaceAuthDependency('master:tunnel:list')],
|
|
)
|
|
async def get_master_tunnel_list(
|
|
request: Request,
|
|
tunnel_page_query: Annotated[TunnelPageQueryModel, Query()],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await MasterService.list_tunnel(query_db, tunnel_page_query, scope, is_page=True)
|
|
result = await MasterSummaryService.enrich_page(query_db, 'tunnel', result, scope)
|
|
return ResponseUtil.success(model_content=result)
|
|
|
|
|
|
@tunnel_controller.get(
|
|
'/{tunnel_id}',
|
|
summary='获取隧道详情接口',
|
|
description='用于获取指定隧道的详细信息',
|
|
response_model=DataResponseModel[TunnelModel],
|
|
dependencies=[UserInterfaceAuthDependency('master:tunnel:query')],
|
|
)
|
|
async def query_detail_master_tunnel(
|
|
request: Request,
|
|
tunnel_id: Annotated[int, Path(gt=0, description='隧道ID')],
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
|
|
) -> Response:
|
|
result = await MasterService.detail_tunnel(query_db, tunnel_id, scope)
|
|
return ResponseUtil.success(data=result)
|
|
|
|
|
|
@tunnel_controller.post(
|
|
'',
|
|
summary='新增隧道接口',
|
|
description='用于新增客户现场隧道',
|
|
response_model=ResponseBaseModel,
|
|
dependencies=[UserInterfaceAuthDependency('master:tunnel:add')],
|
|
)
|
|
@Log(title='隧道管理', business_type=BusinessType.INSERT)
|
|
async def add_master_tunnel(
|
|
request: Request,
|
|
add_tunnel: TunnelModel,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
|
|
) -> Response:
|
|
current_time = datetime.now()
|
|
add_tunnel.create_by = current_user.user.user_name
|
|
add_tunnel.create_time = current_time
|
|
add_tunnel.update_by = current_user.user.user_name
|
|
add_tunnel.update_time = current_time
|
|
result = await MasterService.add_tunnel(query_db, add_tunnel, current_user, scope)
|
|
return ResponseUtil.success(msg=result.message)
|
|
|
|
|
|
@tunnel_controller.put(
|
|
'',
|
|
summary='编辑隧道接口',
|
|
description='用于编辑客户现场隧道',
|
|
response_model=ResponseBaseModel,
|
|
dependencies=[UserInterfaceAuthDependency('master:tunnel:edit')],
|
|
)
|
|
@Log(title='隧道管理', business_type=BusinessType.UPDATE)
|
|
async def edit_master_tunnel(
|
|
request: Request,
|
|
edit_tunnel: TunnelModel,
|
|
query_db: Annotated[AsyncSession, DBSessionDependency()],
|
|
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
|
|
scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
|
|
) -> Response:
|
|
edit_tunnel.update_by = current_user.user.user_name
|
|
edit_tunnel.update_time = datetime.now()
|
|
result = await MasterService.edit_tunnel(query_db, edit_tunnel, current_user, scope)
|
|
return ResponseUtil.success(msg=result.message)
|
|
|
|
|
|
@tunnel_controller.delete(
|
|
'/{tunnel_ids}',
|
|
summary='兼容旧接口,固定拒绝,请使用测试数据批次清理',
|
|
description='兼容旧接口,固定拒绝单条物理删除,请使用测试数据批次清理',
|
|
response_model=ResponseBaseModel,
|
|
dependencies=[UserInterfaceAuthDependency('master:tunnel:remove')],
|
|
)
|
|
@Log(title='隧道管理', business_type=BusinessType.DELETE)
|
|
async def delete_master_tunnel(
|
|
request: Request,
|
|
tunnel_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_tunnel = DeleteTunnelModel(tunnelIds=[int(tunnel_id) for tunnel_id in tunnel_ids.split(',')])
|
|
result = await MasterService.remove_tunnel(query_db, delete_tunnel)
|
|
return ResponseUtil.success(msg=result.message)
|