Files
ShiErFeng/shierfeng-fastapi-backend/module_business/controller/filling_controller.py
T
yujiangandClaude Opus 5.5 3050ccdc4e Feat: 后端新增基础资料与业务管理只读汇总接口
为 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>
2026-10-18 05:03:10 -07:00

206 lines
8.1 KiB
Python

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.operation_vo import (
BusinessOptionModel,
FillingBatchDetailModel,
FillingBatchDetailQueryModel,
FillingBatchModel,
FillingBatchPageQueryModel,
FillingCreateModel,
FillingListItemModel,
FillingModel,
FillingOverviewModel,
FillingPageQueryModel,
PalletScanResponseModel,
)
from module_business.service.filling_service import FillingService
from utils.response_util import ResponseUtil
filling_controller = APIRouterPro(
prefix='/business/filling',
tags=['业务管理-托盘装填'],
dependencies=[PreAuthDependency()],
)
@filling_controller.get(
'/list',
summary='获取托盘装填记录分页列表接口',
description='按当前用户仓库数据范围获取托盘装填记录分页列表',
response_model=PageResponseModel[FillingListItemModel],
dependencies=[UserInterfaceAuthDependency('business:filling:list')],
)
async def get_business_filling_list(
request: Request,
filling_page_query: Annotated[FillingPageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.get_filling_list_services(
query_db,
filling_page_query,
current_user,
test_scope,
is_page=True,
)
return ResponseUtil.success(model_content=result)
@filling_controller.get(
'/summary',
summary='获取工厂装填概况接口',
description='按当前用户仓库数据范围统计今日与本月装填、可装填空托盘和临期仍在仓的托盘',
response_model=DataResponseModel[FillingOverviewModel],
dependencies=[UserInterfaceAuthDependency('business:filling:list')],
)
async def get_business_filling_summary(
request: Request,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.get_filling_overview_services(query_db, current_user, test_scope)
return ResponseUtil.success(data=result)
@filling_controller.get(
'/batches',
summary='获取生产批次装填汇总分页列表接口',
description='按当前用户仓库数据范围,将装填记录按菌种与生产批次聚合,最近装填的批次在前',
response_model=PageResponseModel[FillingBatchModel],
dependencies=[UserInterfaceAuthDependency('business:filling:list')],
)
async def get_business_filling_batches(
request: Request,
batch_page_query: Annotated[FillingBatchPageQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.get_filling_batches_services(query_db, batch_page_query, current_user, test_scope)
return ResponseUtil.success(model_content=result)
@filling_controller.get(
'/batches/detail',
summary='获取生产批次详情接口',
description='按当前用户仓库数据范围返回批次汇总、托盘当前去向与最近装填记录',
response_model=DataResponseModel[FillingBatchDetailModel],
dependencies=[UserInterfaceAuthDependency('business:filling:query')],
)
async def get_business_filling_batch_detail(
request: Request,
batch_detail_query: Annotated[FillingBatchDetailQueryModel, Query()],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.get_filling_batch_detail_services(
query_db,
batch_detail_query,
current_user,
test_scope,
)
return ResponseUtil.success(data=result)
@filling_controller.get(
'/strain-options',
summary='获取装填菌种选项接口',
description='获取全部启用菌种的业务选项',
response_model=DataResponseModel[list[BusinessOptionModel]],
dependencies=[UserInterfaceAuthDependency('business:filling:query')],
)
async def get_business_filling_strain_options(
request: Request,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.get_strain_options_services(query_db, current_user, test_scope)
return ResponseUtil.success(data=result)
@filling_controller.get(
'/scan/{qr_token:path}',
summary='扫描待装填托盘接口',
description='按托盘当前仓库数据范围判断空托盘是否可装填',
response_model=DataResponseModel[PalletScanResponseModel],
dependencies=[UserInterfaceAuthDependency('business:filling:query')],
)
@Log(
title='扫码操作',
business_type=BusinessType.OTHER,
request_log_mode='none',
response_log_mode='summary',
oper_url_mode='route',
)
async def scan_business_filling_pallet(
request: Request,
qr_token: Annotated[
str,
Path(min_length=1, max_length=128, pattern=r'\S', description='二维码固定标识'),
],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.scan_filling_pallet_services(
query_db,
qr_token,
current_user,
test_scope,
)
return ResponseUtil.success(data=result)
@filling_controller.get(
'/{filling_id}',
summary='获取托盘装填记录详情接口',
description='按仓库数据范围获取指定托盘装填记录',
response_model=DataResponseModel[FillingModel],
dependencies=[UserInterfaceAuthDependency('business:filling:query')],
)
async def query_detail_business_filling(
request: Request,
filling_id: Annotated[int, Path(gt=0, description='装填记录ID')],
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency()],
) -> Response:
result = await FillingService.filling_detail_services(query_db, filling_id, current_user, test_scope)
return ResponseUtil.success(data=result)
@filling_controller.post(
'',
summary='单托盘装填接口',
description='在仓库内即时确认单个空托盘装填',
response_model=ResponseBaseModel,
dependencies=[UserInterfaceAuthDependency('business:filling:add')],
)
@Log(title='托盘装填', business_type=BusinessType.INSERT)
async def add_business_filling(
request: Request,
add_filling: FillingCreateModel,
query_db: Annotated[AsyncSession, DBSessionDependency()],
current_user: Annotated[CurrentUserModel, CurrentUserDependency()],
test_scope: Annotated[TestBatchScope, TestBatchScopeDependency(write=True)],
) -> Response:
result = await FillingService.fill_pallet_services(query_db, add_filling, current_user, test_scope)
return ResponseUtil.success(msg=result.message)